daftari 1.21.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 (65) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.js +7 -0
  4. package/dist/cli.js.map +1 -1
  5. package/dist/consolidate/birth.d.ts +74 -0
  6. package/dist/consolidate/birth.d.ts.map +1 -0
  7. package/dist/consolidate/birth.js +253 -0
  8. package/dist/consolidate/birth.js.map +1 -0
  9. package/dist/consolidate/clocks.d.ts +15 -0
  10. package/dist/consolidate/clocks.d.ts.map +1 -0
  11. package/dist/consolidate/clocks.js +127 -0
  12. package/dist/consolidate/clocks.js.map +1 -0
  13. package/dist/consolidate/constants.d.ts +26 -0
  14. package/dist/consolidate/constants.d.ts.map +1 -0
  15. package/dist/consolidate/constants.js +83 -0
  16. package/dist/consolidate/constants.js.map +1 -0
  17. package/dist/consolidate/decorrelation.d.ts +69 -0
  18. package/dist/consolidate/decorrelation.d.ts.map +1 -0
  19. package/dist/consolidate/decorrelation.js +287 -0
  20. package/dist/consolidate/decorrelation.js.map +1 -0
  21. package/dist/consolidate/derivation-prompt.d.ts +28 -0
  22. package/dist/consolidate/derivation-prompt.d.ts.map +1 -0
  23. package/dist/consolidate/derivation-prompt.js +72 -0
  24. package/dist/consolidate/derivation-prompt.js.map +1 -0
  25. package/dist/consolidate/edge-write.d.ts +10 -0
  26. package/dist/consolidate/edge-write.d.ts.map +1 -0
  27. package/dist/consolidate/edge-write.js +76 -0
  28. package/dist/consolidate/edge-write.js.map +1 -0
  29. package/dist/consolidate/index.d.ts +2 -0
  30. package/dist/consolidate/index.d.ts.map +1 -0
  31. package/dist/consolidate/index.js +477 -0
  32. package/dist/consolidate/index.js.map +1 -0
  33. package/dist/consolidate/priority.d.ts +25 -0
  34. package/dist/consolidate/priority.d.ts.map +1 -0
  35. package/dist/consolidate/priority.js +103 -0
  36. package/dist/consolidate/priority.js.map +1 -0
  37. package/dist/consolidate/revision.d.ts +75 -0
  38. package/dist/consolidate/revision.d.ts.map +1 -0
  39. package/dist/consolidate/revision.js +232 -0
  40. package/dist/consolidate/revision.js.map +1 -0
  41. package/dist/consolidate/state.d.ts +10 -0
  42. package/dist/consolidate/state.d.ts.map +1 -0
  43. package/dist/consolidate/state.js +54 -0
  44. package/dist/consolidate/state.js.map +1 -0
  45. package/dist/curation/edges.d.ts +5 -0
  46. package/dist/curation/edges.d.ts.map +1 -1
  47. package/dist/curation/edges.js +82 -9
  48. package/dist/curation/edges.js.map +1 -1
  49. package/dist/curation/shadow.d.ts.map +1 -1
  50. package/dist/curation/shadow.js +10 -0
  51. package/dist/curation/shadow.js.map +1 -1
  52. package/dist/eval/llm.d.ts +3 -1
  53. package/dist/eval/llm.d.ts.map +1 -1
  54. package/dist/eval/llm.js +6 -2
  55. package/dist/eval/llm.js.map +1 -1
  56. package/dist/index.js +1 -1
  57. package/dist/storage/index-db.d.ts +1 -0
  58. package/dist/storage/index-db.d.ts.map +1 -1
  59. package/dist/storage/index-db.js +14 -9
  60. package/dist/storage/index-db.js.map +1 -1
  61. package/dist/utils/git.d.ts +1 -0
  62. package/dist/utils/git.d.ts.map +1 -1
  63. package/dist/utils/git.js +19 -0
  64. package/dist/utils/git.js.map +1 -1
  65. package/package.json +1 -1
