@htilabs/platform-common-models 0.19.0 → 0.20.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 (50) hide show
  1. package/dist/cvcs/index.cjs +4769 -643
  2. package/dist/cvcs/index.cjs.map +1 -1
  3. package/dist/cvcs/index.d.cts +5036 -606
  4. package/dist/cvcs/index.d.ts +5036 -606
  5. package/dist/cvcs/index.js +4769 -643
  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.cjs +5199 -588
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +1 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +5189 -588
  18. package/dist/index.js.map +1 -1
  19. package/dist/information-scope/index.cjs +440 -0
  20. package/dist/information-scope/index.cjs.map +1 -0
  21. package/dist/information-scope/index.d.cts +313 -0
  22. package/dist/information-scope/index.d.ts +313 -0
  23. package/dist/information-scope/index.js +404 -0
  24. package/dist/information-scope/index.js.map +1 -0
  25. package/dist/services/index.cjs +414 -2
  26. package/dist/services/index.cjs.map +1 -1
  27. package/dist/services/index.d.cts +1 -0
  28. package/dist/services/index.d.ts +1 -0
  29. package/dist/services/index.js +403 -1
  30. package/dist/services/index.js.map +1 -1
  31. package/package.json +32 -26
  32. package/src/__tests__/__snapshots__/cvc-sot.snap +3 -3
  33. package/src/__tests__/core-information-scope-invariant.test.ts +709 -456
  34. package/src/__tests__/cvc-sot-snapshot.test.ts +16 -17
  35. package/src/__tests__/cvc-structural.test.ts +2 -2
  36. package/src/__tests__/location-type-routing-invariant.test.ts +25 -8
  37. package/src/cvcs/coreInformationScope.v2.0.0.json +5396 -0
  38. package/src/cvcs/index.ts +2 -2
  39. package/src/cvcs/roiScope.v1.3.0.json +360 -0
  40. package/src/generated/cvc-enums.ts +77 -4
  41. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.migrations.csv +106 -0
  42. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.rows.csv +117 -0
  43. package/src/services/__tests__/fixtures/infoscope-v4/loadInfoscopeV4Fixtures.ts +116 -0
  44. package/src/services/__tests__/informationScopeResolver.test.ts +964 -0
  45. package/src/services/index.ts +10 -3
  46. package/src/services/informationScope.ts +10 -0
  47. package/src/services/informationScopeResolver.ts +672 -0
  48. package/src/services/informationScopeSot.ts +161 -0
  49. package/src/cvcs/coreInformationScope.v1.1.0.json +0 -1290
  50. package/src/cvcs/roiScope.v1.2.0.json +0 -340
