daftari 1.32.0 → 3.0.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 (200) hide show
  1. package/CHANGELOG.md +123 -1
  2. package/README.md +472 -342
  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 +16 -0
  6. package/dist/access/rbac.js.map +1 -1
  7. package/dist/asof/index.d.ts.map +1 -1
  8. package/dist/asof/index.js +23 -2
  9. package/dist/asof/index.js.map +1 -1
  10. package/dist/asof/report.d.ts.map +1 -1
  11. package/dist/asof/report.js +24 -0
  12. package/dist/asof/report.js.map +1 -1
  13. package/dist/asof/snapshot.d.ts +7 -1
  14. package/dist/asof/snapshot.d.ts.map +1 -1
  15. package/dist/asof/snapshot.js +28 -1
  16. package/dist/asof/snapshot.js.map +1 -1
  17. package/dist/backfill/derive.d.ts.map +1 -1
  18. package/dist/backfill/derive.js +8 -0
  19. package/dist/backfill/derive.js.map +1 -1
  20. package/dist/canary/fixtures.d.ts +12 -0
  21. package/dist/canary/fixtures.d.ts.map +1 -0
  22. package/dist/canary/fixtures.js +132 -0
  23. package/dist/canary/fixtures.js.map +1 -0
  24. package/dist/canary/index.d.ts +16 -0
  25. package/dist/canary/index.d.ts.map +1 -0
  26. package/dist/canary/index.js +105 -0
  27. package/dist/canary/index.js.map +1 -0
  28. package/dist/canary/run.d.ts +39 -0
  29. package/dist/canary/run.d.ts.map +1 -0
  30. package/dist/canary/run.js +266 -0
  31. package/dist/canary/run.js.map +1 -0
  32. package/dist/canary/stats.d.ts +36 -0
  33. package/dist/canary/stats.d.ts.map +1 -0
  34. package/dist/canary/stats.js +143 -0
  35. package/dist/canary/stats.js.map +1 -0
  36. package/dist/canon/index.d.ts +15 -0
  37. package/dist/canon/index.d.ts.map +1 -0
  38. package/dist/canon/index.js +167 -0
  39. package/dist/canon/index.js.map +1 -0
  40. package/dist/canon/resolve.d.ts +12 -0
  41. package/dist/canon/resolve.d.ts.map +1 -0
  42. package/dist/canon/resolve.js +67 -0
  43. package/dist/canon/resolve.js.map +1 -0
  44. package/dist/canon/topic.d.ts +20 -0
  45. package/dist/canon/topic.d.ts.map +1 -0
  46. package/dist/canon/topic.js +81 -0
  47. package/dist/canon/topic.js.map +1 -0
  48. package/dist/canon/types.d.ts +37 -0
  49. package/dist/canon/types.d.ts.map +1 -0
  50. package/dist/canon/types.js +9 -0
  51. package/dist/canon/types.js.map +1 -0
  52. package/dist/cli.d.ts.map +1 -1
  53. package/dist/cli.js +6 -0
  54. package/dist/cli.js.map +1 -1
  55. package/dist/court/index.d.ts.map +1 -1
  56. package/dist/court/index.js +48 -0
  57. package/dist/court/index.js.map +1 -1
  58. package/dist/court/triage.d.ts +5 -0
  59. package/dist/court/triage.d.ts.map +1 -0
  60. package/dist/court/triage.js +71 -0
  61. package/dist/court/triage.js.map +1 -0
  62. package/dist/curation/lint-voice.d.ts +3 -0
  63. package/dist/curation/lint-voice.d.ts.map +1 -0
  64. package/dist/curation/lint-voice.js +87 -0
  65. package/dist/curation/lint-voice.js.map +1 -0
  66. package/dist/curation/lint.d.ts +5 -1
  67. package/dist/curation/lint.d.ts.map +1 -1
  68. package/dist/curation/lint.js +41 -5
  69. package/dist/curation/lint.js.map +1 -1
  70. package/dist/curation/read-heat.d.ts +16 -0
  71. package/dist/curation/read-heat.d.ts.map +1 -0
  72. package/dist/curation/read-heat.js +52 -0
  73. package/dist/curation/read-heat.js.map +1 -0
  74. package/dist/curation/structural.d.ts +1 -1
  75. package/dist/curation/structural.d.ts.map +1 -1
  76. package/dist/curation/structural.js +8 -7
  77. package/dist/curation/structural.js.map +1 -1
  78. package/dist/curation/tension-triage.d.ts +57 -0
  79. package/dist/curation/tension-triage.d.ts.map +1 -0
  80. package/dist/curation/tension-triage.js +155 -0
  81. package/dist/curation/tension-triage.js.map +1 -0
  82. package/dist/curation/validity.d.ts +20 -0
  83. package/dist/curation/validity.d.ts.map +1 -0
  84. package/dist/curation/validity.js +191 -0
  85. package/dist/curation/validity.js.map +1 -0
  86. package/dist/fence/detect.d.ts +10 -0
  87. package/dist/fence/detect.d.ts.map +1 -0
  88. package/dist/fence/detect.js +161 -0
  89. package/dist/fence/detect.js.map +1 -0
  90. package/dist/fence/index.d.ts +22 -0
  91. package/dist/fence/index.d.ts.map +1 -0
  92. package/dist/fence/index.js +117 -0
  93. package/dist/fence/index.js.map +1 -0
  94. package/dist/frontmatter/schema.d.ts.map +1 -1
  95. package/dist/frontmatter/schema.js +28 -1
  96. package/dist/frontmatter/schema.js.map +1 -1
  97. package/dist/frontmatter/types.d.ts +6 -1
  98. package/dist/frontmatter/types.d.ts.map +1 -1
  99. package/dist/frontmatter/types.js +8 -0
  100. package/dist/frontmatter/types.js.map +1 -1
  101. package/dist/holders/registry.d.ts +8 -0
  102. package/dist/holders/registry.d.ts.map +1 -0
  103. package/dist/holders/registry.js +18 -0
  104. package/dist/holders/registry.js.map +1 -0
  105. package/dist/holders/types.d.ts +10 -0
  106. package/dist/holders/types.d.ts.map +1 -0
  107. package/dist/holders/types.js +2 -0
  108. package/dist/holders/types.js.map +1 -0
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +10 -6
  111. package/dist/index.js.map +1 -1
  112. package/dist/interview/questions.d.ts.map +1 -1
  113. package/dist/interview/questions.js +41 -9
  114. package/dist/interview/questions.js.map +1 -1
  115. package/dist/resources.d.ts +27 -0
  116. package/dist/resources.d.ts.map +1 -0
  117. package/dist/resources.js +169 -0
  118. package/dist/resources.js.map +1 -0
  119. package/dist/search/current-source.d.ts +1 -0
  120. package/dist/search/current-source.d.ts.map +1 -1
  121. package/dist/search/current-source.js +3 -1
  122. package/dist/search/current-source.js.map +1 -1
  123. package/dist/search/hybrid.d.ts +6 -1
  124. package/dist/search/hybrid.d.ts.map +1 -1
  125. package/dist/search/hybrid.js +23 -4
  126. package/dist/search/hybrid.js.map +1 -1
  127. package/dist/search/reindex.d.ts.map +1 -1
  128. package/dist/search/reindex.js +48 -13
  129. package/dist/search/reindex.js.map +1 -1
  130. package/dist/search/valid-at-source.d.ts +25 -0
  131. package/dist/search/valid-at-source.d.ts.map +1 -0
  132. package/dist/search/valid-at-source.js +131 -0
  133. package/dist/search/valid-at-source.js.map +1 -0
  134. package/dist/serve/index.d.ts.map +1 -1
  135. package/dist/serve/index.js +58 -89
  136. package/dist/serve/index.js.map +1 -1
  137. package/dist/server.d.ts +3 -1
  138. package/dist/server.d.ts.map +1 -1
  139. package/dist/server.js +159 -11
  140. package/dist/server.js.map +1 -1
  141. package/dist/sleep/cycle.d.ts.map +1 -1
  142. package/dist/sleep/cycle.js +38 -6
  143. package/dist/sleep/cycle.js.map +1 -1
  144. package/dist/storage/index-db.d.ts +7 -1
  145. package/dist/storage/index-db.d.ts.map +1 -1
  146. package/dist/storage/index-db.js +133 -8
  147. package/dist/storage/index-db.js.map +1 -1
  148. package/dist/tools/canon.d.ts +3 -0
  149. package/dist/tools/canon.d.ts.map +1 -0
  150. package/dist/tools/canon.js +177 -0
  151. package/dist/tools/canon.js.map +1 -0
  152. package/dist/tools/consumes.d.ts.map +1 -1
  153. package/dist/tools/consumes.js +47 -1
  154. package/dist/tools/consumes.js.map +1 -1
  155. package/dist/tools/curation.d.ts +4 -0
  156. package/dist/tools/curation.d.ts.map +1 -1
  157. package/dist/tools/curation.js +647 -3
  158. package/dist/tools/curation.js.map +1 -1
  159. package/dist/tools/edge-staleness.d.ts.map +1 -1
  160. package/dist/tools/edge-staleness.js +115 -0
  161. package/dist/tools/edge-staleness.js.map +1 -1
  162. package/dist/tools/edges.d.ts.map +1 -1
  163. package/dist/tools/edges.js +94 -0
  164. package/dist/tools/edges.js.map +1 -1
  165. package/dist/tools/read.d.ts +14 -0
  166. package/dist/tools/read.d.ts.map +1 -1
  167. package/dist/tools/read.js +385 -6
  168. package/dist/tools/read.js.map +1 -1
  169. package/dist/tools/receipt.d.ts +1 -1
  170. package/dist/tools/receipt.d.ts.map +1 -1
  171. package/dist/tools/receipt.js +147 -2
  172. package/dist/tools/receipt.js.map +1 -1
  173. package/dist/tools/search.d.ts.map +1 -1
  174. package/dist/tools/search.js +456 -5
  175. package/dist/tools/search.js.map +1 -1
  176. package/dist/tools/staged-actions.d.ts +7 -0
  177. package/dist/tools/staged-actions.d.ts.map +1 -1
  178. package/dist/tools/staged-actions.js +106 -2
  179. package/dist/tools/staged-actions.js.map +1 -1
  180. package/dist/tools/themes.d.ts.map +1 -1
  181. package/dist/tools/themes.js +120 -0
  182. package/dist/tools/themes.js.map +1 -1
  183. package/dist/tools/tier1.d.ts.map +1 -1
  184. package/dist/tools/tier1.js +56 -0
  185. package/dist/tools/tier1.js.map +1 -1
  186. package/dist/tools/tier2.d.ts.map +1 -1
  187. package/dist/tools/tier2.js +111 -1
  188. package/dist/tools/tier2.js.map +1 -1
  189. package/dist/tools/witness.d.ts.map +1 -1
  190. package/dist/tools/witness.js +93 -0
  191. package/dist/tools/witness.js.map +1 -1
  192. package/dist/tools/write.d.ts +8 -0
  193. package/dist/tools/write.d.ts.map +1 -1
  194. package/dist/tools/write.js +391 -3
  195. package/dist/tools/write.js.map +1 -1
  196. package/dist/utils/config.d.ts +2 -0
  197. package/dist/utils/config.d.ts.map +1 -1
  198. package/dist/utils/config.js +74 -0
  199. package/dist/utils/config.js.map +1 -1
  200. package/package.json +5 -2
