daftari 1.20.0 → 1.22.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 (100) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +4 -1
  3. package/dist/access/rbac.d.ts +1 -0
  4. package/dist/access/rbac.d.ts.map +1 -1
  5. package/dist/access/rbac.js +7 -0
  6. package/dist/access/rbac.js.map +1 -1
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +10 -0
  9. package/dist/cli.js.map +1 -1
  10. package/dist/consolidate/birth.d.ts +74 -0
  11. package/dist/consolidate/birth.d.ts.map +1 -0
  12. package/dist/consolidate/birth.js +253 -0
  13. package/dist/consolidate/birth.js.map +1 -0
  14. package/dist/consolidate/clocks.d.ts +15 -0
  15. package/dist/consolidate/clocks.d.ts.map +1 -0
  16. package/dist/consolidate/clocks.js +127 -0
  17. package/dist/consolidate/clocks.js.map +1 -0
  18. package/dist/consolidate/constants.d.ts +26 -0
  19. package/dist/consolidate/constants.d.ts.map +1 -0
  20. package/dist/consolidate/constants.js +83 -0
  21. package/dist/consolidate/constants.js.map +1 -0
  22. package/dist/consolidate/decorrelation.d.ts +69 -0
  23. package/dist/consolidate/decorrelation.d.ts.map +1 -0
  24. package/dist/consolidate/decorrelation.js +287 -0
  25. package/dist/consolidate/decorrelation.js.map +1 -0
  26. package/dist/consolidate/derivation-prompt.d.ts +28 -0
  27. package/dist/consolidate/derivation-prompt.d.ts.map +1 -0
  28. package/dist/consolidate/derivation-prompt.js +72 -0
  29. package/dist/consolidate/derivation-prompt.js.map +1 -0
  30. package/dist/consolidate/edge-write.d.ts +10 -0
  31. package/dist/consolidate/edge-write.d.ts.map +1 -0
  32. package/dist/consolidate/edge-write.js +76 -0
  33. package/dist/consolidate/edge-write.js.map +1 -0
  34. package/dist/consolidate/index.d.ts +2 -0
  35. package/dist/consolidate/index.d.ts.map +1 -0
  36. package/dist/consolidate/index.js +477 -0
  37. package/dist/consolidate/index.js.map +1 -0
  38. package/dist/consolidate/priority.d.ts +25 -0
  39. package/dist/consolidate/priority.d.ts.map +1 -0
  40. package/dist/consolidate/priority.js +103 -0
  41. package/dist/consolidate/priority.js.map +1 -0
  42. package/dist/consolidate/revision.d.ts +75 -0
  43. package/dist/consolidate/revision.d.ts.map +1 -0
  44. package/dist/consolidate/revision.js +232 -0
  45. package/dist/consolidate/revision.js.map +1 -0
  46. package/dist/consolidate/state.d.ts +10 -0
  47. package/dist/consolidate/state.d.ts.map +1 -0
  48. package/dist/consolidate/state.js +54 -0
  49. package/dist/consolidate/state.js.map +1 -0
  50. package/dist/curation/edges.d.ts +5 -0
  51. package/dist/curation/edges.d.ts.map +1 -1
  52. package/dist/curation/edges.js +82 -9
  53. package/dist/curation/edges.js.map +1 -1
  54. package/dist/curation/lint.d.ts +2 -0
  55. package/dist/curation/lint.d.ts.map +1 -1
  56. package/dist/curation/lint.js +5 -0
  57. package/dist/curation/lint.js.map +1 -1
  58. package/dist/curation/provenance.d.ts +1 -0
  59. package/dist/curation/provenance.d.ts.map +1 -1
  60. package/dist/curation/provenance.js +1 -0
  61. package/dist/curation/provenance.js.map +1 -1
  62. package/dist/curation/shadow.d.ts +58 -0
  63. package/dist/curation/shadow.d.ts.map +1 -0
  64. package/dist/curation/shadow.js +221 -0
  65. package/dist/curation/shadow.js.map +1 -0
  66. package/dist/eval/llm.d.ts +3 -1
  67. package/dist/eval/llm.d.ts.map +1 -1
  68. package/dist/eval/llm.js +6 -2
  69. package/dist/eval/llm.js.map +1 -1
  70. package/dist/index.js +1 -1
  71. package/dist/storage/index-db.d.ts +1 -0
  72. package/dist/storage/index-db.d.ts.map +1 -1
  73. package/dist/storage/index-db.js +14 -9
  74. package/dist/storage/index-db.js.map +1 -1
  75. package/dist/tools/curation.d.ts +2 -0
  76. package/dist/tools/curation.d.ts.map +1 -1
  77. package/dist/tools/curation.js +5 -1
  78. package/dist/tools/curation.js.map +1 -1
  79. package/dist/tools/edges.d.ts.map +1 -1
  80. package/dist/tools/edges.js +14 -10
  81. package/dist/tools/edges.js.map +1 -1
  82. package/dist/tools/staged-actions.d.ts +1 -0
  83. package/dist/tools/staged-actions.d.ts.map +1 -1
  84. package/dist/tools/staged-actions.js +18 -5
  85. package/dist/tools/staged-actions.js.map +1 -1
  86. package/dist/tools/write.d.ts +1 -0
  87. package/dist/tools/write.d.ts.map +1 -1
  88. package/dist/tools/write.js +93 -7
  89. package/dist/tools/write.js.map +1 -1
  90. package/dist/utils/config.d.ts +2 -0
  91. package/dist/utils/config.d.ts.map +1 -1
  92. package/dist/utils/config.js +17 -1
  93. package/dist/utils/config.js.map +1 -1
  94. package/dist/utils/git.d.ts +1 -0
  95. package/dist/utils/git.d.ts.map +1 -1
  96. package/dist/utils/git.js +19 -0
  97. package/dist/utils/git.js.map +1 -1
  98. package/package.json +1 -1
  99. package/templates/config.yaml +3 -0
  100. package/templates/reviewer-vault/.daftari/config.yaml +3 -0