@@ -0,0 +1,404 @@
1
+ // src/services/informationScopeResolver.ts
2
+ var INFORMATION_SCOPE_VERSION = 4;
3
+ var INFORMATION_SCOPE_READABLE_VERSIONS = Object.freeze([3, 4]);
4
+ var INFORMATION_SCOPE_SYSTEM_INFO = "system_info";
5
+ var isSelectableScopeRow = (row) => row !== void 0 && row.selectable && row.status !== "retired";
6
+ var isScopeRestRow = (row) => row !== void 0 && row.rowType === "category_rest";
7
+ var isScopeInstrumentRow = (row) => row !== void 0 && row.rowType === "instrument row";
8
+ function kindForPerson(person) {
9
+ if (person.causedHarm) return "offenders";
10
+ if (person.efmAsserted) return "family";
11
+ return "others";
12
+ }
13
+ var PERSON_KINDS = /* @__PURE__ */ new Set(["offenders", "family", "others"]);
14
+ var SPECIAL_DATA_TYPES = /* @__PURE__ */ new Set([
15
+ "none",
16
+ "survivor_confidential",
17
+ "criminal_intelligence",
18
+ "evidence"
19
+ ]);
20
+ var MIGRATION_RULES = /* @__PURE__ */ new Set([
21
+ "identity",
22
+ "row",
23
+ "category",
24
+ "subtract",
25
+ "retired before v4"
26
+ ]);
27
+ var RETIRED_RULES = /* @__PURE__ */ new Set([
28
+ "row",
29
+ "subtract",
30
+ "retired before v4"
31
+ ]);
32
+ var SELECTION_PRECEDENCE = [
33
+ "category",
34
+ "identity",
35
+ "row",
36
+ "retired before v4"
37
+ ];
38
+ var RESTRICTION_PRECEDENCE = [
39
+ "subtract",
40
+ ...SELECTION_PRECEDENCE
41
+ ];
42
+ var asList = (list) => Array.isArray(list) ? list : [];
43
+ function createInformationScopeResolver(input) {
44
+ const rows = Object.freeze([...input.rows]);
45
+ const byCode = /* @__PURE__ */ new Map();
46
+ const order = /* @__PURE__ */ new Map();
47
+ for (const r of rows) {
48
+ if (byCode.has(r.scopeCode)) {
49
+ throw new Error(`information scope: duplicate code "${r.scopeCode}"`);
50
+ }
51
+ byCode.set(r.scopeCode, r);
52
+ order.set(r.scopeCode, order.size);
53
+ }
54
+ const isLive = (code) => {
55
+ const r = byCode.get(code);
56
+ return r !== void 0 && r.status !== "retired";
57
+ };
58
+ const children = /* @__PURE__ */ new Map();
59
+ for (const r of rows) {
60
+ if (r.status !== "retired" && !SPECIAL_DATA_TYPES.has(r.specialDataType)) {
61
+ throw new Error(
62
+ `information scope: "${r.scopeCode}" has specialDataType ${JSON.stringify(r.specialDataType)}`
63
+ );
64
+ }
65
+ if (r.parentScopeCode === null || r.parentScopeCode === "") continue;
66
+ if (!byCode.has(r.parentScopeCode)) {
67
+ throw new Error(
68
+ `information scope: "${r.scopeCode}" names unknown parent "${r.parentScopeCode}"`
69
+ );
70
+ }
71
+ if (r.status === "retired") continue;
72
+ const list = children.get(r.parentScopeCode) ?? [];
73
+ list.push(r.scopeCode);
74
+ children.set(r.parentScopeCode, list);
75
+ }
76
+ const ancestorCache = /* @__PURE__ */ new Map();
77
+ const ancestors = (code) => {
78
+ const hit = ancestorCache.get(code);
79
+ if (hit) return hit;
80
+ const out = [];
81
+ let cur = code;
82
+ while (cur !== null && cur !== "") {
83
+ const r = byCode.get(cur);
84
+ if (!r) break;
85
+ if (out.includes(cur)) throw new Error(`information scope: cycle at "${cur}"`);
86
+ out.push(cur);
87
+ cur = r.parentScopeCode;
88
+ }
89
+ ancestorCache.set(code, out);
90
+ return out;
91
+ };
92
+ for (const r of rows) ancestors(r.scopeCode);
93
+ if (!isLive(INFORMATION_SCOPE_SYSTEM_INFO)) {
94
+ throw new Error(`information scope: the tree has no "${INFORMATION_SCOPE_SYSTEM_INFO}" row`);
95
+ }
96
+ const alwaysCovered = new Set(ancestors(INFORMATION_SCOPE_SYSTEM_INFO));
97
+ const kids = (code) => children.get(code) ?? [];
98
+ const descendantsOf = (code) => {
99
+ const out = [];
100
+ const stack = [...kids(code)];
101
+ while (stack.length > 0) {
102
+ const c = stack.pop();
103
+ out.push(c);
104
+ stack.push(...kids(c));
105
+ }
106
+ return out;
107
+ };
108
+ const restRowOf = (code) => kids(code).find((c) => isScopeRestRow(byCode.get(c)));
109
+ const kindRoot = /* @__PURE__ */ new Map();
110
+ const perKindRow = /* @__PURE__ */ new Map();
111
+ for (const r of rows) {
112
+ if (r.status === "retired" || r.kindBranch === null || !PERSON_KINDS.has(r.kindBranch)) continue;
113
+ if (r.rowType === "person_type") {
114
+ kindRoot.set(r.kindBranch, r.scopeCode);
115
+ continue;
116
+ }
117
+ if (r.kindRow === void 0 || !isLive(r.kindRow)) {
118
+ throw new Error(
119
+ `information scope: per-kind row "${r.scopeCode}" has no live kindRow (${String(r.kindRow)})`
120
+ );
121
+ }
122
+ perKindRow.set(`${r.kindBranch}\0${r.kindRow}`, r.scopeCode);
123
+ }
124
+ const migrations = /* @__PURE__ */ new Map();
125
+ for (const m of input.migrations ?? []) {
126
+ if (!MIGRATION_RULES.has(m.rule)) {
127
+ throw new Error(`information scope: unknown migration rule "${m.rule}" on "${m.from}"`);
128
+ }
129
+ for (const to of m.to) {
130
+ if (!isLive(to)) {
131
+ throw new Error(
132
+ `information scope: migration "${m.from}" (${m.rule}) reads as "${to}", not a live row`
133
+ );
134
+ }
135
+ }
136
+ const perCode = migrations.get(m.from) ?? /* @__PURE__ */ new Map();
137
+ const prior = perCode.get(m.rule);
138
+ if (prior && prior.to.join(" ") !== m.to.join(" ")) {
139
+ throw new Error(`information scope: two "${m.rule}" readings for "${m.from}"`);
140
+ }
141
+ perCode.set(m.rule, {
142
+ from: m.from,
143
+ rule: m.rule,
144
+ to: Object.freeze([...m.to]),
145
+ widens: m.widens === true || prior?.widens === true
146
+ });
147
+ migrations.set(m.from, perCode);
148
+ }
149
+ const normalize = (codes, withSystemInfo = true) => {
150
+ const seen = /* @__PURE__ */ new Set();
151
+ const known = [];
152
+ const unknown = [];
153
+ const all = withSystemInfo ? [INFORMATION_SCOPE_SYSTEM_INFO, ...codes] : [...codes];
154
+ for (const c of all) {
155
+ if (seen.has(c)) continue;
156
+ seen.add(c);
157
+ (byCode.has(c) ? known : unknown).push(c);
158
+ }
159
+ known.sort((a, b) => order.get(a) - order.get(b));
160
+ return [...known, ...unknown];
161
+ };
162
+ const requirePickable = (code, op) => {
163
+ if (!byCode.has(code)) throw new RangeError(`information scope ${op}: unknown code "${code}"`);
164
+ if (!isSelectableScopeRow(byCode.get(code))) {
165
+ throw new RangeError(`information scope ${op}: "${code}" is not selectable`);
166
+ }
167
+ };
168
+ const isCovered = (selection, code) => {
169
+ if (!isLive(code)) return false;
170
+ if (alwaysCovered.has(code)) return true;
171
+ const sel = new Set(asList(selection));
172
+ if (ancestors(code).some((a) => sel.has(a))) return true;
173
+ const rest = restRowOf(code);
174
+ return rest !== void 0 && sel.has(rest);
175
+ };
176
+ const shareVerdict = (selection, code, options = {}) => {
177
+ if (!isLive(code)) return { included: false, reason: "unknown_code" };
178
+ if (!isCovered(selection, code)) return { included: false, reason: "not_covered" };
179
+ const chain = ancestors(code).map((c) => byCode.get(c));
180
+ if (chain.some((r) => r.platformFloor)) return { included: false, reason: "platform_floor" };
181
+ const enabled = new Set(options.enabledOffByDefault ?? []);
182
+ const notEnabled = chain.filter((r) => !r.shareableDefault && !enabled.has(r.scopeCode)).map((r) => r.scopeCode);
183
+ if (notEnabled.length > 0) return { included: false, reason: "off_by_default", notEnabled };
184
+ return { included: true, reason: "included" };
185
+ };
186
+ const expandSelectAll = (code) => {
187
+ if (!byCode.has(code)) throw new RangeError(`information scope expand: unknown code "${code}"`);
188
+ return [...kids(code)];
189
+ };
190
+ const selectAll = (selection, code) => {
191
+ requirePickable(code, "selectAll");
192
+ const drop = new Set(descendantsOf(code));
193
+ return normalize([...selection.filter((c) => !drop.has(c)), code]);
194
+ };
195
+ const deselectChild = (selection, childCode) => {
196
+ requirePickable(childCode, "deselectChild");
197
+ if (alwaysCovered.has(childCode)) {
198
+ throw new RangeError(`information scope deselectChild: "${childCode}" is always included`);
199
+ }
200
+ const sel = new Set(selection);
201
+ const path = ancestors(childCode);
202
+ let top = 0;
203
+ for (let i = 1; i < path.length; i += 1) if (sel.has(path[i])) top = i;
204
+ for (let i = 1; i <= top; i += 1) {
205
+ sel.delete(path[i]);
206
+ for (const c of kids(path[i])) if (c !== path[i - 1]) sel.add(c);
207
+ }
208
+ sel.delete(childCode);
209
+ for (const d of descendantsOf(childCode)) sel.delete(d);
210
+ return normalize(sel);
211
+ };
212
+ const readOne = (from, scopeVersion, precedence) => {
213
+ if (scopeVersion === INFORMATION_SCOPE_VERSION && isLive(from)) {
214
+ return { from, rule: "identity", reads: [from], widens: false };
215
+ }
216
+ const lines = migrations.get(from);
217
+ if (lines) {
218
+ for (const rule of precedence) {
219
+ if (scopeVersion === INFORMATION_SCOPE_VERSION && (rule === "identity" || rule === "category")) {
220
+ continue;
221
+ }
222
+ const line = lines.get(rule);
223
+ if (line) return { from, rule, reads: [...line.to], widens: line.widens === true };
224
+ }
225
+ }
226
+ return { from, rule: "unknown", reads: [], widens: false };
227
+ };
228
+ const read = (list, scopeVersion, precedence, isRestriction) => {
229
+ const stored = [...asList(list)];
230
+ const supported = typeof scopeVersion === "number" && INFORMATION_SCOPE_READABLE_VERSIONS.includes(scopeVersion);
231
+ const codes = [];
232
+ const seen = /* @__PURE__ */ new Set();
233
+ for (const from of stored) {
234
+ if (seen.has(from)) continue;
235
+ seen.add(from);
236
+ codes.push(
237
+ supported ? readOne(from, scopeVersion, precedence) : { from, rule: "unknown", reads: [], widens: false }
238
+ );
239
+ }
240
+ return {
241
+ storedVersion: typeof scopeVersion === "number" ? scopeVersion : null,
242
+ stored,
243
+ version: INFORMATION_SCOPE_VERSION,
244
+ unsupportedVersion: !supported,
245
+ informationScope: normalize(
246
+ codes.flatMap((c) => c.reads),
247
+ !isRestriction
248
+ ),
249
+ codes,
250
+ retired: codes.filter((c) => RETIRED_RULES.has(c.rule)).map((c) => c.from),
251
+ unknown: codes.filter((c) => c.rule === "unknown").map((c) => c.from),
252
+ widened: codes.filter((c) => c.widens).map((c) => c.from)
253
+ };
254
+ };
255
+ const rowForSubject = (homeRow, kind) => {
256
+ const home = byCode.get(homeRow);
257
+ if (!home) throw new RangeError(`information scope rowForSubject: unknown home "${homeRow}"`);
258
+ if (kind === "client") return homeRow;
259
+ const chain = ancestors(homeRow);
260
+ if (byCode.get(chain[chain.length - 1])?.rowType !== "branch") return homeRow;
261
+ if (home.specialDataType === "criminal_intelligence") return homeRow;
262
+ const root = kindRoot.get(kind);
263
+ if (!root) throw new RangeError(`information scope rowForSubject: the tree has no "${kind}" kind`);
264
+ if (chain.includes(root)) return homeRow;
265
+ for (const anc of chain) {
266
+ const perKind = perKindRow.get(`${kind}\0${anc}`);
267
+ if (perKind !== void 0) return perKind;
268
+ }
269
+ return root;
270
+ };
271
+ const expandBranchPickToGrain = (selection, ceiling) => {
272
+ const ceil = asList(ceiling);
273
+ const ceilSet = new Set(ceil);
274
+ const isWithin = (c) => ancestors(c).some((a) => ceilSet.has(a));
275
+ const isAbove = (c) => ceil.some((k) => k !== c && ancestors(k).includes(c));
276
+ const out = [];
277
+ const stack = [...asList(selection)];
278
+ while (stack.length > 0) {
279
+ const c = stack.pop();
280
+ if (isLive(c) && !isWithin(c) && isAbove(c)) stack.push(...kids(c));
281
+ else out.push(c);
282
+ }
283
+ return normalize(out);
284
+ };
285
+ const clampToCeiling = (selection, ceiling) => {
286
+ const ceil = new Set(asList(ceiling));
287
+ return normalize(
288
+ expandBranchPickToGrain(selection, ceiling).filter(
289
+ (c) => isLive(c) && ancestors(c).some((a) => ceil.has(a))
290
+ )
291
+ );
292
+ };
293
+ return {
294
+ version: INFORMATION_SCOPE_VERSION,
295
+ rows,
296
+ row: (code) => byCode.get(code),
297
+ childrenOf: (code) => [...kids(code)],
298
+ ancestorsOf: (code) => [...ancestors(code)],
299
+ isCovered,
300
+ isIncludedOnShare: (selection, code, options) => shareVerdict(selection, code, options).included,
301
+ shareVerdict,
302
+ // Rule 7: the lowest internal viewing level that sees the row. Level 2
303
+ // (autocomplete) sees the level-1 stub (§ 5). Sharing ignores this.
304
+ isVisibleAtLevel: (level, code) => typeof level === "number" && isLive(code) && level >= byCode.get(code).levelFloor,
305
+ expandSelectAll,
306
+ selectAll,
307
+ deselectChild,
308
+ readSelection: (list, scopeVersion) => read(list, scopeVersion, SELECTION_PRECEDENCE, false),
309
+ readRestriction: (list, scopeVersion) => read(list, scopeVersion, RESTRICTION_PRECEDENCE, true),
310
+ rowForSubject,
311
+ expandBranchPickToGrain,
312
+ clampToCeiling
313
+ };
314
+ }
315
+
316
+ // src/services/informationScopeSot.ts
317
+ var ROW_TYPES = /* @__PURE__ */ new Set([
318
+ "branch",
319
+ "category",
320
+ "subcategory",
321
+ "sub-category",
322
+ "person_type",
323
+ "category_rest",
324
+ "instrument row"
325
+ ]);
326
+ var KIND_BRANCHES = /* @__PURE__ */ new Set([
327
+ "client",
328
+ "offenders",
329
+ "family",
330
+ "others",
331
+ "leads"
332
+ ]);
333
+ var LIVE = /* @__PURE__ */ new Set(["as_today", "new"]);
334
+ var MISSINGNESS_ROOT = "missingness_root";
335
+ function keyReader(sot) {
336
+ const byKey = new Map(sot.entries.map((e) => [e.key, e.canonicalCode ?? e.key]));
337
+ return (key) => byKey.get(key) ?? key.replace(/__/g, ".");
338
+ }
339
+ function fail(key, field, value) {
340
+ throw new TypeError(
341
+ `information scope SOT: live entry "${key}" has ${field} ${JSON.stringify(value)}`
342
+ );
343
+ }
344
+ function scopeRowsFromSot(sot) {
345
+ const code = keyReader(sot);
346
+ const missingness = new Set(
347
+ sot.entries.filter((e) => e.key === MISSINGNESS_ROOT || e.parentKey === MISSINGNESS_ROOT).map((e) => e.key)
348
+ );
349
+ const rows = [];
350
+ for (const e of sot.entries) {
351
+ if (missingness.has(e.key)) continue;
352
+ if (e.status === "retired") continue;
353
+ if (e.status === void 0 || !LIVE.has(e.status)) fail(e.key, "status", e.status);
354
+ if (e.rowType === void 0 || !ROW_TYPES.has(e.rowType)) fail(e.key, "rowType", e.rowType);
355
+ const kindBranch = e.kindBranch ?? null;
356
+ if (kindBranch !== null && !KIND_BRANCHES.has(kindBranch)) fail(e.key, "kindBranch", kindBranch);
357
+ if (e.apps === void 0) fail(e.key, "apps", e.apps);
358
+ for (const b of ["selectable", "shareableDefault", "platformFloor"]) {
359
+ if (typeof e[b] !== "boolean") fail(e.key, b, e[b]);
360
+ }
361
+ if (e.levelFloor !== 1 && e.levelFloor !== 3) fail(e.key, "levelFloor", e.levelFloor);
362
+ if (e.specialDataType === void 0) fail(e.key, "specialDataType", e.specialDataType);
363
+ const row = {
364
+ scopeCode: code(e.key),
365
+ parentScopeCode: e.parentKey ? code(e.parentKey) : null,
366
+ rowType: e.rowType,
367
+ kindBranch,
368
+ apps: { pave: e.apps.pave, thread: e.apps.thread, leads: e.apps.leads },
369
+ selectable: e.selectable,
370
+ shareableDefault: e.shareableDefault,
371
+ platformFloor: e.platformFloor,
372
+ levelFloor: e.levelFloor,
373
+ specialDataType: e.specialDataType,
374
+ status: e.status,
375
+ replacesV3: [...e.replacesV3 ?? []]
376
+ };
377
+ if (e.kindRow !== void 0) row.kindRow = code(e.kindRow);
378
+ rows.push(row);
379
+ }
380
+ return rows;
381
+ }
382
+ function scopeMigrationsFromSot(sot) {
383
+ const code = keyReader(sot);
384
+ return (sot.migrations?.table ?? []).map((l) => ({
385
+ from: code(l.from),
386
+ to: l.to.map(code),
387
+ rule: l.rule,
388
+ ...l.note === void 0 ? {} : { note: l.note },
389
+ ...l.widens === void 0 ? {} : { widens: l.widens }
390
+ }));
391
+ }
392
+ export {
393
+ INFORMATION_SCOPE_READABLE_VERSIONS,
394
+ INFORMATION_SCOPE_SYSTEM_INFO,
395
+ INFORMATION_SCOPE_VERSION,
396
+ createInformationScopeResolver,
397
+ isScopeInstrumentRow,
398
+ isScopeRestRow,
399
+ isSelectableScopeRow,
400
+ kindForPerson,
401
+ scopeMigrationsFromSot,
402
+ scopeRowsFromSot
403
+ };
404
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/services/informationScopeResolver.ts","../../src/services/informationScopeSot.ts"],"sourcesContent":["/**\n * @htilabs/platform-common-models — Information scope resolver (CVC-236 v4)\n *\n * The ONE implementation of how a stored information-scope selection reads\n * against the v4 tree, so Thread and PAVE (preview and send, picker and door)\n * cannot disagree. Pure and dependency-free: no imports, no I/O, never\n * mutates its inputs. Browser-safe entry: `@htilabs/platform-common-models/information-scope`.\n *\n * Spec (canon, read-only): htilabstech/prototype\n * docs/share-roi/INFOSCOPE_V4_DEV_HANDOFF_2026-10-09.md\n * @ 00179edcb3f0c00a8b55beeffd1618c8a5c98937 (signed; the handoff and its\n * CSVs are unchanged from 6dab8a95)\n * - § 2 rules 1–7 (\"the resolver contract — build exactly this, nothing\n * cleverer\") — every behaviour below cites its rule;\n * - § 3 the migration rules (identity · row · category · subtract ·\n * retired before v4) and `scopeVersion`; a signed release keeps its list\n * as signed and its current reading is DERIVED at read time; a retired\n * code \"stays recognisable in stored data forever\";\n * - § 7 row 6 a branch-grain pick is expanded to the ceiling's grain\n * before clamping; a sender can never widen;\n * - § 8 the enums.\n * Reference implementation of rule-1 kind-row resolution:\n * tools/infoscope/phase4_stress_test.py `resolve_home` (same SHA).\n *\n * WHAT A SELECTION STORES. `information_scope: string[]` holds canon's scope\n * codes as canon spells them — `names`, `identifying.other`,\n * `offenders.risk` (handoff § 8: \"lowercase snake, or `<kind>.<row>`\") —\n * NOT the package's SOT keys (`offenders__risk`) and NOT seven-segment wire\n * codes (`236-016-001-002-…`). `ScopeRow.scopeCode` / `parentScopeCode` are\n * in that space; `scopeRowsFromSot` maps the SOT into it.\n *\n * ALWAYS COVERED. `system_info` and its ancestor `system` (\"System metadata —\n * always included, never a choice\", handoff § 1; the field placements home\n * the system fields on `system`) are covered by every selection.\n *\n * Two kinds of call:\n * - READS (`isCovered`, `isIncludedOnShare`, `shareVerdict`,\n * `isVisibleAtLevel`, `readSelection`, `readRestriction`,\n * `expandBranchPickToGrain`, `clampToCeiling`) are total: they never\n * throw on stored data. An unknown code, a null list or an unsupported\n * `scopeVersion` (absent, 2, or anything but 3 / 4) includes nothing\n * (fail closed).\n * - PICKER WRITES (`selectAll`, `deselectChild`, `expandSelectAll`), the\n * build-time `rowForSubject`, and the constructor throw on programming\n * errors (an unknown or non-selectable code, a malformed tree).\n */\n\n// ─── Constants ───────────────────────────────────────────────────────────────\n\n/** The tree version this resolver reads to (handoff § 3: \"today 3, after this round 4\"). */\nexport const INFORMATION_SCOPE_VERSION = 4 as const;\n\n/**\n * The `scopeVersion` stamps a stored list may carry and still be read: 3\n * (through the v3 → v4 table) and 4. A 2 list, and an UNSTAMPED list (which\n * is v2-era), must go through canon's conjunctive v2 → v3 table first (SOT\n * v2.0.0 `migrations.readAt` / `migrations.unstamped`: the `retired before\n * v4` lines name \"the flattened v3 reading, not an unconditional one\"); this\n * package ships no v2 → v3 table, so those lists are unsupported and include\n * nothing (fail closed). None was ever persisted (`migrations.unstamped`).\n */\nexport const INFORMATION_SCOPE_READABLE_VERSIONS: readonly number[] = Object.freeze([3, 4]);\n\n/** Required on every stored selection and always included (handoff § 2 rule 1; § 6). */\nexport const INFORMATION_SCOPE_SYSTEM_INFO = \"system_info\" as const;\n\n// ─── Row and migration input shapes ─────────────────────────────────────────\n\n/** A kind of other named person (handoff § 1; § 8 `kind_branch`). */\nexport type ScopePersonKind = \"offenders\" | \"family\" | \"others\";\n\n/** Whose record a record is: the client, or another named person's kind (rule 1). */\nexport type ScopeSubjectKind = \"client\" | ScopePersonKind;\n\n/** `kind_branch` (§ 8); `null` on System and Notes rows (blank in the CSV). */\nexport type ScopeKindBranch = ScopeSubjectKind | \"leads\" | null;\n\n/**\n * `row_type` (§ 8). The tree also carries `branch` (`primary_client`,\n * `other_named_persons`) and the LEADS spelling `sub-category`, which § 8's\n * list omits; both are accepted as written.\n */\nexport type ScopeRowType =\n | \"branch\"\n | \"category\"\n | \"subcategory\"\n | \"sub-category\"\n | \"person_type\"\n | \"category_rest\"\n | \"instrument row\";\n\n/** `status` (§ 8). */\nexport type ScopeRowStatus = \"as_today\" | \"new\" | \"retired\";\n\n/** `special_data_type` (§ 8, plus `evidence`, which the tree carries on `case_attachments`). */\nexport type ScopeSpecialDataType =\n | \"none\"\n | \"survivor_confidential\"\n | \"criminal_intelligence\"\n | \"evidence\";\n\n/** The three app-relevance columns (§ 4). */\nexport type ScopeApp = \"pave\" | \"thread\" | \"leads\";\nexport type ScopeApps = Readonly<Record<ScopeApp, boolean>>;\n\n/**\n * One tree row, in the selection-code space (see header). Bind the SOT with\n * `scopeRowsFromSot`. Extra fields on a caller's row type are carried through\n * (`row(code)` returns the caller's row).\n */\nexport interface ScopeRow {\n /** The code a selection stores (canon's spelling: `offenders.risk`). */\n scopeCode: string;\n parentScopeCode: string | null;\n rowType: ScopeRowType;\n kindBranch: ScopeKindBranch;\n /** On a per-kind row (`offenders.risk`): the client row it copies (`risk`). Required there. */\n kindRow?: string;\n /** App relevance (§ 4). Informational: no resolver decision reads it. */\n apps: ScopeApps;\n selectable: boolean;\n /** `shareable_default = on` (rule 4: `false` = off by default). */\n shareableDefault: boolean;\n platformFloor: boolean;\n levelFloor: 1 | 3;\n specialDataType: ScopeSpecialDataType;\n /** A `retired` row is never covered, offered or written. */\n status: ScopeRowStatus;\n replacesV3?: readonly string[];\n}\n\n/** The four migration rules of handoff § 3, plus the pre-v4 retirement reading. */\nexport type ScopeMigrationRule = \"identity\" | \"row\" | \"category\" | \"subtract\" | \"retired before v4\";\n\n/** One from-to line (selection-code space); `to` is empty for \"(nothing)\". */\nexport interface ScopeMigration {\n from: string;\n to: readonly string[];\n rule: ScopeMigrationRule;\n note?: string;\n /** The line reads WIDER than v3 did (SOT `widens: true`; consent widening is an open question). */\n widens?: boolean;\n}\n\n// ─── Output shapes ───────────────────────────────────────────────────────────\n\n/** How one stored code was read. `unknown` = no row, no table line: it includes nothing. */\nexport type ScopeReadingRule = ScopeMigrationRule | \"unknown\";\n\nexport interface ScopeCodeReading {\n readonly from: string;\n readonly rule: ScopeReadingRule;\n readonly reads: readonly string[];\n /** The table line it read through is flagged as reading wider than v3. */\n readonly widens: boolean;\n}\n\n/**\n * The current (v4) reading of a stored list. `stored` and `storedVersion` are\n * the list as signed, copied, never rewritten (§ 3: \"a signed release keeps\n * its list as signed, at the version signed; its current reading is derived\n * through the table at read time\").\n */\nexport interface ScopeReading {\n /** The stamp as stored; `null` when it was absent or not a number. */\n readonly storedVersion: number | null;\n readonly stored: readonly string[];\n readonly version: typeof INFORMATION_SCOPE_VERSION;\n /** The stamp is not in `INFORMATION_SCOPE_READABLE_VERSIONS`: every code reads `unknown`. */\n readonly unsupportedVersion: boolean;\n /**\n * The derived v4 list: unique, in tree order. A selection reading always\n * contains `system_info`; a restriction reading contains only what it restricts.\n */\n readonly informationScope: readonly string[];\n /** One entry per distinct stored code, in stored order. */\n readonly codes: readonly ScopeCodeReading[];\n /** Stored codes that are retired (read by `row`, `subtract` or `retired before v4`). */\n readonly retired: readonly string[];\n /** Stored codes with no live row and no table line; they include nothing. */\n readonly unknown: readonly string[];\n /** Stored codes whose reading is wider than v3's (`widens`): surface, never hide. */\n readonly widened: readonly string[];\n}\n\nexport type ScopeShareVerdict =\n | { readonly included: true; readonly reason: \"included\" }\n | { readonly included: false; readonly reason: \"not_covered\" | \"platform_floor\" | \"unknown_code\" }\n | {\n readonly included: false;\n readonly reason: \"off_by_default\";\n /** The off-by-default rows in the chain the account has not enabled. */\n readonly notEnabled: readonly string[];\n };\n\nexport type ScopeShareReason = ScopeShareVerdict[\"reason\"];\n\nexport interface ScopeShareOptions {\n /** The off-by-default rows the account's policy has enabled for sharing (rule 4). */\n enabledOffByDefault?: ReadonlySet<string> | readonly string[];\n}\n\nexport interface CreateInformationScopeResolverInput<R extends ScopeRow> {\n rows: readonly R[];\n migrations?: readonly ScopeMigration[];\n}\n\n/** A stored list as it may arrive from storage (reads are total). */\nexport type StoredScopeList = readonly string[] | null | undefined;\n\nexport interface InformationScopeResolver<R extends ScopeRow = ScopeRow> {\n readonly version: typeof INFORMATION_SCOPE_VERSION;\n /** Every row in input order. */\n readonly rows: readonly R[];\n row(code: string): R | undefined;\n /** The live (non-retired) children of `code`, in input order (a copy). */\n childrenOf(code: string): string[];\n /** `code` first, then its parent, up to the root (a copy). Empty for an unknown code. */\n ancestorsOf(code: string): string[];\n\n /** Rules 2 + 3. */\n isCovered(selection: StoredScopeList, code: string): boolean;\n /** Rules 2–5. */\n isIncludedOnShare(selection: StoredScopeList, code: string, options?: ScopeShareOptions): boolean;\n /** `isIncludedOnShare` with the reason, for \"held back and counted\". */\n shareVerdict(\n selection: StoredScopeList,\n code: string,\n options?: ScopeShareOptions,\n ): ScopeShareVerdict;\n /** Rule 7 (the viewing side). */\n isVisibleAtLevel(level: number, code: string): boolean;\n\n /** Rules 3 + 6: the codes a picker writes when it expands `code` (its live children, rest row included). */\n expandSelectAll(code: string): string[];\n /** Rule 6: select-all at `code` (the code itself is stored; its now-redundant descendants drop). */\n selectAll(selection: readonly string[], code: string): string[];\n /** Rules 3 + 6: de-select one child; every selected ancestor is replaced by its other children. */\n deselectChild(selection: readonly string[], childCode: string): string[];\n\n /** § 3: the current v4 reading of a stored selection. */\n readSelection(list: StoredScopeList, scopeVersion: number | null | undefined): ScopeReading;\n /** § 3 `subtract`: the current v4 reading of a stored RESTRICTION. */\n readRestriction(list: StoredScopeList, scopeVersion: number | null | undefined): ScopeReading;\n\n /** Rule 1: the row a record is included under, given its field's home row and its subject. */\n rowForSubject(homeRow: string, kind: ScopeSubjectKind): string;\n\n /** § 7 row 6: expand every pick that sits above the ceiling's grain into its children. */\n expandBranchPickToGrain(selection: StoredScopeList, ceiling: StoredScopeList): string[];\n /** § 7 row 6: expand, then keep only what the ceiling covers. A sender can never widen. */\n clampToCeiling(selection: StoredScopeList, ceiling: StoredScopeList): string[];\n}\n\n// ─── Pure row guards ─────────────────────────────────────────────────────────\n\n/** A row a picker offers as a choice (§ 8 `selectable`; never a retired row). */\nexport const isSelectableScopeRow = (row: ScopeRow | undefined): boolean =>\n row !== undefined && row.selectable && row.status !== \"retired\";\n\n/** The `category_rest` row (rule 3): never offered, covered with its category. */\nexport const isScopeRestRow = (row: ScopeRow | undefined): boolean =>\n row !== undefined && row.rowType === \"category_rest\";\n\n/** One of the 28 `summary_<x>` / `full_<x>` rows (§ 8 `instrument row`). */\nexport const isScopeInstrumentRow = (row: ScopeRow | undefined): boolean =>\n row !== undefined && row.rowType === \"instrument row\";\n\n// ─── Person kind (rule 1, Phase 3 D5) ───────────────────────────────────────\n\n/**\n * Which kind of other named person someone is (handoff § 2 rule 1; § 8; Phase\n * 3 D5): \"This person caused harm\" wins; \"Eligible family member\" (asserted\n * by the advocate, never derived from the relationship) otherwise; neither →\n * `others`. A person with both switches is listed under `offenders`; the\n * caller keeps the family-member VAWA handling, which rides `efmAsserted` on\n * the person, not the kind.\n */\nexport function kindForPerson(person: {\n causedHarm: boolean;\n efmAsserted: boolean;\n}): ScopePersonKind {\n if (person.causedHarm) return \"offenders\";\n if (person.efmAsserted) return \"family\";\n return \"others\";\n}\n\n// ─── The resolver ────────────────────────────────────────────────────────────\n\nconst PERSON_KINDS: ReadonlySet<string> = new Set<ScopePersonKind>([\"offenders\", \"family\", \"others\"]);\nconst SPECIAL_DATA_TYPES: ReadonlySet<string> = new Set<ScopeSpecialDataType>([\n \"none\",\n \"survivor_confidential\",\n \"criminal_intelligence\",\n \"evidence\",\n]);\nconst MIGRATION_RULES: ReadonlySet<string> = new Set<ScopeMigrationRule>([\n \"identity\",\n \"row\",\n \"category\",\n \"subtract\",\n \"retired before v4\",\n]);\nconst RETIRED_RULES: ReadonlySet<ScopeReadingRule> = new Set<ScopeReadingRule>([\n \"row\",\n \"subtract\",\n \"retired before v4\",\n]);\n\n/** Reading precedence per code (§ 3): a stated category line, then identity, row, pre-v4. */\nconst SELECTION_PRECEDENCE: readonly ScopeMigrationRule[] = [\n \"category\",\n \"identity\",\n \"row\",\n \"retired before v4\",\n];\nconst RESTRICTION_PRECEDENCE: readonly ScopeMigrationRule[] = [\n \"subtract\",\n ...SELECTION_PRECEDENCE,\n];\n\nconst asList = (list: StoredScopeList): readonly string[] => (Array.isArray(list) ? list : []);\n\n/**\n * Bind the resolver to one tree (and its migration table). Throws on a\n * malformed tree: a duplicate code, a parent that is not a row, a cycle, no\n * `system_info` row, a live row whose `specialDataType` is missing or not in\n * § 8 (rule 1 routes on it — absence fails closed by refusing to bind), a\n * per-kind row without a `kindRow` that names a row, an unknown migration\n * rule, a migration successor that is not a live row, or two different\n * readings for the same code and rule.\n */\nexport function createInformationScopeResolver<R extends ScopeRow>(\n input: CreateInformationScopeResolverInput<R>,\n): InformationScopeResolver<R> {\n const rows = Object.freeze([...input.rows]);\n const byCode = new Map<string, R>();\n const order = new Map<string, number>();\n for (const r of rows) {\n if (byCode.has(r.scopeCode)) {\n throw new Error(`information scope: duplicate code \"${r.scopeCode}\"`);\n }\n byCode.set(r.scopeCode, r);\n order.set(r.scopeCode, order.size);\n }\n const isLive = (code: string): boolean => {\n const r = byCode.get(code);\n return r !== undefined && r.status !== \"retired\";\n };\n const children = new Map<string, string[]>();\n for (const r of rows) {\n if (r.status !== \"retired\" && !SPECIAL_DATA_TYPES.has(r.specialDataType)) {\n throw new Error(\n `information scope: \"${r.scopeCode}\" has specialDataType ${JSON.stringify(r.specialDataType)}`,\n );\n }\n if (r.parentScopeCode === null || r.parentScopeCode === \"\") continue;\n if (!byCode.has(r.parentScopeCode)) {\n throw new Error(\n `information scope: \"${r.scopeCode}\" names unknown parent \"${r.parentScopeCode}\"`,\n );\n }\n if (r.status === \"retired\") continue;\n const list = children.get(r.parentScopeCode) ?? [];\n list.push(r.scopeCode);\n children.set(r.parentScopeCode, list);\n }\n const ancestorCache = new Map<string, readonly string[]>();\n const ancestors = (code: string): readonly string[] => {\n const hit = ancestorCache.get(code);\n if (hit) return hit;\n const out: string[] = [];\n let cur: string | null = code;\n while (cur !== null && cur !== \"\") {\n const r = byCode.get(cur);\n if (!r) break;\n if (out.includes(cur)) throw new Error(`information scope: cycle at \"${cur}\"`);\n out.push(cur);\n cur = r.parentScopeCode;\n }\n ancestorCache.set(code, out);\n return out;\n };\n for (const r of rows) ancestors(r.scopeCode);\n if (!isLive(INFORMATION_SCOPE_SYSTEM_INFO)) {\n throw new Error(`information scope: the tree has no \"${INFORMATION_SCOPE_SYSTEM_INFO}\" row`);\n }\n /** `system_info` and its ancestors (`system`): covered by every selection. */\n const alwaysCovered: ReadonlySet<string> = new Set(ancestors(INFORMATION_SCOPE_SYSTEM_INFO));\n\n const kids = (code: string): readonly string[] => children.get(code) ?? [];\n const descendantsOf = (code: string): string[] => {\n const out: string[] = [];\n const stack = [...kids(code)];\n while (stack.length > 0) {\n const c = stack.pop() as string;\n out.push(c);\n stack.push(...kids(c));\n }\n return out;\n };\n const restRowOf = (code: string): string | undefined =>\n kids(code).find((c) => isScopeRestRow(byCode.get(c)));\n\n // Rule 1 kind rows, read off the tree: each kind's `person_type` root, and\n // each per-kind row by (kind, the client row it copies).\n const kindRoot = new Map<string, string>();\n const perKindRow = new Map<string, string>();\n for (const r of rows) {\n if (r.status === \"retired\" || r.kindBranch === null || !PERSON_KINDS.has(r.kindBranch)) continue;\n if (r.rowType === \"person_type\") {\n kindRoot.set(r.kindBranch, r.scopeCode);\n continue;\n }\n if (r.kindRow === undefined || !isLive(r.kindRow)) {\n throw new Error(\n `information scope: per-kind row \"${r.scopeCode}\" has no live kindRow (${String(r.kindRow)})`,\n );\n }\n perKindRow.set(`${r.kindBranch}\\u0000${r.kindRow}`, r.scopeCode);\n }\n\n // Migration table, indexed by code then rule.\n const migrations = new Map<string, Map<ScopeMigrationRule, ScopeMigration>>();\n for (const m of input.migrations ?? []) {\n if (!MIGRATION_RULES.has(m.rule)) {\n throw new Error(`information scope: unknown migration rule \"${m.rule}\" on \"${m.from}\"`);\n }\n for (const to of m.to) {\n if (!isLive(to)) {\n throw new Error(\n `information scope: migration \"${m.from}\" (${m.rule}) reads as \"${to}\", not a live row`,\n );\n }\n }\n const perCode = migrations.get(m.from) ?? new Map<ScopeMigrationRule, ScopeMigration>();\n const prior = perCode.get(m.rule);\n if (prior && prior.to.join(\" \") !== m.to.join(\" \")) {\n throw new Error(`information scope: two \"${m.rule}\" readings for \"${m.from}\"`);\n }\n perCode.set(m.rule, {\n from: m.from,\n rule: m.rule,\n to: Object.freeze([...m.to]),\n widens: m.widens === true || prior?.widens === true,\n });\n migrations.set(m.from, perCode);\n }\n\n /**\n * Unique, tree order for known codes, unknown codes kept after in first-seen\n * order; a selection always carries `system_info` (a restriction does not).\n */\n const normalize = (codes: Iterable<string>, withSystemInfo = true): string[] => {\n const seen = new Set<string>();\n const known: string[] = [];\n const unknown: string[] = [];\n const all = withSystemInfo ? [INFORMATION_SCOPE_SYSTEM_INFO, ...codes] : [...codes];\n for (const c of all) {\n if (seen.has(c)) continue;\n seen.add(c);\n (byCode.has(c) ? known : unknown).push(c);\n }\n known.sort((a, b) => (order.get(a) as number) - (order.get(b) as number));\n return [...known, ...unknown];\n };\n\n const requirePickable = (code: string, op: string): void => {\n if (!byCode.has(code)) throw new RangeError(`information scope ${op}: unknown code \"${code}\"`);\n if (!isSelectableScopeRow(byCode.get(code))) {\n throw new RangeError(`information scope ${op}: \"${code}\" is not selectable`);\n }\n };\n\n // Rule 2 (self or any ancestor in the flat list) + rule 3 (a record homed on a\n // category is covered when the category OR its rest row is). `system_info` and\n // `system` are always covered (header).\n const isCovered = (selection: StoredScopeList, code: string): boolean => {\n if (!isLive(code)) return false;\n if (alwaysCovered.has(code)) return true;\n const sel = new Set(asList(selection));\n if (ancestors(code).some((a) => sel.has(a))) return true;\n const rest = restRowOf(code);\n return rest !== undefined && sel.has(rest);\n };\n\n const shareVerdict = (\n selection: StoredScopeList,\n code: string,\n options: ScopeShareOptions = {},\n ): ScopeShareVerdict => {\n if (!isLive(code)) return { included: false, reason: \"unknown_code\" };\n if (!isCovered(selection, code)) return { included: false, reason: \"not_covered\" };\n const chain = ancestors(code).map((c) => byCode.get(c) as R);\n // Rule 5: the floor (or a floor ancestor) never leaves, whatever the list says.\n if (chain.some((r) => r.platformFloor)) return { included: false, reason: \"platform_floor\" };\n // Rule 4: every off-by-default row in the chain must be enabled by the account\n // (the reference runner's `included`: enabling an ancestor does not enable an\n // off-by-default child of it).\n const enabled = new Set(options.enabledOffByDefault ?? []);\n const notEnabled = chain\n .filter((r) => !r.shareableDefault && !enabled.has(r.scopeCode))\n .map((r) => r.scopeCode);\n if (notEnabled.length > 0) return { included: false, reason: \"off_by_default\", notEnabled };\n return { included: true, reason: \"included\" };\n };\n\n const expandSelectAll = (code: string): string[] => {\n if (!byCode.has(code)) throw new RangeError(`information scope expand: unknown code \"${code}\"`);\n return [...kids(code)];\n };\n\n const selectAll = (selection: readonly string[], code: string): string[] => {\n requirePickable(code, \"selectAll\");\n const drop = new Set(descendantsOf(code));\n return normalize([...selection.filter((c) => !drop.has(c)), code]);\n };\n\n const deselectChild = (selection: readonly string[], childCode: string): string[] => {\n requirePickable(childCode, \"deselectChild\");\n if (alwaysCovered.has(childCode)) {\n throw new RangeError(`information scope deselectChild: \"${childCode}\" is always included`);\n }\n const sel = new Set(selection);\n const path = ancestors(childCode); // [child, parent, …, root]\n let top = 0;\n for (let i = 1; i < path.length; i += 1) if (sel.has(path[i])) top = i;\n // Replace every selected ancestor by its OTHER children, all the way down the\n // path (rule 3: the rest row is one of those children, so it is written too).\n for (let i = 1; i <= top; i += 1) {\n sel.delete(path[i]);\n for (const c of kids(path[i])) if (c !== path[i - 1]) sel.add(c);\n }\n sel.delete(childCode);\n for (const d of descendantsOf(childCode)) sel.delete(d);\n return normalize(sel);\n };\n\n const readOne = (\n from: string,\n scopeVersion: number,\n precedence: readonly ScopeMigrationRule[],\n ): ScopeCodeReading => {\n // A v4 list names live codes as written.\n if (scopeVersion === INFORMATION_SCOPE_VERSION && isLive(from)) {\n return { from, rule: \"identity\", reads: [from], widens: false };\n }\n // Every other code reads through the table — including a retired code in a\n // v4 list (§ 3 (c): it \"stays recognisable in stored data forever\").\n const lines = migrations.get(from);\n if (lines) {\n for (const rule of precedence) {\n if (scopeVersion === INFORMATION_SCOPE_VERSION && (rule === \"identity\" || rule === \"category\")) {\n continue; // a v4 code that is not live has no identity reading\n }\n const line = lines.get(rule);\n if (line) return { from, rule, reads: [...line.to], widens: line.widens === true };\n }\n }\n return { from, rule: \"unknown\", reads: [], widens: false };\n };\n\n const read = (\n list: StoredScopeList,\n scopeVersion: number | null | undefined,\n precedence: readonly ScopeMigrationRule[],\n isRestriction: boolean,\n ): ScopeReading => {\n const stored = [...asList(list)];\n const supported =\n typeof scopeVersion === \"number\" && INFORMATION_SCOPE_READABLE_VERSIONS.includes(scopeVersion);\n const codes: ScopeCodeReading[] = [];\n const seen = new Set<string>();\n for (const from of stored) {\n if (seen.has(from)) continue;\n seen.add(from);\n codes.push(\n supported\n ? readOne(from, scopeVersion as number, precedence)\n : { from, rule: \"unknown\", reads: [], widens: false },\n );\n }\n return {\n storedVersion: typeof scopeVersion === \"number\" ? scopeVersion : null,\n stored,\n version: INFORMATION_SCOPE_VERSION,\n unsupportedVersion: !supported,\n informationScope: normalize(\n codes.flatMap((c) => c.reads),\n !isRestriction,\n ),\n codes,\n retired: codes.filter((c) => RETIRED_RULES.has(c.rule)).map((c) => c.from),\n unknown: codes.filter((c) => c.rule === \"unknown\").map((c) => c.from),\n widened: codes.filter((c) => c.widens).map((c) => c.from),\n };\n };\n\n const rowForSubject = (homeRow: string, kind: ScopeSubjectKind): string => {\n const home = byCode.get(homeRow);\n if (!home) throw new RangeError(`information scope rowForSubject: unknown home \"${homeRow}\"`);\n if (kind === \"client\") return homeRow;\n const chain = ancestors(homeRow);\n // System, Notes and the LEADS groups sit under no `branch` row: the record stays home.\n if (byCode.get(chain[chain.length - 1])?.rowType !== \"branch\") return homeRow;\n // A criminal-intelligence row under the client (`derived_risk_signals`) stays home:\n // every per-kind row is survivor_confidential, so re-branching would move CI\n // content across a handling class. The reference keeps it home the same way\n // (`resolve_home` / `leads_codes`).\n if (home.specialDataType === \"criminal_intelligence\") return homeRow;\n const root = kindRoot.get(kind);\n if (!root) throw new RangeError(`information scope rowForSubject: the tree has no \"${kind}\" kind`);\n if (chain.includes(root)) return homeRow;\n // The deepest row the kind defines for the home (D15).\n for (const anc of chain) {\n const perKind = perKindRow.get(`${kind}\\u0000${anc}`);\n if (perKind !== undefined) return perKind;\n }\n return root;\n };\n\n const expandBranchPickToGrain = (\n selection: StoredScopeList,\n ceiling: StoredScopeList,\n ): string[] => {\n const ceil = asList(ceiling);\n const ceilSet = new Set(ceil);\n const isWithin = (c: string): boolean => ancestors(c).some((a) => ceilSet.has(a));\n const isAbove = (c: string): boolean => ceil.some((k) => k !== c && ancestors(k).includes(c));\n const out: string[] = [];\n const stack = [...asList(selection)];\n while (stack.length > 0) {\n const c = stack.pop() as string;\n if (isLive(c) && !isWithin(c) && isAbove(c)) stack.push(...kids(c));\n else out.push(c);\n }\n return normalize(out);\n };\n\n const clampToCeiling = (selection: StoredScopeList, ceiling: StoredScopeList): string[] => {\n const ceil = new Set(asList(ceiling));\n return normalize(\n expandBranchPickToGrain(selection, ceiling).filter(\n (c) => isLive(c) && ancestors(c).some((a) => ceil.has(a)),\n ),\n );\n };\n\n return {\n version: INFORMATION_SCOPE_VERSION,\n rows,\n row: (code) => byCode.get(code),\n childrenOf: (code) => [...kids(code)],\n ancestorsOf: (code) => [...ancestors(code)],\n isCovered,\n isIncludedOnShare: (selection, code, options) =>\n shareVerdict(selection, code, options).included,\n shareVerdict,\n // Rule 7: the lowest internal viewing level that sees the row. Level 2\n // (autocomplete) sees the level-1 stub (§ 5). Sharing ignores this.\n isVisibleAtLevel: (level, code) =>\n typeof level === \"number\" && isLive(code) && level >= (byCode.get(code) as R).levelFloor,\n expandSelectAll,\n selectAll,\n deselectChild,\n readSelection: (list, scopeVersion) => read(list, scopeVersion, SELECTION_PRECEDENCE, false),\n readRestriction: (list, scopeVersion) => read(list, scopeVersion, RESTRICTION_PRECEDENCE, true),\n rowForSubject,\n expandBranchPickToGrain,\n clampToCeiling,\n };\n}\n","/**\n * @htilabs/platform-common-models — CVC-236 SOT → information-scope resolver binding\n *\n * Maps the `core_information_scope` SOT envelope (`coreInformationScope.v2.0.0.json`,\n * exported as `coreInformationScopeSot` from `/cvcs`) into the resolver's\n * input shapes. Pure and dependency-free: the caller passes the envelope.\n *\n * The SOT keys a row by its package key (`offenders__risk`, `identifying__other`:\n * canon's dotted codes with `.` spelled `__`) and by a seven-segment wire code;\n * a stored selection holds canon's dotted code (`offenders.risk`). The\n * adapter reads every key through the entry's `canonicalCode` (present on the\n * dotted rows) and falls back to `__` → `.` for a key with no entry.\n *\n * Rows: the live v4 tree only (`status` `as_today` / `new`). The retired\n * tombstones are left out — a stored retired code reads through the\n * migration table, which names every tombstone — and so is the CVC\n * missingness group (`missingness_root` and its children), which is not a\n * scope row. A live entry missing a field the resolver needs throws: binding\n * fails closed rather than guess.\n *\n * Usage:\n * ```ts\n * import { coreInformationScopeSot } from \"@htilabs/platform-common-models/cvcs\";\n * import {\n * createInformationScopeResolver, scopeRowsFromSot, scopeMigrationsFromSot,\n * } from \"@htilabs/platform-common-models/information-scope\";\n *\n * const scope = createInformationScopeResolver({\n * rows: scopeRowsFromSot(coreInformationScopeSot),\n * migrations: scopeMigrationsFromSot(coreInformationScopeSot),\n * });\n * ```\n */\n\nimport type {\n ScopeKindBranch,\n ScopeMigration,\n ScopeMigrationRule,\n ScopeRow,\n ScopeRowStatus,\n ScopeRowType,\n ScopeSpecialDataType,\n} from \"./informationScopeResolver.js\";\n\n/** The SOT entry fields the adapter reads (structural, so the JSON import binds). */\nexport interface CoreInformationScopeSotEntry {\n key: string;\n canonicalCode?: string;\n parentKey?: string | null;\n rowType?: string;\n kindBranch?: string | null;\n kindRow?: string;\n apps?: { pave: boolean; thread: boolean; leads: boolean };\n selectable?: boolean;\n shareableDefault?: boolean;\n platformFloor?: boolean;\n levelFloor?: number;\n specialDataType?: string;\n status?: string;\n replacesV3?: readonly string[];\n /** On a tombstone: its RESTRICTION reading; the table's `subtract` line is what binds. */\n restrictionSuccessors?: readonly string[];\n}\n\nexport interface CoreInformationScopeSotMigrationLine {\n from: string;\n to: readonly string[];\n rule: string;\n note?: string;\n widens?: boolean;\n}\n\nexport interface CoreInformationScopeSot {\n entries: readonly CoreInformationScopeSotEntry[];\n migrations?: { table: readonly CoreInformationScopeSotMigrationLine[] };\n}\n\nconst ROW_TYPES: ReadonlySet<string> = new Set<ScopeRowType>([\n \"branch\",\n \"category\",\n \"subcategory\",\n \"sub-category\",\n \"person_type\",\n \"category_rest\",\n \"instrument row\",\n]);\nconst KIND_BRANCHES: ReadonlySet<string> = new Set([\n \"client\",\n \"offenders\",\n \"family\",\n \"others\",\n \"leads\",\n]);\nconst LIVE: ReadonlySet<string> = new Set<ScopeRowStatus>([\"as_today\", \"new\"]);\nconst MISSINGNESS_ROOT = \"missingness_root\";\n\n/** Package key → canon scope code, through `canonicalCode`. */\nfunction keyReader(sot: CoreInformationScopeSot): (key: string) => string {\n const byKey = new Map(sot.entries.map((e) => [e.key, e.canonicalCode ?? e.key]));\n return (key) => byKey.get(key) ?? key.replace(/__/g, \".\");\n}\n\nfunction fail(key: string, field: string, value: unknown): never {\n throw new TypeError(\n `information scope SOT: live entry \"${key}\" has ${field} ${JSON.stringify(value)}`,\n );\n}\n\n/** The live v4 tree rows of a CVC-236 SOT, in the resolver's selection-code space. */\nexport function scopeRowsFromSot(sot: CoreInformationScopeSot): ScopeRow[] {\n const code = keyReader(sot);\n const missingness = new Set(\n sot.entries\n .filter((e) => e.key === MISSINGNESS_ROOT || e.parentKey === MISSINGNESS_ROOT)\n .map((e) => e.key),\n );\n const rows: ScopeRow[] = [];\n for (const e of sot.entries) {\n if (missingness.has(e.key)) continue;\n if (e.status === \"retired\") continue;\n if (e.status === undefined || !LIVE.has(e.status)) fail(e.key, \"status\", e.status);\n if (e.rowType === undefined || !ROW_TYPES.has(e.rowType)) fail(e.key, \"rowType\", e.rowType);\n const kindBranch = e.kindBranch ?? null;\n if (kindBranch !== null && !KIND_BRANCHES.has(kindBranch)) fail(e.key, \"kindBranch\", kindBranch);\n if (e.apps === undefined) fail(e.key, \"apps\", e.apps);\n for (const b of [\"selectable\", \"shareableDefault\", \"platformFloor\"] as const) {\n if (typeof e[b] !== \"boolean\") fail(e.key, b, e[b]);\n }\n if (e.levelFloor !== 1 && e.levelFloor !== 3) fail(e.key, \"levelFloor\", e.levelFloor);\n if (e.specialDataType === undefined) fail(e.key, \"specialDataType\", e.specialDataType);\n const row: ScopeRow = {\n scopeCode: code(e.key),\n parentScopeCode: e.parentKey ? code(e.parentKey) : null,\n rowType: e.rowType as ScopeRowType,\n kindBranch: kindBranch as ScopeKindBranch,\n apps: { pave: e.apps.pave, thread: e.apps.thread, leads: e.apps.leads },\n selectable: e.selectable as boolean,\n shareableDefault: e.shareableDefault as boolean,\n platformFloor: e.platformFloor as boolean,\n levelFloor: e.levelFloor,\n specialDataType: e.specialDataType as ScopeSpecialDataType,\n status: e.status as ScopeRowStatus,\n replacesV3: [...(e.replacesV3 ?? [])],\n };\n if (e.kindRow !== undefined) row.kindRow = code(e.kindRow);\n rows.push(row);\n }\n return rows;\n}\n\n/** The v3 → v4 from-to table of a CVC-236 SOT (`migrations.table`), in selection codes. */\nexport function scopeMigrationsFromSot(sot: CoreInformationScopeSot): ScopeMigration[] {\n const code = keyReader(sot);\n return (sot.migrations?.table ?? []).map((l) => ({\n from: code(l.from),\n to: l.to.map(code),\n rule: l.rule as ScopeMigrationRule,\n ...(l.note === undefined ? {} : { note: l.note }),\n ...(l.widens === undefined ? {} : { widens: l.widens }),\n }));\n}\n"],"mappings":";AAkDO,IAAM,4BAA4B;AAWlC,IAAM,sCAAyD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;AAGnF,IAAM,gCAAgC;AAiMtC,IAAM,uBAAuB,CAAC,QACnC,QAAQ,UAAa,IAAI,cAAc,IAAI,WAAW;AAGjD,IAAM,iBAAiB,CAAC,QAC7B,QAAQ,UAAa,IAAI,YAAY;AAGhC,IAAM,uBAAuB,CAAC,QACnC,QAAQ,UAAa,IAAI,YAAY;AAYhC,SAAS,cAAc,QAGV;AAClB,MAAI,OAAO,WAAY,QAAO;AAC9B,MAAI,OAAO,YAAa,QAAO;AAC/B,SAAO;AACT;AAIA,IAAM,eAAoC,oBAAI,IAAqB,CAAC,aAAa,UAAU,QAAQ,CAAC;AACpG,IAAM,qBAA0C,oBAAI,IAA0B;AAAA,EAC5E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AACD,IAAM,kBAAuC,oBAAI,IAAwB;AAAA,EACvE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AACD,IAAM,gBAA+C,oBAAI,IAAsB;AAAA,EAC7E;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGD,IAAM,uBAAsD;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,IAAM,yBAAwD;AAAA,EAC5D;AAAA,EACA,GAAG;AACL;AAEA,IAAM,SAAS,CAAC,SAA8C,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC;AAWrF,SAAS,+BACd,OAC6B;AAC7B,QAAM,OAAO,OAAO,OAAO,CAAC,GAAG,MAAM,IAAI,CAAC;AAC1C,QAAM,SAAS,oBAAI,IAAe;AAClC,QAAM,QAAQ,oBAAI,IAAoB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