agent-recall-core 3.4.40 → 3.4.42
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.
- package/dist/helpers/auto-name.d.ts +2 -1
- package/dist/helpers/auto-name.d.ts.map +1 -1
- package/dist/helpers/auto-name.js +45 -6
- package/dist/helpers/auto-name.js.map +1 -1
- package/dist/helpers/journal-sig-theme.d.ts +18 -0
- package/dist/helpers/journal-sig-theme.d.ts.map +1 -1
- package/dist/helpers/journal-sig-theme.js +6 -1
- package/dist/helpers/journal-sig-theme.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/extraction.d.ts +136 -0
- package/dist/storage/extraction.d.ts.map +1 -0
- package/dist/storage/extraction.js +368 -0
- package/dist/storage/extraction.js.map +1 -0
- package/dist/storage/fs-utils.d.ts +21 -0
- package/dist/storage/fs-utils.d.ts.map +1 -1
- package/dist/storage/fs-utils.js +86 -0
- package/dist/storage/fs-utils.js.map +1 -1
- package/dist/storage/hook-health.d.ts +50 -0
- package/dist/storage/hook-health.d.ts.map +1 -0
- package/dist/storage/hook-health.js +183 -0
- package/dist/storage/hook-health.js.map +1 -0
- package/dist/storage/paths.d.ts +23 -4
- package/dist/storage/paths.d.ts.map +1 -1
- package/dist/storage/paths.js +26 -9
- package/dist/storage/paths.js.map +1 -1
- package/dist/storage/recency-index.d.ts +79 -0
- package/dist/storage/recency-index.d.ts.map +1 -0
- package/dist/storage/recency-index.js +204 -0
- package/dist/storage/recency-index.js.map +1 -0
- package/dist/storage/session-card.d.ts +74 -0
- package/dist/storage/session-card.d.ts.map +1 -0
- package/dist/storage/session-card.js +219 -0
- package/dist/storage/session-card.js.map +1 -0
- package/dist/storage/working-memory.d.ts +193 -0
- package/dist/storage/working-memory.d.ts.map +1 -0
- package/dist/storage/working-memory.js +328 -0
- package/dist/storage/working-memory.js.map +1 -0
- package/dist/supabase/recall-backend.d.ts +1 -1
- package/dist/supabase/recall-backend.d.ts.map +1 -1
- package/dist/supabase/recall-backend.js.map +1 -1
- package/dist/supabase/sync.d.ts.map +1 -1
- package/dist/supabase/sync.js +13 -2
- package/dist/supabase/sync.js.map +1 -1
- package/dist/tools-logic/drill-down.d.ts +9 -2
- package/dist/tools-logic/drill-down.d.ts.map +1 -1
- package/dist/tools-logic/drill-down.js +32 -1
- package/dist/tools-logic/drill-down.js.map +1 -1
- package/dist/tools-logic/journal-search.d.ts.map +1 -1
- package/dist/tools-logic/journal-search.js +7 -1
- package/dist/tools-logic/journal-search.js.map +1 -1
- package/dist/tools-logic/resurrect.d.ts +113 -0
- package/dist/tools-logic/resurrect.d.ts.map +1 -0
- package/dist/tools-logic/resurrect.js +602 -0
- package/dist/tools-logic/resurrect.js.map +1 -0
- package/dist/tools-logic/session-start-lite.d.ts +6 -0
- package/dist/tools-logic/session-start-lite.d.ts.map +1 -1
- package/dist/tools-logic/session-start-lite.js +15 -0
- package/dist/tools-logic/session-start-lite.js.map +1 -1
- package/dist/tools-logic/session-start.d.ts +29 -0
- package/dist/tools-logic/session-start.d.ts.map +1 -1
- package/dist/tools-logic/session-start.js +97 -2
- package/dist/tools-logic/session-start.js.map +1 -1
- package/dist/tools-logic/smart-recall.d.ts +9 -4
- package/dist/tools-logic/smart-recall.d.ts.map +1 -1
- package/dist/tools-logic/smart-recall.js +170 -4
- package/dist/tools-logic/smart-recall.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hook-health.ts — F5, fail-loud hook health (continuity wave, 2026-07-31).
|
|
3
|
+
*
|
|
4
|
+
* WHY: every hook catch block in the CLI is stderr-only today (index.ts:
|
|
5
|
+
* 932-935, 1079-1082, 1163-1165, 1184-1186) — a hook that silently fails
|
|
6
|
+
* leaves zero persistent trace, so a broken hook can run for weeks before
|
|
7
|
+
* anyone notices a session went unrecorded. This module is the storage layer
|
|
8
|
+
* a future CLI catch-block wiring (Wave-2 integrator) reports failures into.
|
|
9
|
+
*
|
|
10
|
+
* Pattern: same shape as supabase/sync.ts's logSyncError (append + roll@500)
|
|
11
|
+
* and storage/lifecycle-telemetry.ts (best-effort, AR_ROOT-aware, never
|
|
12
|
+
* throws into the caller). Two files:
|
|
13
|
+
* - hook-health.jsonl — append-only failure log, rolled to the last 500
|
|
14
|
+
* lines once it grows past that (same cap/roll contract as sync-errors).
|
|
15
|
+
* - hook-health.json — a small derived STATE snapshot a renderer can read
|
|
16
|
+
* in O(1) without re-parsing the whole JSONL: {last_failure, failures_24h}.
|
|
17
|
+
*
|
|
18
|
+
* Both paths are resolved via getRoot() (AGENT_RECALL_ROOT / setRoot()
|
|
19
|
+
* override-aware) — never os.homedir() directly. This is the same root-fix
|
|
20
|
+
* this wave applied to sync.ts's logSyncError for the identical reason: a
|
|
21
|
+
* hardcoded home-dir path would let test suites pollute the real user's
|
|
22
|
+
* store the same way sync-errors.log did.
|
|
23
|
+
*/
|
|
24
|
+
import * as fs from "node:fs";
|
|
25
|
+
import * as path from "node:path";
|
|
26
|
+
import { getRoot } from "../types.js";
|
|
27
|
+
import { ensureDir, writeJsonAtomic } from "./fs-utils.js";
|
|
28
|
+
const ROLL_LIMIT = 500;
|
|
29
|
+
const WINDOW_MS = 24 * 60 * 60 * 1000; // 24h
|
|
30
|
+
const MESSAGE_CAP = 500; // chars — a hook failure message is a log line, not a dump
|
|
31
|
+
function hookHealthJsonlPath() {
|
|
32
|
+
return path.join(getRoot(), "hook-health.jsonl");
|
|
33
|
+
}
|
|
34
|
+
function hookHealthJsonPath() {
|
|
35
|
+
return path.join(getRoot(), "hook-health.json");
|
|
36
|
+
}
|
|
37
|
+
/** Best-effort string form of an unknown error value. Never throws. */
|
|
38
|
+
function messageOf(err) {
|
|
39
|
+
try {
|
|
40
|
+
if (err instanceof Error)
|
|
41
|
+
return err.message;
|
|
42
|
+
if (typeof err === "string")
|
|
43
|
+
return err;
|
|
44
|
+
return JSON.stringify(err);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return String(err);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Roll `p` down to its last ROLL_LIMIT non-empty lines once it exceeds that
|
|
52
|
+
* count — same tmp+rename atomic-ish pattern as sync.ts's logSyncError cap.
|
|
53
|
+
* Best-effort: any read/write failure here is swallowed by the caller.
|
|
54
|
+
*/
|
|
55
|
+
function rollJsonl(p) {
|
|
56
|
+
let content;
|
|
57
|
+
try {
|
|
58
|
+
content = fs.readFileSync(p, "utf-8");
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return; // file doesn't exist yet (or unreadable) — nothing to roll
|
|
62
|
+
}
|
|
63
|
+
const lines = content.split("\n").filter(Boolean);
|
|
64
|
+
if (lines.length <= ROLL_LIMIT)
|
|
65
|
+
return;
|
|
66
|
+
const trimmed = lines.slice(-ROLL_LIMIT).join("\n") + "\n";
|
|
67
|
+
const tmp = p + ".tmp." + process.pid;
|
|
68
|
+
fs.writeFileSync(tmp, trimmed, "utf-8");
|
|
69
|
+
fs.renameSync(tmp, p);
|
|
70
|
+
}
|
|
71
|
+
/** Parse every well-formed row out of the JSONL file. Skips malformed lines. */
|
|
72
|
+
function readAllRows(p) {
|
|
73
|
+
let content;
|
|
74
|
+
try {
|
|
75
|
+
content = fs.readFileSync(p, "utf-8");
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
const rows = [];
|
|
81
|
+
for (const line of content.split("\n")) {
|
|
82
|
+
const trimmed = line.trim();
|
|
83
|
+
if (!trimmed)
|
|
84
|
+
continue;
|
|
85
|
+
try {
|
|
86
|
+
const row = JSON.parse(trimmed);
|
|
87
|
+
if (row && typeof row.ts === "string" && typeof row.hook === "string" && typeof row.message === "string") {
|
|
88
|
+
rows.push({ ts: row.ts, hook: row.hook, message: row.message });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// skip malformed line — one bad row must never break the whole read
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return rows;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Count rows whose `ts` falls strictly within the last 24h of `now`.
|
|
99
|
+
*
|
|
100
|
+
* Date logic vs TODAY (Worker Done-Definition #4): a row timestamped in the
|
|
101
|
+
* FUTURE (clock skew, malformed input, or a hostile/buggy caller) must NOT
|
|
102
|
+
* count as "within the last 24h" — it is not in the past at all. Guard with
|
|
103
|
+
* `t <= now` in addition to the window bound, otherwise a future-dated row
|
|
104
|
+
* would render as recent (and even keep counting as "24h fresh" for the next
|
|
105
|
+
* WINDOW_MS milliseconds after `now` catches up to it).
|
|
106
|
+
*/
|
|
107
|
+
function countWithin24h(rows, now) {
|
|
108
|
+
let count = 0;
|
|
109
|
+
for (const row of rows) {
|
|
110
|
+
const t = Date.parse(row.ts);
|
|
111
|
+
if (!Number.isFinite(t))
|
|
112
|
+
continue;
|
|
113
|
+
if (t > now)
|
|
114
|
+
continue; // future-dated — never counted as recent
|
|
115
|
+
if (now - t <= WINDOW_MS)
|
|
116
|
+
count++;
|
|
117
|
+
}
|
|
118
|
+
return count;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Record one hook failure. Best-effort: NEVER throws into the caller — a
|
|
122
|
+
* failure to record a failure must not compound into a second failure.
|
|
123
|
+
*/
|
|
124
|
+
export function recordHookFailure(hook, err) {
|
|
125
|
+
try {
|
|
126
|
+
const root = getRoot();
|
|
127
|
+
ensureDir(root);
|
|
128
|
+
const jsonlPath = hookHealthJsonlPath();
|
|
129
|
+
const row = {
|
|
130
|
+
ts: new Date().toISOString(),
|
|
131
|
+
hook,
|
|
132
|
+
message: messageOf(err).slice(0, MESSAGE_CAP),
|
|
133
|
+
};
|
|
134
|
+
fs.appendFileSync(jsonlPath, JSON.stringify(row) + "\n", "utf-8");
|
|
135
|
+
rollJsonl(jsonlPath);
|
|
136
|
+
// Recompute failures_24h from the (now-rolled) log so the derived state
|
|
137
|
+
// file always reflects what's actually on disk, not a running counter
|
|
138
|
+
// that could drift from it across process restarts.
|
|
139
|
+
const rows = readAllRows(jsonlPath);
|
|
140
|
+
const state = {
|
|
141
|
+
last_failure: row,
|
|
142
|
+
failures_24h: countWithin24h(rows, Date.now()),
|
|
143
|
+
};
|
|
144
|
+
writeJsonAtomic(hookHealthJsonPath(), state);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// NEVER throw — hook health recording must not break the hook it reports on.
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Read the derived hook health state for renderers (Wave-2's `ar health` /
|
|
152
|
+
* hook-start ⚠️ line). Never throws — returns a zeroed/empty state on any
|
|
153
|
+
* read error (missing file, corrupt JSON) so a renderer never needs its own
|
|
154
|
+
* try/catch around this call.
|
|
155
|
+
*/
|
|
156
|
+
export function readHookHealth() {
|
|
157
|
+
try {
|
|
158
|
+
const p = hookHealthJsonPath();
|
|
159
|
+
if (!fs.existsSync(p)) {
|
|
160
|
+
return { last_failure: null, failures_24h: 0 };
|
|
161
|
+
}
|
|
162
|
+
const raw = fs.readFileSync(p, "utf-8");
|
|
163
|
+
const parsed = JSON.parse(raw);
|
|
164
|
+
const lastFailure = parsed.last_failure;
|
|
165
|
+
const validLastFailure = lastFailure &&
|
|
166
|
+
typeof lastFailure === "object" &&
|
|
167
|
+
typeof lastFailure.ts === "string" &&
|
|
168
|
+
typeof lastFailure.hook === "string" &&
|
|
169
|
+
typeof lastFailure.message === "string"
|
|
170
|
+
? { ts: lastFailure.ts, hook: lastFailure.hook, message: lastFailure.message }
|
|
171
|
+
: null;
|
|
172
|
+
return {
|
|
173
|
+
last_failure: validLastFailure,
|
|
174
|
+
failures_24h: typeof parsed.failures_24h === "number" && Number.isFinite(parsed.failures_24h)
|
|
175
|
+
? parsed.failures_24h
|
|
176
|
+
: 0,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return { last_failure: null, failures_24h: 0 };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=hook-health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-health.js","sourceRoot":"","sources":["../../src/storage/hook-health.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE3D,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM;AAC7C,MAAM,WAAW,GAAG,GAAG,CAAC,CAAC,2DAA2D;AAkBpF,SAAS,mBAAmB;IAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,mBAAmB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,kBAAkB;IACzB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,kBAAkB,CAAC,CAAC;AAClD,CAAC;AAED,uEAAuE;AACvE,SAAS,SAAS,CAAC,GAAY;IAC7B,IAAI,CAAC;QACH,IAAI,GAAG,YAAY,KAAK;YAAE,OAAO,GAAG,CAAC,OAAO,CAAC;QAC7C,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,GAAG,CAAC;QACxC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACH,C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,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE;YAC9E,CAAC,CAAC,IAAI,CAAC;QACX,OAAO;YACL,YAAY,EAAE,gBAAgB;YAC9B,YAAY,EAAE,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC;gBAC3F,CAAC,CAAC,MAAM,CAAC,YAAY;gBACrB,CAAC,CAAC,CAAC;SACN,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;IACjD,CAAC;AACH,CAAC"}
|
package/dist/storage/paths.d.ts
CHANGED
|
@@ -145,10 +145,29 @@ export declare function journalDir(project: string): string;
|
|
|
145
145
|
* Defaults to false so counting paths (session_start, dashboard_export)
|
|
146
146
|
* don't inflate session counts with archived entries (v3.4.26 fix).
|
|
147
147
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
148
|
+
* F4 (continuity wave, 2026-07-31): journal/archive/raw/ (the lossless
|
|
149
|
+
* hook-archive verbatim tier written by archiveSession()) is DELIBERATELY
|
|
150
|
+
* NEVER included here, even when includeArchive=true — this used to be
|
|
151
|
+
* pushed unconditionally (Wave 2), which made it an ACCIDENTAL, unlabeled
|
|
152
|
+
* 4th journal source for every includeArchive=true caller (journalSearch,
|
|
153
|
+
* readJournalFile's backlink resolution). Two concrete problems that caused:
|
|
154
|
+
* 1. Filename collision: raw dumps are named `${date}--${sessionId}.md`
|
|
155
|
+
* (archive-write.ts), the SAME `${date}--` prefix convention
|
|
156
|
+
* smart-named journal files use (`YYYY-MM-DD--{saveType}--{lines}L--
|
|
157
|
+
* {slug}.md`). readJournalFile's date-prefix matcher can't tell them
|
|
158
|
+
* apart, so a raw dump for a date could be silently concatenated into
|
|
159
|
+
* (or returned AS) that date's "journal" content.
|
|
160
|
+
* 2. Noise: raw dumps are unstructured transcript slices (hook stdin
|
|
161
|
+
* records, tool_use/tool_result blocks, hook-boilerplate) — treating
|
|
162
|
+
* them as curated journal prose by default surfaced low-value noise
|
|
163
|
+
* on every recall (empirically confirmed: `ar search --include-palace`
|
|
164
|
+
* hit raw text this way; see reports/2026-07-31-continuity-fixture.md
|
|
165
|
+
* §4 Test 1).
|
|
166
|
+
* The gated, labeled replacement is smartRecall's explicit low-confidence
|
|
167
|
+
* "archive" source (tools-logic/smart-recall.ts) plus drill-down.ts's
|
|
168
|
+
* `VerbatimKey kind:"archive"` branch. Any caller that intentionally wants
|
|
169
|
+
* raw/ content should use `archiveRawDir(project)` directly instead of
|
|
170
|
+
* `journalDirs(project, true)`.
|
|
152
171
|
*/
|
|
153
172
|
export declare function journalDirs(project: string, includeArchive?: boolean): string[];
|
|
154
173
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/storage/paths.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGvD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,WAAW,qBAAqB;IACpC,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,8EAA8E;IAC9E,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,qBAAqB,GAAG,IAAI,CAatG;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAuB3E;AAED;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AM,CAErD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
|
package/dist/storage/paths.js
CHANGED
|
@@ -183,27 +183,44 @@ export function journalDir(project) {
|
|
|
183
183
|
* Defaults to false so counting paths (session_start, dashboard_export)
|
|
184
184
|
* don't inflate session counts with archived entries (v3.4.26 fix).
|
|
185
185
|
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
186
|
+
* F4 (continuity wave, 2026-07-31): journal/archive/raw/ (the lossless
|
|
187
|
+
* hook-archive verbatim tier written by archiveSession()) is DELIBERATELY
|
|
188
|
+
* NEVER included here, even when includeArchive=true — this used to be
|
|
189
|
+
* pushed unconditionally (Wave 2), which made it an ACCIDENTAL, unlabeled
|
|
190
|
+
* 4th journal source for every includeArchive=true caller (journalSearch,
|
|
191
|
+
* readJournalFile's backlink resolution). Two concrete problems that caused:
|
|
192
|
+
* 1. Filename collision: raw dumps are named `${date}--${sessionId}.md`
|
|
193
|
+
* (archive-write.ts), the SAME `${date}--` prefix convention
|
|
194
|
+
* smart-named journal files use (`YYYY-MM-DD--{saveType}--{lines}L--
|
|
195
|
+
* {slug}.md`). readJournalFile's date-prefix matcher can't tell them
|
|
196
|
+
* apart, so a raw dump for a date could be silently concatenated into
|
|
197
|
+
* (or returned AS) that date's "journal" content.
|
|
198
|
+
* 2. Noise: raw dumps are unstructured transcript slices (hook stdin
|
|
199
|
+
* records, tool_use/tool_result blocks, hook-boilerplate) — treating
|
|
200
|
+
* them as curated journal prose by default surfaced low-value noise
|
|
201
|
+
* on every recall (empirically confirmed: `ar search --include-palace`
|
|
202
|
+
* hit raw text this way; see reports/2026-07-31-continuity-fixture.md
|
|
203
|
+
* §4 Test 1).
|
|
204
|
+
* The gated, labeled replacement is smartRecall's explicit low-confidence
|
|
205
|
+
* "archive" source (tools-logic/smart-recall.ts) plus drill-down.ts's
|
|
206
|
+
* `VerbatimKey kind:"archive"` branch. Any caller that intentionally wants
|
|
207
|
+
* raw/ content should use `archiveRawDir(project)` directly instead of
|
|
208
|
+
* `journalDirs(project, true)`.
|
|
190
209
|
*/
|
|
191
210
|
export function journalDirs(project, includeArchive = false) {
|
|
192
211
|
const dirs = [];
|
|
193
212
|
const primary = journalDir(project);
|
|
194
213
|
if (fs.existsSync(primary))
|
|
195
214
|
dirs.push(primary);
|
|
196
|
-
// Archive: journal/archive/ holds entries moved by journalRollup
|
|
215
|
+
// Archive: journal/archive/ holds ROLLUP entries moved by journalRollup
|
|
216
|
+
// (weekly summaries + individual entries that aged out) — unchanged.
|
|
197
217
|
// Only included when caller explicitly requests it (recall, readJournalFile,
|
|
198
218
|
// journalSearch). Excluded by default so session counting doesn't inflate.
|
|
219
|
+
// journal/archive/raw/ is intentionally NOT pushed here — see doc comment above.
|
|
199
220
|
if (includeArchive) {
|
|
200
221
|
const archiveDir = path.join(primary, "archive");
|
|
201
222
|
if (fs.existsSync(archiveDir))
|
|
202
223
|
dirs.push(archiveDir);
|
|
203
|
-
// Wave 2: lossless verbatim tier (journal/archive/raw).
|
|
204
|
-
const rawDir = path.join(primary, "archive", "raw");
|
|
205
|
-
if (fs.existsSync(rawDir))
|
|
206
|
-
dirs.push(rawDir);
|
|
207
224
|
}
|
|
208
225
|
// Legacy: ~/.claude/projects/*/memory/journal/
|
|
209
226
|
const legacyRoot = getLegacyRoot();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/storage/paths.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,C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,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,eAAe,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-project recency index (F2, continuity wave 2026-07-31).
|
|
3
|
+
*
|
|
4
|
+
* A single, project-agnostic JSONL ledger of recent sessions. Written by the
|
|
5
|
+
* CLI hook-end path (Wave 2 integration wires the actual `appendRecentSession`
|
|
6
|
+
* call site — out of scope here, see packages/cli/src/index.ts) and read at
|
|
7
|
+
* `session_start` to render a "Continuity" card: what was worked on most
|
|
8
|
+
* recently, ACROSS projects, ranked by pure recency. This is deliberately
|
|
9
|
+
* NOT relevance-scored — `recallInsights` (session-start.ts's `cross_project`
|
|
10
|
+
* field) already covers semantic matching; this module's only job is "what
|
|
11
|
+
* happened most recently, anywhere".
|
|
12
|
+
*
|
|
13
|
+
* Root incident (2026-07-31 continuity-wave design doc, fact 6): session_start
|
|
14
|
+
* had zero recency signal outside the CURRENT project's own journal — a long
|
|
15
|
+
* work session captured under one slug was completely invisible from every
|
|
16
|
+
* OTHER slug's session_start next time around. This index is deliberately
|
|
17
|
+
* GLOBAL (stored directly under the AR root, not under projects/<slug>/) so
|
|
18
|
+
* it survives slug fragmentation (the F1 misfiling bug) by design: even when
|
|
19
|
+
* a session lands under the wrong/unexpected slug, its continuity entry is
|
|
20
|
+
* still visible from ANY project's cold start, because the reader never
|
|
21
|
+
* filters by the current slug.
|
|
22
|
+
*
|
|
23
|
+
* Storage: `<AR_ROOT>/recent-sessions.jsonl`, one JSON object per line,
|
|
24
|
+
* append-only, rolling-truncated at 500 lines — same append+roll shape as
|
|
25
|
+
* `logSyncError` (packages/core/src/supabase/sync.ts:79-94), except the path
|
|
26
|
+
* here resolves via `getRoot()` (respects `setRoot()` / `AGENT_RECALL_ROOT`)
|
|
27
|
+
* instead of sync.ts's hardcoded `os.homedir()`. That hardcoding is a KNOWN,
|
|
28
|
+
* separately-tracked test-pollution bug (design doc fact 8, fixed under F5) —
|
|
29
|
+
* this module is written correctly from the start rather than copying it.
|
|
30
|
+
*/
|
|
31
|
+
export interface RecentSessionEntry {
|
|
32
|
+
/** ISO-8601 timestamp of the session (when the entry was appended). */
|
|
33
|
+
ts: string;
|
|
34
|
+
/** Claude Code session id. */
|
|
35
|
+
sid: string;
|
|
36
|
+
/** Project slug this session was filed under. */
|
|
37
|
+
slug: string;
|
|
38
|
+
/** F1 slug-resolution confidence (0 when "auto"/unresolved), if known. */
|
|
39
|
+
slug_confidence?: number;
|
|
40
|
+
/** Short session title/summary. */
|
|
41
|
+
title: string;
|
|
42
|
+
/** Best-effort next-step text, if one was distilled for this session. */
|
|
43
|
+
next_step?: string;
|
|
44
|
+
/** Count of artifacts (files touched) this session, if known. */
|
|
45
|
+
artifact_count?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Append one entry to the recency index.
|
|
49
|
+
*
|
|
50
|
+
* Best-effort: any fs failure (permissions, disk full, concurrent-write
|
|
51
|
+
* race) is swallowed. This ledger is a "nice to have" continuity aid, not a
|
|
52
|
+
* system of record — a broken write here must never break the caller's hot
|
|
53
|
+
* path (hook-end / session_end).
|
|
54
|
+
*/
|
|
55
|
+
export declare function appendRecentSession(entry: RecentSessionEntry): void;
|
|
56
|
+
/**
|
|
57
|
+
* Read the last `n` entries, newest-first.
|
|
58
|
+
*
|
|
59
|
+
* Cross-project by design: this index is not scoped to any one project's
|
|
60
|
+
* directory (unlike journal/palace storage), so entries written under ANY
|
|
61
|
+
* slug are returned without filtering. Corrupt/partial lines (e.g. a torn
|
|
62
|
+
* write from a crash mid-append) are skipped individually rather than
|
|
63
|
+
* aborting the whole read. Returns `[]` when the index does not exist yet,
|
|
64
|
+
* when `n <= 0`, or on any read failure — never throws.
|
|
65
|
+
*/
|
|
66
|
+
export declare function readRecentSessions(n: number): RecentSessionEntry[];
|
|
67
|
+
/**
|
|
68
|
+
* Render an ISO timestamp as a short relative "ago" string for the
|
|
69
|
+
* continuity card (e.g. "just now", "12m ago", "3h ago", "2d ago").
|
|
70
|
+
*
|
|
71
|
+
* Worker Done-Definition #4 (date logic vs TODAY): a future-dated or
|
|
72
|
+
* clock-skewed timestamp (client clock drift, a bad manual entry, or a
|
|
73
|
+
* process crossing a DST boundary) must never render as a nonsensical
|
|
74
|
+
* negative duration — clamped to "just now" instead. Beyond a week, falls
|
|
75
|
+
* back to a plain ISO date: a relative "23d ago" stops being useful and an
|
|
76
|
+
* absolute anchor reads better at that distance.
|
|
77
|
+
*/
|
|
78
|
+
export declare function formatAgo(ts: string, now?: number): string;
|
|
79
|
+
//# sourceMappingURL=recency-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recency-index.d.ts","sourceRoot":"","sources":["../../src/storage/recency-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAuBH,MAAM,WAAW,kBAAkB;IACjC,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAgED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CASnE;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAqBlE;AAOD;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,GAAE,MAAmB,GAAG,MAAM,CAUtE"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-project recency index (F2, continuity wave 2026-07-31).
|
|
3
|
+
*
|
|
4
|
+
* A single, project-agnostic JSONL ledger of recent sessions. Written by the
|
|
5
|
+
* CLI hook-end path (Wave 2 integration wires the actual `appendRecentSession`
|
|
6
|
+
* call site — out of scope here, see packages/cli/src/index.ts) and read at
|
|
7
|
+
* `session_start` to render a "Continuity" card: what was worked on most
|
|
8
|
+
* recently, ACROSS projects, ranked by pure recency. This is deliberately
|
|
9
|
+
* NOT relevance-scored — `recallInsights` (session-start.ts's `cross_project`
|
|
10
|
+
* field) already covers semantic matching; this module's only job is "what
|
|
11
|
+
* happened most recently, anywhere".
|
|
12
|
+
*
|
|
13
|
+
* Root incident (2026-07-31 continuity-wave design doc, fact 6): session_start
|
|
14
|
+
* had zero recency signal outside the CURRENT project's own journal — a long
|
|
15
|
+
* work session captured under one slug was completely invisible from every
|
|
16
|
+
* OTHER slug's session_start next time around. This index is deliberately
|
|
17
|
+
* GLOBAL (stored directly under the AR root, not under projects/<slug>/) so
|
|
18
|
+
* it survives slug fragmentation (the F1 misfiling bug) by design: even when
|
|
19
|
+
* a session lands under the wrong/unexpected slug, its continuity entry is
|
|
20
|
+
* still visible from ANY project's cold start, because the reader never
|
|
21
|
+
* filters by the current slug.
|
|
22
|
+
*
|
|
23
|
+
* Storage: `<AR_ROOT>/recent-sessions.jsonl`, one JSON object per line,
|
|
24
|
+
* append-only, rolling-truncated at 500 lines — same append+roll shape as
|
|
25
|
+
* `logSyncError` (packages/core/src/supabase/sync.ts:79-94), except the path
|
|
26
|
+
* here resolves via `getRoot()` (respects `setRoot()` / `AGENT_RECALL_ROOT`)
|
|
27
|
+
* instead of sync.ts's hardcoded `os.homedir()`. That hardcoding is a KNOWN,
|
|
28
|
+
* separately-tracked test-pollution bug (design doc fact 8, fixed under F5) —
|
|
29
|
+
* this module is written correctly from the start rather than copying it.
|
|
30
|
+
*/
|
|
31
|
+
import * as fs from "node:fs";
|
|
32
|
+
import * as path from "node:path";
|
|
33
|
+
import { getRoot } from "../types.js";
|
|
34
|
+
const RECENCY_FILENAME = "recent-sessions.jsonl";
|
|
35
|
+
const MAX_LINES = 500;
|
|
36
|
+
/**
|
|
37
|
+
* H2 (review fix, 2026-07-31): only roll once the file is this far PAST
|
|
38
|
+
* MAX_LINES, trimming back down to MAX_LINES. Without this throttle, EVERY
|
|
39
|
+
* append past 500 lines triggered a fresh read→writeFileSync(tmp)→renameSync
|
|
40
|
+
* roll — a second process's plain `appendFileSync` straddling that rename
|
|
41
|
+
* lands on the unlinked inode: its write succeeds but the data silently
|
|
42
|
+
* vanishes once the rename swaps the directory entry to the new (trimmed)
|
|
43
|
+
* inode. Rolling only once every SLACK appends shrinks the number of roll
|
|
44
|
+
* events — and therefore the number of chances for another process's append
|
|
45
|
+
* to land inside one — by ~50x.
|
|
46
|
+
*/
|
|
47
|
+
const ROLL_SLACK = 50;
|
|
48
|
+
/** H2: best-effort exclusive lock guarding the roll itself (see rollIfNeeded). */
|
|
49
|
+
const ROLL_LOCK_STALE_MS = 5000;
|
|
50
|
+
function recencyIndexPath() {
|
|
51
|
+
return path.join(getRoot(), RECENCY_FILENAME);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Rolling truncate at MAX_LINES, mirroring `logSyncError`'s pattern
|
|
55
|
+
* (packages/core/src/supabase/sync.ts:79-94): read back, filter blank
|
|
56
|
+
* lines, keep only the last MAX_LINES, write to a temp file, then rename
|
|
57
|
+
* over the original (avoids a reader ever observing a half-written file).
|
|
58
|
+
*
|
|
59
|
+
* H2 (review fix, 2026-07-31): two additional safeguards against a
|
|
60
|
+
* concurrent-append race that could otherwise silently lose a second
|
|
61
|
+
* process's just-written entry (see ROLL_SLACK's doc comment above):
|
|
62
|
+
* 1. Throttle — only roll once `lines.length` exceeds MAX_LINES + ROLL_SLACK
|
|
63
|
+
* (not on every single append past MAX_LINES), shrinking how often the
|
|
64
|
+
* read→write→rename window opens at all.
|
|
65
|
+
* 2. Best-effort exclusive lockfile (`<file>.lock`, O_EXCL create, stale
|
|
66
|
+
* after ROLL_LOCK_STALE_MS) guarding the roll itself, so two processes
|
|
67
|
+
* that both cross the threshold near-simultaneously can't run competing
|
|
68
|
+
* rolls. Mirrors the O_EXCL-style lock convention used elsewhere in this
|
|
69
|
+
* codebase (e.g. the CLI's `.hook-end-lock`) rather than the heavier
|
|
70
|
+
* mkdir-based `filelock.ts` (that one busy-waits up to 5s on EVERY
|
|
71
|
+
* acquire — overkill for an operation that fires once per ~50 appends).
|
|
72
|
+
* Best-effort: if the lock can't be acquired (another process is
|
|
73
|
+
* actively rolling), this call simply SKIPS its own roll — the file is a
|
|
74
|
+
* little larger until the next append tries again; it never blocks or
|
|
75
|
+
* throws. This is defense-in-depth on top of the throttle above, not a
|
|
76
|
+
* complete substitute for it — the append itself is still lock-free.
|
|
77
|
+
*/
|
|
78
|
+
function rollIfNeeded(filePath) {
|
|
79
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
80
|
+
const lines = content.split("\n").filter(Boolean);
|
|
81
|
+
if (lines.length <= MAX_LINES + ROLL_SLACK)
|
|
82
|
+
return;
|
|
83
|
+
const trimmed = lines.slice(-MAX_LINES).join("\n") + "\n";
|
|
84
|
+
const lockPath = filePath + ".lock";
|
|
85
|
+
let fd;
|
|
86
|
+
try {
|
|
87
|
+
fd = fs.openSync(lockPath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// Lock already held. If it's stale (a crashed writer, >ROLL_LOCK_STALE_MS
|
|
91
|
+
// old), force-break it and take it; otherwise skip this roll entirely.
|
|
92
|
+
try {
|
|
93
|
+
const stat = fs.statSync(lockPath);
|
|
94
|
+
if (Date.now() - stat.mtimeMs <= ROLL_LOCK_STALE_MS)
|
|
95
|
+
return; // held by an active writer
|
|
96
|
+
fs.unlinkSync(lockPath);
|
|
97
|
+
fd = fs.openSync(lockPath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return; // lost the race to break the stale lock, or another fs error — skip, never throw
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const tmpPath = filePath + ".tmp";
|
|
105
|
+
fs.writeFileSync(tmpPath, trimmed, "utf-8");
|
|
106
|
+
fs.renameSync(tmpPath, filePath);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
try {
|
|
110
|
+
fs.closeSync(fd);
|
|
111
|
+
}
|
|
112
|
+
catch { /* already closed */ }
|
|
113
|
+
try {
|
|
114
|
+
fs.unlinkSync(lockPath);
|
|
115
|
+
}
|
|
116
|
+
catch { /* already removed */ }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Append one entry to the recency index.
|
|
121
|
+
*
|
|
122
|
+
* Best-effort: any fs failure (permissions, disk full, concurrent-write
|
|
123
|
+
* race) is swallowed. This ledger is a "nice to have" continuity aid, not a
|
|
124
|
+
* system of record — a broken write here must never break the caller's hot
|
|
125
|
+
* path (hook-end / session_end).
|
|
126
|
+
*/
|
|
127
|
+
export function appendRecentSession(entry) {
|
|
128
|
+
try {
|
|
129
|
+
const filePath = recencyIndexPath();
|
|
130
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
131
|
+
fs.appendFileSync(filePath, JSON.stringify(entry) + "\n", "utf-8");
|
|
132
|
+
rollIfNeeded(filePath);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Best-effort — never throw from an append-only telemetry ledger.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Read the last `n` entries, newest-first.
|
|
140
|
+
*
|
|
141
|
+
* Cross-project by design: this index is not scoped to any one project's
|
|
142
|
+
* directory (unlike journal/palace storage), so entries written under ANY
|
|
143
|
+
* slug are returned without filtering. Corrupt/partial lines (e.g. a torn
|
|
144
|
+
* write from a crash mid-append) are skipped individually rather than
|
|
145
|
+
* aborting the whole read. Returns `[]` when the index does not exist yet,
|
|
146
|
+
* when `n <= 0`, or on any read failure — never throws.
|
|
147
|
+
*/
|
|
148
|
+
export function readRecentSessions(n) {
|
|
149
|
+
if (n <= 0)
|
|
150
|
+
return [];
|
|
151
|
+
try {
|
|
152
|
+
const filePath = recencyIndexPath();
|
|
153
|
+
if (!fs.existsSync(filePath))
|
|
154
|
+
return [];
|
|
155
|
+
const lines = fs.readFileSync(filePath, "utf-8").split("\n").filter(Boolean);
|
|
156
|
+
const out = [];
|
|
157
|
+
for (let i = lines.length - 1; i >= 0 && out.length < n; i--) {
|
|
158
|
+
try {
|
|
159
|
+
const parsed = JSON.parse(lines[i]);
|
|
160
|
+
if (parsed && typeof parsed.slug === "string" && typeof parsed.title === "string" && typeof parsed.ts === "string") {
|
|
161
|
+
out.push(parsed);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// Skip a corrupt/partial line rather than aborting the whole read.
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const MINUTE_MS = 60_000;
|
|
175
|
+
const HOUR_MS = 60 * MINUTE_MS;
|
|
176
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
177
|
+
const WEEK_MS = 7 * DAY_MS;
|
|
178
|
+
/**
|
|
179
|
+
* Render an ISO timestamp as a short relative "ago" string for the
|
|
180
|
+
* continuity card (e.g. "just now", "12m ago", "3h ago", "2d ago").
|
|
181
|
+
*
|
|
182
|
+
* Worker Done-Definition #4 (date logic vs TODAY): a future-dated or
|
|
183
|
+
* clock-skewed timestamp (client clock drift, a bad manual entry, or a
|
|
184
|
+
* process crossing a DST boundary) must never render as a nonsensical
|
|
185
|
+
* negative duration — clamped to "just now" instead. Beyond a week, falls
|
|
186
|
+
* back to a plain ISO date: a relative "23d ago" stops being useful and an
|
|
187
|
+
* absolute anchor reads better at that distance.
|
|
188
|
+
*/
|
|
189
|
+
export function formatAgo(ts, now = Date.now()) {
|
|
190
|
+
const then = new Date(ts).getTime();
|
|
191
|
+
if (Number.isNaN(then))
|
|
192
|
+
return "unknown time";
|
|
193
|
+
const diffMs = now - then;
|
|
194
|
+
if (diffMs < MINUTE_MS)
|
|
195
|
+
return "just now"; // covers <60s AND any future/skewed timestamp
|
|
196
|
+
if (diffMs < HOUR_MS)
|
|
197
|
+
return `${Math.floor(diffMs / MINUTE_MS)}m ago`;
|
|
198
|
+
if (diffMs < DAY_MS)
|
|
199
|
+
return `${Math.floor(diffMs / HOUR_MS)}h ago`;
|
|
200
|
+
if (diffMs < WEEK_MS)
|
|
201
|
+
return `${Math.floor(diffMs / DAY_MS)}d ago`;
|
|
202
|
+
return new Date(then).toISOString().slice(0, 10);
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=recency-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recency-index.js","sourceRoot":"","sources":["../../src/storage/recency-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AACjD,MAAM,SAAS,GAAG,GAAG,CA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