@edihasaj/recall 2.0.7 → 2.0.8
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/README.md +11 -0
- package/dist/{chunk-W75S5CK3.js → chunk-3LL5S473.js} +2 -2
- package/dist/{chunk-YDVBXHX2.js → chunk-3ZA4YOFN.js} +5 -5
- package/dist/{chunk-QPOOF2GK.js → chunk-4LTGMFHN.js} +3 -3
- package/dist/{chunk-S46JVROA.js → chunk-6U7YMPBE.js} +2 -2
- package/dist/{chunk-BTD3BYVV.js → chunk-BOUMOPKD.js} +2 -2
- package/dist/{chunk-63H4ENYA.js → chunk-HYDNV5T2.js} +351 -139
- package/dist/chunk-HYDNV5T2.js.map +1 -0
- package/dist/{chunk-BJZCBMU4.js → chunk-J3F3CLWL.js} +7 -7
- package/dist/{chunk-MZTZKBRL.js → chunk-JSKYG7TC.js} +2 -2
- package/dist/{chunk-M5MPUMCJ.js → chunk-LOWPEB72.js} +3 -3
- package/dist/{chunk-DQMKYMUS.js → chunk-MD2LUEVD.js} +435 -89
- package/dist/chunk-MD2LUEVD.js.map +1 -0
- package/dist/{chunk-EX5UTOIU.js → chunk-N2ONUBXR.js} +9 -9
- package/dist/{chunk-VH3FI2X3.js → chunk-OHWHU653.js} +843 -144
- package/dist/chunk-OHWHU653.js.map +1 -0
- package/dist/{chunk-MQPMF5F3.js → chunk-PW42PFVO.js} +7 -7
- package/dist/{chunk-2WBJWKIK.js → chunk-QKGE74LD.js} +8 -5
- package/dist/chunk-QKGE74LD.js.map +1 -0
- package/dist/{chunk-FOJHR4JJ.js → chunk-QOMNHKYE.js} +2 -2
- package/dist/{chunk-AVUTQWZE.js → chunk-RSBIISGE.js} +5 -5
- package/dist/{chunk-V3MYT3AT.js → chunk-URQEUH7T.js} +3 -3
- package/dist/{chunk-EDUIDJWZ.js → chunk-VV2QPDAM.js} +2 -2
- package/dist/{chunk-EDUIDJWZ.js.map → chunk-VV2QPDAM.js.map} +1 -1
- package/dist/{cleanup-EDWLCJPH.js → cleanup-QC7EHMUB.js} +11 -11
- package/dist/cli.js +209 -162
- package/dist/cli.js.map +1 -1
- package/dist/{codex-trust-H6KNABHV.js → codex-trust-4RI6LCAI.js} +4 -4
- package/dist/daemon.js +208 -48
- package/dist/daemon.js.map +1 -1
- package/dist/dispatcher-XGATH6Q5.js +22 -0
- package/dist/{embeddings-W24SA6R3.js → embeddings-RS3GK3TS.js} +5 -5
- package/dist/ingest-RGPV5QYT.js +20 -0
- package/dist/{keychain-LVWMAS7D.js → keychain-BRWB5CL5.js} +3 -3
- package/dist/mcp.js +15 -15
- package/dist/{memory-value-GMYJ5NGO.js → memory-value-6KDRPDXE.js} +11 -11
- package/dist/{provenance-KSBMVJO5.js → provenance-NLVTH5ZK.js} +9 -9
- package/dist/quality-QPRUXM4B.js +25 -0
- package/dist/retrieval-N5FQRL2V.js +15 -0
- package/dist/{store-QYLHMBPE.js → store-DXJJ7VOQ.js} +4 -4
- package/dist/sync-server.js +2 -2
- package/dist/{tasks-7P7XOGSC.js → tasks-32RY4KNA.js} +11 -11
- package/dist/{usage-KVVZQTZA.js → usage-3EMXD6MZ.js} +4 -4
- package/dist/webui/assets/{GraphPage-DJhwG-72.js → GraphPage-BH_Mch3C.js} +2 -2
- package/dist/webui/assets/{GraphPage-DJhwG-72.js.map → GraphPage-BH_Mch3C.js.map} +1 -1
- package/dist/webui/assets/{index-Cpn2MjW0.js → index-CPFc-fiv.js} +25 -25
- package/dist/webui/assets/index-CPFc-fiv.js.map +1 -0
- package/dist/webui/index.html +1 -1
- package/package.json +1 -1
- package/dist/chunk-2WBJWKIK.js.map +0 -1
- package/dist/chunk-63H4ENYA.js.map +0 -1
- package/dist/chunk-DQMKYMUS.js.map +0 -1
- package/dist/chunk-VH3FI2X3.js.map +0 -1
- package/dist/dispatcher-W3PTGEKN.js +0 -22
- package/dist/ingest-FF67DX3F.js +0 -20
- package/dist/quality-6BN2ERKC.js +0 -25
- package/dist/retrieval-QLC3DNMW.js +0 -15
- package/dist/webui/assets/index-Cpn2MjW0.js.map +0 -1
- /package/dist/{chunk-W75S5CK3.js.map → chunk-3LL5S473.js.map} +0 -0
- /package/dist/{chunk-YDVBXHX2.js.map → chunk-3ZA4YOFN.js.map} +0 -0
- /package/dist/{chunk-QPOOF2GK.js.map → chunk-4LTGMFHN.js.map} +0 -0
- /package/dist/{chunk-S46JVROA.js.map → chunk-6U7YMPBE.js.map} +0 -0
- /package/dist/{chunk-BTD3BYVV.js.map → chunk-BOUMOPKD.js.map} +0 -0
- /package/dist/{chunk-BJZCBMU4.js.map → chunk-J3F3CLWL.js.map} +0 -0
- /package/dist/{chunk-MZTZKBRL.js.map → chunk-JSKYG7TC.js.map} +0 -0
- /package/dist/{chunk-M5MPUMCJ.js.map → chunk-LOWPEB72.js.map} +0 -0
- /package/dist/{chunk-EX5UTOIU.js.map → chunk-N2ONUBXR.js.map} +0 -0
- /package/dist/{chunk-MQPMF5F3.js.map → chunk-PW42PFVO.js.map} +0 -0
- /package/dist/{chunk-FOJHR4JJ.js.map → chunk-QOMNHKYE.js.map} +0 -0
- /package/dist/{chunk-AVUTQWZE.js.map → chunk-RSBIISGE.js.map} +0 -0
- /package/dist/{chunk-V3MYT3AT.js.map → chunk-URQEUH7T.js.map} +0 -0
- /package/dist/{cleanup-EDWLCJPH.js.map → cleanup-QC7EHMUB.js.map} +0 -0
- /package/dist/{codex-trust-H6KNABHV.js.map → codex-trust-4RI6LCAI.js.map} +0 -0
- /package/dist/{dispatcher-W3PTGEKN.js.map → dispatcher-XGATH6Q5.js.map} +0 -0
- /package/dist/{embeddings-W24SA6R3.js.map → embeddings-RS3GK3TS.js.map} +0 -0
- /package/dist/{ingest-FF67DX3F.js.map → ingest-RGPV5QYT.js.map} +0 -0
- /package/dist/{keychain-LVWMAS7D.js.map → keychain-BRWB5CL5.js.map} +0 -0
- /package/dist/{memory-value-GMYJ5NGO.js.map → memory-value-6KDRPDXE.js.map} +0 -0
- /package/dist/{provenance-KSBMVJO5.js.map → provenance-NLVTH5ZK.js.map} +0 -0
- /package/dist/{quality-6BN2ERKC.js.map → quality-QPRUXM4B.js.map} +0 -0
- /package/dist/{retrieval-QLC3DNMW.js.map → retrieval-N5FQRL2V.js.map} +0 -0
- /package/dist/{store-QYLHMBPE.js.map → store-DXJJ7VOQ.js.map} +0 -0
- /package/dist/{tasks-7P7XOGSC.js.map → tasks-32RY4KNA.js.map} +0 -0
- /package/dist/{usage-KVVZQTZA.js.map → usage-3EMXD6MZ.js.map} +0 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
hasCommand,
|
|
4
4
|
resolveCodexHomes,
|
|
5
5
|
resolveUserHomeDir
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4LTGMFHN.js";
|
|
7
7
|
import {
|
|
8
8
|
RECALL_DB_USER_VERSION,
|
|
9
9
|
captureCorrectionFallback,
|
|
@@ -15,12 +15,13 @@ import {
|
|
|
15
15
|
getDbUserVersion,
|
|
16
16
|
inferRepoSlugFromPath,
|
|
17
17
|
initDb,
|
|
18
|
+
isUnscopedSessionPath,
|
|
18
19
|
listActivityEvents,
|
|
19
20
|
listInjectedHistoryIdsForSession,
|
|
20
21
|
resolveLocalRepoPath,
|
|
21
22
|
signalOutcomeFallback,
|
|
22
23
|
startSessionLifecycle
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-HYDNV5T2.js";
|
|
24
25
|
import {
|
|
25
26
|
detectCorrections,
|
|
26
27
|
isHighRiskRule,
|
|
@@ -28,7 +29,7 @@ import {
|
|
|
28
29
|
isWorkspaceRootAlias,
|
|
29
30
|
peekTasks,
|
|
30
31
|
redactSensitiveText
|
|
31
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-MD2LUEVD.js";
|
|
32
33
|
import {
|
|
33
34
|
detectAndRecordRetrievalMissesSemantic,
|
|
34
35
|
listInjectedMemoryIdsForSession,
|
|
@@ -36,10 +37,10 @@ import {
|
|
|
36
37
|
pathMatchesMemory,
|
|
37
38
|
recordCompletionUseValueEventsSemantic,
|
|
38
39
|
toolCallTouchesMemory
|
|
39
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-PW42PFVO.js";
|
|
40
41
|
import {
|
|
41
42
|
textMatches
|
|
42
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-3LL5S473.js";
|
|
43
44
|
import {
|
|
44
45
|
appendEvidence,
|
|
45
46
|
createMemory,
|
|
@@ -48,35 +49,42 @@ import {
|
|
|
48
49
|
queryMemories,
|
|
49
50
|
recordAudit,
|
|
50
51
|
rejectMemory
|
|
51
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-J3F3CLWL.js";
|
|
52
53
|
import {
|
|
53
54
|
desc
|
|
54
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-URQEUH7T.js";
|
|
55
56
|
import {
|
|
56
57
|
defineOwn,
|
|
57
58
|
deleteOwn
|
|
58
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-6U7YMPBE.js";
|
|
59
60
|
import {
|
|
60
61
|
atomicWriteUtf8File,
|
|
61
62
|
getEmbeddingModelInfo,
|
|
62
63
|
readUtf8FileIfExists,
|
|
63
64
|
tagActivitySource
|
|
64
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-QKGE74LD.js";
|
|
65
66
|
import {
|
|
66
67
|
init_keychain,
|
|
67
68
|
keychain_exports
|
|
68
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-QOMNHKYE.js";
|
|
69
70
|
import {
|
|
70
71
|
activityEvents,
|
|
71
72
|
and,
|
|
72
73
|
eq,
|
|
74
|
+
gte,
|
|
73
75
|
hookCalls,
|
|
76
|
+
isNotNull,
|
|
77
|
+
lte,
|
|
78
|
+
memories,
|
|
79
|
+
memoryInjections,
|
|
80
|
+
memoryValueEvents,
|
|
81
|
+
ne,
|
|
74
82
|
sql
|
|
75
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-BOUMOPKD.js";
|
|
76
84
|
import {
|
|
77
85
|
__toCommonJS,
|
|
78
86
|
init_define_RECALL_BUILD_INFO
|
|
79
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-VV2QPDAM.js";
|
|
80
88
|
|
|
81
89
|
// src/adapters/markdown.ts
|
|
82
90
|
init_define_RECALL_BUILD_INFO();
|
|
@@ -237,6 +245,155 @@ function unregisterStrayApps(strayPaths, options = {}) {
|
|
|
237
245
|
return result;
|
|
238
246
|
}
|
|
239
247
|
|
|
248
|
+
// src/reliability/report.ts
|
|
249
|
+
init_define_RECALL_BUILD_INFO();
|
|
250
|
+
function ratio(numerator, denominator) {
|
|
251
|
+
return denominator > 0 ? numerator / denominator : 0;
|
|
252
|
+
}
|
|
253
|
+
function computeReliabilityReport(db, options = {}) {
|
|
254
|
+
const end = (/* @__PURE__ */ new Date()).toISOString();
|
|
255
|
+
const start = options.since ?? new Date(Date.now() - 14 * 864e5).toISOString();
|
|
256
|
+
const activityConditions = [gte(activityEvents.created_at, start)];
|
|
257
|
+
const injectionConditions = [gte(memoryInjections.injected_at, start)];
|
|
258
|
+
const valueConditions = [gte(memoryValueEvents.created_at, start)];
|
|
259
|
+
if (options.repo) {
|
|
260
|
+
activityConditions.push(eq(activityEvents.repo, options.repo));
|
|
261
|
+
injectionConditions.push(eq(memoryInjections.repo, options.repo));
|
|
262
|
+
valueConditions.push(eq(memoryValueEvents.repo, options.repo));
|
|
263
|
+
}
|
|
264
|
+
const activity = db.select().from(activityEvents).where(and(...activityConditions)).all();
|
|
265
|
+
const injections = db.select().from(memoryInjections).where(and(...injectionConditions)).all();
|
|
266
|
+
const valueEvents = db.select().from(memoryValueEvents).where(and(...valueConditions)).all();
|
|
267
|
+
const lifecycle = activity.filter(
|
|
268
|
+
(event) => event.session_id && (event.event_type === "session_start" || event.event_type === "session_end")
|
|
269
|
+
);
|
|
270
|
+
const sessionIds = new Set(lifecycle.map((event) => event.session_id));
|
|
271
|
+
const attributedSessionIds = new Set(
|
|
272
|
+
lifecycle.filter((event) => Boolean(event.repo)).map((event) => event.session_id)
|
|
273
|
+
);
|
|
274
|
+
const scopedSessionIds = new Set(attributedSessionIds);
|
|
275
|
+
const unscopedPathBySession = /* @__PURE__ */ new Map();
|
|
276
|
+
const scopeCache = /* @__PURE__ */ new Map();
|
|
277
|
+
const isUnscoped = (repoPath) => {
|
|
278
|
+
let cached = scopeCache.get(repoPath);
|
|
279
|
+
if (cached === void 0) {
|
|
280
|
+
cached = isUnscopedSessionPath(repoPath);
|
|
281
|
+
scopeCache.set(repoPath, cached);
|
|
282
|
+
}
|
|
283
|
+
return cached;
|
|
284
|
+
};
|
|
285
|
+
for (const event of lifecycle) {
|
|
286
|
+
if (!event.session_id) continue;
|
|
287
|
+
const request = typeof event.request === "string" ? JSON.parse(event.request) : event.request;
|
|
288
|
+
const repoPath = typeof request?.repo_path === "string" ? request.repo_path : "";
|
|
289
|
+
if (!repoPath) continue;
|
|
290
|
+
if (isUnscoped(repoPath)) {
|
|
291
|
+
if (!unscopedPathBySession.has(event.session_id)) unscopedPathBySession.set(event.session_id, repoPath);
|
|
292
|
+
} else {
|
|
293
|
+
scopedSessionIds.add(event.session_id);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const unscopedSessions = sessionIds.size - scopedSessionIds.size;
|
|
297
|
+
const unscopedPathCounts = /* @__PURE__ */ new Map();
|
|
298
|
+
for (const [sessionId, repoPath] of unscopedPathBySession) {
|
|
299
|
+
if (scopedSessionIds.has(sessionId)) continue;
|
|
300
|
+
unscopedPathCounts.set(repoPath, (unscopedPathCounts.get(repoPath) ?? 0) + 1);
|
|
301
|
+
}
|
|
302
|
+
const unscopedTopPaths = [...unscopedPathCounts.entries()].sort((left, right) => right[1] - left[1] || left[0].localeCompare(right[0])).slice(0, 3).map(([path, sessions]) => ({ path, sessions }));
|
|
303
|
+
const emittedPairs = /* @__PURE__ */ new Set();
|
|
304
|
+
for (const event of activity) {
|
|
305
|
+
if (event.event_type !== "session_event" || !event.session_id) continue;
|
|
306
|
+
const request = typeof event.request === "string" ? JSON.parse(event.request) : event.request;
|
|
307
|
+
if (request?.name !== "memory_emitted") continue;
|
|
308
|
+
const memoryIds = Array.isArray(event.memory_ids) ? event.memory_ids : [];
|
|
309
|
+
for (const memoryId of memoryIds) {
|
|
310
|
+
emittedPairs.add(`${event.session_id}\0${memoryId}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const selectedPairs = new Set(
|
|
314
|
+
injections.map((injection) => `${injection.session_id}\0${injection.memory_id}`)
|
|
315
|
+
);
|
|
316
|
+
const emittedSelected = [...emittedPairs].filter((key) => selectedPairs.has(key)).length;
|
|
317
|
+
const observedUses = valueEvents.filter((event) => event.event_type === "used").length;
|
|
318
|
+
const resolvedOutcomes = injections.filter((injection) => injection.outcome != null).length;
|
|
319
|
+
const retrievalMisses = valueEvents.filter((event) => event.event_type === "retrieval_miss").length;
|
|
320
|
+
const retrievalUses = valueEvents.filter((event) => event.event_type === "used").length;
|
|
321
|
+
const candidates = db.select({ id: memories.id, auto_inject: memories.auto_inject, repo: memories.repo }).from(memories).where(eq(memories.status, "candidate")).all();
|
|
322
|
+
const injectableCandidates = candidates.filter((memory) => memory.auto_inject);
|
|
323
|
+
const candidatesByRepo = /* @__PURE__ */ new Map();
|
|
324
|
+
for (const memory of injectableCandidates) {
|
|
325
|
+
const key = memory.repo ?? "global";
|
|
326
|
+
candidatesByRepo.set(key, (candidatesByRepo.get(key) ?? 0) + 1);
|
|
327
|
+
}
|
|
328
|
+
const candidateBacklog = options.repo ? injectableCandidates.length : Math.max(0, ...candidatesByRepo.values());
|
|
329
|
+
const activeMemories = db.select({ id: memories.id }).from(memories).where(eq(memories.status, "active")).all().length;
|
|
330
|
+
const repoAttribution = ratio(attributedSessionIds.size, scopedSessionIds.size);
|
|
331
|
+
const scopeCoverage = ratio(scopedSessionIds.size, sessionIds.size);
|
|
332
|
+
const emissionCoverage = ratio(emittedSelected, selectedPairs.size);
|
|
333
|
+
const outcomeCoverage = ratio(resolvedOutcomes, emittedSelected);
|
|
334
|
+
const retrievalObservations = retrievalMisses + retrievalUses;
|
|
335
|
+
const checks = [
|
|
336
|
+
{ name: "repo_attribution", status: scopedSessionIds.size === 0 ? "warn" : repoAttribution >= 0.95 ? "pass" : repoAttribution >= 0.8 ? "warn" : "fail", value: repoAttribution, target: ">=95%" },
|
|
337
|
+
// Unscoped sessions cannot receive repo memory. Surface the share instead
|
|
338
|
+
// of hiding it behind a perfect attribution rate; never fails on its own.
|
|
339
|
+
{ name: "session_scope_coverage", status: sessionIds.size === 0 || scopeCoverage < 0.5 ? "warn" : "pass", value: scopeCoverage, target: ">=50%" },
|
|
340
|
+
{ name: "emission_coverage", status: selectedPairs.size === 0 ? "warn" : emissionCoverage >= 0.99 ? "pass" : emissionCoverage >= 0.95 ? "warn" : "fail", value: emissionCoverage, target: ">=99%" },
|
|
341
|
+
{ name: "outcome_coverage", status: emittedSelected === 0 ? "warn" : outcomeCoverage >= 0.8 ? "pass" : outcomeCoverage >= 0.5 ? "warn" : "fail", value: outcomeCoverage, target: ">=80%" },
|
|
342
|
+
{ name: "retrieval_observations", status: retrievalObservations >= 20 ? "pass" : retrievalObservations >= 5 ? "warn" : "fail", value: retrievalObservations, target: ">=20" },
|
|
343
|
+
{ name: "candidate_backlog", status: candidateBacklog <= 50 ? "pass" : candidateBacklog <= 100 ? "warn" : "fail", value: candidateBacklog, target: "<=50" }
|
|
344
|
+
];
|
|
345
|
+
const overall = checks.some((check) => check.status === "fail") ? "fail" : checks.some((check) => check.status === "warn") ? "warn" : "pass";
|
|
346
|
+
return {
|
|
347
|
+
window_start: start,
|
|
348
|
+
window_end: end,
|
|
349
|
+
sessions: sessionIds.size,
|
|
350
|
+
sessions_requiring_repo: scopedSessionIds.size,
|
|
351
|
+
sessions_with_repo: attributedSessionIds.size,
|
|
352
|
+
sessions_unscoped: unscopedSessions,
|
|
353
|
+
unscoped_top_paths: unscopedTopPaths,
|
|
354
|
+
repo_attribution_rate: repoAttribution,
|
|
355
|
+
selected_injections: selectedPairs.size,
|
|
356
|
+
emitted_injections: emittedSelected,
|
|
357
|
+
emission_coverage: emissionCoverage,
|
|
358
|
+
observed_uses: observedUses,
|
|
359
|
+
resolved_outcomes: resolvedOutcomes,
|
|
360
|
+
outcome_coverage: outcomeCoverage,
|
|
361
|
+
retrieval_misses: retrievalMisses,
|
|
362
|
+
retrieval_observations: retrievalObservations,
|
|
363
|
+
candidate_backlog: candidateBacklog,
|
|
364
|
+
candidate_injectable_total: injectableCandidates.length,
|
|
365
|
+
candidate_total: candidates.length,
|
|
366
|
+
active_memories: activeMemories,
|
|
367
|
+
checks,
|
|
368
|
+
overall
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function formatReliabilityReport(report) {
|
|
372
|
+
const percent = (value) => `${(value * 100).toFixed(1)}%`;
|
|
373
|
+
const home = process.env.HOME ?? "";
|
|
374
|
+
const displayPath = (path) => home && path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
375
|
+
const lines = [
|
|
376
|
+
"# Recall Reliability",
|
|
377
|
+
"",
|
|
378
|
+
`Window: ${report.window_start} to ${report.window_end}`,
|
|
379
|
+
`Overall: ${report.overall.toUpperCase()}`,
|
|
380
|
+
"",
|
|
381
|
+
`Sessions: ${report.sessions} (${report.sessions_requiring_repo} required repo, ${report.sessions_with_repo} attributed, ${percent(report.repo_attribution_rate)}; ${report.sessions_unscoped} unscoped)`,
|
|
382
|
+
...report.unscoped_top_paths.length > 0 ? [`Unscoped cwd (no git checkout \u2014 open the repo itself or set RECALL_REPO_OVERRIDE): ${report.unscoped_top_paths.map((entry) => `${displayPath(entry.path)} (${entry.sessions})`).join(", ")}`] : [],
|
|
383
|
+
`Injections: ${report.selected_injections} selected, ${report.emitted_injections} emitted (${percent(report.emission_coverage)})`,
|
|
384
|
+
`Evidence: ${report.observed_uses} observed uses, ${report.resolved_outcomes} resolved outcomes (${percent(report.outcome_coverage)})`,
|
|
385
|
+
`Retrieval: ${report.retrieval_observations} observations, ${report.retrieval_misses} misses`,
|
|
386
|
+
`Memory: ${report.active_memories} active, ${report.candidate_injectable_total} injectable candidates total, ${report.candidate_backlog} max in one repo, ${report.candidate_total} total candidates`,
|
|
387
|
+
"",
|
|
388
|
+
"## Checks"
|
|
389
|
+
];
|
|
390
|
+
for (const check of report.checks) {
|
|
391
|
+
const value = check.name.endsWith("coverage") || check.name === "repo_attribution" ? percent(check.value) : String(check.value);
|
|
392
|
+
lines.push(`${check.status.toUpperCase().padEnd(4)} ${check.name}: ${value} (target ${check.target})`);
|
|
393
|
+
}
|
|
394
|
+
return lines.join("\n");
|
|
395
|
+
}
|
|
396
|
+
|
|
240
397
|
// src/hooks/calls.ts
|
|
241
398
|
init_define_RECALL_BUILD_INFO();
|
|
242
399
|
import { randomUUID } from "crypto";
|
|
@@ -426,6 +583,193 @@ function learnFromToolOutcome(db, outcome) {
|
|
|
426
583
|
return { action: "created", memory_id: id };
|
|
427
584
|
}
|
|
428
585
|
|
|
586
|
+
// src/cli/hook-codex-payload.ts
|
|
587
|
+
init_define_RECALL_BUILD_INFO();
|
|
588
|
+
import { appendFileSync, mkdirSync as mkdirSync2, renameSync, rmSync, statSync } from "fs";
|
|
589
|
+
import { homedir } from "os";
|
|
590
|
+
import { dirname, join as join2 } from "path";
|
|
591
|
+
var SESSION_ID_KEYS = [
|
|
592
|
+
"session_id",
|
|
593
|
+
"sessionId",
|
|
594
|
+
"session-id",
|
|
595
|
+
"thread_id",
|
|
596
|
+
"threadId",
|
|
597
|
+
"conversation_id",
|
|
598
|
+
"conversationId"
|
|
599
|
+
];
|
|
600
|
+
var CONTAINER_KEYS = ["session", "thread", "conversation", "payload", "data"];
|
|
601
|
+
var IDENTITY_CONTAINERS = /* @__PURE__ */ new Set(["session", "thread", "conversation"]);
|
|
602
|
+
var MAX_CONTAINER_DEPTH = 2;
|
|
603
|
+
var PLACEHOLDER_SESSION_ID = "hook";
|
|
604
|
+
var DEFAULT_RECENT_SESSION_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
605
|
+
var DEFAULT_SESSION_AMBIGUITY_WINDOW_MS = 2 * 60 * 1e3;
|
|
606
|
+
var MAX_CANDIDATE_SESSIONS = 64;
|
|
607
|
+
var DEFAULT_HOOK_LOG_MAX_BYTES = 1024 * 1024;
|
|
608
|
+
var ROLLOUT_THREAD_ID = /(?:^|[\\/])rollout-[^\\/]*?-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl(?:\.zst)?$/i;
|
|
609
|
+
function extractCodexSessionId(payload) {
|
|
610
|
+
return findSessionId(payload, [], false, 0);
|
|
611
|
+
}
|
|
612
|
+
function findSessionId(record, path, allowBareId, depth) {
|
|
613
|
+
for (const key of SESSION_ID_KEYS) {
|
|
614
|
+
const value = nonEmptyString(record[key]);
|
|
615
|
+
if (value) return { session_id: value, key_path: [...path, key].join(".") };
|
|
616
|
+
}
|
|
617
|
+
if (allowBareId) {
|
|
618
|
+
const value = nonEmptyString(record.id);
|
|
619
|
+
if (value) return { session_id: value, key_path: [...path, "id"].join(".") };
|
|
620
|
+
}
|
|
621
|
+
if (depth >= MAX_CONTAINER_DEPTH) return null;
|
|
622
|
+
for (const key of CONTAINER_KEYS) {
|
|
623
|
+
const nested = record[key];
|
|
624
|
+
if (!isPlainRecord(nested)) continue;
|
|
625
|
+
const match = findSessionId(nested, [...path, key], IDENTITY_CONTAINERS.has(key), depth + 1);
|
|
626
|
+
if (match) return match;
|
|
627
|
+
}
|
|
628
|
+
return null;
|
|
629
|
+
}
|
|
630
|
+
function extractCodexTranscriptSessionId(transcriptPath) {
|
|
631
|
+
const value = nonEmptyString(transcriptPath);
|
|
632
|
+
if (!value) return null;
|
|
633
|
+
return ROLLOUT_THREAD_ID.exec(value)?.[1] ?? null;
|
|
634
|
+
}
|
|
635
|
+
function findRecentCodexSession(db, query) {
|
|
636
|
+
const now = query.now ?? /* @__PURE__ */ new Date();
|
|
637
|
+
const maxAgeMs = query.maxAgeMs ?? DEFAULT_RECENT_SESSION_MAX_AGE_MS;
|
|
638
|
+
const ambiguityWindowMs = query.ambiguityWindowMs ?? DEFAULT_SESSION_AMBIGUITY_WINDOW_MS;
|
|
639
|
+
const since = new Date(now.getTime() - maxAgeMs).toISOString();
|
|
640
|
+
const source = tagActivitySource("hook", query.agent ?? "codex");
|
|
641
|
+
const lastAt = sql`max(${activityEvents.created_at})`;
|
|
642
|
+
const sessions = db.select({
|
|
643
|
+
session_id: activityEvents.session_id,
|
|
644
|
+
last_at: lastAt,
|
|
645
|
+
last_event: activityEvents.event_type
|
|
646
|
+
}).from(activityEvents).where(and(
|
|
647
|
+
eq(activityEvents.source, source),
|
|
648
|
+
isNotNull(activityEvents.session_id),
|
|
649
|
+
ne(activityEvents.session_id, PLACEHOLDER_SESSION_ID),
|
|
650
|
+
ne(activityEvents.session_id, ""),
|
|
651
|
+
gte(activityEvents.created_at, since),
|
|
652
|
+
lte(activityEvents.created_at, now.toISOString()),
|
|
653
|
+
sql`json_extract(${activityEvents.request}, '$.repo_path') = ${query.cwd}`
|
|
654
|
+
)).groupBy(activityEvents.session_id).orderBy(desc(lastAt)).limit(MAX_CANDIDATE_SESSIONS).all();
|
|
655
|
+
const top = sessions.find((session) => session.last_event !== "session_end");
|
|
656
|
+
const topId = nonEmptyString(top?.session_id);
|
|
657
|
+
if (!top || !topId) return { status: "none" };
|
|
658
|
+
const rivalCutoff = now.getTime() - ambiguityWindowMs;
|
|
659
|
+
const rivals = sessions.filter(
|
|
660
|
+
(session) => session.session_id !== top.session_id && Date.parse(session.last_at) >= rivalCutoff
|
|
661
|
+
);
|
|
662
|
+
if (rivals.length > 0) return { status: "ambiguous", candidate_count: rivals.length + 1 };
|
|
663
|
+
return { status: "found", session_id: topId };
|
|
664
|
+
}
|
|
665
|
+
function resolveCodexSessionEndSessionId(payload, opts) {
|
|
666
|
+
const direct = extractCodexSessionId(payload);
|
|
667
|
+
if (direct) {
|
|
668
|
+
return { status: "resolved", session_id: direct.session_id, resolved_via: direct.key_path };
|
|
669
|
+
}
|
|
670
|
+
const record = payload;
|
|
671
|
+
const fromTranscript = extractCodexTranscriptSessionId(record.transcript_path);
|
|
672
|
+
if (fromTranscript) {
|
|
673
|
+
return { status: "resolved", session_id: fromTranscript, resolved_via: "transcript_path" };
|
|
674
|
+
}
|
|
675
|
+
const agent = opts.agent ?? "codex";
|
|
676
|
+
const cwd = nonEmptyString(record.cwd);
|
|
677
|
+
const maxAgeMs = opts.maxAgeMs ?? DEFAULT_RECENT_SESSION_MAX_AGE_MS;
|
|
678
|
+
const details = {
|
|
679
|
+
agent,
|
|
680
|
+
cwd,
|
|
681
|
+
hook_event_name: nonEmptyString(record.hook_event_name),
|
|
682
|
+
turn_id: nonEmptyString(record.turn_id),
|
|
683
|
+
payload_keys: Object.keys(record).sort(),
|
|
684
|
+
max_age_ms: maxAgeMs
|
|
685
|
+
};
|
|
686
|
+
if (!cwd) {
|
|
687
|
+
return { status: "unresolved", reason: "no_session_id_no_cwd", ...details };
|
|
688
|
+
}
|
|
689
|
+
const recent = findRecentCodexSession(opts.getDb(), {
|
|
690
|
+
cwd,
|
|
691
|
+
agent,
|
|
692
|
+
now: opts.now,
|
|
693
|
+
maxAgeMs,
|
|
694
|
+
ambiguityWindowMs: opts.ambiguityWindowMs
|
|
695
|
+
});
|
|
696
|
+
if (recent.status === "found") {
|
|
697
|
+
return { status: "resolved", session_id: recent.session_id, resolved_via: `recent_session:${cwd}` };
|
|
698
|
+
}
|
|
699
|
+
if (recent.status === "ambiguous") {
|
|
700
|
+
return {
|
|
701
|
+
status: "unresolved",
|
|
702
|
+
reason: "ambiguous_recent_sessions",
|
|
703
|
+
candidate_count: recent.candidate_count,
|
|
704
|
+
...details
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
return { status: "unresolved", reason: "no_recent_session_for_cwd", ...details };
|
|
708
|
+
}
|
|
709
|
+
function resolveCodexSessionIdOrExit(payload, opts) {
|
|
710
|
+
const resolution = resolveCodexSessionEndSessionId(payload, opts);
|
|
711
|
+
if (resolution.status === "unresolved") exitCodexSessionEndUnresolved(resolution);
|
|
712
|
+
if (resolution.resolved_via !== "session_id") {
|
|
713
|
+
appendHookDebugLog(
|
|
714
|
+
`session-end resolved (${opts.agent ?? "codex"}): session_id=${resolution.session_id} resolved_via=${resolution.resolved_via}`
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
return resolution.session_id;
|
|
718
|
+
}
|
|
719
|
+
function hookDebugLogPath() {
|
|
720
|
+
return join2(homedir(), ".recall", "logs", "hook-debug.log");
|
|
721
|
+
}
|
|
722
|
+
function appendHookDebugLog(line) {
|
|
723
|
+
try {
|
|
724
|
+
const logPath = hookDebugLogPath();
|
|
725
|
+
mkdirSync2(dirname(logPath), { recursive: true });
|
|
726
|
+
rotateIfOversized(logPath);
|
|
727
|
+
appendFileSync(logPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
728
|
+
`);
|
|
729
|
+
} catch {
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
function rotateIfOversized(logPath) {
|
|
733
|
+
const configured = process.env.RECALL_HOOK_LOG_MAX_BYTES;
|
|
734
|
+
const maxBytes = configured === void 0 ? DEFAULT_HOOK_LOG_MAX_BYTES : Number.parseInt(configured, 10);
|
|
735
|
+
if (!(maxBytes > 0)) return;
|
|
736
|
+
let size;
|
|
737
|
+
try {
|
|
738
|
+
size = statSync(logPath).size;
|
|
739
|
+
} catch {
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
if (size < maxBytes) return;
|
|
743
|
+
const rotated = `${logPath}.1`;
|
|
744
|
+
rmSync(rotated, { force: true });
|
|
745
|
+
renameSync(logPath, rotated);
|
|
746
|
+
}
|
|
747
|
+
function formatCodexSessionEndUnresolved(details) {
|
|
748
|
+
const hours = details.max_age_ms / 36e5;
|
|
749
|
+
const window = Number.isInteger(hours) ? `${hours}h` : `${hours.toFixed(1)}h`;
|
|
750
|
+
const why = details.reason === "no_session_id_no_cwd" ? "payload has no session id and no cwd" : details.reason === "ambiguous_recent_sessions" ? `payload has no session id and ${details.candidate_count ?? "several"} ${details.agent} sessions were active in cwd` : `payload has no session id and no open ${details.agent} session for cwd in the last ${window}`;
|
|
751
|
+
return [
|
|
752
|
+
`session-end skipped (${details.agent}): ${why}`,
|
|
753
|
+
`reason=${details.reason}`,
|
|
754
|
+
`cwd=${JSON.stringify(details.cwd)}`,
|
|
755
|
+
`hook_event_name=${JSON.stringify(details.hook_event_name)}`,
|
|
756
|
+
`turn_id=${JSON.stringify(details.turn_id)}`,
|
|
757
|
+
`payload_keys=${details.payload_keys.join(",")}`
|
|
758
|
+
].join(" ");
|
|
759
|
+
}
|
|
760
|
+
function exitCodexSessionEndUnresolved(details) {
|
|
761
|
+
appendHookDebugLog(formatCodexSessionEndUnresolved(details));
|
|
762
|
+
process.exit(0);
|
|
763
|
+
}
|
|
764
|
+
function nonEmptyString(value) {
|
|
765
|
+
if (typeof value !== "string") return null;
|
|
766
|
+
const trimmed = value.trim();
|
|
767
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
768
|
+
}
|
|
769
|
+
function isPlainRecord(value) {
|
|
770
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
771
|
+
}
|
|
772
|
+
|
|
429
773
|
// src/cli/hook.ts
|
|
430
774
|
var DEFAULT_DAEMON_ORIGIN = `http://127.0.0.1:${process.env.RECALL_PORT ?? "7890"}`;
|
|
431
775
|
var DEFAULT_DAEMON_TIMEOUT_MS = 15e3;
|
|
@@ -1060,11 +1404,12 @@ async function readSessionStartInputFromStdin(agent) {
|
|
|
1060
1404
|
async function readSessionEndInputFromStdin(agent) {
|
|
1061
1405
|
const payload = await readClaudeCodeHookPayloadFromStdin();
|
|
1062
1406
|
const codexPayload = payload;
|
|
1407
|
+
const sessionId = agent === "codex" ? resolveCodexSessionIdOrExit(payload, { agent, getDb: () => initDb() }) : requireNonEmpty(payload.session_id ?? "", "session_id");
|
|
1063
1408
|
return {
|
|
1064
1409
|
agent,
|
|
1065
1410
|
path: extractClaudeToolPath(payload.tool_input),
|
|
1066
1411
|
repo_path: payload.cwd,
|
|
1067
|
-
session_id:
|
|
1412
|
+
session_id: sessionId,
|
|
1068
1413
|
last_assistant_turn: codexPayload.last_assistant_message
|
|
1069
1414
|
};
|
|
1070
1415
|
}
|
|
@@ -1407,16 +1752,16 @@ import {
|
|
|
1407
1752
|
copyFileSync,
|
|
1408
1753
|
existsSync,
|
|
1409
1754
|
lstatSync,
|
|
1410
|
-
mkdirSync as
|
|
1755
|
+
mkdirSync as mkdirSync3,
|
|
1411
1756
|
readFileSync,
|
|
1412
1757
|
readdirSync,
|
|
1413
|
-
renameSync,
|
|
1414
|
-
rmSync,
|
|
1415
|
-
statSync,
|
|
1758
|
+
renameSync as renameSync2,
|
|
1759
|
+
rmSync as rmSync2,
|
|
1760
|
+
statSync as statSync2,
|
|
1416
1761
|
unlinkSync
|
|
1417
1762
|
} from "fs";
|
|
1418
1763
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
1419
|
-
import { basename, dirname, join as
|
|
1764
|
+
import { basename, dirname as dirname2, join as join3 } from "path";
|
|
1420
1765
|
import Database from "better-sqlite3";
|
|
1421
1766
|
var DEFAULT_BACKUP_RETENTION = 2;
|
|
1422
1767
|
var DEFAULT_INSTALL_BACKUP_RETENTION = 1;
|
|
@@ -1425,8 +1770,8 @@ var DAILY_BACKUP_RE = /^recall-(\d{4}-\d{2}-\d{2})\.db$/;
|
|
|
1425
1770
|
var BACKUP_FILE_RE = /\.db(\.|$)/;
|
|
1426
1771
|
var INSTALL_BACKUP_DIR_RE = /^published-\d+\.\d+\.\d+-/;
|
|
1427
1772
|
function getBackupsDir(dbPath = getDbPath()) {
|
|
1428
|
-
const dir =
|
|
1429
|
-
|
|
1773
|
+
const dir = join3(dirname2(dbPath), "backups");
|
|
1774
|
+
mkdirSync3(dir, { recursive: true });
|
|
1430
1775
|
return dir;
|
|
1431
1776
|
}
|
|
1432
1777
|
function todayStamp(now = /* @__PURE__ */ new Date()) {
|
|
@@ -1450,18 +1795,18 @@ function ensureDailyBackup(options = {}) {
|
|
|
1450
1795
|
if (!existsSync(dbPath)) return result;
|
|
1451
1796
|
const dir = getBackupsDir(dbPath);
|
|
1452
1797
|
const stamp = todayStamp(options.now);
|
|
1453
|
-
const target =
|
|
1798
|
+
const target = join3(dir, `recall-${stamp}.db`);
|
|
1454
1799
|
if (!existsSync(target)) {
|
|
1455
1800
|
atomicSnapshotFile(dbPath, target);
|
|
1456
1801
|
result.created = target;
|
|
1457
1802
|
} else if (!isRegularFileWithoutSymlink(target)) {
|
|
1458
1803
|
throw new Error(`Refusing unsafe backup path: ${target}`);
|
|
1459
1804
|
}
|
|
1460
|
-
const all = readdirSync(dir).filter((name) => BACKUP_FILE_RE.test(name)).filter((name) => isRegularFileWithoutSymlink(
|
|
1805
|
+
const all = readdirSync(dir).filter((name) => BACKUP_FILE_RE.test(name)).filter((name) => isRegularFileWithoutSymlink(join3(dir, name))).map((name) => ({ name, path: join3(dir, name), mtime: statSync2(join3(dir, name)).mtimeMs }));
|
|
1461
1806
|
const entries = all.filter((entry) => DAILY_BACKUP_RE.test(entry.name)).sort((a, b) => b.mtime - a.mtime);
|
|
1462
1807
|
result.retained = entries.slice(0, retention).map((e) => e.path);
|
|
1463
1808
|
for (const drop of entries.slice(retention)) {
|
|
1464
|
-
|
|
1809
|
+
rmSync2(drop.path, { force: true });
|
|
1465
1810
|
result.removed.push(drop.path);
|
|
1466
1811
|
}
|
|
1467
1812
|
const installEntries = listInstallBackupDirectories(dir);
|
|
@@ -1469,7 +1814,7 @@ function ensureDailyBackup(options = {}) {
|
|
|
1469
1814
|
result.retained.push(keep.path);
|
|
1470
1815
|
}
|
|
1471
1816
|
for (const drop of installEntries.slice(installRetention)) {
|
|
1472
|
-
|
|
1817
|
+
rmSync2(drop.directory, { recursive: true, force: true });
|
|
1473
1818
|
result.removed.push(drop.directory);
|
|
1474
1819
|
}
|
|
1475
1820
|
if (oneOffMaxAgeDays > 0) {
|
|
@@ -1481,7 +1826,7 @@ function ensureDailyBackup(options = {}) {
|
|
|
1481
1826
|
result.retained.push(entry.path);
|
|
1482
1827
|
continue;
|
|
1483
1828
|
}
|
|
1484
|
-
|
|
1829
|
+
rmSync2(entry.path, { force: true });
|
|
1485
1830
|
result.removed.push(entry.path);
|
|
1486
1831
|
}
|
|
1487
1832
|
}
|
|
@@ -1492,9 +1837,9 @@ function listBackups(dbPath = getDbPath()) {
|
|
|
1492
1837
|
if (!existsSync(dir)) return [];
|
|
1493
1838
|
const flat = readdirSync(dir).map((name) => {
|
|
1494
1839
|
if (!BACKUP_FILE_RE.test(name)) return null;
|
|
1495
|
-
const path =
|
|
1840
|
+
const path = join3(dir, name);
|
|
1496
1841
|
if (!isRegularFileWithoutSymlink(path)) return null;
|
|
1497
|
-
const stat =
|
|
1842
|
+
const stat = statSync2(path);
|
|
1498
1843
|
const match = name.match(DAILY_BACKUP_RE);
|
|
1499
1844
|
return {
|
|
1500
1845
|
date: match ? match[1] : new Date(stat.mtimeMs).toISOString().slice(0, 10),
|
|
@@ -1506,19 +1851,19 @@ function listBackups(dbPath = getDbPath()) {
|
|
|
1506
1851
|
const installs = listInstallBackupDirectories(dir).map((entry) => ({
|
|
1507
1852
|
date: new Date(entry.mtime).toISOString().slice(0, 10),
|
|
1508
1853
|
path: entry.path,
|
|
1509
|
-
size_bytes:
|
|
1854
|
+
size_bytes: statSync2(entry.path).size,
|
|
1510
1855
|
kind: "install"
|
|
1511
1856
|
}));
|
|
1512
1857
|
return [...flat, ...installs].sort((a, b) => b.date.localeCompare(a.date));
|
|
1513
1858
|
}
|
|
1514
1859
|
function listInstallBackupDirectories(dir) {
|
|
1515
1860
|
return readdirSync(dir).filter((name) => INSTALL_BACKUP_DIR_RE.test(name)).map((name) => {
|
|
1516
|
-
const directory =
|
|
1517
|
-
const path =
|
|
1861
|
+
const directory = join3(dir, name);
|
|
1862
|
+
const path = join3(directory, "recall.db");
|
|
1518
1863
|
if (!isDirectoryWithoutSymlink(directory) || !isRegularFileWithoutSymlink(path) || !isSqliteDatabase(path)) {
|
|
1519
1864
|
return null;
|
|
1520
1865
|
}
|
|
1521
|
-
return { directory, path, mtime:
|
|
1866
|
+
return { directory, path, mtime: statSync2(path).mtimeMs };
|
|
1522
1867
|
}).filter((entry) => entry !== null).sort((a, b) => b.mtime - a.mtime);
|
|
1523
1868
|
}
|
|
1524
1869
|
function verifyBackupIntegrity(path) {
|
|
@@ -1534,7 +1879,7 @@ function restoreBackup(date, options = {}) {
|
|
|
1534
1879
|
validateBackupDate(date);
|
|
1535
1880
|
const dbPath = options.dbPath ?? getDbPath();
|
|
1536
1881
|
const dir = getBackupsDir(dbPath);
|
|
1537
|
-
const from =
|
|
1882
|
+
const from = join3(dir, `recall-${date}.db`);
|
|
1538
1883
|
if (!existsSync(from)) {
|
|
1539
1884
|
return { restored: false, from, to: dbPath };
|
|
1540
1885
|
}
|
|
@@ -1543,7 +1888,7 @@ function restoreBackup(date, options = {}) {
|
|
|
1543
1888
|
}
|
|
1544
1889
|
for (const suffix of ["-shm", "-wal"]) {
|
|
1545
1890
|
const sidecar = `${dbPath}${suffix}`;
|
|
1546
|
-
if (existsSync(sidecar))
|
|
1891
|
+
if (existsSync(sidecar)) rmSync2(sidecar, { force: true });
|
|
1547
1892
|
}
|
|
1548
1893
|
atomicCopyFile(from, dbPath);
|
|
1549
1894
|
return { restored: true, from, to: dbPath };
|
|
@@ -1577,14 +1922,14 @@ function atomicCopyFile(source, target) {
|
|
|
1577
1922
|
if (!isRegularFileWithoutSymlink(source)) {
|
|
1578
1923
|
throw new Error(`Refusing unsafe backup source: ${source}`);
|
|
1579
1924
|
}
|
|
1580
|
-
const temp =
|
|
1581
|
-
|
|
1925
|
+
const temp = join3(
|
|
1926
|
+
dirname2(target),
|
|
1582
1927
|
`.${basename(target)}.${process.pid}.${randomUUID2()}.tmp`
|
|
1583
1928
|
);
|
|
1584
1929
|
try {
|
|
1585
1930
|
copyFileSync(source, temp, constants.COPYFILE_EXCL);
|
|
1586
1931
|
chmodSync(temp, 384);
|
|
1587
|
-
|
|
1932
|
+
renameSync2(temp, target);
|
|
1588
1933
|
} catch (error) {
|
|
1589
1934
|
try {
|
|
1590
1935
|
unlinkSync(temp);
|
|
@@ -1604,8 +1949,8 @@ function atomicSnapshotFile(source, target) {
|
|
|
1604
1949
|
if (!isRegularFileWithoutSymlink(source)) {
|
|
1605
1950
|
throw new Error(`Refusing unsafe backup source: ${source}`);
|
|
1606
1951
|
}
|
|
1607
|
-
const temp =
|
|
1608
|
-
|
|
1952
|
+
const temp = join3(
|
|
1953
|
+
dirname2(target),
|
|
1609
1954
|
`.${basename(target)}.${process.pid}.${randomUUID2()}.tmp`
|
|
1610
1955
|
);
|
|
1611
1956
|
const sqlite = new Database(source, { readonly: true, fileMustExist: true });
|
|
@@ -1620,9 +1965,9 @@ function atomicSnapshotFile(source, target) {
|
|
|
1620
1965
|
snapshot.close();
|
|
1621
1966
|
}
|
|
1622
1967
|
chmodSync(temp, 384);
|
|
1623
|
-
|
|
1968
|
+
renameSync2(temp, target);
|
|
1624
1969
|
} catch (error) {
|
|
1625
|
-
|
|
1970
|
+
rmSync2(temp, { force: true });
|
|
1626
1971
|
throw error;
|
|
1627
1972
|
} finally {
|
|
1628
1973
|
sqlite.close();
|
|
@@ -1636,18 +1981,227 @@ function isSqliteDatabase(path) {
|
|
|
1636
1981
|
}
|
|
1637
1982
|
}
|
|
1638
1983
|
|
|
1984
|
+
// src/reliability/verdict.ts
|
|
1985
|
+
init_define_RECALL_BUILD_INFO();
|
|
1986
|
+
import { execFile } from "child_process";
|
|
1987
|
+
import { dirname as dirname3, join as join4 } from "path";
|
|
1988
|
+
var RELIABILITY_VERDICT_FILE = "reliability-verdict.json";
|
|
1989
|
+
var RELIABILITY_VERDICT_WINDOW_DAYS = 14;
|
|
1990
|
+
var RELIABILITY_SUSTAINED_FAIL_DAYS = 7;
|
|
1991
|
+
var RELIABILITY_NOTIFY_INTERVAL_MS = 864e5;
|
|
1992
|
+
var DAY_MS = 864e5;
|
|
1993
|
+
var STALE_VERDICT_MS = 48 * 36e5;
|
|
1994
|
+
function computeReliabilityVerdict(db, options = {}) {
|
|
1995
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
1996
|
+
const since = new Date(now.getTime() - RELIABILITY_VERDICT_WINDOW_DAYS * DAY_MS).toISOString();
|
|
1997
|
+
const report = computeReliabilityReport(db, { since });
|
|
1998
|
+
return deriveReliabilityVerdict(report, { now, previous: options.previous ?? null });
|
|
1999
|
+
}
|
|
2000
|
+
function deriveReliabilityVerdict(measured, options = {}) {
|
|
2001
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
2002
|
+
const previous = options.previous ?? null;
|
|
2003
|
+
const computedAt = now.toISOString();
|
|
2004
|
+
let firstFailAt = null;
|
|
2005
|
+
let consecutiveFailDays = 0;
|
|
2006
|
+
if (measured.overall === "fail") {
|
|
2007
|
+
const dayGap = previous ? (Date.parse(utcDay(computedAt)) - Date.parse(utcDay(previous.computed_at))) / DAY_MS : Number.NaN;
|
|
2008
|
+
if (previous?.overall === "fail" && previous.first_fail_at && now.getTime() >= Date.parse(previous.computed_at) && dayGap >= 0 && dayGap <= 1) {
|
|
2009
|
+
firstFailAt = previous.first_fail_at;
|
|
2010
|
+
consecutiveFailDays = Math.max(1, previous.consecutive_fail_days) + dayGap;
|
|
2011
|
+
} else {
|
|
2012
|
+
firstFailAt = computedAt;
|
|
2013
|
+
consecutiveFailDays = 1;
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
return {
|
|
2017
|
+
computed_at: computedAt,
|
|
2018
|
+
overall: measured.overall,
|
|
2019
|
+
checks: measured.checks.map((check) => ({
|
|
2020
|
+
name: check.name,
|
|
2021
|
+
status: check.status,
|
|
2022
|
+
value: Number.isFinite(check.value) ? check.value : 0,
|
|
2023
|
+
target: check.target
|
|
2024
|
+
})),
|
|
2025
|
+
first_fail_at: firstFailAt,
|
|
2026
|
+
consecutive_fail_days: consecutiveFailDays,
|
|
2027
|
+
sustained_fail: firstFailAt !== null && now.getTime() - Date.parse(firstFailAt) >= RELIABILITY_SUSTAINED_FAIL_DAYS * DAY_MS,
|
|
2028
|
+
last_notified_at: previous?.last_notified_at ?? null
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
function reliabilityVerdictDataDir() {
|
|
2032
|
+
return dirname3(getDbPath());
|
|
2033
|
+
}
|
|
2034
|
+
function reliabilityVerdictPath(dataDir) {
|
|
2035
|
+
return join4(dataDir, RELIABILITY_VERDICT_FILE);
|
|
2036
|
+
}
|
|
2037
|
+
function persistReliabilityVerdict(dataDir, verdict) {
|
|
2038
|
+
atomicWriteUtf8File(reliabilityVerdictPath(dataDir), `${JSON.stringify(verdict, null, 2)}
|
|
2039
|
+
`);
|
|
2040
|
+
}
|
|
2041
|
+
function readReliabilityVerdict(dataDir) {
|
|
2042
|
+
try {
|
|
2043
|
+
const raw = readUtf8FileIfExists(reliabilityVerdictPath(dataDir));
|
|
2044
|
+
return raw === null ? null : parseReliabilityVerdict(JSON.parse(raw));
|
|
2045
|
+
} catch {
|
|
2046
|
+
return null;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
async function runReliabilityVerdictCycle(db, dataDir, deps = {}) {
|
|
2050
|
+
const now = deps.now?.() ?? /* @__PURE__ */ new Date();
|
|
2051
|
+
const previous = readReliabilityVerdict(dataDir);
|
|
2052
|
+
let verdict = computeReliabilityVerdict(db, { now, previous });
|
|
2053
|
+
persistReliabilityVerdict(dataDir, verdict);
|
|
2054
|
+
if (!verdict.sustained_fail) return verdict;
|
|
2055
|
+
const message = formatSustainedFailMessage(verdict);
|
|
2056
|
+
(deps.logError ?? console.error)(`[recall] ${message}`);
|
|
2057
|
+
if (deps.notify && isNotificationDue(verdict, now)) {
|
|
2058
|
+
let delivered = false;
|
|
2059
|
+
try {
|
|
2060
|
+
delivered = await deps.notify(message);
|
|
2061
|
+
} catch {
|
|
2062
|
+
delivered = false;
|
|
2063
|
+
}
|
|
2064
|
+
if (delivered) {
|
|
2065
|
+
verdict = { ...verdict, last_notified_at: now.toISOString() };
|
|
2066
|
+
persistReliabilityVerdict(dataDir, verdict);
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
return verdict;
|
|
2070
|
+
}
|
|
2071
|
+
function formatSustainedFailMessage(verdict) {
|
|
2072
|
+
const failing = verdict.checks.filter((check) => check.status === "fail").map((check) => check.name);
|
|
2073
|
+
return `reliability FAIL for ${failDays(verdict)} days: ${failing.join(", ") || "no individual check"}`;
|
|
2074
|
+
}
|
|
2075
|
+
function isNotificationDue(verdict, now) {
|
|
2076
|
+
if (!verdict.last_notified_at) return true;
|
|
2077
|
+
return now.getTime() - Date.parse(verdict.last_notified_at) >= RELIABILITY_NOTIFY_INTERVAL_MS;
|
|
2078
|
+
}
|
|
2079
|
+
function notifyMacOS(message, options = {}) {
|
|
2080
|
+
if ((options.platform ?? process.platform) !== "darwin") return Promise.resolve(false);
|
|
2081
|
+
return new Promise((resolve6) => {
|
|
2082
|
+
try {
|
|
2083
|
+
execFile("/usr/bin/osascript", ["-e", buildNotificationScript(message)], { timeout: 1e4 }, (error) => {
|
|
2084
|
+
resolve6(!error);
|
|
2085
|
+
});
|
|
2086
|
+
} catch {
|
|
2087
|
+
resolve6(false);
|
|
2088
|
+
}
|
|
2089
|
+
});
|
|
2090
|
+
}
|
|
2091
|
+
function buildNotificationScript(message) {
|
|
2092
|
+
const escaped = message.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/[\r\n]+/g, " ");
|
|
2093
|
+
return `display notification "${escaped}" with title "Recall"`;
|
|
2094
|
+
}
|
|
2095
|
+
function loadReliabilityVerdictConfigFromEnv(env = process.env) {
|
|
2096
|
+
const underTest = Boolean(env.VITEST) || env.NODE_ENV === "test";
|
|
2097
|
+
return {
|
|
2098
|
+
enabled: env.RECALL_RELIABILITY_VERDICT_ENABLED !== "false",
|
|
2099
|
+
notify: env.RECALL_RELIABILITY_VERDICT_NOTIFY !== "false" && !underTest,
|
|
2100
|
+
delayMs: boundedSeconds(env.RECALL_RELIABILITY_VERDICT_DELAY_SECONDS, 120, 1) * 1e3,
|
|
2101
|
+
intervalMs: boundedSeconds(env.RECALL_RELIABILITY_VERDICT_INTERVAL_SECONDS, 86400, 300) * 1e3
|
|
2102
|
+
};
|
|
2103
|
+
}
|
|
2104
|
+
var CHECK_HINTS = {
|
|
2105
|
+
repo_attribution: "sessions start outside a recognized repo or hooks are missing \u2014 see ## Agents",
|
|
2106
|
+
session_scope_coverage: "most sessions start outside a repo (home, /tmp, ~/Projects) and cannot receive repo memory",
|
|
2107
|
+
retrieval_observations: "too few used/missed retrieval observations in 14 d \u2014 inspect query and hook telemetry",
|
|
2108
|
+
emission_coverage: "memories selected but the hook did not emit them",
|
|
2109
|
+
outcome_coverage: "emitted memories never resolved \u2014 check session-end hooks",
|
|
2110
|
+
candidate_backlog: "run `recall maintenance cleanup` (a dry run unless you pass --apply)"
|
|
2111
|
+
};
|
|
2112
|
+
function formatReliabilityVerdictSection(verdict, now = /* @__PURE__ */ new Date()) {
|
|
2113
|
+
if (!verdict) {
|
|
2114
|
+
return ["No verdict yet \u2014 the daemon computes one daily; run `recall reliability` now."];
|
|
2115
|
+
}
|
|
2116
|
+
let headline = `Overall: ${verdict.overall.toUpperCase()}`;
|
|
2117
|
+
if (verdict.overall === "fail" && verdict.first_fail_at) {
|
|
2118
|
+
headline = `Overall: FAIL since ${verdict.first_fail_at.slice(0, 10)} (${describeDays(failDays(verdict))})`;
|
|
2119
|
+
if (verdict.sustained_fail) headline += " \u2014 sustained; the daemon notifies once a day";
|
|
2120
|
+
}
|
|
2121
|
+
let computed = `Computed: ${verdict.computed_at.slice(0, 19)}Z over the last ${RELIABILITY_VERDICT_WINDOW_DAYS} days`;
|
|
2122
|
+
const ageMs = now.getTime() - Date.parse(verdict.computed_at);
|
|
2123
|
+
if (ageMs > STALE_VERDICT_MS) {
|
|
2124
|
+
computed += ` \u2014 STALE (${describeDays(Math.floor(ageMs / DAY_MS))} old); is the daemon running? See Launchd/Systemd above`;
|
|
2125
|
+
}
|
|
2126
|
+
const lines = [headline, computed];
|
|
2127
|
+
const flagged = verdict.checks.filter((check) => check.status !== "pass");
|
|
2128
|
+
if (flagged.length === 0) {
|
|
2129
|
+
lines.push("All checks pass.");
|
|
2130
|
+
return lines;
|
|
2131
|
+
}
|
|
2132
|
+
for (const check of flagged) {
|
|
2133
|
+
lines.push(`${check.status.toUpperCase().padEnd(4)} ${check.name}: ${formatCheckValue(check)} (target ${check.target})`);
|
|
2134
|
+
lines.push(` ${CHECK_HINTS[check.name] ?? "run `recall reliability` for the measured numbers"}`);
|
|
2135
|
+
}
|
|
2136
|
+
return lines;
|
|
2137
|
+
}
|
|
2138
|
+
function formatCheckValue(check) {
|
|
2139
|
+
if (check.target.includes("%")) return `${(check.value * 100).toFixed(1)}%`;
|
|
2140
|
+
return Number.isInteger(check.value) ? String(check.value) : check.value.toFixed(2);
|
|
2141
|
+
}
|
|
2142
|
+
function failDays(verdict) {
|
|
2143
|
+
if (!verdict.first_fail_at) return 0;
|
|
2144
|
+
return Math.max(0, Math.floor((Date.parse(verdict.computed_at) - Date.parse(verdict.first_fail_at)) / DAY_MS));
|
|
2145
|
+
}
|
|
2146
|
+
function describeDays(days) {
|
|
2147
|
+
if (days < 1) return "less than 1 day";
|
|
2148
|
+
return days === 1 ? "1 day" : `${days} days`;
|
|
2149
|
+
}
|
|
2150
|
+
function utcDay(iso) {
|
|
2151
|
+
return new Date(iso).toISOString().slice(0, 10);
|
|
2152
|
+
}
|
|
2153
|
+
function boundedSeconds(raw, fallback, floor) {
|
|
2154
|
+
const parsed = raw === void 0 ? Number.NaN : Number.parseInt(raw, 10);
|
|
2155
|
+
return Math.max(floor, Number.isFinite(parsed) ? parsed : fallback);
|
|
2156
|
+
}
|
|
2157
|
+
function parseReliabilityVerdict(value) {
|
|
2158
|
+
if (!isRecord(value)) return null;
|
|
2159
|
+
if (!isTimestamp(value.computed_at) || !isStatus(value.overall) || !Array.isArray(value.checks)) return null;
|
|
2160
|
+
const checks = [];
|
|
2161
|
+
for (const check of value.checks) {
|
|
2162
|
+
if (!isRecord(check) || typeof check.name !== "string" || !isStatus(check.status)) return null;
|
|
2163
|
+
if (typeof check.value !== "number" || typeof check.target !== "string") return null;
|
|
2164
|
+
checks.push({ name: check.name, status: check.status, value: check.value, target: check.target });
|
|
2165
|
+
}
|
|
2166
|
+
const firstFailAt = value.first_fail_at;
|
|
2167
|
+
if (firstFailAt !== null && !isTimestamp(firstFailAt)) return null;
|
|
2168
|
+
const days = value.consecutive_fail_days;
|
|
2169
|
+
if (typeof days !== "number" || !Number.isInteger(days) || days < 0) return null;
|
|
2170
|
+
if (typeof value.sustained_fail !== "boolean") return null;
|
|
2171
|
+
const lastNotifiedAt = value.last_notified_at ?? null;
|
|
2172
|
+
if (lastNotifiedAt !== null && !isTimestamp(lastNotifiedAt)) return null;
|
|
2173
|
+
return {
|
|
2174
|
+
computed_at: value.computed_at,
|
|
2175
|
+
overall: value.overall,
|
|
2176
|
+
checks,
|
|
2177
|
+
first_fail_at: firstFailAt,
|
|
2178
|
+
consecutive_fail_days: days,
|
|
2179
|
+
sustained_fail: value.sustained_fail,
|
|
2180
|
+
last_notified_at: lastNotifiedAt
|
|
2181
|
+
};
|
|
2182
|
+
}
|
|
2183
|
+
function isRecord(value) {
|
|
2184
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2185
|
+
}
|
|
2186
|
+
function isStatus(value) {
|
|
2187
|
+
return value === "pass" || value === "warn" || value === "fail";
|
|
2188
|
+
}
|
|
2189
|
+
function isTimestamp(value) {
|
|
2190
|
+
return typeof value === "string" && Number.isFinite(Date.parse(value));
|
|
2191
|
+
}
|
|
2192
|
+
|
|
1639
2193
|
// src/doctor/report.ts
|
|
1640
2194
|
init_define_RECALL_BUILD_INFO();
|
|
1641
2195
|
import { existsSync as existsSync8, readFileSync as readFileSync6 } from "fs";
|
|
1642
|
-
import { basename as
|
|
2196
|
+
import { basename as basename3, dirname as dirname10, join as join13 } from "path";
|
|
1643
2197
|
import Database3 from "better-sqlite3";
|
|
1644
2198
|
|
|
1645
2199
|
// src/daemon/launchd.ts
|
|
1646
2200
|
init_define_RECALL_BUILD_INFO();
|
|
1647
|
-
import { chmodSync as chmodSync2, existsSync as existsSync2, mkdirSync as
|
|
1648
|
-
import { homedir } from "os";
|
|
1649
|
-
import { dirname as
|
|
1650
|
-
import { execFileSync as
|
|
2201
|
+
import { chmodSync as chmodSync2, closeSync, existsSync as existsSync2, mkdirSync as mkdirSync4, openSync, rmSync as rmSync3, statSync as statSync3, unlinkSync as unlinkSync2, writeFileSync } from "fs";
|
|
2202
|
+
import { homedir as homedir2 } from "os";
|
|
2203
|
+
import { dirname as dirname5, join as join6, resolve as resolve2 } from "path";
|
|
2204
|
+
import { execFileSync as execFileSync5 } from "child_process";
|
|
1651
2205
|
|
|
1652
2206
|
// src/daemon/launchd-start.ts
|
|
1653
2207
|
init_define_RECALL_BUILD_INFO();
|
|
@@ -1699,6 +2253,66 @@ function ensureLaunchdStarted(domain, label, plist, run = (args) => {
|
|
|
1699
2253
|
throw lastError;
|
|
1700
2254
|
}
|
|
1701
2255
|
|
|
2256
|
+
// src/daemon/macos-app-identity.ts
|
|
2257
|
+
init_define_RECALL_BUILD_INFO();
|
|
2258
|
+
import { execFileSync as execFileSync4 } from "child_process";
|
|
2259
|
+
import { realpathSync } from "fs";
|
|
2260
|
+
import { basename as basename2, dirname as dirname4, join as join5 } from "path";
|
|
2261
|
+
var RECALL_APP_BUNDLE_IDENTIFIER = "com.edihasaj.recall";
|
|
2262
|
+
function findRecallAppIdentity(nodePath, daemonScript, dependencies = {}) {
|
|
2263
|
+
const canonicalPath = dependencies.realpath ?? realpathSync;
|
|
2264
|
+
const readBundleIdentifier = dependencies.readBundleIdentifier ?? readRecallBundleIdentifier;
|
|
2265
|
+
try {
|
|
2266
|
+
const node = canonicalPath(nodePath);
|
|
2267
|
+
const daemon = canonicalPath(daemonScript);
|
|
2268
|
+
if (basename2(node) !== "node" || basename2(dirname4(node)) !== "bin") return void 0;
|
|
2269
|
+
const runtimePath = dirname4(dirname4(node));
|
|
2270
|
+
if (basename2(runtimePath) !== "Runtime" || basename2(dirname4(runtimePath)) !== "Resources" || basename2(dirname4(dirname4(runtimePath))) !== "Contents") {
|
|
2271
|
+
return void 0;
|
|
2272
|
+
}
|
|
2273
|
+
const appPath = dirname4(dirname4(dirname4(runtimePath)));
|
|
2274
|
+
if (!basename2(appPath).endsWith(".app")) return void 0;
|
|
2275
|
+
if (node !== join5(runtimePath, "bin", "node")) return void 0;
|
|
2276
|
+
if (daemon !== join5(runtimePath, "dist", "daemon.js")) return void 0;
|
|
2277
|
+
const infoPlistPath = join5(appPath, "Contents", "Info.plist");
|
|
2278
|
+
if (readBundleIdentifier(infoPlistPath) !== RECALL_APP_BUNDLE_IDENTIFIER) return void 0;
|
|
2279
|
+
return { appPath, runtimePath, bundleIdentifier: RECALL_APP_BUNDLE_IDENTIFIER };
|
|
2280
|
+
} catch {
|
|
2281
|
+
return void 0;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
function associatedBundleIdentifiers(existing, bundleIdentifier = RECALL_APP_BUNDLE_IDENTIFIER) {
|
|
2285
|
+
const identifiers = typeof existing === "string" ? [existing] : Array.isArray(existing) ? existing.filter((value) => typeof value === "string") : [];
|
|
2286
|
+
return identifiers.includes(bundleIdentifier) ? identifiers : [...identifiers, bundleIdentifier];
|
|
2287
|
+
}
|
|
2288
|
+
function launchdPlistIdentity(plist) {
|
|
2289
|
+
const record = isRecord2(plist) ? plist : {};
|
|
2290
|
+
const programArguments = Array.isArray(record.ProgramArguments) ? record.ProgramArguments : [];
|
|
2291
|
+
return {
|
|
2292
|
+
label: stringValue(record.Label),
|
|
2293
|
+
nodePath: Object.hasOwn(record, "Program") ? stringValue(record.Program) : stringValue(programArguments[0]),
|
|
2294
|
+
daemonScript: stringValue(programArguments[1]),
|
|
2295
|
+
associatedBundleIdentifiers: record.AssociatedBundleIdentifiers,
|
|
2296
|
+
hasAssociatedBundleIdentifiers: Object.hasOwn(record, "AssociatedBundleIdentifiers")
|
|
2297
|
+
};
|
|
2298
|
+
}
|
|
2299
|
+
function readRecallBundleIdentifier(infoPlistPath, extract = (args) => execFileSync4("plutil", args, {
|
|
2300
|
+
encoding: "utf8",
|
|
2301
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2302
|
+
})) {
|
|
2303
|
+
try {
|
|
2304
|
+
return extract(["-extract", "CFBundleIdentifier", "raw", "-expect", "string", "-o", "-", infoPlistPath]).trim() || void 0;
|
|
2305
|
+
} catch {
|
|
2306
|
+
return void 0;
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
function isRecord2(value) {
|
|
2310
|
+
return typeof value === "object" && value !== null;
|
|
2311
|
+
}
|
|
2312
|
+
function stringValue(value) {
|
|
2313
|
+
return typeof value === "string" ? value : void 0;
|
|
2314
|
+
}
|
|
2315
|
+
|
|
1702
2316
|
// src/daemon/provider-env.ts
|
|
1703
2317
|
init_define_RECALL_BUILD_INFO();
|
|
1704
2318
|
var DAEMON_PROVIDER_ENV_KEYS = [
|
|
@@ -1734,46 +2348,54 @@ function readDaemonProviderEnvironment(environment) {
|
|
|
1734
2348
|
var DEFAULT_LABEL = "com.recall.daemon";
|
|
1735
2349
|
function installLaunchAgent(opts = {}) {
|
|
1736
2350
|
assertDarwin();
|
|
1737
|
-
const
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
2351
|
+
const plistPath = launchAgentPlistPath(opts.label);
|
|
2352
|
+
mkdirSync4(dirname5(plistPath), { recursive: true });
|
|
2353
|
+
const cfg = withLaunchAgentWriteLock(plistPath, () => {
|
|
2354
|
+
const cfg2 = resolveConfig(opts, { preferRequestedLabel: true });
|
|
2355
|
+
mkdirSync4(dirname5(cfg2.stdoutPath), { recursive: true });
|
|
2356
|
+
writeFileSync(cfg2.plistPath, renderPlist(cfg2), { mode: 384 });
|
|
2357
|
+
chmodSync2(cfg2.plistPath, 384);
|
|
2358
|
+
return cfg2;
|
|
2359
|
+
});
|
|
1742
2360
|
tryRun("launchctl", ["bootout", domainTarget(), cfg.plistPath]);
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
return
|
|
2361
|
+
execFileSync5("launchctl", ["bootstrap", domainTarget(), cfg.plistPath], stdioOpts());
|
|
2362
|
+
execFileSync5("launchctl", ["enable", `${domainTarget()}/${cfg.label}`], stdioOpts());
|
|
2363
|
+
execFileSync5("launchctl", ["kickstart", `${domainTarget()}/${cfg.label}`], stdioOpts());
|
|
2364
|
+
return getLaunchAgentStatusForConfig(cfg);
|
|
1747
2365
|
}
|
|
1748
|
-
function uninstallLaunchAgent(label
|
|
2366
|
+
function uninstallLaunchAgent(label) {
|
|
1749
2367
|
assertDarwin();
|
|
1750
2368
|
const cfg = resolveConfig({ label });
|
|
1751
2369
|
tryRun("launchctl", ["bootout", domainTarget(), cfg.plistPath]);
|
|
1752
2370
|
tryRun("launchctl", ["disable", `${domainTarget()}/${cfg.label}`]);
|
|
1753
|
-
|
|
1754
|
-
return
|
|
2371
|
+
rmSync3(cfg.plistPath, { force: true });
|
|
2372
|
+
return getLaunchAgentStatusForConfig(cfg);
|
|
1755
2373
|
}
|
|
1756
|
-
function startLaunchAgent(label
|
|
2374
|
+
function startLaunchAgent(label) {
|
|
1757
2375
|
assertDarwin();
|
|
1758
2376
|
const cfg = resolveConfig({ label });
|
|
1759
2377
|
if (!exists(cfg.plistPath)) {
|
|
1760
2378
|
throw new Error(`LaunchAgent not installed: ${cfg.plistPath}`);
|
|
1761
2379
|
}
|
|
1762
|
-
|
|
2380
|
+
persistAppAssociation(cfg);
|
|
2381
|
+
execFileSync5("launchctl", ["enable", `${domainTarget()}/${cfg.label}`], stdioOpts());
|
|
1763
2382
|
ensureLaunchdStarted(domainTarget(), cfg.label, cfg.plistPath);
|
|
1764
|
-
return
|
|
2383
|
+
return getLaunchAgentStatusForConfig(cfg);
|
|
1765
2384
|
}
|
|
1766
|
-
function stopLaunchAgent(label
|
|
2385
|
+
function stopLaunchAgent(label) {
|
|
1767
2386
|
assertDarwin();
|
|
1768
2387
|
const cfg = resolveConfig({ label });
|
|
1769
2388
|
if (exists(cfg.plistPath)) {
|
|
1770
2389
|
tryRun("launchctl", ["bootout", domainTarget(), cfg.plistPath]);
|
|
1771
2390
|
}
|
|
1772
|
-
return
|
|
2391
|
+
return getLaunchAgentStatusForConfig(cfg);
|
|
1773
2392
|
}
|
|
1774
|
-
function getLaunchAgentStatus(label
|
|
2393
|
+
function getLaunchAgentStatus(label) {
|
|
1775
2394
|
assertDarwin();
|
|
1776
2395
|
const cfg = resolveConfig({ label });
|
|
2396
|
+
return getLaunchAgentStatusForConfig(cfg);
|
|
2397
|
+
}
|
|
2398
|
+
function getLaunchAgentStatusForConfig(cfg) {
|
|
1777
2399
|
const installed = exists(cfg.plistPath);
|
|
1778
2400
|
const output = tryOutput("launchctl", ["print", `${domainTarget()}/${cfg.label}`]);
|
|
1779
2401
|
return {
|
|
@@ -1784,10 +2406,10 @@ function getLaunchAgentStatus(label = DEFAULT_LABEL) {
|
|
|
1784
2406
|
state: output.ok ? extractState(output.output) : void 0
|
|
1785
2407
|
};
|
|
1786
2408
|
}
|
|
1787
|
-
function getLaunchAgentInfo(label
|
|
2409
|
+
function getLaunchAgentInfo(label) {
|
|
1788
2410
|
assertDarwin();
|
|
1789
2411
|
const cfg = resolveConfig({ label });
|
|
1790
|
-
const status =
|
|
2412
|
+
const status = getLaunchAgentStatusForConfig(cfg);
|
|
1791
2413
|
const installed = readInstalledConfig(cfg.plistPath);
|
|
1792
2414
|
const lines = [
|
|
1793
2415
|
`Label: ${status.label}`,
|
|
@@ -1822,31 +2444,31 @@ function getLaunchAgentInfo(label = DEFAULT_LABEL) {
|
|
|
1822
2444
|
lines.push(`Stderr: ${installed?.stderrPath ?? cfg.stderrPath}`);
|
|
1823
2445
|
return lines.join("\n");
|
|
1824
2446
|
}
|
|
1825
|
-
function resolveConfig(opts) {
|
|
1826
|
-
const
|
|
1827
|
-
const home =
|
|
2447
|
+
function resolveConfig(opts, { preferRequestedLabel = false } = {}) {
|
|
2448
|
+
const plistLabel = opts.label ?? DEFAULT_LABEL;
|
|
2449
|
+
const home = homedir2();
|
|
1828
2450
|
const port = opts.port ?? parseInt(process.env.RECALL_PORT ?? "7890", 10);
|
|
1829
2451
|
const maintenanceIntervalSeconds = opts.maintenanceIntervalSeconds ?? parseInt(process.env.RECALL_MAINTENANCE_INTERVAL_SECONDS ?? "3600", 10);
|
|
1830
2452
|
const dataDir = resolve2(
|
|
1831
|
-
opts.dataDir ?? process.env.RECALL_DATA_DIR ??
|
|
2453
|
+
opts.dataDir ?? process.env.RECALL_DATA_DIR ?? join6(home, ".recall")
|
|
1832
2454
|
);
|
|
1833
2455
|
const nodePath = resolve2(opts.nodePath ?? process.execPath);
|
|
1834
2456
|
const daemonScript = resolve2(
|
|
1835
|
-
opts.daemonScript ??
|
|
2457
|
+
opts.daemonScript ?? join6(process.cwd(), "dist", "daemon.js")
|
|
1836
2458
|
);
|
|
1837
|
-
const plistPath =
|
|
1838
|
-
const logDir =
|
|
2459
|
+
const plistPath = launchAgentPlistPath(plistLabel, home);
|
|
2460
|
+
const logDir = join6(dataDir, "logs");
|
|
1839
2461
|
const installed = readInstalledConfig(plistPath);
|
|
1840
2462
|
return {
|
|
1841
|
-
label,
|
|
2463
|
+
label: preferRequestedLabel ? opts.label ?? installed?.label ?? plistLabel : installed?.label ?? plistLabel,
|
|
1842
2464
|
port,
|
|
1843
2465
|
maintenanceIntervalSeconds,
|
|
1844
2466
|
dataDir,
|
|
1845
2467
|
nodePath,
|
|
1846
2468
|
daemonScript,
|
|
1847
2469
|
plistPath,
|
|
1848
|
-
stdoutPath:
|
|
1849
|
-
stderrPath:
|
|
2470
|
+
stdoutPath: join6(logDir, "daemon.stdout.log"),
|
|
2471
|
+
stderrPath: join6(logDir, "daemon.stderr.log"),
|
|
1850
2472
|
repoRoots: opts.repoRoots ?? process.env.RECALL_REPO_ROOTS,
|
|
1851
2473
|
repoOverride: opts.repoOverride ?? process.env.RECALL_REPO_OVERRIDE ?? installed?.repoOverride,
|
|
1852
2474
|
embeddingProvider: opts.embeddingProvider ?? process.env.RECALL_EMBEDDING_PROVIDER,
|
|
@@ -1855,7 +2477,8 @@ function resolveConfig(opts) {
|
|
|
1855
2477
|
providerEnvironment: resolveDaemonProviderEnvironment(
|
|
1856
2478
|
process.env,
|
|
1857
2479
|
installed?.providerEnvironment
|
|
1858
|
-
)
|
|
2480
|
+
),
|
|
2481
|
+
installed
|
|
1859
2482
|
};
|
|
1860
2483
|
}
|
|
1861
2484
|
function renderPlist(cfg) {
|
|
@@ -1884,6 +2507,7 @@ function renderPlist(cfg) {
|
|
|
1884
2507
|
<string>${escapeXml(cfg.nodePath)}</string>
|
|
1885
2508
|
<string>${escapeXml(cfg.daemonScript)}</string>
|
|
1886
2509
|
</array>
|
|
2510
|
+
${renderAssociatedBundleIdentifiers(cfg)}
|
|
1887
2511
|
<key>EnvironmentVariables</key>
|
|
1888
2512
|
<dict>
|
|
1889
2513
|
${environmentXml}
|
|
@@ -1902,6 +2526,29 @@ ${environmentXml}
|
|
|
1902
2526
|
</plist>
|
|
1903
2527
|
`;
|
|
1904
2528
|
}
|
|
2529
|
+
function renderAssociatedBundleIdentifiers(cfg) {
|
|
2530
|
+
const identity = findRecallAppIdentity(cfg.nodePath, cfg.daemonScript);
|
|
2531
|
+
if (!identity) return "";
|
|
2532
|
+
return ` <key>AssociatedBundleIdentifiers</key>
|
|
2533
|
+
<array>
|
|
2534
|
+
<string>${escapeXml(identity.bundleIdentifier)}</string>
|
|
2535
|
+
</array>
|
|
2536
|
+
`;
|
|
2537
|
+
}
|
|
2538
|
+
function persistAppAssociation(cfg) {
|
|
2539
|
+
withLaunchAgentWriteLock(cfg.plistPath, () => {
|
|
2540
|
+
const installed = readInstalledConfig(cfg.plistPath);
|
|
2541
|
+
if (!installed?.nodePath || !installed.daemonScript) return;
|
|
2542
|
+
const identity = findRecallAppIdentity(installed.nodePath, installed.daemonScript);
|
|
2543
|
+
if (!identity) return;
|
|
2544
|
+
const identifiers = associatedBundleIdentifiers(installed.associatedBundleIdentifiers);
|
|
2545
|
+
if (sameIdentifiers(identifiers, installed.associatedBundleIdentifiers)) return;
|
|
2546
|
+
const value = `<array>${identifiers.map((identifier) => `<string>${escapeXml(identifier)}</string>`).join("")}</array>`;
|
|
2547
|
+
const operation = installed.hasAssociatedBundleIdentifiers ? "-replace" : "-insert";
|
|
2548
|
+
execFileSync5("plutil", [operation, "AssociatedBundleIdentifiers", "-xml", value, cfg.plistPath], stdioOpts());
|
|
2549
|
+
chmodSync2(cfg.plistPath, 384);
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
1905
2552
|
function domainTarget() {
|
|
1906
2553
|
const uid = process.getuid?.();
|
|
1907
2554
|
if (uid == null) {
|
|
@@ -1916,14 +2563,14 @@ function extractState(output) {
|
|
|
1916
2563
|
}
|
|
1917
2564
|
function tryRun(cmd, args) {
|
|
1918
2565
|
try {
|
|
1919
|
-
|
|
2566
|
+
execFileSync5(cmd, args, stdioOpts());
|
|
1920
2567
|
} catch {
|
|
1921
2568
|
return;
|
|
1922
2569
|
}
|
|
1923
2570
|
}
|
|
1924
2571
|
function tryOutput(cmd, args) {
|
|
1925
2572
|
try {
|
|
1926
|
-
const output =
|
|
2573
|
+
const output = execFileSync5(cmd, args, {
|
|
1927
2574
|
encoding: "utf8",
|
|
1928
2575
|
stdio: ["ignore", "pipe", "pipe"]
|
|
1929
2576
|
});
|
|
@@ -1938,14 +2585,16 @@ function tryOutput(cmd, args) {
|
|
|
1938
2585
|
function readInstalledConfig(plistPath) {
|
|
1939
2586
|
if (!exists(plistPath)) return null;
|
|
1940
2587
|
try {
|
|
1941
|
-
const raw =
|
|
2588
|
+
const raw = execFileSync5("plutil", ["-convert", "json", "-o", "-", plistPath], {
|
|
1942
2589
|
encoding: "utf8",
|
|
1943
2590
|
stdio: ["ignore", "pipe", "pipe"]
|
|
1944
2591
|
});
|
|
1945
2592
|
const parsed = JSON.parse(raw);
|
|
2593
|
+
const identity = launchdPlistIdentity(parsed);
|
|
1946
2594
|
return {
|
|
1947
|
-
|
|
1948
|
-
|
|
2595
|
+
label: identity.label,
|
|
2596
|
+
nodePath: identity.nodePath,
|
|
2597
|
+
daemonScript: identity.daemonScript,
|
|
1949
2598
|
port: parsed?.EnvironmentVariables?.RECALL_PORT,
|
|
1950
2599
|
maintenanceIntervalSeconds: parsed?.EnvironmentVariables?.RECALL_MAINTENANCE_INTERVAL_SECONDS,
|
|
1951
2600
|
dataDir: parsed?.EnvironmentVariables?.RECALL_DATA_DIR,
|
|
@@ -1958,12 +2607,48 @@ function readInstalledConfig(plistPath) {
|
|
|
1958
2607
|
parsed?.EnvironmentVariables ?? {}
|
|
1959
2608
|
),
|
|
1960
2609
|
stdoutPath: parsed?.StandardOutPath,
|
|
1961
|
-
stderrPath: parsed?.StandardErrorPath
|
|
2610
|
+
stderrPath: parsed?.StandardErrorPath,
|
|
2611
|
+
associatedBundleIdentifiers: identity.associatedBundleIdentifiers,
|
|
2612
|
+
hasAssociatedBundleIdentifiers: identity.hasAssociatedBundleIdentifiers
|
|
1962
2613
|
};
|
|
1963
2614
|
} catch {
|
|
1964
2615
|
return null;
|
|
1965
2616
|
}
|
|
1966
2617
|
}
|
|
2618
|
+
function sameIdentifiers(next, existing) {
|
|
2619
|
+
const current = typeof existing === "string" ? [existing] : Array.isArray(existing) ? existing.filter((value) => typeof value === "string") : [];
|
|
2620
|
+
return next.length === current.length && next.every((value, index) => value === current[index]);
|
|
2621
|
+
}
|
|
2622
|
+
function launchAgentPlistPath(label = DEFAULT_LABEL, home = homedir2()) {
|
|
2623
|
+
return join6(home, "Library", "LaunchAgents", `${label}.plist`);
|
|
2624
|
+
}
|
|
2625
|
+
function withLaunchAgentWriteLock(plistPath, action) {
|
|
2626
|
+
const lockPath = `${plistPath}.recall-identity.lock`;
|
|
2627
|
+
const deadline = Date.now() + 5e3;
|
|
2628
|
+
let descriptor;
|
|
2629
|
+
while (descriptor === void 0) {
|
|
2630
|
+
try {
|
|
2631
|
+
descriptor = openSync(lockPath, "wx", 384);
|
|
2632
|
+
} catch (error) {
|
|
2633
|
+
if (error?.code !== "EEXIST") throw error;
|
|
2634
|
+
try {
|
|
2635
|
+
if (Date.now() - statSync3(lockPath).mtimeMs > 3e4) unlinkSync2(lockPath);
|
|
2636
|
+
} catch (statError) {
|
|
2637
|
+
if (statError?.code !== "ENOENT") throw statError;
|
|
2638
|
+
}
|
|
2639
|
+
if (Date.now() >= deadline) {
|
|
2640
|
+
throw new Error(`Timed out waiting to update launchd plist: ${plistPath}`);
|
|
2641
|
+
}
|
|
2642
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
try {
|
|
2646
|
+
return action();
|
|
2647
|
+
} finally {
|
|
2648
|
+
closeSync(descriptor);
|
|
2649
|
+
unlinkSync2(lockPath);
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
1967
2652
|
function stdioOpts() {
|
|
1968
2653
|
return {
|
|
1969
2654
|
stdio: "pipe"
|
|
@@ -1983,17 +2668,17 @@ function assertDarwin() {
|
|
|
1983
2668
|
|
|
1984
2669
|
// src/daemon/systemd.ts
|
|
1985
2670
|
init_define_RECALL_BUILD_INFO();
|
|
1986
|
-
import { chmodSync as chmodSync3, existsSync as existsSync3, mkdirSync as
|
|
1987
|
-
import { homedir as
|
|
1988
|
-
import { dirname as
|
|
2671
|
+
import { chmodSync as chmodSync3, existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync2, rmSync as rmSync4, writeFileSync as writeFileSync2 } from "fs";
|
|
2672
|
+
import { homedir as homedir3 } from "os";
|
|
2673
|
+
import { dirname as dirname6, join as join7, resolve as resolve3 } from "path";
|
|
1989
2674
|
import { fileURLToPath } from "url";
|
|
1990
|
-
import { execFileSync as
|
|
2675
|
+
import { execFileSync as execFileSync6 } from "child_process";
|
|
1991
2676
|
var DEFAULT_LABEL2 = "recall-daemon";
|
|
1992
2677
|
function installSystemdUnit(opts = {}) {
|
|
1993
2678
|
assertLinux();
|
|
1994
2679
|
const cfg = resolveConfig2(opts);
|
|
1995
|
-
|
|
1996
|
-
|
|
2680
|
+
mkdirSync5(dirname6(cfg.unitPath), { recursive: true });
|
|
2681
|
+
mkdirSync5(cfg.logDir, { recursive: true });
|
|
1997
2682
|
writeFileSync2(cfg.unitPath, renderUnit(cfg), { mode: 384 });
|
|
1998
2683
|
chmodSync3(cfg.unitPath, 384);
|
|
1999
2684
|
for (const args of systemdInstallCommands(cfg.label)) systemctl(args);
|
|
@@ -2013,7 +2698,7 @@ function uninstallSystemdUnit(label = DEFAULT_LABEL2) {
|
|
|
2013
2698
|
assertLinux();
|
|
2014
2699
|
const cfg = resolveConfig2({ label });
|
|
2015
2700
|
trySystemctl(["--user", "disable", "--now", `${cfg.label}.service`]);
|
|
2016
|
-
|
|
2701
|
+
rmSync4(cfg.unitPath, { force: true });
|
|
2017
2702
|
trySystemctl(["--user", "daemon-reload"]);
|
|
2018
2703
|
return getSystemdStatus(cfg.label);
|
|
2019
2704
|
}
|
|
@@ -2086,19 +2771,19 @@ function getSystemdInfo(label = DEFAULT_LABEL2) {
|
|
|
2086
2771
|
}
|
|
2087
2772
|
function resolveConfig2(opts) {
|
|
2088
2773
|
const label = opts.label ?? DEFAULT_LABEL2;
|
|
2089
|
-
const home =
|
|
2774
|
+
const home = homedir3();
|
|
2090
2775
|
const port = opts.port ?? parseInt(process.env.RECALL_PORT ?? "7890", 10);
|
|
2091
2776
|
const maintenanceIntervalSeconds = opts.maintenanceIntervalSeconds ?? parseInt(process.env.RECALL_MAINTENANCE_INTERVAL_SECONDS ?? "3600", 10);
|
|
2092
2777
|
const dataDir = resolve3(
|
|
2093
|
-
opts.dataDir ?? process.env.RECALL_DATA_DIR ??
|
|
2778
|
+
opts.dataDir ?? process.env.RECALL_DATA_DIR ?? join7(home, ".recall")
|
|
2094
2779
|
);
|
|
2095
2780
|
const nodePath = resolve3(opts.nodePath ?? process.execPath);
|
|
2096
2781
|
const daemonScript = resolve3(
|
|
2097
2782
|
opts.daemonScript ?? defaultDaemonScript()
|
|
2098
2783
|
);
|
|
2099
|
-
const configHome = process.env.XDG_CONFIG_HOME ??
|
|
2100
|
-
const unitPath =
|
|
2101
|
-
const logDir =
|
|
2784
|
+
const configHome = process.env.XDG_CONFIG_HOME ?? join7(home, ".config");
|
|
2785
|
+
const unitPath = join7(configHome, "systemd", "user", `${label}.service`);
|
|
2786
|
+
const logDir = join7(dataDir, "logs");
|
|
2102
2787
|
const installed = readInstalledConfig2(unitPath);
|
|
2103
2788
|
return {
|
|
2104
2789
|
label,
|
|
@@ -2121,8 +2806,8 @@ function resolveConfig2(opts) {
|
|
|
2121
2806
|
};
|
|
2122
2807
|
}
|
|
2123
2808
|
function defaultDaemonScript() {
|
|
2124
|
-
const here =
|
|
2125
|
-
return
|
|
2809
|
+
const here = dirname6(fileURLToPath(import.meta.url));
|
|
2810
|
+
return join7(here, "daemon.js");
|
|
2126
2811
|
}
|
|
2127
2812
|
function renderUnit(cfg) {
|
|
2128
2813
|
const envLines = [
|
|
@@ -2195,18 +2880,18 @@ function unescapeSystemdValue(value) {
|
|
|
2195
2880
|
return value.replaceAll("%%", "%").replaceAll('\\"', '"').replaceAll("\\\\", "\\");
|
|
2196
2881
|
}
|
|
2197
2882
|
function systemctl(args) {
|
|
2198
|
-
|
|
2883
|
+
execFileSync6("systemctl", args, { stdio: "pipe" });
|
|
2199
2884
|
}
|
|
2200
2885
|
function trySystemctl(args) {
|
|
2201
2886
|
try {
|
|
2202
|
-
|
|
2887
|
+
execFileSync6("systemctl", args, { stdio: "pipe" });
|
|
2203
2888
|
} catch {
|
|
2204
2889
|
return;
|
|
2205
2890
|
}
|
|
2206
2891
|
}
|
|
2207
2892
|
function trySystemctlOutput(args) {
|
|
2208
2893
|
try {
|
|
2209
|
-
const output =
|
|
2894
|
+
const output = execFileSync6("systemctl", args, {
|
|
2210
2895
|
encoding: "utf8",
|
|
2211
2896
|
stdio: ["ignore", "pipe", "pipe"]
|
|
2212
2897
|
});
|
|
@@ -2228,13 +2913,13 @@ function assertLinux() {
|
|
|
2228
2913
|
init_define_RECALL_BUILD_INFO();
|
|
2229
2914
|
import {
|
|
2230
2915
|
existsSync as existsSync4,
|
|
2231
|
-
mkdirSync as
|
|
2916
|
+
mkdirSync as mkdirSync6,
|
|
2232
2917
|
readFileSync as readFileSync3,
|
|
2233
|
-
realpathSync,
|
|
2234
|
-
renameSync as
|
|
2918
|
+
realpathSync as realpathSync2,
|
|
2919
|
+
renameSync as renameSync3,
|
|
2235
2920
|
writeFileSync as writeFileSync3
|
|
2236
2921
|
} from "fs";
|
|
2237
|
-
import { dirname as
|
|
2922
|
+
import { dirname as dirname7, join as join8, resolve as resolve4 } from "path";
|
|
2238
2923
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
2239
2924
|
var CLAUDE_CONFIG_RELATIVE_PATH = [".claude", "settings.json"];
|
|
2240
2925
|
var CLAUDE_MD_RELATIVE_PATH = [".claude", "CLAUDE.md"];
|
|
@@ -2246,7 +2931,7 @@ var CLAUDE_MD_BEGIN_NAME_RE = /recall:managed:(?:memory|claude-md):begin/;
|
|
|
2246
2931
|
var CLAUDE_MD_BLOCK_RE = /<!--\s*recall:managed:(?:memory|claude-md):begin(?:\s+v\d+)?\s*-->[\s\S]*?<!--\s*recall:managed:(?:memory|claude-md):end\s*-->\n?/g;
|
|
2247
2932
|
var SESSION_START_MATCHER = "startup|resume|clear|compact";
|
|
2248
2933
|
var SESSION_END_MATCHER = "clear|resume|logout|prompt_input_exit|bypass_permissions_disabled|other";
|
|
2249
|
-
var configPath = () =>
|
|
2934
|
+
var configPath = () => join8(resolveUserHomeDir(), ...CLAUDE_CONFIG_RELATIVE_PATH);
|
|
2250
2935
|
var claudeCodeAdapter = {
|
|
2251
2936
|
name: "claude-code",
|
|
2252
2937
|
configPath,
|
|
@@ -2445,7 +3130,7 @@ function resolveCliPath() {
|
|
|
2445
3130
|
if (fromArgv && /(?:^|\/)cli\.[cm]?js$/.test(fromArgv) && existsSync4(fromArgv)) {
|
|
2446
3131
|
return resolve4(fromArgv);
|
|
2447
3132
|
}
|
|
2448
|
-
const sibling = resolve4(
|
|
3133
|
+
const sibling = resolve4(dirname7(fileURLToPath2(import.meta.url)), "..", "cli.js");
|
|
2449
3134
|
if (existsSync4(sibling)) {
|
|
2450
3135
|
return sibling;
|
|
2451
3136
|
}
|
|
@@ -2467,8 +3152,8 @@ function readSettingsFile(configPath2) {
|
|
|
2467
3152
|
return { raw, settings: parsed };
|
|
2468
3153
|
}
|
|
2469
3154
|
function writeSettingsFile(configPath2, previousRaw, settings) {
|
|
2470
|
-
const parentDir =
|
|
2471
|
-
|
|
3155
|
+
const parentDir = dirname7(configPath2);
|
|
3156
|
+
mkdirSync6(parentDir, { recursive: true });
|
|
2472
3157
|
if (previousRaw != null) {
|
|
2473
3158
|
const backupPath = `${configPath2}.recall.bak.${Date.now()}`;
|
|
2474
3159
|
writeFileSync3(backupPath, previousRaw);
|
|
@@ -2476,7 +3161,7 @@ function writeSettingsFile(configPath2, previousRaw, settings) {
|
|
|
2476
3161
|
const tmpPath = `${configPath2}.tmp.${process.pid}`;
|
|
2477
3162
|
writeFileSync3(tmpPath, `${JSON.stringify(settings, null, 2)}
|
|
2478
3163
|
`);
|
|
2479
|
-
|
|
3164
|
+
renameSync3(tmpPath, configPath2);
|
|
2480
3165
|
}
|
|
2481
3166
|
function ensureHooksObject(settings) {
|
|
2482
3167
|
if (!settings.hooks) {
|
|
@@ -2515,7 +3200,7 @@ ${CLAUDE_MD_END}
|
|
|
2515
3200
|
`;
|
|
2516
3201
|
}
|
|
2517
3202
|
function claudeMdPath() {
|
|
2518
|
-
return
|
|
3203
|
+
return join8(resolveUserHomeDir(), ...CLAUDE_MD_RELATIVE_PATH);
|
|
2519
3204
|
}
|
|
2520
3205
|
function installClaudeCodeMemoryOverride(options = {}) {
|
|
2521
3206
|
if (process.env.RECALL_SETUP_SKIP_CLAUDE_MD === "1") {
|
|
@@ -2527,9 +3212,9 @@ function installClaudeCodeMemoryOverride(options = {}) {
|
|
|
2527
3212
|
};
|
|
2528
3213
|
}
|
|
2529
3214
|
const targetPath = options.configPath ?? claudeMdPath();
|
|
2530
|
-
const targetDir =
|
|
3215
|
+
const targetDir = dirname7(targetPath);
|
|
2531
3216
|
if (!existsSync4(targetDir)) {
|
|
2532
|
-
|
|
3217
|
+
mkdirSync6(targetDir, { recursive: true });
|
|
2533
3218
|
}
|
|
2534
3219
|
const desired = buildClaudeMdBlock();
|
|
2535
3220
|
const filePath = resolveClaudeMdFilePath(targetPath);
|
|
@@ -2601,7 +3286,7 @@ function uninstallClaudeCodeMemoryOverride(options = {}) {
|
|
|
2601
3286
|
}
|
|
2602
3287
|
function resolveClaudeMdFilePath(targetPath) {
|
|
2603
3288
|
try {
|
|
2604
|
-
return
|
|
3289
|
+
return realpathSync2(targetPath);
|
|
2605
3290
|
} catch (error) {
|
|
2606
3291
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
2607
3292
|
return targetPath;
|
|
@@ -2629,7 +3314,7 @@ init_define_RECALL_BUILD_INFO();
|
|
|
2629
3314
|
|
|
2630
3315
|
// src/agents/cursor.ts
|
|
2631
3316
|
init_define_RECALL_BUILD_INFO();
|
|
2632
|
-
import { join as
|
|
3317
|
+
import { join as join9 } from "path";
|
|
2633
3318
|
|
|
2634
3319
|
// src/agents/hookless.ts
|
|
2635
3320
|
init_define_RECALL_BUILD_INFO();
|
|
@@ -2638,8 +3323,8 @@ import { resolve as resolve5 } from "path";
|
|
|
2638
3323
|
|
|
2639
3324
|
// src/agents/mcp-json.ts
|
|
2640
3325
|
init_define_RECALL_BUILD_INFO();
|
|
2641
|
-
import { existsSync as existsSync5, mkdirSync as
|
|
2642
|
-
import { dirname as
|
|
3326
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync7, readFileSync as readFileSync4, renameSync as renameSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
3327
|
+
import { dirname as dirname8 } from "path";
|
|
2643
3328
|
var RECALL_SERVER_KEY = "recall";
|
|
2644
3329
|
function commandArgsEntry(spec) {
|
|
2645
3330
|
return {
|
|
@@ -2762,14 +3447,14 @@ function readJsonConfig(configPath2) {
|
|
|
2762
3447
|
return { raw, parsed: object };
|
|
2763
3448
|
}
|
|
2764
3449
|
function writeJsonConfig(configPath2, previousRaw, value) {
|
|
2765
|
-
|
|
3450
|
+
mkdirSync7(dirname8(configPath2), { recursive: true });
|
|
2766
3451
|
if (previousRaw != null) {
|
|
2767
3452
|
writeFileSync4(`${configPath2}.recall.bak.${Date.now()}`, previousRaw);
|
|
2768
3453
|
}
|
|
2769
3454
|
const tmpPath = `${configPath2}.tmp.${process.pid}`;
|
|
2770
3455
|
writeFileSync4(tmpPath, `${JSON.stringify(value, null, 2)}
|
|
2771
3456
|
`);
|
|
2772
|
-
|
|
3457
|
+
renameSync4(tmpPath, configPath2);
|
|
2773
3458
|
}
|
|
2774
3459
|
function ensureContainer(config, key) {
|
|
2775
3460
|
if (config[key] === void 0) {
|
|
@@ -2789,8 +3474,8 @@ function sameJson2(left, right) {
|
|
|
2789
3474
|
|
|
2790
3475
|
// src/agents/rules-block.ts
|
|
2791
3476
|
init_define_RECALL_BUILD_INFO();
|
|
2792
|
-
import { existsSync as existsSync6, mkdirSync as
|
|
2793
|
-
import { dirname as
|
|
3477
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as readFileSync5, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "fs";
|
|
3478
|
+
import { dirname as dirname9 } from "path";
|
|
2794
3479
|
function beginMarker(block) {
|
|
2795
3480
|
return `<!-- recall:managed:${block.name}:begin v${block.version} -->`;
|
|
2796
3481
|
}
|
|
@@ -2827,7 +3512,7 @@ function installManagedRules(targetPath, block) {
|
|
|
2827
3512
|
};
|
|
2828
3513
|
}
|
|
2829
3514
|
const next = block.ownsFile ? `${block.preamble ?? ""}${desired}` : mergeIntoExisting(existing, desired, block);
|
|
2830
|
-
|
|
3515
|
+
mkdirSync8(dirname9(targetPath), { recursive: true });
|
|
2831
3516
|
writeFileSync5(targetPath, next);
|
|
2832
3517
|
return {
|
|
2833
3518
|
ok: true,
|
|
@@ -2853,7 +3538,7 @@ function uninstallManagedRules(targetPath, block) {
|
|
|
2853
3538
|
}
|
|
2854
3539
|
const stripped = removeLegacyBlocks(existing.replace(blockRe(block), ""), block).replace(/\n{3,}/g, "\n\n");
|
|
2855
3540
|
if (block.ownsFile && stripped.trim() === (block.preamble ?? "").trim()) {
|
|
2856
|
-
|
|
3541
|
+
rmSync5(targetPath, { force: true });
|
|
2857
3542
|
return { ok: true, changed: true, config_path: targetPath, message: `Removed ${targetPath}` };
|
|
2858
3543
|
}
|
|
2859
3544
|
writeFileSync5(targetPath, stripped.trim().length === 0 ? "" : ensureTrailingNewline(stripped));
|
|
@@ -3009,10 +3694,10 @@ function projectPath(options, ...segments) {
|
|
|
3009
3694
|
// src/agents/cursor.ts
|
|
3010
3695
|
var LABEL = "Cursor";
|
|
3011
3696
|
function cursorHome(options = {}) {
|
|
3012
|
-
return
|
|
3697
|
+
return join9(options.homeDir ?? resolveUserHomeDir(), ".cursor");
|
|
3013
3698
|
}
|
|
3014
3699
|
function cursorGlobalMcpPath(options = {}) {
|
|
3015
|
-
return
|
|
3700
|
+
return join9(cursorHome(options), "mcp.json");
|
|
3016
3701
|
}
|
|
3017
3702
|
function cursorProjectMcpPath(options = {}) {
|
|
3018
3703
|
return projectPath(options, ".cursor", "mcp.json");
|
|
@@ -3092,14 +3777,14 @@ var geminiCliAdapter = {
|
|
|
3092
3777
|
|
|
3093
3778
|
// src/agents/github-copilot.ts
|
|
3094
3779
|
init_define_RECALL_BUILD_INFO();
|
|
3095
|
-
import { join as
|
|
3780
|
+
import { join as join10 } from "path";
|
|
3096
3781
|
var LABEL2 = "GitHub Copilot";
|
|
3097
3782
|
function copilotHome(options = {}) {
|
|
3098
|
-
if (options.homeDir) return
|
|
3099
|
-
return process.env.COPILOT_HOME ??
|
|
3783
|
+
if (options.homeDir) return join10(options.homeDir, ".copilot");
|
|
3784
|
+
return process.env.COPILOT_HOME ?? join10(resolveUserHomeDir(), ".copilot");
|
|
3100
3785
|
}
|
|
3101
3786
|
function copilotMcpConfigPath(options = {}) {
|
|
3102
|
-
return
|
|
3787
|
+
return join10(copilotHome(options), "mcp-config.json");
|
|
3103
3788
|
}
|
|
3104
3789
|
function copilotInstructionsPath(options = {}) {
|
|
3105
3790
|
return projectPath(options, ".github", "copilot-instructions.md");
|
|
@@ -3126,16 +3811,16 @@ var githubCopilotAdapter = createHooklessAdapter({
|
|
|
3126
3811
|
|
|
3127
3812
|
// src/agents/opencode.ts
|
|
3128
3813
|
init_define_RECALL_BUILD_INFO();
|
|
3129
|
-
import { join as
|
|
3814
|
+
import { join as join11 } from "path";
|
|
3130
3815
|
var LABEL3 = "opencode";
|
|
3131
3816
|
function opencodeConfigDir(options = {}) {
|
|
3132
|
-
return
|
|
3817
|
+
return join11(options.homeDir ?? resolveUserHomeDir(), ".config", "opencode");
|
|
3133
3818
|
}
|
|
3134
3819
|
function opencodeConfigPath(options = {}) {
|
|
3135
|
-
return
|
|
3820
|
+
return join11(opencodeConfigDir(options), "opencode.json");
|
|
3136
3821
|
}
|
|
3137
3822
|
function opencodeAgentsPath(options = {}) {
|
|
3138
|
-
return
|
|
3823
|
+
return join11(opencodeConfigDir(options), "AGENTS.md");
|
|
3139
3824
|
}
|
|
3140
3825
|
var opencodeAdapter = createHooklessAdapter({
|
|
3141
3826
|
name: "opencode",
|
|
@@ -3202,16 +3887,16 @@ var qwenAdapter = {
|
|
|
3202
3887
|
|
|
3203
3888
|
// src/agents/windsurf.ts
|
|
3204
3889
|
init_define_RECALL_BUILD_INFO();
|
|
3205
|
-
import { join as
|
|
3890
|
+
import { join as join12 } from "path";
|
|
3206
3891
|
var LABEL4 = "Windsurf";
|
|
3207
3892
|
function windsurfConfigDir(options = {}) {
|
|
3208
|
-
return
|
|
3893
|
+
return join12(options.homeDir ?? resolveUserHomeDir(), ".codeium", "windsurf");
|
|
3209
3894
|
}
|
|
3210
3895
|
function windsurfMcpConfigPath(options = {}) {
|
|
3211
|
-
return
|
|
3896
|
+
return join12(windsurfConfigDir(options), "mcp_config.json");
|
|
3212
3897
|
}
|
|
3213
3898
|
function windsurfGlobalRulesPath(options = {}) {
|
|
3214
|
-
return
|
|
3899
|
+
return join12(windsurfConfigDir(options), "memories", "global_rules.md");
|
|
3215
3900
|
}
|
|
3216
3901
|
var windsurfAdapter = createHooklessAdapter({
|
|
3217
3902
|
name: "windsurf",
|
|
@@ -3356,7 +4041,8 @@ function getDoctorReport() {
|
|
|
3356
4041
|
upgrade,
|
|
3357
4042
|
cleanup: readCleanupHealth(dbPath),
|
|
3358
4043
|
dispatcher: readDispatcherHealth(dbPath),
|
|
3359
|
-
app_registrations: inspectAppRegistrations()
|
|
4044
|
+
app_registrations: inspectAppRegistrations(),
|
|
4045
|
+
reliability_verdict: readReliabilityVerdict(dirname10(dbPath))
|
|
3360
4046
|
};
|
|
3361
4047
|
}
|
|
3362
4048
|
function readDispatcherHealth(dbPath) {
|
|
@@ -3531,8 +4217,8 @@ function inspectHooklessInstall(agent, home) {
|
|
|
3531
4217
|
};
|
|
3532
4218
|
}
|
|
3533
4219
|
function inspectClaudeCodeInstall(home) {
|
|
3534
|
-
const configPath2 =
|
|
3535
|
-
const userConfigPath =
|
|
4220
|
+
const configPath2 = join13(home, ".claude", "settings.json");
|
|
4221
|
+
const userConfigPath = join13(home, ".claude.json");
|
|
3536
4222
|
const detected = existsSync8(configPath2) || existsSync8(userConfigPath) || hasCommand("claude");
|
|
3537
4223
|
const notes = [];
|
|
3538
4224
|
let mcp = false;
|
|
@@ -3564,7 +4250,7 @@ function inspectClaudeCodeInstall(home) {
|
|
|
3564
4250
|
}
|
|
3565
4251
|
if (!mcp) notes.push("MCP server 'recall' not registered in user configuration");
|
|
3566
4252
|
const claudeMd = checkClaudeCodeMemoryOverride({
|
|
3567
|
-
configPath:
|
|
4253
|
+
configPath: join13(home, ".claude", "CLAUDE.md")
|
|
3568
4254
|
});
|
|
3569
4255
|
if (claudeMd.status === "stale") {
|
|
3570
4256
|
notes.push("CLAUDE.md memory-override block is out of date \u2014 run `recall doctor --fix`");
|
|
@@ -3585,8 +4271,8 @@ function inspectClaudeCodeInstall(home) {
|
|
|
3585
4271
|
};
|
|
3586
4272
|
}
|
|
3587
4273
|
function inspectCodexHome(codexHome) {
|
|
3588
|
-
const configPath2 =
|
|
3589
|
-
const hooksPath =
|
|
4274
|
+
const configPath2 = join13(codexHome, "config.toml");
|
|
4275
|
+
const hooksPath = join13(codexHome, "hooks.json");
|
|
3590
4276
|
const detected = existsSync8(configPath2) || hasCommand("codex");
|
|
3591
4277
|
const notes = [];
|
|
3592
4278
|
let mcp = false;
|
|
@@ -3633,7 +4319,7 @@ function inspectCodexInstall(home) {
|
|
|
3633
4319
|
const notes = [...primary.notes];
|
|
3634
4320
|
for (const entry of entries.slice(1)) {
|
|
3635
4321
|
for (const note of entry.notes) {
|
|
3636
|
-
notes.push(`${
|
|
4322
|
+
notes.push(`${basename3(entry.codexHome)}: ${note}`);
|
|
3637
4323
|
}
|
|
3638
4324
|
}
|
|
3639
4325
|
return {
|
|
@@ -3697,13 +4383,16 @@ function formatDoctorReport(report) {
|
|
|
3697
4383
|
}
|
|
3698
4384
|
}
|
|
3699
4385
|
for (const trust of agent.hook_trust ?? []) {
|
|
3700
|
-
lines.push(` ${
|
|
4386
|
+
lines.push(` ${basename3(trust.home)} trust:${trust.status}${trust.error ? ` (${trust.error})` : ""}`);
|
|
3701
4387
|
if (trust.status === "review-required") lines.push(" Review the current Recall commands in Codex /hooks for this profile.");
|
|
3702
4388
|
}
|
|
3703
4389
|
for (const note of agent.notes) {
|
|
3704
4390
|
lines.push(` - ${note}`);
|
|
3705
4391
|
}
|
|
3706
4392
|
}
|
|
4393
|
+
if (report.reliability_verdict !== void 0) {
|
|
4394
|
+
lines.push("", "## Reliability", ...formatReliabilityVerdictSection(report.reliability_verdict));
|
|
4395
|
+
}
|
|
3707
4396
|
if (report.cleanup) {
|
|
3708
4397
|
lines.push("", "## Cleanup");
|
|
3709
4398
|
if (report.cleanup.last_run_at) {
|
|
@@ -3772,7 +4461,12 @@ export {
|
|
|
3772
4461
|
getRepoContextArtifactPath,
|
|
3773
4462
|
writeRepoContextArtifact,
|
|
3774
4463
|
unregisterStrayApps,
|
|
4464
|
+
computeReliabilityReport,
|
|
4465
|
+
formatReliabilityReport,
|
|
3775
4466
|
getHookCallStats,
|
|
4467
|
+
toolOutcomeFromPayload,
|
|
4468
|
+
extractCodexSessionId,
|
|
4469
|
+
resolveCodexSessionEndSessionId,
|
|
3776
4470
|
executePromptHook,
|
|
3777
4471
|
executeToolHook,
|
|
3778
4472
|
executeAssistantCompletionHook,
|
|
@@ -3818,8 +4512,13 @@ export {
|
|
|
3818
4512
|
startSystemdUnit,
|
|
3819
4513
|
stopSystemdUnit,
|
|
3820
4514
|
getSystemdInfo,
|
|
4515
|
+
reliabilityVerdictDataDir,
|
|
4516
|
+
readReliabilityVerdict,
|
|
4517
|
+
runReliabilityVerdictCycle,
|
|
4518
|
+
notifyMacOS,
|
|
4519
|
+
loadReliabilityVerdictConfigFromEnv,
|
|
3821
4520
|
getDoctorStatusReport,
|
|
3822
4521
|
getDoctorReport,
|
|
3823
4522
|
formatDoctorReport
|
|
3824
4523
|
};
|
|
3825
|
-
//# sourceMappingURL=chunk-
|
|
4524
|
+
//# sourceMappingURL=chunk-OHWHU653.js.map
|