@@ -0,0 +1,127 @@
1
+ // The three session-start clocks (spec §3.1), as pure functions over injected
2
+ // edges/docs — no I/O, so they are exhaustively testable with a fixed `now`.
3
+ // The I/O wrapper that feeds them is runConsolidate (index.ts).
4
+ //
5
+ // NOTE (Stage 1 scope): the decay clock keys off edge aged-strength only. The
6
+ // spec's TTL-on-docs input (`ttl_days` frontmatter feeding the same clock) is
7
+ // deferred to a later stage; it is additive and does not change the edge math.
8
+ import { EDGE_K_CAP } from "../curation/edges.js";
9
+ import { CONSOLIDATE_MAX_INTERVAL_DAYS, CONSOLIDATE_PATH_STRENGTH_FLOOR, reviewIntervalDays, } from "./constants.js";
10
+ import { docContentHash } from "./state.js";
11
+ const MS_PER_DAY = 86_400_000;
12
+ function daysBetween(thenISO, now) {
13
+ return (now.getTime() - new Date(thenISO).getTime()) / MS_PER_DAY;
14
+ }
15
+ // Decay + backstop clocks. Backstop dominates (it is the guarantee): an edge past
16
+ // the max-interval cap is backstop-overdue regardless of strength; otherwise an
17
+ // edge past its strength-scaled review interval is decay-due.
18
+ export function decayBackstopDue(edges, now) {
19
+ const out = [];
20
+ for (const e of edges) {
21
+ if (e.status === "revoked")
22
+ continue;
23
+ // Direction-unconfirmed edges are not trusted to bear triggers (spec §3.4);
24
+ // they stay visible as undirected relationships but never become due.
25
+ if (e.directionVerdict === "symmetric")
26
+ continue;
27
+ // Clamp at 0: a future-dated lastRederived (clock skew) yields a negative age;
28
+ // either way such an edge is fresh, not due (consistent with priority.ts ageOf).
29
+ const age = Math.max(0, daysBetween(e.lastRederived, now));
30
+ if (age >= CONSOLIDATE_MAX_INTERVAL_DAYS) {
31
+ out.push({
32
+ fromPath: e.fromPath,
33
+ toPath: e.toPath,
34
+ strength: e.strength,
35
+ reason: "backstop",
36
+ });
37
+ }
38
+ else if (age >= reviewIntervalDays(e.strength)) {
39
+ out.push({ fromPath: e.fromPath, toPath: e.toPath, strength: e.strength, reason: "decay" });
40
+ }
41
+ }
42
+ return out;
43
+ }
44
+ const edgeKey = (from, to) => `${from}\n${to}`;
45
+ // Event clock: forward walk from changed premises over derives_from edges. An
46
+ // edge (from → to) means `from` depends on `to`; a changed `to` makes `from` due.
47
+ //
48
+ // Attenuation: edge `strength` is the aged value in [0, EDGE_K_CAP] (k·decay), so
49
+ // a strong edge has strength > 1 — multiplying raw strengths would *amplify* the
50
+ // signal and never hit the floor. We normalize each hop to a factor in [0,1]
51
+ // (strength / EDGE_K_CAP): a fully-earned edge passes the change-signal undimmed,
52
+ // a weak/aged edge attenuates it. Reach = ∏(factors); a path stops below the
53
+ // floor (spec §3.1, C-Q2).
54
+ //
55
+ // Max-product relaxation: a node can be reached by several paths with different
56
+ // products. We keep the BEST (largest) product per node and re-expand when a
57
+ // strictly larger product arrives — a plain visited-on-first-touch guard would
58
+ // prune a node's descendants using whatever (possibly weaker) path reached it
59
+ // first, which is order-dependent and wrongly drops reachable edges. Dedup is by
60
+ // the full edge (from,to): two distinct edges sharing a `from` (a←b and a←c) are
61
+ // separate review units (§4) and must both surface.
62
+ export function eventDue(changedPaths, edges) {
63
+ const byPremise = new Map();
64
+ for (const e of edges) {
65
+ if (e.status === "revoked")
66
+ continue;
67
+ // Direction-unconfirmed edges don't propagate change signals (spec §3.4):
68
+ // we can't trust which endpoint is the premise, so a change on either side
69
+ // must not fabricate a due dependent.
70
+ if (e.directionVerdict === "symmetric")
71
+ continue;
72
+ const list = byPremise.get(e.toPath) ?? [];
73
+ list.push(e);
74
+ byPremise.set(e.toPath, list);
75
+ }
76
+ const due = new Map();
77
+ const bestProduct = new Map();
78
+ const queue = [];
79
+ for (const p of changedPaths) {
80
+ if ((bestProduct.get(p) ?? -1) < 1) {
81
+ bestProduct.set(p, 1);
82
+ queue.push({ path: p, product: 1 });
83
+ }
84
+ }
85
+ // Hard stop: products only decrease (factors ≤ 1) and we re-enqueue only on
86
+ // strict improvement, so this converges; the cap is a defensive backstop.
87
+ const maxExpansions = edges.length * edges.length + edges.length + changedPaths.length + 16;
88
+ let head = 0;
89
+ let expansions = 0;
90
+ while (head < queue.length && expansions < maxExpansions) {
91
+ const item = queue[head++];
92
+ if (!item)
93
+ break;
94
+ expansions += 1;
95
+ if (item.product < (bestProduct.get(item.path) ?? 0))
96
+ continue; // stale entry
97
+ for (const e of byPremise.get(item.path) ?? []) {
98
+ const factor = Math.min(Math.max(e.strength / EDGE_K_CAP, 0), 1);
99
+ const carried = item.product * factor;
100
+ if (carried < CONSOLIDATE_PATH_STRENGTH_FLOOR)
101
+ continue; // signal faded
102
+ const key = edgeKey(e.fromPath, e.toPath);
103
+ if (!due.has(key)) {
104
+ due.set(key, {
105
+ fromPath: e.fromPath,
106
+ toPath: e.toPath,
107
+ strength: e.strength,
108
+ reason: "event",
109
+ });
110
+ }
111
+ if (carried > (bestProduct.get(e.fromPath) ?? 0)) {
112
+ bestProduct.set(e.fromPath, carried);
113
+ queue.push({ path: e.fromPath, product: carried });
114
+ }
115
+ }
116
+ }
117
+ return [...due.values()];
118
+ }
119
+ // Birth queue: docs never processed, or whose content changed since (edited ⇒
120
+ // re-birth, spec §4.0). Stage 1 only computes this; it never marks anything
121
+ // processed (no births are executed — that is Stage 2).
122
+ export function birthQueue(docs, birthProcessed) {
123
+ return docs
124
+ .filter((d) => birthProcessed[d.relPath] !== docContentHash(d.content))
125
+ .map((d) => d.relPath);
126
+ }
127
+ //# sourceMappingURL=clocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clocks.js","sourceRoot":"","sources":["../../src/consolidate/clocks.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,gEAAgE;AAChE,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,+EAA+E;AAE/E,OAAO,EAAwB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,6BAA6B,EAC7B,+BAA+B,EAC/B,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAU5C,MAAM,UAAU,GAAG,UAAU,CAAC;AAC9B,SAAS,WAAW,CAAC,OAAe,EAAE,GAAS;IAC7C,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC;AACpE,CAAC;AAED,kFAAkF;AAClF,gFAAgF;AAChF,8DAA8D;AAC9D,MAAM,UAAU,gBAAgB,CAAC,KAAwB,EAAE,GAAS;IAClE,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS;YAAE,SAAS;QACrC,4EAA4E;QAC5E,sEAAsE;QACtE,IAAI,CAAC,CAAC,gBAAgB,KAAK,WAAW;YAAE,SAAS;QACjD,+EAA+E;QAC/E,iFAAiF;QACjF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC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wDAAwD;AACxD,MAAM,UAAU,UAAU,CACxB,IAAiD,EACjD,cAAsC;IAEtC,OAAO,IAAI;SACR,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SACtE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,26 @@
1
+ export declare const CONSOLIDATE_MIN_INTERVAL_DAYS = 1;
2
+ export declare const CONSOLIDATE_MAX_INTERVAL_DAYS = 90;
3
+ export declare function reviewIntervalDays(strength: number): number;
4
+ export declare const CONSOLIDATE_PATH_STRENGTH_FLOOR = 0.1;
5
+ export declare const CONSOLIDATE_SLICE_FRACTIONS: {
6
+ readonly backstop: 0.25;
7
+ readonly main: 0.45;
8
+ readonly periphery: 0.15;
9
+ readonly birth: 0.15;
10
+ };
11
+ export declare const CONSOLIDATE_DEFAULT_BUDGET = 50;
12
+ export declare const CONSOLIDATE_PANEL_SIZE = 2;
13
+ export declare const CONSOLIDATE_BIRTH_TOP_K = 20;
14
+ export declare const CONSOLIDATE_DEFAULT_MODEL = "claude-haiku-4-5-20251001";
15
+ export declare const CONSOLIDATE_AGENT = "agent:curation-loop";
16
+ export declare const CONSOLIDATE_PROMPT_TEMPLATES: readonly ["forward", "reverse", "contrast"];
17
+ export type ConsolidatePromptTemplate = (typeof CONSOLIDATE_PROMPT_TEMPLATES)[number];
18
+ export declare const CONSOLIDATE_DECORRELATION_MIN_LIFT = 0.05;
19
+ export declare const CONSOLIDATE_DIRECTION_MIN_ACCURACY = 0.85;
20
+ export declare const CONSOLIDATE_PRICING_PER_MTOKEN: Record<string, {
21
+ input: number;
22
+ output: number;
23
+ }>;
24
+ export declare function isModelPriced(model: string): boolean;
25
+ export declare function estimateCostUSD(model: string, inputTokens: number, outputTokens: number): number;
26
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/consolidate/constants.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAC/C,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG3D;AAID,eAAO,MAAM,+BAA+B,MAAM,CAAC;AAKnD,eAAO,MAAM,2BAA2B;;;;;CAK9B,CAAC;AAIX,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAM7C,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAIxC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAK1C,eAAO,MAAM,yBAAyB,8BAA8B,CAAC;AAMrE,eAAO,MAAM,iBAAiB,wBAAwB,CAAC;AAOvD,eAAO,MAAM,4BAA4B,6CAA8C,CAAC;AACxF,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAC;AAOtF,eAAO,MAAM,kCAAkC,OAAO,CAAC;AAKvD,eAAO,MAAM,kCAAkC,OAAO,CAAC;AAQvD,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAI5F,CAAC;AAGF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAQhG"}
@@ -0,0 +1,83 @@
1
+ // Provisional scheduler constants. EVERY value here is a calibration target
2
+ // (spec §10 — calibrate from shadow data); the loop runs on these placeholders
3
+ // until Stage 5. Single-sourced + exported so calibration has one home, mirroring
4
+ // EDGE_* / SHADOW_* in the curation layer.
5
+ // Review interval f(aged strength): MIN · 2^strength, hard-capped by MAX (the
6
+ // max-interval backstop — nothing rests longer than this without re-derivation).
7
+ export const CONSOLIDATE_MIN_INTERVAL_DAYS = 1;
8
+ export const CONSOLIDATE_MAX_INTERVAL_DAYS = 90; // aligns with EDGE_HALF_LIFE_DAYS
9
+ export function reviewIntervalDays(strength) {
10
+ const grown = CONSOLIDATE_MIN_INTERVAL_DAYS * 2 ** Math.max(0, strength);
11
+ return Math.min(grown, CONSOLIDATE_MAX_INTERVAL_DAYS);
12
+ }
13
+ // Event-blast attenuation: a forward path's reach = ∏(edge strengths); it stops
14
+ // where the product drops below this floor (spec §3.1, C-Q2).
15
+ export const CONSOLIDATE_PATH_STRENGTH_FLOOR = 0.1;
16
+ // Compute-budget partition (spec §3.3). Fractions of the per-session budget.
17
+ // backstop is GUARANTEED; periphery is blast-blind fairness; birth is one-time
18
+ // cold-start population. Provisional — tuned against B coverage metrics (§6.2).
19
+ export const CONSOLIDATE_SLICE_FRACTIONS = {
20
+ backstop: 0.25,
21
+ main: 0.45,
22
+ periphery: 0.15,
23
+ birth: 0.15,
24
+ };
25
+ // Stage 1 has no LLM calls, so "budget" = max queue items emitted per session.
26
+ // With Component A (Stage 2) this becomes the re-derivation-call cap.
27
+ export const CONSOLIDATE_DEFAULT_BUDGET = 50;
28
+ // --- Stage 2 (Component A) ----------------------------------------------------
29
+ // Panel size M: votes cast per due edge per session (spec §4.1, brief item 2).
30
+ // Starting M=2 — provisional, TBD — calibrate from shadow data.
31
+ export const CONSOLIDATE_PANEL_SIZE = 2;
32
+ // Birth-mode neighbor retrieval: top-K embedding neighbors per unprocessed doc
33
+ // (spec §4.0). 20 = the K in the §10.2 recall@20 kill condition.
34
+ export const CONSOLIDATE_BIRTH_TOP_K = 20;
35
+ // Default LLM model for re-derivation. Haiku 4.5 — cheapest tier where the
36
+ // task is "detect derivation," not "subtle reasoning." Override via the
37
+ // DAFTARI_CONSOLIDATE_MODEL env var when calibrating against bigger models.
38
+ export const CONSOLIDATE_DEFAULT_MODEL = "claude-haiku-4-5-20251001";
39
+ // The agent principal Stage 2 attributes its writes to (spec §8). The server
40
+ // is started as `--user agent:curation-loop --role curation-loop`; this string
41
+ // is the free-text `agent` claim on edge_observe/contest (the authenticated
42
+ // principal is recorded separately by the shadow path).
43
+ export const CONSOLIDATE_AGENT = "agent:curation-loop";
44
+ // Prompt-framing axis (v1 = the only varied axis, see brief item 3). Three
45
+ // deterministic templates that re-derive the same edge claim from different
46
+ // directions. Each template is independent of the others by *framing*, not
47
+ // by model or input — whether that is enough to decorrelate votes is the
48
+ // load-bearing question the decorrelation report (brief item 8) decides.
49
+ export const CONSOLIDATE_PROMPT_TEMPLATES = ["forward", "reverse", "contrast"];
50
+ // Decorrelation lift (brief item 8 / spec §10.2). `majority_accuracy −
51
+ // max(single_vote_accuracy)`. Retained as an informational metric: under the
52
+ // foundational-ordering prompt (which replaced the prompt-framing axes) the
53
+ // axes send an identical deterministic prompt, so lift is ~0 by construction —
54
+ // confirming the axes no longer decorrelate, the verdict doc's conclusion.
55
+ export const CONSOLIDATE_DECORRELATION_MIN_LIFT = 0.05;
56
+ // The report's PASS gate is now ACCURACY, not lift (spec §5 — it measures the
57
+ // foundational prompt's direction-recovery accuracy on the fixture). Matches the
58
+ // real-prose gate's 85% directional kill condition.
59
+ export const CONSOLIDATE_DIRECTION_MIN_ACCURACY = 0.85;
60
+ // LLM pricing — USD per million tokens, current as of 2026-06-16 for
61
+ // claude-haiku-4-5-20251001. VERIFY against current pricing before reading the
62
+ // cost-USD figure as gospel; this table is a recoverable mistake (the raw
63
+ // token counts ARE logged into the shadow journal, so historical sessions can
64
+ // be re-costed when prices move). Override per-model via the table; unknown
65
+ // models fall back to Haiku pricing with a flag in the report.
66
+ export const CONSOLIDATE_PRICING_PER_MTOKEN = {
67
+ "claude-haiku-4-5-20251001": { input: 1.0, output: 5.0 },
68
+ "claude-sonnet-4-6": { input: 3.0, output: 15.0 },
69
+ "claude-opus-4-8": { input: 15.0, output: 75.0 },
70
+ };
71
+ // True when the model has its own pricing row (vs falling back to Haiku rates).
72
+ export function isModelPriced(model) {
73
+ return Object.hasOwn(CONSOLIDATE_PRICING_PER_MTOKEN, model);
74
+ }
75
+ export function estimateCostUSD(model, inputTokens, outputTokens) {
76
+ const p = CONSOLIDATE_PRICING_PER_MTOKEN[model] ??
77
+ CONSOLIDATE_PRICING_PER_MTOKEN["claude-haiku-4-5-20251001"];
78
+ // Clamp negatives: a bad token count must not produce a negative "cost".
79
+ const inTok = Math.max(0, inputTokens);
80
+ const outTok = Math.max(0, outputTokens);
81
+ return (inTok * p.input + outTok * p.output) / 1_000_000;
82
+ }
83
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/consolidate/constants.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+EAA+E;AAC/E,kFAAkF;AAClF,2CAA2C;AAE3C,8EAA8E;AAC9E,iFAAiF;AACjF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,CAAC,CAAC,kCAAkC;AAEnF,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,MAAM,KAAK,GAAG,6BAA6B,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACzE,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC;AACxD,CAAC;AAED,gFAAgF;AAChF,8DAA8D;AAC9D,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,CAAC;AAEnD,6EAA6E;AAC7E,+EAA+E;AAC/E,gFAAgF;AAChF,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,IAAI;IACV,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,IAAI;CACH,CAAC;AA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EF,gFAAgF;AAChF,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,MAAM,CAAC,MAAM,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,WAAmB,EAAE,YAAoB;IACtF,MAAM,CAAC,GACL,8BAA8B,CAAC,KAAK,CAAC;QACrC,8BAA8B,CAAC,2BAA2B,CAAC,CAAC;IAC9D,yEAAyE;IACzE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;IACzC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,69 @@
1
+ import type { LlmClient } from "../eval/llm.js";
2
+ import { type Result } from "../frontmatter/types.js";
3
+ import { type ConsolidatePromptTemplate } from "./constants.js";
4
+ import { type DerivationVerdict } from "./derivation-prompt.js";
5
+ export type FixtureTruth = "derives" | "depends" | "neither";
6
+ export interface DecorrelationFixtureEdge {
7
+ id: string;
8
+ fromPath: string;
9
+ toPath: string;
10
+ fromContent: string;
11
+ toContent: string;
12
+ truth: FixtureTruth;
13
+ edgeClass?: "forward-temporal" | "backward-causal" | "symmetric";
14
+ rationale?: string;
15
+ }
16
+ export interface DecorrelationFixture {
17
+ version: 1;
18
+ edges: DecorrelationFixtureEdge[];
19
+ }
20
+ export type VoteVerdict = FixtureTruth | "symmetric";
21
+ export interface DecorrelationVote {
22
+ axis: ConsolidatePromptTemplate;
23
+ verdict: VoteVerdict | "error";
24
+ reason?: string;
25
+ }
26
+ export interface DecorrelationPerEdge {
27
+ id: string;
28
+ truth: FixtureTruth;
29
+ votes: DecorrelationVote[];
30
+ majorityVerdict: VoteVerdict | "tie" | "all-error";
31
+ majorityCorrect: boolean;
32
+ }
33
+ export interface DecorrelationMetrics {
34
+ singleVoteAccuracy: Record<ConsolidatePromptTemplate, number>;
35
+ majorityAccuracy: number;
36
+ liftOverBestSingle: number;
37
+ axisAgreementRate: number;
38
+ errorCorrelation: number;
39
+ }
40
+ export interface DecorrelationReport {
41
+ fixtureSize: number;
42
+ fixtureSource: string;
43
+ axes: readonly ConsolidatePromptTemplate[];
44
+ model: string;
45
+ metrics: DecorrelationMetrics;
46
+ passes: boolean;
47
+ perEdge: DecorrelationPerEdge[];
48
+ axisCounts: Record<ConsolidatePromptTemplate, {
49
+ correct: number;
50
+ wrong: number;
51
+ errored: number;
52
+ }>;
53
+ }
54
+ export declare function parseFixture(raw: unknown): Result<DecorrelationFixture, Error>;
55
+ export declare function loadFixture(path: string): Result<DecorrelationFixture, Error>;
56
+ export declare function mapDerivationToFixture(v: DerivationVerdict): VoteVerdict;
57
+ export interface DecorrelationRunDeps {
58
+ llm: LlmClient;
59
+ }
60
+ export interface DecorrelationRunOpts {
61
+ model: string;
62
+ axes?: readonly ConsolidatePromptTemplate[];
63
+ fixtureSource: string;
64
+ }
65
+ export declare function runDecorrelation(fixture: DecorrelationFixture, deps: DecorrelationRunDeps, opts: DecorrelationRunOpts): Promise<Result<DecorrelationReport, Error>>;
66
+ export declare function majorityVerdict(votes: DecorrelationVote[]): VoteVerdict | "tie" | "all-error";
67
+ export declare function computeMetrics(perEdge: DecorrelationPerEdge[], axes: readonly ConsolidatePromptTemplate[]): DecorrelationMetrics;
68
+ export declare function formatDecorrelationReport(report: DecorrelationReport): string;
69
+ //# sourceMappingURL=decorrelation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorrelation.d.ts","sourceRoot":"","sources":["../../src/consolidate/decorrelation.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEpE,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM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oBAAoB,EAAE,EAC/B,IAAI,EAAE,SAAS,yBAAyB,EAAE,GACzC,oBAAoB,CAsDtB;AAID,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAuB7E"}
@@ -0,0 +1,287 @@
1
+ // Axis-decorrelation report (brief item 8). Runs the v1 prompt-framing
2
+ // templates against a ground-truth-labeled fixture and asks: does the panel
3
+ // beat its best single axis? If not, the axes are decorative — multi-model
4
+ // must land inside Stage 2, not be deferred to Stage 5.
5
+ //
6
+ // THE FIXTURE IS THE GATE — not this code. This module ships the math + the
7
+ // CLI surface; the real ~50-pair hand-built fixture lives in
8
+ // tests/fixtures/decorrelation-fixture.json and is built in a separate
9
+ // session (see the chunk-6 handoff). Until it exists, the gate cannot fire
10
+ // meaningfully and the report is exercise-only.
11
+ //
12
+ // Verdict space: the fixture ground truth is the 3-class {derives, depends,
13
+ // neither} directional claim. The report now elicits with the SHARED
14
+ // foundational-ordering prompt birth runs (derivation-prompt.ts, closing F3) and
15
+ // maps its {related, premise} verdict onto that 3-class truth (+ a 4th
16
+ // "symmetric" vote that never matches a directional truth, so a fabricated
17
+ // mutual answer is correctly scored wrong).
18
+ //
19
+ // NOTE (axes are now redundant): the foundational prompt is order-agnostic and
20
+ // temperature-0 deterministic, so the three prompt-framing axes send an
21
+ // identical prompt and agree by construction — the report measures the
22
+ // foundational prompt's per-edge ACCURACY (spec §5), not prompt-framing
23
+ // decorrelation (which the verdict doc already found decorative). Collapsing the
24
+ // axes loop to a single judgment is a follow-up; the structure is retained here
25
+ // to keep the report/CLI surface stable.
26
+ import { readFileSync } from "node:fs";
27
+ import { err, ok } from "../frontmatter/types.js";
28
+ // Import birth's reconciliation so the report measures EXACTLY what birth ships.
29
+ import { reconcileDirection } from "./birth.js";
30
+ import { CONSOLIDATE_DECORRELATION_MIN_LIFT, CONSOLIDATE_DIRECTION_MIN_ACCURACY, CONSOLIDATE_PROMPT_TEMPLATES, } from "./constants.js";
31
+ import { DERIVATION_SYSTEM, DERIVATION_VERDICT_SCHEMA, derivationUserBody, parseDerivationVerdict, } from "./derivation-prompt.js";
32
+ // --- fixture I/O -------------------------------------------------------------
33
+ export function parseFixture(raw) {
34
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
35
+ return err(new Error("fixture: expected an object with `version` and `edges`"));
36
+ }
37
+ const obj = raw;
38
+ if (obj.version !== 1) {
39
+ return err(new Error(`fixture: unsupported version ${JSON.stringify(obj.version)}`));
40
+ }
41
+ if (!Array.isArray(obj.edges)) {
42
+ return err(new Error("fixture: `edges` must be an array"));
43
+ }
44
+ const edges = [];
45
+ for (let i = 0; i < obj.edges.length; i++) {
46
+ const e = obj.edges[i];
47
+ if (typeof e.id !== "string" ||
48
+ typeof e.fromPath !== "string" ||
49
+ typeof e.toPath !== "string" ||
50
+ typeof e.fromContent !== "string" ||
51
+ typeof e.toContent !== "string" ||
52
+ (e.truth !== "derives" && e.truth !== "depends" && e.truth !== "neither")) {
53
+ return err(new Error(`fixture: edge[${i}] malformed (need id, fromPath, toPath, fromContent, toContent, truth)`));
54
+ }
55
+ edges.push({
56
+ id: e.id,
57
+ fromPath: e.fromPath,
58
+ toPath: e.toPath,
59
+ fromContent: e.fromContent,
60
+ toContent: e.toContent,
61
+ truth: e.truth,
62
+ ...(typeof e.edgeClass === "string" &&
63
+ (e.edgeClass === "forward-temporal" ||
64
+ e.edgeClass === "backward-causal" ||
65
+ e.edgeClass === "symmetric")
66
+ ? { edgeClass: e.edgeClass }
67
+ : {}),
68
+ ...(typeof e.rationale === "string" ? { rationale: e.rationale } : {}),
69
+ });
70
+ }
71
+ return ok({ version: 1, edges });
72
+ }
73
+ export function loadFixture(path) {
74
+ let raw;
75
+ try {
76
+ raw = readFileSync(path, "utf-8");
77
+ }
78
+ catch (e) {
79
+ return err(new Error(`fixture: cannot read ${path}: ${e instanceof Error ? e.message : String(e)}`));
80
+ }
81
+ let parsed;
82
+ try {
83
+ parsed = JSON.parse(raw);
84
+ }
85
+ catch (e) {
86
+ return err(new Error(`fixture: invalid JSON: ${e instanceof Error ? e.message : String(e)}`));
87
+ }
88
+ return parseFixture(parsed);
89
+ }
90
+ // --- prompt + verdict mapping (shared foundational prompt, closing F3) --------
91
+ const MAX_DOC_CHARS = 1500;
92
+ function truncate(s) {
93
+ return s.length <= MAX_DOC_CHARS ? s : `${s.slice(0, MAX_DOC_CHARS)}\n…[truncated]`;
94
+ }
95
+ // Map the foundational {related, premise} verdict onto the fixture's 3-class
96
+ // directional truth (DOC A = fromPath/fromContent, DOC B = toPath/toContent):
97
+ // related:false → neither
98
+ // premise === "B" → A derives from B → "derives"
99
+ // premise === "A" → B derives from A → "depends"
100
+ // premise === "symmetric" → "symmetric" (never matches a directional truth)
101
+ export function mapDerivationToFixture(v) {
102
+ if (!v.related)
103
+ return "neither";
104
+ if (v.premise === "symmetric")
105
+ return "symmetric";
106
+ return v.premise === "B" ? "derives" : "depends";
107
+ }
108
+ // Run BOTH presentation orders and reconcile via birth's reconcileDirection
109
+ // (doc=from, neighbor=to), then map to the 3-class fixture truth:
110
+ // directed, premise=neighbor(to) → A derives from B → "derives"
111
+ // directed, premise=doc(from) → B derives from A → "depends"
112
+ // symmetric / order-contested → "symmetric" (no directional truth matches)
113
+ // unrelated → "neither"
114
+ // Any LLM/parse failure in either order yields "error".
115
+ async function reconcileEdgeToFixture(edge, elicit) {
116
+ // Order 1: DOC A = from, DOC B = to.
117
+ const r1 = await elicit(edge.fromPath, edge.fromContent, edge.toPath, edge.toContent);
118
+ if (!r1.ok)
119
+ return { verdict: "error", reason: r1.error.message };
120
+ const p1 = parseDerivationVerdict(r1.value.parsed);
121
+ if (!p1.ok)
122
+ return { verdict: "error", reason: p1.error.message };
123
+ // Order 2: DOC A = to, DOC B = from.
124
+ const r2 = await elicit(edge.toPath, edge.toContent, edge.fromPath, edge.fromContent);
125
+ if (!r2.ok)
126
+ return { verdict: "error", reason: r2.error.message };
127
+ const p2 = parseDerivationVerdict(r2.value.parsed);
128
+ if (!p2.ok)
129
+ return { verdict: "error", reason: p2.error.message };
130
+ const outcome = reconcileDirection(p1.value, p2.value);
131
+ const reason = p1.value.reason;
132
+ if (outcome.kind === "unrelated")
133
+ return { verdict: "neither", reason };
134
+ if (outcome.kind === "symmetric")
135
+ return { verdict: "symmetric", reason };
136
+ // directed: premise "neighbor" (=to) ⇒ derives; "doc" (=from) ⇒ depends.
137
+ return { verdict: outcome.premise === "neighbor" ? "derives" : "depends", reason };
138
+ }
139
+ export async function runDecorrelation(fixture, deps, opts) {
140
+ const axes = opts.axes ?? CONSOLIDATE_PROMPT_TEMPLATES;
141
+ const perEdge = [];
142
+ const axisCounts = {};
143
+ for (const a of axes)
144
+ axisCounts[a] = { correct: 0, wrong: 0, errored: 0 };
145
+ // One foundational elicitation per (edge, order) at temp 0. Birth runs BOTH
146
+ // orders and reconciles (option c), abstaining → symmetric on order-disagreement;
147
+ // the report mirrors that EXACTLY via birth's reconcileDirection so its accuracy
148
+ // is birth's trusted-directed rate, not a single-order upper bound (closes F3).
149
+ const elicit = (aPath, aContent, bPath, bContent) => deps.llm.completeJson({
150
+ model: opts.model,
151
+ system: DERIVATION_SYSTEM,
152
+ user: derivationUserBody(aPath, truncate(aContent), bPath, truncate(bContent)),
153
+ schema: DERIVATION_VERDICT_SCHEMA,
154
+ temperature: 0,
155
+ });
156
+ for (const edge of fixture.edges) {
157
+ // Reconcile ONCE per edge (the prompt-framing axes are identical under the
158
+ // deterministic prompt), then emit the same vote for every axis so the
159
+ // per-axis/majority/lift machinery is preserved.
160
+ const verdict = await reconcileEdgeToFixture(edge, elicit);
161
+ const votes = axes.map((axis) => ({
162
+ axis,
163
+ verdict: verdict.verdict,
164
+ ...(verdict.reason ? { reason: verdict.reason } : {}),
165
+ }));
166
+ for (const axis of axes) {
167
+ if (verdict.verdict === "error")
168
+ axisCounts[axis].errored++;
169
+ else if (verdict.verdict === edge.truth)
170
+ axisCounts[axis].correct++;
171
+ else
172
+ axisCounts[axis].wrong++;
173
+ }
174
+ const majority = majorityVerdict(votes);
175
+ perEdge.push({
176
+ id: edge.id,
177
+ truth: edge.truth,
178
+ votes,
179
+ majorityVerdict: majority,
180
+ majorityCorrect: majority === edge.truth,
181
+ });
182
+ }
183
+ const metrics = computeMetrics(perEdge, axes);
184
+ return ok({
185
+ fixtureSize: fixture.edges.length,
186
+ fixtureSource: opts.fixtureSource,
187
+ axes,
188
+ model: opts.model,
189
+ metrics,
190
+ passes: metrics.majorityAccuracy >= CONSOLIDATE_DIRECTION_MIN_ACCURACY,
191
+ perEdge,
192
+ axisCounts: axisCounts,
193
+ });
194
+ }
195
+ // --- math (exported for unit testing) ---------------------------------------
196
+ // Most common non-error verdict. Returns "tie" when the top two are tied (the
197
+ // panel can't decide), or "all-error" when every vote errored.
198
+ export function majorityVerdict(votes) {
199
+ const counts = new Map();
200
+ let nonErrors = 0;
201
+ for (const v of votes) {
202
+ if (v.verdict === "error")
203
+ continue;
204
+ counts.set(v.verdict, (counts.get(v.verdict) ?? 0) + 1);
205
+ nonErrors++;
206
+ }
207
+ if (nonErrors === 0)
208
+ return "all-error";
209
+ const sorted = [...counts.entries()].sort((a, b) => b[1] - a[1]);
210
+ if (sorted.length > 1 && sorted[0][1] === sorted[1][1])
211
+ return "tie";
212
+ return sorted[0][0];
213
+ }
214
+ export function computeMetrics(perEdge, axes) {
215
+ const singleVoteAccuracy = {};
216
+ for (const a of axes) {
217
+ let correct = 0;
218
+ let nonError = 0;
219
+ for (const row of perEdge) {
220
+ const v = row.votes.find((x) => x.axis === a);
221
+ if (!v || v.verdict === "error")
222
+ continue;
223
+ nonError++;
224
+ if (v.verdict === row.truth)
225
+ correct++;
226
+ }
227
+ singleVoteAccuracy[a] = nonError === 0 ? 0 : correct / nonError;
228
+ }
229
+ const majCorrect = perEdge.filter((p) => p.majorityCorrect).length;
230
+ const majorityAccuracy = perEdge.length === 0 ? 0 : majCorrect / perEdge.length;
231
+ const bestSingle = Math.max(0, ...axes.map((a) => singleVoteAccuracy[a]));
232
+ const liftOverBestSingle = majorityAccuracy - bestSingle;
233
+ // Axis agreement: of rows where ALL axes returned a verdict, fraction where
234
+ // all verdicts matched.
235
+ let allVoted = 0;
236
+ let allAgreed = 0;
237
+ for (const row of perEdge) {
238
+ const nonErr = row.votes.filter((v) => v.verdict !== "error");
239
+ if (nonErr.length < axes.length)
240
+ continue;
241
+ allVoted++;
242
+ const unique = new Set(nonErr.map((v) => v.verdict));
243
+ if (unique.size === 1)
244
+ allAgreed++;
245
+ }
246
+ const axisAgreementRate = allVoted === 0 ? 0 : allAgreed / allVoted;
247
+ // Error correlation: of rows where >=2 axes were wrong, fraction where ALL
248
+ // the wrong axes gave the SAME wrong verdict. High = the axes share a
249
+ // failure mode (not independent), even if `lift` looked acceptable.
250
+ let multiWrong = 0;
251
+ let multiWrongAgreed = 0;
252
+ for (const row of perEdge) {
253
+ const wrong = row.votes.filter((v) => v.verdict !== "error" && v.verdict !== row.truth);
254
+ if (wrong.length < 2)
255
+ continue;
256
+ multiWrong++;
257
+ const uniqueWrong = new Set(wrong.map((v) => v.verdict));
258
+ if (uniqueWrong.size === 1)
259
+ multiWrongAgreed++;
260
+ }
261
+ const errorCorrelation = multiWrong === 0 ? 0 : multiWrongAgreed / multiWrong;
262
+ return {
263
+ singleVoteAccuracy: singleVoteAccuracy,
264
+ majorityAccuracy,
265
+ liftOverBestSingle,
266
+ axisAgreementRate,
267
+ errorCorrelation,
268
+ };
269
+ }
270
+ // --- text report ------------------------------------------------------------
271
+ export function formatDecorrelationReport(report) {
272
+ const lines = [];
273
+ lines.push(`decorrelation report — fixture: ${report.fixtureSource}`);
274
+ lines.push(` size: ${report.fixtureSize} edges | axes: ${report.axes.join(", ")} | model: ${report.model}`);
275
+ lines.push(` per-axis accuracy:`);
276
+ for (const a of report.axes) {
277
+ const c = report.axisCounts[a];
278
+ lines.push(` ${a}: ${(report.metrics.singleVoteAccuracy[a] * 100).toFixed(1)}% (correct ${c.correct} / wrong ${c.wrong} / errored ${c.errored})`);
279
+ }
280
+ lines.push(` majority accuracy: ${(report.metrics.majorityAccuracy * 100).toFixed(1)}%`);
281
+ lines.push(` lift over best single: ${(report.metrics.liftOverBestSingle * 100).toFixed(2)} pp (informational; min-lift ${(CONSOLIDATE_DECORRELATION_MIN_LIFT * 100).toFixed(1)} pp — axes identical under the foundational prompt)`);
282
+ lines.push(` axis agreement rate: ${(report.metrics.axisAgreementRate * 100).toFixed(1)}%`);
283
+ lines.push(` error correlation: ${(report.metrics.errorCorrelation * 100).toFixed(1)}%`);
284
+ lines.push(` VERDICT: ${report.passes ? "PASS — foundational prompt recovers direction" : "FAIL — direction recovery below the accuracy bar"} (accuracy gate: >= ${(CONSOLIDATE_DIRECTION_MIN_ACCURACY * 100).toFixed(0)}%)`);
285
+ return `${lines.join("\n")}\n`;
286
+ }
287
+ //# sourceMappingURL=decorrelation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorrelation.js","sourceRoot":"","sources":["../../src/consolidate/decorrelation.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,4EAA4E;AAC5E,2EAA2E;AAC3E,wDAAwD;AACxD,EAAE;AACF,4EAA4E;AAC5E,6DAA6D;AAC7D,uEAAuE;AACvE,2EAA2E;AAC3E,gDAAgD;AAChD,EAAE;AACF,4EAA4E;AAC5E,qEAAqE;AACrE,iFAAiF;AACjF,uEAAuE;AACvE,2EAA2E;AAC3E,4CAA4C;AAC5C,EAAE;AACF,+EAA+E;AAC/E,wEAAwE;AACxE,uEAAuE;AACvE,wEAAwE;AACxE,iFAAiF;AACjF,gFAAgF;AAChF,yCAAyC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,yBAAyB,CAAC;AAC/D,iFAAiF;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EACL,kCAAkC,EAClC,kCAAkC,EAClC,4BAA4B,GAE7B,MA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