@@ -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;AAEX,+EAA+E;AAC/E,sEAAsE;AACtE,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAE7C,iFAAiF;AAEjF,+EAA+E;AAC/E,gEAAgE;AAChE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,+EAA+E;AAC/E,iEAAiE;AACjE,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C,2EAA2E;AAC3E,wEAAwE;AACxE,4EAA4E;AAC5E,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AAErE,6EAA6E;AAC7E,+EAA+E;AAC/E,4EAA4E;AAC5E,wDAAwD;A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AAC,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,yBAAyB,CAAC;AAG/D,OAAO,EAIL,KAAK,yBAAyB,EAC/B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGL,KAAK,iBAAiB,EAGvB,MAAM,wBAAwB,CAAC;AAIhC,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAE7D,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,YAAY,CAAC;IAGpB,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E,MAAM,CAAA;KAAE,CACpD,CAAC;CACH;AAID,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,oBAAoB,EAAE,KAAK,CAAC,CA6C9E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAgB7E;AAeD,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,iBAAiB,GAAG,WAAW,CAIxE;AAyCD,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,SAAS,CAAC;CAChB;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IAId,IAAI,CAAC,EAAE,SAAS,yBAAyB,EAAE,CAAC;IAC5C,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,oBAAoB,EAC7B,IAAI,EAAE,oBAAoB,EAC1B,IAAI,EAAE,oBAAoB,GACzB,OAAO,CAAC,MAAM,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC,CA2D7C;AAMD,wBAAgB,eAAe,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,WAAW,GAAG,KAAK,GAAG,WAAW,CAY7F;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,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,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EAEzB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAqFhC,gFAAgF;AAEhF,MAAM,UAAU,YAAY,CAAC,GAAY;IACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAClE,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC,CAAC;IAClF,CAAC;IACD,MAAM,GAAG,GAAG,GAA8B,CAAC;IAC3C,IAAI,GAAG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CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CACpN,CAAC;IACF,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { type Result } from "../frontmatter/types.js";
2
+ export type PremiseSide = "A" | "B" | "symmetric";
3
+ export interface DerivationVerdict {
4
+ related: boolean;
5
+ premise: PremiseSide | null;
6
+ reason: string;
7
+ }
8
+ export declare const DERIVATION_VERDICT_SCHEMA: {
9
+ readonly type: "object";
10
+ readonly required: readonly ["related", "premise", "reason"];
11
+ readonly properties: {
12
+ readonly related: {
13
+ readonly type: "boolean";
14
+ };
15
+ readonly premise: {
16
+ readonly enum: readonly ["A", "B", "symmetric"];
17
+ readonly description: "which doc is the load-bearing premise; ignored when related is false";
18
+ };
19
+ readonly reason: {
20
+ readonly type: "string";
21
+ readonly minLength: 1;
22
+ };
23
+ };
24
+ };
25
+ export declare const DERIVATION_SYSTEM: string;
26
+ export declare function derivationUserBody(aPath: string, aContent: string, bPath: string, bContent: string): string;
27
+ export declare function parseDerivationVerdict(raw: unknown): Result<DerivationVerdict, Error>;
28
+ //# sourceMappingURL=derivation-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derivation-prompt.d.ts","sourceRoot":"","sources":["../../src/consolidate/derivation-prompt.ts"],"names":[],"mappings":"AAeA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAE/D,MAAM,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,WAAW,CAAC;AAElD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB;AAMD,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;CAW5B,CAAC;AAEX,eAAO,MAAM,iBAAiB,QAKmC,CAAC;AAKlE,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,MAAM,CAYR;AAKD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAwBrF"}
@@ -0,0 +1,72 @@
1
+ // Shared foundational-ordering derivation elicitation (spec §3.1).
2
+ //
3
+ // Replaces birth.ts's private derives/depends/neither token and decorrelation's
4
+ // duplicate. The judgment is two-part:
5
+ // - related: is there a load-bearing derivation at all? (the reliable signal —
6
+ // detection + promiscuity rejection; related=false ⇒ no edge)
7
+ // - premise: foundational ordering — which doc is the load-bearing premise, the
8
+ // one that must be established first for the other to make sense. "symmetric"
9
+ // when each conditions the other; null only on parse failure.
10
+ //
11
+ // The prompt is presentation-order-agnostic by construction: it asks for a content
12
+ // role ("which is the premise"), never "does A derive from B", so it carries no
13
+ // position/token bias (validated ~50% DOC1-bias at temp 0). Direction is elicited
14
+ // at temperature 0 — a factual, deterministic judgment, not a creative one.
15
+ import { err, ok } from "../frontmatter/types.js";
16
+ const PREMISE_SIDES = new Set(["A", "B", "symmetric"]);
17
+ // Embedded in the system prompt as a hint to the LLM (completeJson does not do
18
+ // strict JSON-Schema validation; parseDerivationVerdict is the real gate).
19
+ export const DERIVATION_VERDICT_SCHEMA = {
20
+ type: "object",
21
+ required: ["related", "premise", "reason"],
22
+ properties: {
23
+ related: { type: "boolean" },
24
+ premise: {
25
+ enum: ["A", "B", "symmetric"],
26
+ description: "which doc is the load-bearing premise; ignored when related is false",
27
+ },
28
+ reason: { type: "string", minLength: 1 },
29
+ },
30
+ };
31
+ export const DERIVATION_SYSTEM = "You assess whether one document's central claim is a load-bearing derivation of " +
32
+ "another's, and if so which is the foundational premise. A load-bearing dependency " +
33
+ "means one claim rests on the other as a premise it could not stand without — not a " +
34
+ "passing reference, a citation, or mere co-occurrence. Be conservative: when the " +
35
+ "dependency is shallow or ambiguous, judge that there is none.";
36
+ // Foundational-ordering question. By contract this body contains no "derive"
37
+ // token and no "[template:" tag — it asks for a content role, not a directional
38
+ // verb, so it is presentation-order-agnostic.
39
+ export function derivationUserBody(aPath, aContent, bPath, bContent) {
40
+ return (`DOC A (path: ${aPath}):\n${aContent}\n\n` +
41
+ `DOC B (path: ${bPath}):\n${bContent}\n\n` +
42
+ "First: is there a load-bearing dependency between these two central claims — does " +
43
+ "one rest on the other as a foundational premise (not a passing mention, a citation, " +
44
+ "or mere co-occurrence)? If there is no such dependency, set related to false.\n\n" +
45
+ "If there is a dependency: which of DOC A or DOC B is the load-bearing premise — the " +
46
+ 'one that would have to be established first for the other to make sense? Answer "A" ' +
47
+ 'or "B". If each claim conditions the other so that neither could be established first, ' +
48
+ 'answer "symmetric".\n\nReturn JSON.');
49
+ }
50
+ // Mirrors birth's reject-and-continue parser, in the {related, premise} space.
51
+ // A false `related` discards any premise (-> null); a true `related` requires a
52
+ // valid premise side. `reason` is always required.
53
+ export function parseDerivationVerdict(raw) {
54
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
55
+ return err(new Error("verdict: expected object"));
56
+ }
57
+ const obj = raw;
58
+ if (typeof obj.related !== "boolean") {
59
+ return err(new Error(`verdict: 'related' must be a boolean, got ${JSON.stringify(obj.related)}`));
60
+ }
61
+ if (typeof obj.reason !== "string" || obj.reason.trim().length === 0) {
62
+ return err(new Error("verdict: 'reason' is required (and non-empty)"));
63
+ }
64
+ if (obj.related === false) {
65
+ return ok({ related: false, premise: null, reason: obj.reason });
66
+ }
67
+ if (typeof obj.premise !== "string" || !PREMISE_SIDES.has(obj.premise)) {
68
+ return err(new Error(`verdict: 'premise' must be one of A|B|symmetric, got ${JSON.stringify(obj.premise)}`));
69
+ }
70
+ return ok({ related: true, premise: obj.premise, reason: obj.reason });
71
+ }
72
+ //# sourceMappingURL=derivation-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derivation-prompt.js","source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C,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAsB,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;AACxF,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type ContestEdgeInput, type DerivesFromEdge, type ObserveEdgeInput } from "../curation/edges.js";
2
+ import { type Result } from "../frontmatter/types.js";
3
+ export interface EdgeWriteConfig {
4
+ vaultRoot: string;
5
+ shadowMode: boolean;
6
+ principal?: string;
7
+ }
8
+ export declare function makeObserve(config: EdgeWriteConfig): (input: ObserveEdgeInput) => Promise<Result<DerivesFromEdge, Error>>;
9
+ export declare function makeContest(config: EdgeWriteConfig): (input: ContestEdgeInput) => Promise<Result<DerivesFromEdge, Error>>;
10
+ //# sourceMappingURL=edge-write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge-write.d.ts","sourceRoot":"","sources":["../../src/consolidate/edge-write.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAEtB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAM,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IAIpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA2BD,wBAAgB,WAAW,CACzB,MAAM,EAAE,eAAe,GACtB,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,CAuBtE;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,eAAe,GACtB,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,CAiBtE"}