@@ -0,0 +1,155 @@
1
+ // Tension Triage Card (Story 1) — the pure engine.
2
+ //
3
+ // Composes the vault's LIVE tensions into a human-legible card: each tension
4
+ // grouped by cluster, annotated with its blast, and — per contested side —
5
+ // tier, confidence, and read-heat. The point is legibility, not automation:
6
+ // this function computes NO composite severity score. Ranking the queue is the
7
+ // human's job in v0; a learned priority function is a later, separate concern.
8
+ //
9
+ // Purity: all vault-derived inputs (doc metadata, read-heat, per-tension blast)
10
+ // are passed in already resolved, so the composition is testable with synthetic
11
+ // data and never touches the filesystem or the RBAC layer. The async loader in
12
+ // the tool wires the real vault reads.
13
+ import { err, ok } from "../frontmatter/types.js";
14
+ import { computeReadHeat } from "./read-heat.js";
15
+ import { readReadLog } from "./read-log.js";
16
+ import { ageInDays } from "./staleness.js";
17
+ import { listTensions } from "./tension.js";
18
+ import { bucketHiddenDownstream, buildReverseLinkMap, buildReverseSourceMap, computeBlast, } from "./tension-blast.js";
19
+ import { computeTensionClusters } from "./tension-clusters.js";
20
+ import { loadDocuments } from "./vault-docs.js";
21
+ const READ_HEAT_WINDOW_DAYS = 30;
22
+ function sideFor(path, claim, inputs) {
23
+ const m = inputs.docMeta.get(path);
24
+ return {
25
+ path,
26
+ claim,
27
+ tier: m ? m.tier : null,
28
+ confidence: m ? m.confidence : null,
29
+ read_heat: inputs.readHeat.get(path) ?? null,
30
+ criticality: m ? m.criticality : null,
31
+ provenance: m ? m.provenance : null,
32
+ updated_by: m ? m.updated_by : null,
33
+ };
34
+ }
35
+ function enrich(tension, inputs, now) {
36
+ const b = tension.id ? inputs.blastByTension.get(tension.id) : undefined;
37
+ return {
38
+ id: tension.id ?? "",
39
+ title: tension.title,
40
+ kind: tension.kind,
41
+ age_days: ageInDays(tension.date, now),
42
+ a: sideFor(tension.sourceA, tension.claimA, inputs),
43
+ b: sideFor(tension.sourceB, tension.claimB, inputs),
44
+ primary_blast: b ? b.primary_blast : null,
45
+ advisory_blast: b ? b.advisory_blast : null,
46
+ hidden_downstream: b ? b.hidden_downstream : null,
47
+ };
48
+ }
49
+ // Live-contested scope, mirroring tension-clusters' inScope: unresolved,
50
+ // non-accepted, real two-endpoint edge. Kept local so the module has no
51
+ // cross-dependency on a private helper.
52
+ function inScope(t) {
53
+ if (t.resolved)
54
+ return false;
55
+ if (t.resolution?.kind === "accepted")
56
+ return false;
57
+ if (!t.sourceA || !t.sourceB)
58
+ return false;
59
+ if (t.sourceA === t.sourceB)
60
+ return false;
61
+ return true;
62
+ }
63
+ export function computeTensionTriage(tensions, inputs, now = new Date()) {
64
+ const scoped = tensions.filter(inScope);
65
+ // Reuse the cluster computation for grouping + deterministic size-desc order.
66
+ const { clusters } = computeTensionClusters(scoped, now);
67
+ // doc path → cluster id, so each tension routes to its cluster bucket.
68
+ const clusterOfDoc = new Map();
69
+ for (const c of clusters) {
70
+ for (const doc of c.documents)
71
+ clusterOfDoc.set(doc, c.id);
72
+ }
73
+ const tensionsByCluster = new Map();
74
+ for (const t of scoped) {
75
+ const cid = clusterOfDoc.get(t.sourceA);
76
+ if (cid === undefined)
77
+ continue;
78
+ if (!tensionsByCluster.has(cid))
79
+ tensionsByCluster.set(cid, []);
80
+ tensionsByCluster.get(cid).push(t);
81
+ }
82
+ const triageClusters = clusters.map((c) => {
83
+ const raw = tensionsByCluster.get(c.id) ?? [];
84
+ const enriched = raw
85
+ .map((t) => enrich(t, inputs, now))
86
+ // Oldest first; tie-break on id ascending for a stable order.
87
+ .sort((x, y) => (y.age_days !== x.age_days ? y.age_days - x.age_days : x.id < y.id ? -1 : 1));
88
+ return { cluster_id: c.id, documents: c.documents, tensions: enriched };
89
+ });
90
+ return {
91
+ cluster_count: triageClusters.length,
92
+ tension_count: scoped.length,
93
+ clusters: triageClusters,
94
+ };
95
+ }
96
+ // Async loader: reads the vault's tensions, documents, read log, and computes
97
+ // per-tension blast, then feeds them all into computeTensionTriage. Mirrors
98
+ // loadTensionClusters' Result + entryFilter signature — the visibility policy
99
+ // (#212) is injected by the tool layer so this module never imports RBAC.
100
+ //
101
+ // Blast is seeded on BOTH endpoints of each tension (the contested pair): the
102
+ // downstream of the pair is what a resolver's change would touch. The reverse
103
+ // maps are built once and reused across every tension. hidden_downstream is
104
+ // "none" here — the RBAC recompute (#217) lives in the tool handler, not the
105
+ // loader (v0 default: apply the entryFilter, don't replicate per-tension
106
+ // kept/hidden downstream counting).
107
+ export async function loadTensionTriage(vaultRoot, now = new Date(), entryFilter = (e) => e, windowDays = READ_HEAT_WINDOW_DAYS) {
108
+ const tensionsResult = await listTensions(vaultRoot);
109
+ if (!tensionsResult.ok)
110
+ return err(tensionsResult.error);
111
+ const tensions = entryFilter(tensionsResult.value);
112
+ const docsResult = await loadDocuments(vaultRoot);
113
+ if (!docsResult.ok)
114
+ return err(docsResult.error);
115
+ const docs = docsResult.value;
116
+ const docMeta = new Map();
117
+ const readHeatDocs = [];
118
+ for (const d of docs) {
119
+ docMeta.set(d.path, {
120
+ tier: d.frontmatter.tier,
121
+ confidence: d.frontmatter.confidence,
122
+ criticality: d.frontmatter.criticality,
123
+ provenance: d.frontmatter.provenance,
124
+ updated_by: d.frontmatter.updated_by,
125
+ created: d.frontmatter.created,
126
+ });
127
+ readHeatDocs.push({ file: d.path, created: d.frontmatter.created });
128
+ }
129
+ const readLogResult = await readReadLog(vaultRoot);
130
+ if (!readLogResult.ok)
131
+ return err(readLogResult.error);
132
+ const readHeat = computeReadHeat(readLogResult.value, readHeatDocs, {
133
+ now,
134
+ windowDays,
135
+ });
136
+ const reverseSource = buildReverseSourceMap(docs);
137
+ const reverseLink = buildReverseLinkMap(docs);
138
+ const blastByTension = new Map();
139
+ for (const t of tensions.filter(inScope)) {
140
+ if (!t.id)
141
+ continue;
142
+ const { primary_blast, advisory_blast } = computeBlast({
143
+ seeds: [t.sourceA, t.sourceB],
144
+ reverseSource,
145
+ reverseLink,
146
+ });
147
+ blastByTension.set(t.id, {
148
+ primary_blast,
149
+ advisory_blast,
150
+ hidden_downstream: bucketHiddenDownstream(0),
151
+ });
152
+ }
153
+ return ok(computeTensionTriage(tensions, { docMeta, readHeat, blastByTension }, now));
154
+ }
155
+ //# sourceMappingURL=tension-triage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tension-triage.js","sourceRoot":"","sources":["../../src/curation/tension-triage.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,+EAA+E;AAC/E,uCAAuC;AAGvC,OAAO,EAAE,GAAG,EAAE,EAA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AC;QACzC,IAAI,CAAC,CAAC,CAAC,EAAE;YAAE,SAAS;QACpB,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,YAAY,CAAC;YACrD,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC;YAC7B,aAAa;YACb,WAAW;SACZ,CAAC,CAAC;QACH,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,aAAa;YACb,cAAc;YACd,iBAAiB,EAAE,sBAAsB,CAAC,CAAC,CAAC;SAC7C,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,CAAC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;AACxF,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { LoadedDoc } from "./vault-docs.js";
2
+ export type ValidityState = "in-window" | "expired" | "not-yet" | "unknown";
3
+ export interface ValidityInput {
4
+ valid_from: string | null;
5
+ valid_until: string | null;
6
+ }
7
+ export interface ValidityReport {
8
+ from: string | null;
9
+ until: string | null;
10
+ state: ValidityState;
11
+ banner: string | null;
12
+ }
13
+ export declare function computeValidity(input: ValidityInput, at: string): ValidityReport | null;
14
+ export interface ValidityConflict {
15
+ path: string;
16
+ kind: "malformed-endpoint" | "inverted" | "supersession-overlap" | "supersession-gap" | "expired-canonical";
17
+ detail: string;
18
+ }
19
+ export declare function validityConflicts(docs: LoadedDoc[], now: Date): ValidityConflict[];
20
+ //# sourceMappingURL=validity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validity.d.ts","sourceRoot":"","sources":["../../src/curation/validity.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAK5E,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,aAAa,CAAC;IAGrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAiBD,wBAAgB,eAAe,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAoDvF;AAID,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EACA,oBAAoB,GACpB,UAAU,GACV,sBAAsB,GACtB,kBAAkB,GAClB,mBAAmB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB;AAcD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,gBAAgB,EAAE,CAmGlF"}
@@ -0,0 +1,191 @@
1
+ // Valid time — when a fact is true IN THE WORLD, as opposed to when the vault
2
+ // recorded it (transaction time: git history, created/updated).
3
+ //
4
+ // THE INTERVAL IS HALF-OPEN: [valid_from, valid_until). Day D is in-window iff
5
+ // `valid_from <= D < valid_until`, so `valid_until` names the first day the
6
+ // claim did NOT hold. Two things fall out of that and both are load-bearing:
7
+ // a successor's valid_from is EXACTLY its predecessor's valid_until (contiguity
8
+ // is identity, not arithmetic — there is no off-by-one to get wrong, which
9
+ // matters most on the boundary write an agent drives), and `until <= from` is
10
+ // an empty window rather than a merely odd one.
11
+ //
12
+ // Pure and total, mirroring staleness.ts / decay.ts. Never throws. A document
13
+ // with no authored interval reads as nothing-to-say (null), which is the
14
+ // silent baseline — absence of validity is NOT a claim of permanent validity,
15
+ // and treating it as one would invent exactly the assertion this axis exists
16
+ // to stop the vault inventing.
17
+ //
18
+ // This module deliberately does not touch decay.ts. Routing validity through
19
+ // DecayInput would make an expired interval promote a document to `warn`,
20
+ // which consolidate/admit.ts reads as edge-blocking — a behavioral change to
21
+ // the cortex loop smuggled in as a type extension. Validity is its own signal
22
+ // and travels alongside decay, never inside it.
23
+ import { normalizeIsoDate } from "../utils/dates.js";
24
+ const MS_PER_DAY = 86_400_000;
25
+ // Whole days between two canonical ISO dates. Both are already normalized by
26
+ // the caller, so Date.parse cannot fail here; the guard is belt-and-braces.
27
+ function daysBetween(fromISO, toISO) {
28
+ const a = Date.parse(`${fromISO}T00:00:00Z`);
29
+ const b = Date.parse(`${toISO}T00:00:00Z`);
30
+ if (Number.isNaN(a) || Number.isNaN(b))
31
+ return 0;
32
+ return Math.floor((b - a) / MS_PER_DAY);
33
+ }
34
+ // Evaluates a document's interval against a date. Returns null iff both
35
+ // endpoints are absent — nothing to report, following computeDecay's contract
36
+ // for a healthy document.
37
+ //
38
+ // `at` is the evaluation date (YYYY-MM-DD): today for a read, or the caller's
39
+ // `valid_at` for a bi-temporal query.
40
+ export function computeValidity(input, at) {
41
+ const rawFrom = input.valid_from;
42
+ const rawUntil = input.valid_until;
43
+ if (rawFrom === null && rawUntil === null)
44
+ return null;
45
+ const from = rawFrom === null ? null : normalizeIsoDate(rawFrom);
46
+ const until = rawUntil === null ? null : normalizeIsoDate(rawUntil);
47
+ const when = normalizeIsoDate(at);
48
+ // An endpoint the author wrote but that does not parse cannot be compared.
49
+ // It reads as `unknown` rather than as absent: letting a typo fall through
50
+ // as "open-ended" would assert something nobody wrote. The raw value still
51
+ // travels on the report so vault_lint can name it.
52
+ const malformed = (rawFrom !== null && from === null) || (rawUntil !== null && until === null);
53
+ if (malformed || when === null) {
54
+ return { from: rawFrom, until: rawUntil, state: "unknown", banner: null };
55
+ }
56
+ // An inverted or empty window (`until <= from`) is a contradiction, and it
57
+ // must read as `unknown` rather than being evaluated. Evaluating it would
58
+ // mark the document `not-yet` before `from` and `expired` after `until` —
59
+ // never `in-window` on any day — so one transposed date would silently
60
+ // produce a stale banner on vault_read, removal under valid_only, a wake
61
+ // entry in daftari sleep, and an interview question about a fact that never
62
+ // stopped being true. Lint reports the inversion; this keeps the bad state
63
+ // from propagating while it goes unfixed.
64
+ if (from !== null && until !== null && until <= from) {
65
+ return { from: rawFrom, until: rawUntil, state: "unknown", banner: null };
66
+ }
67
+ // ISO dates sort lexically, so string comparison is valid date comparison.
68
+ //
69
+ // The interval is HALF-OPEN: [from, until). Day D is in-window iff
70
+ // `from <= D < until`. This makes contiguity identity rather than
71
+ // arithmetic — a successor's valid_from is exactly its predecessor's
72
+ // valid_until, with no off-by-one to get wrong — and matches the
73
+ // invalid-at semantics the external systems settled on. It also means
74
+ // `valid_until` is the first day the claim did NOT hold, which is what the
75
+ // supersession boundary writes directly.
76
+ if (from !== null && when < from) {
77
+ return { from: rawFrom, until: rawUntil, state: "not-yet", banner: null };
78
+ }
79
+ if (until !== null && when >= until) {
80
+ const agoDays = daysBetween(until, when);
81
+ return {
82
+ from: rawFrom,
83
+ until: rawUntil,
84
+ state: "expired",
85
+ banner: `⚠ STALE — validity ended ${until} (${agoDays}d ago)`,
86
+ };
87
+ }
88
+ return { from: rawFrom, until: rawUntil, state: "in-window", banner: null };
89
+ }
90
+ function todayISO(now) {
91
+ return now.toISOString().slice(0, 10);
92
+ }
93
+ function fmOf(doc) {
94
+ return doc.frontmatter;
95
+ }
96
+ // Deterministic, semantics-free checks over authored intervals. Advisory, like
97
+ // every other lint check: this reports, it does not fix, and it never logs a
98
+ // tension — two documents disagreeing about an interval is not proof of
99
+ // contradiction, and vault_tension_log stays a deliberate act.
100
+ export function validityConflicts(docs, now) {
101
+ const out = [];
102
+ const today = todayISO(now);
103
+ const byPath = new Map();
104
+ for (const d of docs)
105
+ byPath.set(d.path, d);
106
+ for (const d of docs) {
107
+ const fm = fmOf(d);
108
+ const rawFrom = fm.valid_from ?? null;
109
+ const rawUntil = fm.valid_until ?? null;
110
+ if (rawFrom === null && rawUntil === null)
111
+ continue;
112
+ const from = rawFrom === null ? null : normalizeIsoDate(rawFrom);
113
+ const until = rawUntil === null ? null : normalizeIsoDate(rawUntil);
114
+ // 1. malformed-endpoint — the finding that replaces the deleted schema
115
+ // hook. Reports the raw value verbatim so an author can find the typo.
116
+ if (rawFrom !== null && from === null) {
117
+ out.push({
118
+ path: d.path,
119
+ kind: "malformed-endpoint",
120
+ detail: `valid_from is not a YYYY-MM-DD date: "${rawFrom}"`,
121
+ });
122
+ }
123
+ if (rawUntil !== null && until === null) {
124
+ out.push({
125
+ path: d.path,
126
+ kind: "malformed-endpoint",
127
+ detail: `valid_until is not a YYYY-MM-DD date: "${rawUntil}"`,
128
+ });
129
+ }
130
+ // A malformed endpoint makes every downstream comparison meaningless.
131
+ if ((rawFrom !== null && from === null) || (rawUntil !== null && until === null))
132
+ continue;
133
+ // 2. inverted — one document contradicting itself. Under a half-open
134
+ // interval, `until === from` is the degenerate empty window (no day is
135
+ // in it), so it is the same defect and reported the same way.
136
+ if (from !== null && until !== null && until <= from) {
137
+ out.push({
138
+ path: d.path,
139
+ kind: "inverted",
140
+ detail: until === from
141
+ ? `valid_from and valid_until are both ${from} — a half-open window [${from}, ${until}) contains no days`
142
+ : `valid_until ${until} is not after valid_from ${from}`,
143
+ });
144
+ continue;
145
+ }
146
+ // 3 & 4. The supersession pair checks. This is what makes a superseded_by
147
+ // edge auditable rather than an unfalsifiable assertion.
148
+ const successorPath = fm.superseded_by;
149
+ if (successorPath !== null && until !== null) {
150
+ const successor = byPath.get(successorPath);
151
+ const sFrom = successor ? normalizeIsoDate(successor.frontmatter.valid_from ?? "") : null;
152
+ if (successor && sFrom !== null) {
153
+ // Half-open makes the clean handoff exact equality: the predecessor's
154
+ // window ends the instant the successor's begins, sharing no day.
155
+ // Anything earlier overlaps; anything later leaves a gap.
156
+ if (sFrom < until) {
157
+ out.push({
158
+ path: d.path,
159
+ kind: "supersession-overlap",
160
+ detail: `this document claims validity until ${until}, but its successor ` +
161
+ `claims validity from ${sFrom} — the vault asserts both held at once`,
162
+ });
163
+ }
164
+ else if (sFrom > until) {
165
+ out.push({
166
+ path: d.path,
167
+ kind: "supersession-gap",
168
+ detail: `this document's validity ends ${until} and its successor's begins ` +
169
+ `${sFrom} — no document records a belief for the days between`,
170
+ });
171
+ }
172
+ }
173
+ }
174
+ // 5. expired-canonical — the strongest signal in the set. The document
175
+ // admits it stopped being true and nothing replaced it.
176
+ if (fm.status === "canonical" &&
177
+ fm.domain === "accumulation" &&
178
+ until !== null &&
179
+ until < today &&
180
+ successorPath === null) {
181
+ out.push({
182
+ path: d.path,
183
+ kind: "expired-canonical",
184
+ detail: `canonical document's validity ended ${until} with no superseded_by — ` +
185
+ "it says it stopped being true and nothing replaced it",
186
+ });
187
+ }
188
+ }
189
+ return out;
190
+ }
191
+ //# sourceMappingURL=validity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validity.js","sourceRoot":"","sources":["../../src/curation/validity.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gEAAgE;AAChE,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,6EAA6E;AAC7E,gFAAgF;AAChF,2EAA2E;AAC3E,8EAA8E;AAC9E,gDAAgD;AAChD,EAAE;AACF,8EAA8E;AAC9E,yEAAyE;AACzE,8EAA8E;AAC9E,6EAA6E;AAC7E,+BAA+B;AAC/B,EAAE;AACF,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,gDAAgD;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGrD,MAAM,UAAU,GAAG,UAAU,CAAC;AAqB9B,6EAA6E;AAC7E,4EAA4E;AAC5E,SAAS,WAAW,CAAC,OAAe,EAAE,KAAa;IACjD,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO,YAAY,CAAC,CAAC;IAC7C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,K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BAChC,sEAAsE;gBACtE,kEAAkE;gBAClE,0DAA0D;gBAC1D,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;oBAClB,GAAG,CAAC,IAAI,CAAC;wBACP,IAAI,EAAE,CAAC,CAAC,IAAI;wBACZ,IAAI,EAAE,sBAAsB;wBAC5B,MAAM,EACJ,uCAAuC,KAAK,sBAAsB;4BAClE,wBAAwB,KAAK,wCAAwC;qBACxE,CAAC,CAAC;gBACL,CAAC;qBAAM,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;oBACzB,GAAG,CAAC,IAAI,CAAC;wBACP,IAAI,EAAE,CAAC,CAAC,IAAI;wBACZ,IAAI,EAAE,kBAAkB;wBACxB,MAAM,EACJ,iCAAiC,KAAK,8BAA8B;4BACpE,GAAG,KAAK,sDAAsD;qBACjE,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,uEAAuE;QACvE,2DAA2D;QAC3D,IACE,EAAE,CAAC,MAAM,KAAK,WAAW;YACzB,EAAE,CAAC,MAAM,KAAK,cAAc;YAC5B,KAAK,KAAK,IAAI;YACd,KAAK,GAAG,KAAK;YACb,aAAa,KAAK,IAAI,EACtB,CAAC;YACD,GAAG,CAAC,IAAI,CAAC;gBACP,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,IAAI,EAAE,mBAAmB;gBACzB,MAAM,EACJ,uCAAuC,KAAK,2BAA2B;oBACvE,uDAAuD;aAC1D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,10 @@
1
+ export type InjectionClass = "override-instruction" | "role-impersonation" | "tool-solicitation" | "exfiltration";
2
+ export interface InjectionMatch {
3
+ cls: InjectionClass;
4
+ offset: number;
5
+ }
6
+ export declare function maskCode(text: string): string;
7
+ export declare function detectInjection(text: string): InjectionMatch[];
8
+ export declare function injectionClasses(text: string): InjectionClass[];
9
+ export declare function lineForOffset(text: string, offset: number): number;
10
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/fence/detect.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,cAAc,GACtB,sBAAsB,GACtB,oBAAoB,GACpB,mBAAmB,GACnB,cAAc,CAAC;AAKnB,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,cAAc,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AA4DD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA4C7C;AAID,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CA8B9D;AAID,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAG/D;AAKD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQlE"}
@@ -0,0 +1,161 @@
1
+ // Instruction-shaped-text detection. Pure: no LLM, no I/O, no state.
2
+ //
3
+ // This is the content-derived leg of the fence trigger (2026-07-27 read-path
4
+ // fence spec, Decision 2). It answers "does this text look like it is trying to
5
+ // instruct the reader" — never "is this text malicious", which is not a
6
+ // question a regex can answer. Its output is advisory in both places it is
7
+ // used: the fence adds framing, lint reports.
8
+ // Ordered so a document's findings read in a stable class order regardless of
9
+ // where the matches fall.
10
+ const CLASSES = [
11
+ "override-instruction",
12
+ "role-impersonation",
13
+ "tool-solicitation",
14
+ "exfiltration",
15
+ ];
16
+ const PATTERNS = {
17
+ "override-instruction": [
18
+ /\b(ignore|disregard|forget|override)\b[^.\n]{0,40}\b(previous|prior|above|earlier|all|any)\b[^.\n]{0,40}\b(instruction|prompt|rule|direction|guidance)/gi,
19
+ ],
20
+ "role-impersonation": [/^[ \t]*(system|assistant)[ \t]*:/gim, /<\/?(system|assistant)>/gi],
21
+ // Every tool carrying destructiveHint, plus stage_action — a staged write is
22
+ // a mutation request even though its own annotation is not destructive.
23
+ //
24
+ // This list is duplicated from the tool definitions rather than imported:
25
+ // this module is pure and has no dependency on the tool layer, and pulling
26
+ // the registry in to read four field values would invert that. The
27
+ // duplication is guarded instead — test/fence/detect.test.ts derives the
28
+ // expected set from the real ToolDefinition arrays and fails if a
29
+ // destructive tool is added without appearing here.
30
+ "tool-solicitation": [
31
+ /\bvault_(write|append|merge|set_tier|set_confidence|supersede|deprecate|promote|ratify|stage_action|tension_log|tension_resolve|edge_contest)\s*\(/gi,
32
+ ],
33
+ exfiltration: [/\b(send|post|upload|exfiltrate|forward)\b[^.\n]{0,60}https?:\/\//gi],
34
+ };
35
+ // Classes evaluated against code-masked text rather than raw text.
36
+ //
37
+ // `system:` and `<assistant>` appear constantly in an engineering vault's code
38
+ // samples, transcripts and API docs, so scanning them raw makes the detector
39
+ // useless on exactly the corpus daftari is built for. The cost is a declared
40
+ // residual (spec residual 2): a role-impersonation payload inside a fenced code
41
+ // block is invisible to the fence trigger. That evasion costs the attacker
42
+ // three characters, so it is admitted for this one class only — the other three
43
+ // read raw text, where the same trick does not help.
44
+ const MASKED_CLASSES = new Set(["role-impersonation"]);
45
+ // Replaces fenced code block CONTENT with spaces, preserving both length and
46
+ // newlines so every offset and line number computed against the masked text is
47
+ // valid against the original. Blanking rather than deleting is the whole point.
48
+ //
49
+ // Open/close pairing follows CommonMark: a fence closes only on the SAME
50
+ // delimiter character, at least as long as the opener, with nothing but
51
+ // whitespace after it. Matching any fence-like line against any other is not a
52
+ // cosmetic shortcut — a document that shows a ``` example inside a ````` block
53
+ // has an odd number of fence-like lines, so a naive toggle ends the scan still
54
+ // "open" and blanks everything to EOF. Since masking gates the
55
+ // role-impersonation class, that would silently disable the one security-
56
+ // relevant detector for the rest of the file, far past the declared residual.
57
+ function blankRange(out, from, to) {
58
+ for (let i = Math.max(0, from); i < Math.min(to, out.length); i += 1) {
59
+ if (out[i] !== "\n")
60
+ out[i] = " ";
61
+ }
62
+ }
63
+ export function maskCode(text) {
64
+ const out = text.split("");
65
+ const fenceLine = /^[ \t]*(`{3,}|~{3,})([^\n]*)$/;
66
+ let openChar = null;
67
+ let openLen = 0;
68
+ let contentFrom = -1;
69
+ let offset = 0;
70
+ for (const line of text.split("\n")) {
71
+ const m = fenceLine.exec(line);
72
+ if (m !== null) {
73
+ const delim = m[1];
74
+ const char = delim[0];
75
+ const len = delim.length;
76
+ if (openChar === null) {
77
+ // Opening fence. Its info string is legible; content starts next line.
78
+ openChar = char;
79
+ openLen = len;
80
+ contentFrom = offset + line.length;
81
+ }
82
+ else if (char === openChar && len >= openLen && m[2].trim() === "") {
83
+ blankRange(out, contentFrom, offset);
84
+ openChar = null;
85
+ contentFrom = -1;
86
+ }
87
+ // A fence-like line that does not satisfy the close rule is content of
88
+ // the open block, and is blanked with the rest of it.
89
+ }
90
+ offset += line.length + 1; // +1 for the newline split() removed
91
+ }
92
+ // An unterminated fence blanks to end of text: a payload after an unclosed
93
+ // ``` is inside a code block as far as every renderer is concerned.
94
+ if (openChar !== null)
95
+ blankRange(out, contentFrom, out.length);
96
+ // Inline code spans, same treatment, same reason.
97
+ const inline = /`[^`\n]+`/g;
98
+ inline.lastIndex = 0;
99
+ for (;;) {
100
+ const m = inline.exec(text);
101
+ if (m === null)
102
+ break;
103
+ blankRange(out, m.index + 1, m.index + m[0].length - 1);
104
+ }
105
+ return out.join("");
106
+ }
107
+ // Every instruction-shaped match in `text`, sorted by class order then offset.
108
+ // Returns [] for empty or benign input. Never throws.
109
+ export function detectInjection(text) {
110
+ if (text.length === 0)
111
+ return [];
112
+ let masked = null;
113
+ const matches = [];
114
+ for (const cls of CLASSES) {
115
+ let subject = text;
116
+ if (MASKED_CLASSES.has(cls)) {
117
+ masked ??= maskCode(text);
118
+ subject = masked;
119
+ }
120
+ for (const pattern of PATTERNS[cls]) {
121
+ // Fresh lastIndex per use: the module-level regexes are /g and shared.
122
+ pattern.lastIndex = 0;
123
+ for (;;) {
124
+ const m = pattern.exec(subject);
125
+ if (m === null)
126
+ break;
127
+ matches.push({ cls, offset: m.index });
128
+ // Zero-length matches cannot happen with these patterns, but a stuck
129
+ // lastIndex would spin forever if one ever could.
130
+ if (m[0].length === 0)
131
+ pattern.lastIndex += 1;
132
+ }
133
+ }
134
+ }
135
+ matches.sort((a, b) => {
136
+ const byClass = CLASSES.indexOf(a.cls) - CLASSES.indexOf(b.cls);
137
+ return byClass !== 0 ? byClass : a.offset - b.offset;
138
+ });
139
+ return matches;
140
+ }
141
+ // The distinct classes present, in CLASSES order. This is what the fence
142
+ // predicate consumes — it needs "is this non-empty", not the match list.
143
+ export function injectionClasses(text) {
144
+ const seen = new Set(detectInjection(text).map((m) => m.cls));
145
+ return CLASSES.filter((c) => seen.has(c));
146
+ }
147
+ // 1-indexed line containing `offset`. Lint reports locations so that "the
148
+ // remedy is one ordinary write" is true rather than aspirational; a line number
149
+ // discloses nothing the operator cannot already read, unlike the matched text.
150
+ export function lineForOffset(text, offset) {
151
+ if (offset <= 0)
152
+ return 1;
153
+ const upto = offset < text.length ? offset : text.length;
154
+ let line = 1;
155
+ for (let i = 0; i < upto; i += 1) {
156
+ if (text[i] === "\n")
157
+ line += 1;
158
+ }
159
+ return line;
160
+ }
161
+ //# sourceMappingURL=detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/fence/detect.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,6EAA6E;AAC7E,gFAAgF;AAChF,wEAAwE;AACxE,2EAA2E;AAC3E,8CAA8C;AAgB9C,8EAA8E;AAC9E,0BAA0B;AAC1B,MAAM,OAAO,GAA8B;IACzC,sBAAsB;IACtB,oBAAoB;IACpB,mBAAmB;IACnB,cAAc;CACN,CAAC;AAEX,MAAM,QAAQ,GAA8C;IAC1D,sBAAsB,EAAE;QACtB,0JAA0J;KAC3J;IACD,oBAAoB,EAAE,CAAC,qCAAqC,EAAE,2BAA2B,CAAC;IAC1F,6EAA6E;IAC7E,wEAAwE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,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Tier } from "../frontmatter/types.js";
2
+ import { type InjectionClass } from "./detect.js";
3
+ export type FenceReason = "source-tier" | "instruction-shaped";
4
+ export interface Fence {
5
+ nonce: string;
6
+ open: (reason: FenceReason) => string;
7
+ close: (reason: FenceReason) => string;
8
+ }
9
+ export declare const FENCE_PREFIX = "\u27E6daftari:";
10
+ export declare function newFence(...avoid: readonly string[]): Fence;
11
+ export declare const SOURCE_PREAMBLE: string;
12
+ export declare const UNLABELLED_PREAMBLE: string;
13
+ export declare const SOURCE_NOTICE: string;
14
+ export declare const UNLABELLED_NOTICE: string;
15
+ export declare function preambleFor(reason: FenceReason): string;
16
+ export declare function noticeFor(reason: FenceReason): string;
17
+ export declare function fenceBody(text: string, fence: Fence, reason: FenceReason): string;
18
+ export declare function fenceSpan(text: string, fence: Fence, reason: FenceReason): string;
19
+ export declare function containsFenceMarker(text: string): boolean;
20
+ export declare function fenceReason(tier: Tier | null | undefined, flags: readonly InjectionClass[]): FenceReason | null;
21
+ export declare function fenceReasonForBody(tier: Tier | null | undefined, body: string, heuristic?: boolean): FenceReason | null;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fence/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,KAAK,cAAc,EAAoB,MAAM,aAAa,CAAC;AAKpE,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,oBAAoB,CAAC;AAE/D,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,MAAM,CAAC;IACtC,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,MAAM,CAAC;CACxC;AAID,eAAO,MAAM,YAAY,mBAAc,CAAC;A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