@edihasaj/recall 2.0.16 → 2.0.18
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 +34 -4
- package/dist/{chunk-MLC3KO2O.js → chunk-2YFC2U6M.js} +7 -7
- package/dist/{chunk-YELXEWKH.js → chunk-CGZP6FXD.js} +3 -3
- package/dist/{chunk-LEOXFQJJ.js → chunk-EJNIQVIJ.js} +2 -2
- package/dist/{chunk-EKFOHVHS.js → chunk-HKA2KAB2.js} +233 -28
- package/dist/chunk-HKA2KAB2.js.map +1 -0
- package/dist/{chunk-VRAG5V66.js → chunk-JMAWDCQM.js} +1091 -48
- package/dist/chunk-JMAWDCQM.js.map +1 -0
- package/dist/{chunk-GDN44ZC7.js → chunk-LGM46TRO.js} +2 -2
- package/dist/{chunk-SEXZABB2.js → chunk-MXF255YS.js} +5 -5
- package/dist/{chunk-GCMP2YYN.js → chunk-OIIAMDOT.js} +4 -3
- package/dist/{chunk-GCMP2YYN.js.map → chunk-OIIAMDOT.js.map} +1 -1
- package/dist/{chunk-FYMMTODQ.js → chunk-PVEH3GEI.js} +2 -2
- package/dist/{chunk-FYMMTODQ.js.map → chunk-PVEH3GEI.js.map} +1 -1
- package/dist/{chunk-DAW6FUGL.js → chunk-SARDP34D.js} +5 -5
- package/dist/{chunk-SYSSACWJ.js → chunk-SHS4CTN3.js} +43 -20
- package/dist/chunk-SHS4CTN3.js.map +1 -0
- package/dist/{chunk-DOYTMHDI.js → chunk-SYYBKTWO.js} +2 -2
- package/dist/{chunk-Q2F7EQCA.js → chunk-UNKEHYFD.js} +2 -2
- package/dist/{chunk-7UWVXXTU.js → chunk-VNKQBRLB.js} +3 -3
- package/dist/{chunk-QPR77YXP.js → chunk-XBYAK7LC.js} +13 -11
- package/dist/chunk-XBYAK7LC.js.map +1 -0
- package/dist/{chunk-THC7QOAK.js → chunk-XOKSI4EY.js} +7 -7
- package/dist/{chunk-DVLQYARZ.js → chunk-YFK2AD34.js} +3 -3
- package/dist/{chunk-ZF23OPYV.js → chunk-Z2NS4E63.js} +31 -38
- package/dist/chunk-Z2NS4E63.js.map +1 -0
- package/dist/{cleanup-WJFE6IVP.js → cleanup-PYF3MQXT.js} +11 -11
- package/dist/cli.js +58 -191
- package/dist/cli.js.map +1 -1
- package/dist/{codex-trust-3BFTJFRD.js → codex-trust-JTJSVDJ4.js} +4 -4
- package/dist/daemon.js +1213 -188
- package/dist/daemon.js.map +1 -1
- package/dist/dispatcher-JZKQYPLF.js +22 -0
- package/dist/{embeddings-H352GFKD.js → embeddings-3NAF5DFW.js} +5 -5
- package/dist/ingest-KWIQFV6X.js +20 -0
- package/dist/{keychain-A2Z7D7YE.js → keychain-FLEYJZCO.js} +3 -3
- package/dist/mcp.js +15 -15
- package/dist/{memory-value-M3TA7SEK.js → memory-value-DT5DNGJA.js} +11 -11
- package/dist/{provenance-CXU6LZK7.js → provenance-ZBYCDVTO.js} +9 -9
- package/dist/quality-UQME7OTQ.js +25 -0
- package/dist/retrieval-V7TY5HRU.js +15 -0
- package/dist/{store-YCVWABSH.js → store-UQFDKVUA.js} +4 -4
- package/dist/sync-server.js +2 -2
- package/dist/{tasks-4UL2FIAQ.js → tasks-2LMQ3ZXB.js} +11 -11
- package/dist/{usage-HZ27RG53.js → usage-ZXD4DO5J.js} +4 -4
- package/package.json +2 -1
- package/vendor/recall-cloud-sync/PROVENANCE.md +40 -0
- package/vendor/recall-cloud-sync/managed-worker.mjs +48 -0
- package/vendor/recall-cloud-sync/private-token.mjs +95 -0
- package/vendor/recall-cloud-sync/recall-sync-local.mjs +415 -0
- package/vendor/recall-cloud-sync/recall-sync.mjs +1300 -0
- package/dist/chunk-EKFOHVHS.js.map +0 -1
- package/dist/chunk-QPR77YXP.js.map +0 -1
- package/dist/chunk-SYSSACWJ.js.map +0 -1
- package/dist/chunk-VRAG5V66.js.map +0 -1
- package/dist/chunk-ZF23OPYV.js.map +0 -1
- package/dist/dispatcher-5JVGZNWT.js +0 -22
- package/dist/ingest-NVYEOSVZ.js +0 -20
- package/dist/quality-4CG6U273.js +0 -25
- package/dist/retrieval-42CPYUDW.js +0 -15
- /package/dist/{chunk-MLC3KO2O.js.map → chunk-2YFC2U6M.js.map} +0 -0
- /package/dist/{chunk-YELXEWKH.js.map → chunk-CGZP6FXD.js.map} +0 -0
- /package/dist/{chunk-LEOXFQJJ.js.map → chunk-EJNIQVIJ.js.map} +0 -0
- /package/dist/{chunk-GDN44ZC7.js.map → chunk-LGM46TRO.js.map} +0 -0
- /package/dist/{chunk-SEXZABB2.js.map → chunk-MXF255YS.js.map} +0 -0
- /package/dist/{chunk-DAW6FUGL.js.map → chunk-SARDP34D.js.map} +0 -0
- /package/dist/{chunk-DOYTMHDI.js.map → chunk-SYYBKTWO.js.map} +0 -0
- /package/dist/{chunk-Q2F7EQCA.js.map → chunk-UNKEHYFD.js.map} +0 -0
- /package/dist/{chunk-7UWVXXTU.js.map → chunk-VNKQBRLB.js.map} +0 -0
- /package/dist/{chunk-THC7QOAK.js.map → chunk-XOKSI4EY.js.map} +0 -0
- /package/dist/{chunk-DVLQYARZ.js.map → chunk-YFK2AD34.js.map} +0 -0
- /package/dist/{cleanup-WJFE6IVP.js.map → cleanup-PYF3MQXT.js.map} +0 -0
- /package/dist/{codex-trust-3BFTJFRD.js.map → codex-trust-JTJSVDJ4.js.map} +0 -0
- /package/dist/{dispatcher-5JVGZNWT.js.map → dispatcher-JZKQYPLF.js.map} +0 -0
- /package/dist/{embeddings-H352GFKD.js.map → embeddings-3NAF5DFW.js.map} +0 -0
- /package/dist/{ingest-NVYEOSVZ.js.map → ingest-KWIQFV6X.js.map} +0 -0
- /package/dist/{keychain-A2Z7D7YE.js.map → keychain-FLEYJZCO.js.map} +0 -0
- /package/dist/{memory-value-M3TA7SEK.js.map → memory-value-DT5DNGJA.js.map} +0 -0
- /package/dist/{provenance-CXU6LZK7.js.map → provenance-ZBYCDVTO.js.map} +0 -0
- /package/dist/{quality-4CG6U273.js.map → quality-UQME7OTQ.js.map} +0 -0
- /package/dist/{retrieval-42CPYUDW.js.map → retrieval-V7TY5HRU.js.map} +0 -0
- /package/dist/{store-YCVWABSH.js.map → store-UQFDKVUA.js.map} +0 -0
- /package/dist/{tasks-4UL2FIAQ.js.map → tasks-2LMQ3ZXB.js.map} +0 -0
- /package/dist/{usage-HZ27RG53.js.map → usage-ZXD4DO5J.js.map} +0 -0
package/dist/daemon.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
computeQualityReport,
|
|
3
3
|
listQualitySnapshots,
|
|
4
4
|
recordQualitySnapshot
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-SARDP34D.js";
|
|
6
6
|
import {
|
|
7
7
|
ensureDailyBackup,
|
|
8
8
|
extractCodexSessionId,
|
|
@@ -16,23 +16,27 @@ import {
|
|
|
16
16
|
handleSessionStartHook,
|
|
17
17
|
handleToolHook,
|
|
18
18
|
loadReliabilityVerdictConfigFromEnv,
|
|
19
|
-
notifyMacOS,
|
|
20
19
|
readReliabilityVerdict,
|
|
21
20
|
reliabilityVerdictDataDir,
|
|
22
21
|
resolveCodexSessionEndSessionId,
|
|
23
22
|
runReliabilityVerdictCycle,
|
|
24
23
|
toolOutcomeFromPayload,
|
|
25
24
|
writeRepoContextArtifact
|
|
26
|
-
} from "./chunk-
|
|
27
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-Z2NS4E63.js";
|
|
26
|
+
import "./chunk-CGZP6FXD.js";
|
|
28
27
|
import {
|
|
29
28
|
createRecallMcpServer
|
|
30
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-XBYAK7LC.js";
|
|
31
30
|
import {
|
|
32
31
|
graphQuery
|
|
33
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-MXF255YS.js";
|
|
34
33
|
import {
|
|
34
|
+
CloudError,
|
|
35
|
+
DEFAULT_CLOUD_API,
|
|
36
|
+
LEGACY_LAUNCHD_LABEL,
|
|
35
37
|
bootstrapHistoryEmbeddings,
|
|
38
|
+
buildChildEnv,
|
|
39
|
+
buildEngineArgs,
|
|
36
40
|
compileContext,
|
|
37
41
|
compileContextHybrid,
|
|
38
42
|
computeMetrics,
|
|
@@ -41,6 +45,7 @@ import {
|
|
|
41
45
|
createPolicy,
|
|
42
46
|
endEvalSession,
|
|
43
47
|
endSessionLifecycle,
|
|
48
|
+
ensurePrivateDir,
|
|
44
49
|
ensureRepoBootstrapped,
|
|
45
50
|
evaluatePolicy,
|
|
46
51
|
findHistorySnippetByRepoKind,
|
|
@@ -49,28 +54,40 @@ import {
|
|
|
49
54
|
incrementEvalCounter,
|
|
50
55
|
inferRepoSlugFromPath,
|
|
51
56
|
initDb,
|
|
57
|
+
isCloudQueryEnabled,
|
|
52
58
|
listActivityEvents,
|
|
53
59
|
listActivitySessions,
|
|
54
60
|
listHistorySnippets,
|
|
55
61
|
listPendingApprovals,
|
|
56
62
|
listPolicies,
|
|
63
|
+
loadCloudConfig,
|
|
64
|
+
normalizePassphrase,
|
|
65
|
+
normalizeSecret,
|
|
57
66
|
pruneMemories,
|
|
67
|
+
readPrivatePassphrase,
|
|
68
|
+
readPrivateSecret,
|
|
58
69
|
recordSessionLifecycleEvent,
|
|
59
70
|
recordSignal,
|
|
71
|
+
removeFile,
|
|
60
72
|
removeHistoryFtsRow,
|
|
61
73
|
removeHistoryVecRow,
|
|
62
74
|
requestApproval,
|
|
63
75
|
resolveApproval,
|
|
76
|
+
resolveCloudPaths,
|
|
64
77
|
runValueRetrievalEval,
|
|
78
|
+
saveCloudConfig,
|
|
65
79
|
scanAndStore,
|
|
80
|
+
setCloudQueryEnabled,
|
|
66
81
|
signalOutcomeFallback,
|
|
67
82
|
startEvalSession,
|
|
68
83
|
startSessionLifecycle,
|
|
69
84
|
summarizeValueRetrievalEval,
|
|
70
85
|
syncHistoryFtsIndex,
|
|
71
86
|
updateHistorySnippet,
|
|
72
|
-
|
|
73
|
-
|
|
87
|
+
validateApi,
|
|
88
|
+
verifyHistoryEmbeddings,
|
|
89
|
+
writePrivateFile
|
|
90
|
+
} from "./chunk-JMAWDCQM.js";
|
|
74
91
|
import {
|
|
75
92
|
DEFAULT_ENQUEUE_CONFIG,
|
|
76
93
|
autoResolveContradictions,
|
|
@@ -88,12 +105,12 @@ import {
|
|
|
88
105
|
processReviewFeedback,
|
|
89
106
|
resolveContradiction,
|
|
90
107
|
runDeterministicCleanup
|
|
91
|
-
} from "./chunk-
|
|
92
|
-
import "./chunk-
|
|
93
|
-
import "./chunk-
|
|
108
|
+
} from "./chunk-HKA2KAB2.js";
|
|
109
|
+
import "./chunk-2YFC2U6M.js";
|
|
110
|
+
import "./chunk-EJNIQVIJ.js";
|
|
94
111
|
import {
|
|
95
112
|
Sentry
|
|
96
|
-
} from "./chunk-
|
|
113
|
+
} from "./chunk-UNKEHYFD.js";
|
|
97
114
|
import {
|
|
98
115
|
confirmMemory,
|
|
99
116
|
createMemory,
|
|
@@ -110,9 +127,9 @@ import {
|
|
|
110
127
|
rollbackMemory,
|
|
111
128
|
safeIngestMemoryById,
|
|
112
129
|
statusFromConfidence
|
|
113
|
-
} from "./chunk-
|
|
114
|
-
import "./chunk-
|
|
115
|
-
import "./chunk-
|
|
130
|
+
} from "./chunk-XOKSI4EY.js";
|
|
131
|
+
import "./chunk-YFK2AD34.js";
|
|
132
|
+
import "./chunk-SYYBKTWO.js";
|
|
116
133
|
import {
|
|
117
134
|
bootstrapEmbeddings,
|
|
118
135
|
getEmbeddingModelInfo,
|
|
@@ -120,12 +137,14 @@ import {
|
|
|
120
137
|
loadEmbeddingConfigFromEnv,
|
|
121
138
|
queueMemoryEmbeddingSync,
|
|
122
139
|
rebuildEmbeddingIndexResponsive,
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
rebuildMemoryFtsIndexResponsive,
|
|
141
|
+
verifyEmbeddings,
|
|
142
|
+
verifyMemoryFtsIndex
|
|
143
|
+
} from "./chunk-SHS4CTN3.js";
|
|
125
144
|
import {
|
|
126
145
|
hasProviderConfigured,
|
|
127
146
|
init_keychain
|
|
128
|
-
} from "./chunk-
|
|
147
|
+
} from "./chunk-LGM46TRO.js";
|
|
129
148
|
import {
|
|
130
149
|
clearGraph,
|
|
131
150
|
countEntities,
|
|
@@ -136,7 +155,7 @@ import {
|
|
|
136
155
|
listEntitiesForMemory,
|
|
137
156
|
listMemoryIdsForEntity,
|
|
138
157
|
neighborsOf
|
|
139
|
-
} from "./chunk-
|
|
158
|
+
} from "./chunk-VNKQBRLB.js";
|
|
140
159
|
import {
|
|
141
160
|
activityEvents,
|
|
142
161
|
eq,
|
|
@@ -146,11 +165,11 @@ import {
|
|
|
146
165
|
implicitSignals,
|
|
147
166
|
lt,
|
|
148
167
|
memories
|
|
149
|
-
} from "./chunk-
|
|
168
|
+
} from "./chunk-OIIAMDOT.js";
|
|
150
169
|
import {
|
|
151
170
|
define_RECALL_BUILD_INFO_default,
|
|
152
171
|
init_define_RECALL_BUILD_INFO
|
|
153
|
-
} from "./chunk-
|
|
172
|
+
} from "./chunk-PVEH3GEI.js";
|
|
154
173
|
|
|
155
174
|
// src/daemon.ts
|
|
156
175
|
init_define_RECALL_BUILD_INFO();
|
|
@@ -194,12 +213,1032 @@ function emit(name, payload) {
|
|
|
194
213
|
|
|
195
214
|
// src/daemon.ts
|
|
196
215
|
import { homedir } from "os";
|
|
197
|
-
import { join as join3 } from "path";
|
|
198
216
|
|
|
199
|
-
// src/
|
|
217
|
+
// src/cloud/service.ts
|
|
218
|
+
init_define_RECALL_BUILD_INFO();
|
|
219
|
+
import { hostname as hostname2 } from "os";
|
|
220
|
+
import { isAbsolute as isAbsolute2, relative } from "path";
|
|
221
|
+
|
|
222
|
+
// src/cloud/engine.ts
|
|
200
223
|
init_define_RECALL_BUILD_INFO();
|
|
201
|
-
import { existsSync
|
|
224
|
+
import { existsSync } from "fs";
|
|
202
225
|
import { dirname, join } from "path";
|
|
226
|
+
import { fileURLToPath } from "url";
|
|
227
|
+
var ENGINE_DIR = join("vendor", "recall-cloud-sync");
|
|
228
|
+
function resolveEngineFiles(fromUrl = import.meta.url) {
|
|
229
|
+
const here = dirname(fileURLToPath(fromUrl));
|
|
230
|
+
for (const up of ["..", join("..", "..")]) {
|
|
231
|
+
const dir = join(here, up, ENGINE_DIR);
|
|
232
|
+
const engine = join(dir, "recall-sync.mjs");
|
|
233
|
+
const wrapper = join(dir, "managed-worker.mjs");
|
|
234
|
+
if (existsSync(engine) && existsSync(wrapper)) return { engine, wrapper };
|
|
235
|
+
}
|
|
236
|
+
throw new CloudError("The Recall Cloud sync engine is not bundled with this install", "engine-missing", 500);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/cloud/legacy.ts
|
|
240
|
+
init_define_RECALL_BUILD_INFO();
|
|
241
|
+
import { spawnSync } from "child_process";
|
|
242
|
+
import { chmodSync, copyFileSync, lstatSync, renameSync, rmSync } from "fs";
|
|
243
|
+
import { hostname } from "os";
|
|
244
|
+
import { basename, isAbsolute, join as join2, resolve } from "path";
|
|
245
|
+
var VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
246
|
+
"api",
|
|
247
|
+
"token-file",
|
|
248
|
+
"interval",
|
|
249
|
+
"device-id",
|
|
250
|
+
"db",
|
|
251
|
+
"device-alias",
|
|
252
|
+
"state-file",
|
|
253
|
+
"status",
|
|
254
|
+
"full-reconcile-interval",
|
|
255
|
+
"limit",
|
|
256
|
+
"rejected-retention-days"
|
|
257
|
+
]);
|
|
258
|
+
var KNOWN_ENV = /* @__PURE__ */ new Set([
|
|
259
|
+
"RECALL_CLOUD_API",
|
|
260
|
+
"RECALL_CLOUD_DEVICE_ID",
|
|
261
|
+
"RECALL_CLOUD_E2EE_PASSPHRASE",
|
|
262
|
+
"RECALL_CLOUD_TOKEN",
|
|
263
|
+
"RECALL_DB",
|
|
264
|
+
"RECALL_REJECTED_RETENTION_DAYS"
|
|
265
|
+
]);
|
|
266
|
+
function unsupported(message) {
|
|
267
|
+
return new CloudError(message, "legacy-unsupported", 409);
|
|
268
|
+
}
|
|
269
|
+
function expandHome(value, home) {
|
|
270
|
+
if (value === "~") return home;
|
|
271
|
+
if (value.startsWith("~/")) return join2(home, value.slice(2));
|
|
272
|
+
return value;
|
|
273
|
+
}
|
|
274
|
+
function parseInt10(value, min, label) {
|
|
275
|
+
if (!/^\d{1,9}$/.test(value) || Number(value) < min) {
|
|
276
|
+
throw unsupported(`The existing sync job has an invalid ${label}, so it was left unchanged`);
|
|
277
|
+
}
|
|
278
|
+
return Number(value);
|
|
279
|
+
}
|
|
280
|
+
function parseAliases(values) {
|
|
281
|
+
const aliases = {};
|
|
282
|
+
for (const entry of values) {
|
|
283
|
+
const at = entry.indexOf("=");
|
|
284
|
+
const from = at > 0 ? entry.slice(0, at).trim() : "";
|
|
285
|
+
const to = at > 0 ? entry.slice(at + 1).trim() : "";
|
|
286
|
+
if (!from || !to || from.includes(":") || to.includes(":")) {
|
|
287
|
+
throw unsupported("The existing sync job has an invalid device alias, so it was left unchanged");
|
|
288
|
+
}
|
|
289
|
+
aliases[from] = to;
|
|
290
|
+
}
|
|
291
|
+
return aliases;
|
|
292
|
+
}
|
|
293
|
+
function parseLegacyPlist(plist, paths, osHostname = hostname) {
|
|
294
|
+
const root = plist && typeof plist === "object" ? plist : {};
|
|
295
|
+
if (root.Label !== LEGACY_LAUNCHD_LABEL) {
|
|
296
|
+
throw unsupported("The existing sync job does not have the standard Recall Cloud Sync label, so it was left unchanged");
|
|
297
|
+
}
|
|
298
|
+
const argv = Array.isArray(root.ProgramArguments) && root.ProgramArguments.every((v) => typeof v === "string") ? root.ProgramArguments : null;
|
|
299
|
+
if (!argv || argv.length < 3 || basename(argv[1]) !== "recall-sync.mjs" || argv[2] !== "watch") {
|
|
300
|
+
throw unsupported("The existing sync job is not a standard Recall Cloud watch job, so it was left unchanged");
|
|
301
|
+
}
|
|
302
|
+
const flags = /* @__PURE__ */ new Map();
|
|
303
|
+
let e2ee = false;
|
|
304
|
+
for (let i = 3; i < argv.length; i++) {
|
|
305
|
+
const arg = argv[i];
|
|
306
|
+
const name = arg.startsWith("--") ? arg.slice(2) : "";
|
|
307
|
+
const label = /^[a-z0-9-]{1,40}$/.test(name) ? `--${name}` : "an unknown argument";
|
|
308
|
+
if (name === "e2ee") {
|
|
309
|
+
e2ee = true;
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (!VALUE_FLAGS.has(name)) {
|
|
313
|
+
throw unsupported(`The existing sync job uses an option Recall cannot migrate safely (${label}), so it was left unchanged`);
|
|
314
|
+
}
|
|
315
|
+
const value = argv[i + 1];
|
|
316
|
+
if (value === void 0 || value.startsWith("--")) {
|
|
317
|
+
throw unsupported(`The existing sync job is missing a value for ${label}, so it was left unchanged`);
|
|
318
|
+
}
|
|
319
|
+
const existing = flags.get(name) ?? [];
|
|
320
|
+
if (existing.length > 0 && name !== "device-alias") {
|
|
321
|
+
throw unsupported(`The existing sync job repeats ${label}, so it was left unchanged`);
|
|
322
|
+
}
|
|
323
|
+
flags.set(name, [...existing, value]);
|
|
324
|
+
i++;
|
|
325
|
+
}
|
|
326
|
+
const env = {};
|
|
327
|
+
if (root.EnvironmentVariables && typeof root.EnvironmentVariables === "object") {
|
|
328
|
+
for (const [key, value] of Object.entries(root.EnvironmentVariables)) {
|
|
329
|
+
if (typeof value !== "string") continue;
|
|
330
|
+
if ((key.startsWith("RECALL_CLOUD_") || key.startsWith("RECALL_")) && !KNOWN_ENV.has(key)) {
|
|
331
|
+
throw unsupported("The existing sync job sets an environment option Recall cannot migrate safely, so it was left unchanged");
|
|
332
|
+
}
|
|
333
|
+
env[key] = value;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const first = (name) => flags.get(name)?.[0];
|
|
337
|
+
const home = paths.home;
|
|
338
|
+
const legacyHome = env.HOME;
|
|
339
|
+
const homeDiffers = legacyHome !== void 0 && resolve(legacyHome) !== resolve(home);
|
|
340
|
+
const absolutePath = (value, fallback2, label) => {
|
|
341
|
+
const raw = value ?? fallback2;
|
|
342
|
+
const usesHome = value === void 0 || value === "~" || value.startsWith("~/");
|
|
343
|
+
if (usesHome && homeDiffers) {
|
|
344
|
+
throw unsupported(`The existing sync job runs with a different HOME, so its ${label} cannot be moved safely and it was left unchanged`);
|
|
345
|
+
}
|
|
346
|
+
const expanded = expandHome(raw, home);
|
|
347
|
+
if (!isAbsolute(expanded)) {
|
|
348
|
+
throw unsupported(`The existing sync job uses a relative ${label}, so it was left unchanged`);
|
|
349
|
+
}
|
|
350
|
+
return resolve(expanded);
|
|
351
|
+
};
|
|
352
|
+
const apiValue = first("api") ?? env.RECALL_CLOUD_API;
|
|
353
|
+
const tokenFile = first("token-file");
|
|
354
|
+
if (!apiValue) throw unsupported("The existing sync job has no API address, so it was left unchanged");
|
|
355
|
+
if (!tokenFile) {
|
|
356
|
+
throw unsupported("The existing sync job does not use a token file. Use Connect with a fresh token instead.");
|
|
357
|
+
}
|
|
358
|
+
let passphrase = null;
|
|
359
|
+
if (e2ee) {
|
|
360
|
+
passphrase = env.RECALL_CLOUD_E2EE_PASSPHRASE ?? null;
|
|
361
|
+
if (!passphrase) {
|
|
362
|
+
throw new CloudError(
|
|
363
|
+
"The existing sync job uses end-to-end encryption but its passphrase is not recoverable. Nothing was changed; reconnect with your passphrase instead.",
|
|
364
|
+
"encryption-required",
|
|
365
|
+
409
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const retention = first("rejected-retention-days") ?? env.RECALL_REJECTED_RETENTION_DAYS;
|
|
370
|
+
return {
|
|
371
|
+
api: validateApi(apiValue),
|
|
372
|
+
tokenFile: absolutePath(tokenFile, tokenFile, "token file"),
|
|
373
|
+
intervalSeconds: first("interval") ? parseInt10(first("interval"), 1, "interval") : 300,
|
|
374
|
+
deviceId: first("device-id") ?? env.RECALL_CLOUD_DEVICE_ID ?? env.HOSTNAME ?? osHostname(),
|
|
375
|
+
deviceAliases: parseAliases(flags.get("device-alias") ?? []),
|
|
376
|
+
dbPath: absolutePath(first("db") ?? env.RECALL_DB, join2(home, ".recall", "recall.db"), "database path"),
|
|
377
|
+
stateFile: absolutePath(first("state-file"), join2(home, ".config", "recall-cloud", "sync-state.json"), "sync state file"),
|
|
378
|
+
fullReconcileSeconds: first("full-reconcile-interval") ? parseInt10(first("full-reconcile-interval"), 1, "reconcile interval") : null,
|
|
379
|
+
statuses: first("status") ?? null,
|
|
380
|
+
limit: first("limit") ? parseInt10(first("limit"), 1, "limit") : null,
|
|
381
|
+
rejectedRetentionDays: retention != null ? parseInt10(retention, 0, "retention") : null,
|
|
382
|
+
e2ee,
|
|
383
|
+
passphrase
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function defaultLaunchctl(args) {
|
|
387
|
+
const result = spawnSync("launchctl", args, { encoding: "utf8", timeout: 1e4 });
|
|
388
|
+
return { status: result.status, stdout: result.stdout ?? "", stderr: result.stderr ?? "" };
|
|
389
|
+
}
|
|
390
|
+
function defaultReadPlist(plistPath) {
|
|
391
|
+
const stat = lstatSync(plistPath);
|
|
392
|
+
if (!stat.isFile() || stat.isSymbolicLink()) throw unsupported("The existing sync job file is not a regular file");
|
|
393
|
+
const result = spawnSync("/usr/bin/plutil", ["-convert", "json", "-o", "-", plistPath], {
|
|
394
|
+
encoding: "utf8",
|
|
395
|
+
timeout: 1e4,
|
|
396
|
+
maxBuffer: 1024 * 1024
|
|
397
|
+
});
|
|
398
|
+
if (result.status !== 0) throw unsupported("The existing sync job file could not be read");
|
|
399
|
+
return JSON.parse(result.stdout);
|
|
400
|
+
}
|
|
401
|
+
var LegacyLaunchd = class {
|
|
402
|
+
constructor(deps) {
|
|
403
|
+
this.deps = deps;
|
|
404
|
+
this.platform = deps.platform ?? process.platform;
|
|
405
|
+
this.launchctl = deps.launchctl ?? defaultLaunchctl;
|
|
406
|
+
this.readPlist = deps.readPlist ?? defaultReadPlist;
|
|
407
|
+
this.uid = deps.uid ?? (() => typeof process.getuid === "function" ? process.getuid() : 0);
|
|
408
|
+
this.sleep = deps.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms)));
|
|
409
|
+
this.now = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
410
|
+
}
|
|
411
|
+
deps;
|
|
412
|
+
platform;
|
|
413
|
+
launchctl;
|
|
414
|
+
readPlist;
|
|
415
|
+
uid;
|
|
416
|
+
sleep;
|
|
417
|
+
now;
|
|
418
|
+
get target() {
|
|
419
|
+
return `gui/${this.uid()}/${LEGACY_LAUNCHD_LABEL}`;
|
|
420
|
+
}
|
|
421
|
+
plistExists() {
|
|
422
|
+
if (this.platform !== "darwin") return false;
|
|
423
|
+
try {
|
|
424
|
+
lstatSync(this.deps.paths.legacyPlist);
|
|
425
|
+
return true;
|
|
426
|
+
} catch {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
loadedState() {
|
|
431
|
+
if (this.platform !== "darwin") return "absent";
|
|
432
|
+
const result = this.launchctl(["print", this.target]);
|
|
433
|
+
if (result.status === 0) return "loaded";
|
|
434
|
+
if (result.status === 113 || /could not find service|not found/i.test(`${result.stderr}${result.stdout}`)) return "absent";
|
|
435
|
+
return "unknown";
|
|
436
|
+
}
|
|
437
|
+
readSettings() {
|
|
438
|
+
return parseLegacyPlist(this.readPlist(this.deps.paths.legacyPlist), this.deps.paths);
|
|
439
|
+
}
|
|
440
|
+
/** Boots the old job out, then requires launchd to prove it is gone. Fails closed otherwise. */
|
|
441
|
+
async bootoutAndProve() {
|
|
442
|
+
this.launchctl(["bootout", this.target]);
|
|
443
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
444
|
+
if (this.loadedState() === "absent") return;
|
|
445
|
+
await this.sleep(300);
|
|
446
|
+
}
|
|
447
|
+
throw new CloudError(
|
|
448
|
+
"macOS did not stop the old Recall Cloud Sync item (it may be blocked in Login Items & Extensions). Nothing was started, so there is no duplicate sync. Allow or remove the old item, then try again.",
|
|
449
|
+
"migration-blocked",
|
|
450
|
+
409
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
/** Moves the old plist out of LaunchAgents (kept for rollback) so it cannot relaunch at login. */
|
|
454
|
+
retirePlist() {
|
|
455
|
+
const { legacyPlist, backupDir } = this.deps.paths;
|
|
456
|
+
const stamp = this.now().toISOString().replace(/[:.]/g, "-");
|
|
457
|
+
const backup = join2(backupDir, `${LEGACY_LAUNCHD_LABEL}.plist.${stamp}`);
|
|
458
|
+
try {
|
|
459
|
+
ensurePrivateDir(backupDir);
|
|
460
|
+
try {
|
|
461
|
+
renameSync(legacyPlist, backup);
|
|
462
|
+
} catch {
|
|
463
|
+
copyFileSync(legacyPlist, backup);
|
|
464
|
+
rmSync(legacyPlist, { force: true });
|
|
465
|
+
}
|
|
466
|
+
chmodSync(backup, 384);
|
|
467
|
+
return backup;
|
|
468
|
+
} catch {
|
|
469
|
+
throw new CloudError(
|
|
470
|
+
"The old sync job was stopped but its LaunchAgent file could not be moved aside, so cloud sync was not started.",
|
|
471
|
+
"migration-blocked",
|
|
472
|
+
409
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// src/cloud/state.ts
|
|
479
|
+
init_define_RECALL_BUILD_INFO();
|
|
480
|
+
import { createHash } from "crypto";
|
|
481
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
482
|
+
import { resolve as resolve2 } from "path";
|
|
483
|
+
function engineStateKey(config) {
|
|
484
|
+
return createHash("sha256").update(`${config.api}\0${config.deviceId}\0${resolve2(config.dbPath)}`).digest("hex");
|
|
485
|
+
}
|
|
486
|
+
function requestFullReconcile(config) {
|
|
487
|
+
let state = null;
|
|
488
|
+
try {
|
|
489
|
+
if (!existsSync2(config.stateFile)) return false;
|
|
490
|
+
state = JSON.parse(readFileSync(config.stateFile, "utf8"));
|
|
491
|
+
} catch {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
const entry = state?.entries?.[engineStateKey(config)];
|
|
495
|
+
if (!entry || typeof entry !== "object") return false;
|
|
496
|
+
entry.fullReconciledAt = null;
|
|
497
|
+
try {
|
|
498
|
+
writePrivateFile(config.stateFile, `${JSON.stringify(state, null, 2)}
|
|
499
|
+
`);
|
|
500
|
+
} catch {
|
|
501
|
+
throw new CloudError(
|
|
502
|
+
"Recall could not reset the sync position for the new token, so Connect was not completed. Nothing is syncing.",
|
|
503
|
+
"config-invalid",
|
|
504
|
+
500
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
return true;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/cloud/worker.ts
|
|
511
|
+
init_define_RECALL_BUILD_INFO();
|
|
512
|
+
import { spawn as nodeSpawn } from "child_process";
|
|
513
|
+
function classifyEngineOutput(line) {
|
|
514
|
+
if (/failed (?:401|403)\b/i.test(line)) return "The cloud rejected this device's token";
|
|
515
|
+
if (/failed (?:408|425|429|5\d\d)\b/i.test(line)) return "The cloud is temporarily unavailable";
|
|
516
|
+
if (/failed 409\b/i.test(line) && /encrypted|encryption|private|aliases/i.test(line)) {
|
|
517
|
+
return "Cloud encryption settings conflict. Use private sync with the original passphrase and check device aliases.";
|
|
518
|
+
}
|
|
519
|
+
if (/failed \d{3}\b/i.test(line)) return "A cloud request failed";
|
|
520
|
+
if (/fetch failed|network error|ENOTFOUND|ECONNREFUSED|ETIMEDOUT|aborted|timeout/i.test(line)) return "Network error while syncing";
|
|
521
|
+
if (/database is locked|SQLITE_BUSY/i.test(line)) return "The local database was busy";
|
|
522
|
+
if (/Recall DB not found/i.test(line)) return "The local Recall database was not found";
|
|
523
|
+
if (/e2ee|passphrase/i.test(line)) return "Encryption is not configured correctly";
|
|
524
|
+
if (/credential|token/i.test(line)) return "The sync credentials could not be used";
|
|
525
|
+
if (/sync error/i.test(line)) return "A sync cycle failed";
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
var CloudWorker = class {
|
|
529
|
+
onPull;
|
|
530
|
+
spawnFn;
|
|
531
|
+
startTimeoutMs;
|
|
532
|
+
stopGraceMs;
|
|
533
|
+
stopDeadlineMs;
|
|
534
|
+
backoffMs;
|
|
535
|
+
maxRestarts;
|
|
536
|
+
restartWindowMs;
|
|
537
|
+
log;
|
|
538
|
+
child = null;
|
|
539
|
+
launch = null;
|
|
540
|
+
state = "stopped";
|
|
541
|
+
stopping = false;
|
|
542
|
+
stopFailed = false;
|
|
543
|
+
startedAt = null;
|
|
544
|
+
lastError = null;
|
|
545
|
+
lastSyncAt = null;
|
|
546
|
+
lastExit = null;
|
|
547
|
+
restarts = 0;
|
|
548
|
+
restartTimes = [];
|
|
549
|
+
startTimer = null;
|
|
550
|
+
backoffTimer = null;
|
|
551
|
+
waiters = [];
|
|
552
|
+
buffer = "";
|
|
553
|
+
constructor(options = {}) {
|
|
554
|
+
this.onPull = options.onPull ?? (() => {
|
|
555
|
+
});
|
|
556
|
+
this.spawnFn = options.spawn ?? ((command, args, opts) => nodeSpawn(command, args, opts));
|
|
557
|
+
this.startTimeoutMs = options.startTimeoutMs ?? 2e4;
|
|
558
|
+
this.stopGraceMs = options.stopGraceMs ?? 3e3;
|
|
559
|
+
this.stopDeadlineMs = options.stopDeadlineMs ?? 2e3;
|
|
560
|
+
this.backoffMs = options.backoffMs ?? [2e3, 1e4, 3e4, 6e4];
|
|
561
|
+
this.maxRestarts = options.maxRestarts ?? 5;
|
|
562
|
+
this.restartWindowMs = options.restartWindowMs ?? 10 * 6e4;
|
|
563
|
+
this.log = options.log ?? (() => {
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
start(launch) {
|
|
567
|
+
if (this.child && this.stopFailed) {
|
|
568
|
+
throw new Error("The previous sync engine has not exited yet");
|
|
569
|
+
}
|
|
570
|
+
if (this.child || this.state === "backoff" || this.state === "starting" || this.state === "running") return;
|
|
571
|
+
this.launch = launch;
|
|
572
|
+
this.stopping = false;
|
|
573
|
+
this.restarts = 0;
|
|
574
|
+
this.restartTimes = [];
|
|
575
|
+
this.lastError = null;
|
|
576
|
+
this.lastSyncAt = null;
|
|
577
|
+
this.spawnChild();
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Resolves only after the child has been observed to exit. If it does not exit
|
|
581
|
+
* within the bounded deadline, the child stays tracked (state "failed"), no
|
|
582
|
+
* replacement can start, and the promise rejects so callers do not report a
|
|
583
|
+
* disconnect that has not happened.
|
|
584
|
+
*/
|
|
585
|
+
async stop() {
|
|
586
|
+
this.stopping = true;
|
|
587
|
+
this.clearTimers();
|
|
588
|
+
const child = this.child;
|
|
589
|
+
if (!child) {
|
|
590
|
+
this.state = "stopped";
|
|
591
|
+
this.stopFailed = false;
|
|
592
|
+
this.stopping = false;
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
let release = () => {
|
|
596
|
+
};
|
|
597
|
+
const exited = new Promise((resolve4) => {
|
|
598
|
+
release = () => resolve4("exited");
|
|
599
|
+
this.waiters.push(release);
|
|
600
|
+
});
|
|
601
|
+
try {
|
|
602
|
+
if (child.connected) child.send?.({ type: "stop" });
|
|
603
|
+
} catch {
|
|
604
|
+
}
|
|
605
|
+
this.signal(child, "SIGTERM");
|
|
606
|
+
const killTimer = setTimeout(() => this.signal(child, "SIGKILL"), this.stopGraceMs);
|
|
607
|
+
let deadlineTimer;
|
|
608
|
+
const deadline = new Promise((resolve4) => {
|
|
609
|
+
deadlineTimer = setTimeout(() => resolve4("timeout"), this.stopGraceMs + this.stopDeadlineMs);
|
|
610
|
+
});
|
|
611
|
+
const outcome = await Promise.race([exited, deadline]);
|
|
612
|
+
clearTimeout(killTimer);
|
|
613
|
+
clearTimeout(deadlineTimer);
|
|
614
|
+
if (outcome === "timeout") {
|
|
615
|
+
this.waiters = this.waiters.filter((waiter) => waiter !== release);
|
|
616
|
+
this.state = "failed";
|
|
617
|
+
this.stopFailed = true;
|
|
618
|
+
this.lastError = "The sync engine did not stop";
|
|
619
|
+
throw new Error("The sync engine did not stop");
|
|
620
|
+
}
|
|
621
|
+
this.stopFailed = false;
|
|
622
|
+
this.stopping = false;
|
|
623
|
+
}
|
|
624
|
+
signal(child, signal) {
|
|
625
|
+
try {
|
|
626
|
+
child.kill(signal);
|
|
627
|
+
} catch {
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
/** Synchronous last resort for process 'exit' handlers. */
|
|
631
|
+
killSync() {
|
|
632
|
+
this.stopping = true;
|
|
633
|
+
this.clearTimers();
|
|
634
|
+
try {
|
|
635
|
+
this.child?.kill("SIGKILL");
|
|
636
|
+
} catch {
|
|
637
|
+
}
|
|
638
|
+
this.child = null;
|
|
639
|
+
this.state = "stopped";
|
|
640
|
+
}
|
|
641
|
+
status() {
|
|
642
|
+
return {
|
|
643
|
+
state: this.state,
|
|
644
|
+
pid: this.child?.pid ?? null,
|
|
645
|
+
startedAt: this.startedAt,
|
|
646
|
+
restarts: this.restarts,
|
|
647
|
+
lastError: this.lastError,
|
|
648
|
+
lastSyncAt: this.lastSyncAt,
|
|
649
|
+
lastExit: this.lastExit
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
spawnChild() {
|
|
653
|
+
const launch = this.launch;
|
|
654
|
+
if (!launch) return;
|
|
655
|
+
let child;
|
|
656
|
+
try {
|
|
657
|
+
child = this.spawnFn(launch.command, launch.args, {
|
|
658
|
+
env: launch.env,
|
|
659
|
+
stdio: ["ignore", "pipe", "pipe", "ipc"],
|
|
660
|
+
windowsHide: true
|
|
661
|
+
});
|
|
662
|
+
} catch {
|
|
663
|
+
this.lastError = "The sync engine could not be started";
|
|
664
|
+
this.scheduleRestart();
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
this.child = child;
|
|
668
|
+
this.state = "starting";
|
|
669
|
+
this.startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
670
|
+
this.buffer = "";
|
|
671
|
+
child.stdout?.on("data", (chunk) => this.onOutput(chunk));
|
|
672
|
+
child.stderr?.on("data", (chunk) => this.onOutput(chunk));
|
|
673
|
+
child.on("error", () => {
|
|
674
|
+
this.lastError = "The sync engine could not be started";
|
|
675
|
+
if (child.pid === void 0) this.handleExit(child, null, null);
|
|
676
|
+
});
|
|
677
|
+
child.on("exit", (code, signal) => this.handleExit(child, code, signal));
|
|
678
|
+
this.startTimer = setTimeout(() => {
|
|
679
|
+
if (this.child === child && this.state === "starting") {
|
|
680
|
+
this.lastError = "The sync engine did not start in time";
|
|
681
|
+
child.kill("SIGKILL");
|
|
682
|
+
}
|
|
683
|
+
}, this.startTimeoutMs);
|
|
684
|
+
}
|
|
685
|
+
onOutput(chunk) {
|
|
686
|
+
this.buffer += chunk.toString("utf8");
|
|
687
|
+
const lines = this.buffer.split("\n");
|
|
688
|
+
this.buffer = (lines.pop() ?? "").slice(-4096);
|
|
689
|
+
for (const line of lines) {
|
|
690
|
+
if (line.includes("watch started")) {
|
|
691
|
+
if (this.state === "starting") this.state = "running";
|
|
692
|
+
if (this.startTimer) clearTimeout(this.startTimer);
|
|
693
|
+
this.startTimer = null;
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
if (/\bpull ok fetched=/.test(line)) {
|
|
697
|
+
this.lastSyncAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
698
|
+
this.lastError = null;
|
|
699
|
+
this.onPull();
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
const reason = classifyEngineOutput(line);
|
|
703
|
+
if (reason) this.lastError = reason;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
handleExit(child, code, signal) {
|
|
707
|
+
if (this.child !== child) return;
|
|
708
|
+
this.child = null;
|
|
709
|
+
this.clearTimers();
|
|
710
|
+
this.lastExit = { code, signal: signal ?? null, at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
711
|
+
if (this.stopping) {
|
|
712
|
+
this.state = "stopped";
|
|
713
|
+
this.stopFailed = false;
|
|
714
|
+
const waiters = this.waiters;
|
|
715
|
+
this.waiters = [];
|
|
716
|
+
for (const resolve4 of waiters) resolve4();
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
this.scheduleRestart();
|
|
720
|
+
}
|
|
721
|
+
scheduleRestart() {
|
|
722
|
+
const now = Date.now();
|
|
723
|
+
this.restartTimes = [...this.restartTimes.filter((t) => now - t < this.restartWindowMs), now];
|
|
724
|
+
if (this.restartTimes.length > this.maxRestarts) {
|
|
725
|
+
this.state = "failed";
|
|
726
|
+
this.lastError = this.lastError ?? "The sync engine keeps stopping";
|
|
727
|
+
this.log("[recall-cloud] sync engine stopped repeatedly; giving up until reconnected");
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
this.restarts += 1;
|
|
731
|
+
this.state = "backoff";
|
|
732
|
+
const delay = this.backoffMs[Math.min(this.restarts - 1, this.backoffMs.length - 1)] ?? 6e4;
|
|
733
|
+
this.backoffTimer = setTimeout(() => {
|
|
734
|
+
this.backoffTimer = null;
|
|
735
|
+
if (!this.stopping && !this.child) this.spawnChild();
|
|
736
|
+
}, delay);
|
|
737
|
+
}
|
|
738
|
+
clearTimers() {
|
|
739
|
+
if (this.startTimer) clearTimeout(this.startTimer);
|
|
740
|
+
if (this.backoffTimer) clearTimeout(this.backoffTimer);
|
|
741
|
+
this.startTimer = null;
|
|
742
|
+
this.backoffTimer = null;
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
// src/cloud/service.ts
|
|
747
|
+
function safeMessage(error) {
|
|
748
|
+
return error instanceof CloudError ? error.message : "Cloud sync could not be started";
|
|
749
|
+
}
|
|
750
|
+
function isInside(directory, file) {
|
|
751
|
+
const rel = relative(directory, file);
|
|
752
|
+
return rel !== "" && !rel.startsWith("..") && !isAbsolute2(rel);
|
|
753
|
+
}
|
|
754
|
+
var CloudService = class {
|
|
755
|
+
paths;
|
|
756
|
+
env;
|
|
757
|
+
worker;
|
|
758
|
+
legacy;
|
|
759
|
+
engineFn;
|
|
760
|
+
nodePath;
|
|
761
|
+
osHostname;
|
|
762
|
+
now;
|
|
763
|
+
log;
|
|
764
|
+
chain = Promise.resolve();
|
|
765
|
+
startError = null;
|
|
766
|
+
constructor(deps = {}) {
|
|
767
|
+
this.env = deps.env ?? process.env;
|
|
768
|
+
this.paths = deps.paths ?? resolveCloudPaths(this.env);
|
|
769
|
+
this.log = deps.log ?? (() => {
|
|
770
|
+
});
|
|
771
|
+
this.worker = deps.worker ?? new CloudWorker({ log: this.log, onPull: () => {
|
|
772
|
+
try {
|
|
773
|
+
const config = loadCloudConfig(this.paths);
|
|
774
|
+
if (config?.enabled) deps.onPull?.(config.dbPath);
|
|
775
|
+
} catch {
|
|
776
|
+
this.log("[recall-cloud] local index notification failed");
|
|
777
|
+
}
|
|
778
|
+
} });
|
|
779
|
+
this.legacy = deps.legacy ?? new LegacyLaunchd({ paths: this.paths });
|
|
780
|
+
this.engineFn = deps.engine ?? (() => resolveEngineFiles());
|
|
781
|
+
this.nodePath = deps.nodePath ?? process.execPath;
|
|
782
|
+
this.osHostname = deps.osHostname ?? hostname2;
|
|
783
|
+
this.now = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
784
|
+
}
|
|
785
|
+
/** The Mac App Store edition never syncs to the cloud. */
|
|
786
|
+
available() {
|
|
787
|
+
return this.env.RECALL_DISTRIBUTION !== "mac-app-store";
|
|
788
|
+
}
|
|
789
|
+
status() {
|
|
790
|
+
const available = this.available();
|
|
791
|
+
let config = null;
|
|
792
|
+
let error = null;
|
|
793
|
+
if (available) {
|
|
794
|
+
try {
|
|
795
|
+
config = loadCloudConfig(this.paths);
|
|
796
|
+
} catch (e) {
|
|
797
|
+
error = safeMessage(e);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
const worker = this.worker.status();
|
|
801
|
+
const detected = available && this.legacy.plistExists();
|
|
802
|
+
const loadedState = detected ? this.legacy.loadedState() : "absent";
|
|
803
|
+
const loaded = loadedState === "loaded";
|
|
804
|
+
const unknown = loadedState === "unknown";
|
|
805
|
+
let state;
|
|
806
|
+
if (!available) state = "unavailable";
|
|
807
|
+
else if (error) state = "failed";
|
|
808
|
+
else if (config?.migrationPending) state = "migration-pending";
|
|
809
|
+
else if (!config || !config.enabled) state = "disconnected";
|
|
810
|
+
else if (worker.state === "failed" || worker.state === "stopped" && this.startError) state = "failed";
|
|
811
|
+
else state = worker.state;
|
|
812
|
+
if (state === "failed" && !error) error = this.startError ?? worker.lastError;
|
|
813
|
+
else if (state === "backoff" || state === "running" || state === "starting") error = worker.lastError;
|
|
814
|
+
return {
|
|
815
|
+
available,
|
|
816
|
+
state,
|
|
817
|
+
enabled: Boolean(config?.enabled),
|
|
818
|
+
worker: { pid: worker.pid, startedAt: worker.startedAt, restarts: worker.restarts, lastExit: worker.lastExit, lastSyncAt: worker.lastSyncAt },
|
|
819
|
+
config: config ? {
|
|
820
|
+
api: config.api,
|
|
821
|
+
deviceId: config.deviceId,
|
|
822
|
+
intervalSeconds: config.intervalSeconds,
|
|
823
|
+
e2ee: config.e2ee,
|
|
824
|
+
migratedFrom: config.migratedFrom,
|
|
825
|
+
optInAt: config.optInAt,
|
|
826
|
+
queryEnrichment: isCloudQueryEnabled(config, this.env)
|
|
827
|
+
} : null,
|
|
828
|
+
legacy: { detected, loaded, unknown, canMigrate: available && detected && !config?.enabled },
|
|
829
|
+
error
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
setQueryEnrichment(enabled) {
|
|
833
|
+
return this.exclusive(async () => {
|
|
834
|
+
if (typeof enabled !== "boolean") throw new CloudError("Online retrieval enabled must be a boolean", "invalid");
|
|
835
|
+
setCloudQueryEnabled(enabled, this.env, this.paths);
|
|
836
|
+
return this.status();
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
/** Called once when the daemon is listening. No config, or disabled, means a no-op. */
|
|
840
|
+
startIfEnabled() {
|
|
841
|
+
return this.exclusive(async () => {
|
|
842
|
+
if (!this.available()) return;
|
|
843
|
+
let config;
|
|
844
|
+
try {
|
|
845
|
+
config = loadCloudConfig(this.paths);
|
|
846
|
+
} catch (e) {
|
|
847
|
+
this.startError = safeMessage(e);
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
if (!config || !config.enabled) return;
|
|
851
|
+
this.launchSafely(config);
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
connect(input) {
|
|
855
|
+
return this.exclusive(async () => {
|
|
856
|
+
this.assertAvailable();
|
|
857
|
+
if (input.optIn !== true) {
|
|
858
|
+
throw new CloudError("Confirm that you want to sync this Mac to Recall Cloud first", "opt-in-required");
|
|
859
|
+
}
|
|
860
|
+
const engine = this.engineFn();
|
|
861
|
+
void engine;
|
|
862
|
+
const token = normalizeSecret(String(input.token ?? "").trim(), "token");
|
|
863
|
+
const typedPassphrase = input.e2eePassphrase == null || input.e2eePassphrase === "" ? null : normalizePassphrase(input.e2eePassphrase);
|
|
864
|
+
const existing = loadCloudConfig(this.paths);
|
|
865
|
+
this.assertNoLegacy();
|
|
866
|
+
if (input.privacyMode !== void 0 && input.privacyMode !== "private" && input.privacyMode !== "searchable") {
|
|
867
|
+
throw new CloudError("Choose private sync or Cloud-assisted search", "invalid");
|
|
868
|
+
}
|
|
869
|
+
if (input.privacyMode === "searchable" && (typedPassphrase || existing?.e2ee)) {
|
|
870
|
+
throw new CloudError("An encrypted device cannot switch to server-readable sync. Keep private sync and use the original passphrase.", "encryption-required", 409);
|
|
871
|
+
}
|
|
872
|
+
let passphrase = typedPassphrase;
|
|
873
|
+
if (!passphrase && existing?.e2ee) {
|
|
874
|
+
try {
|
|
875
|
+
passphrase = existing.passphraseFile ? readPrivatePassphrase(existing.passphraseFile) : null;
|
|
876
|
+
} catch {
|
|
877
|
+
passphrase = null;
|
|
878
|
+
}
|
|
879
|
+
if (!passphrase) {
|
|
880
|
+
throw new CloudError(
|
|
881
|
+
"This Mac previously used end-to-end encryption. Enter the same passphrase to reconnect; Recall will not sync unencrypted.",
|
|
882
|
+
"encryption-required",
|
|
883
|
+
409
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
if (input.privacyMode === "private" && !passphrase) {
|
|
888
|
+
throw new CloudError("Private sync requires a saved passphrase. Use the same one on every device.", "encryption-required", 409);
|
|
889
|
+
}
|
|
890
|
+
if (typedPassphrase && existing?.e2ee && existing.passphraseFile) {
|
|
891
|
+
let saved = null;
|
|
892
|
+
try {
|
|
893
|
+
saved = readPrivatePassphrase(existing.passphraseFile);
|
|
894
|
+
} catch {
|
|
895
|
+
}
|
|
896
|
+
if (saved && typedPassphrase !== saved) {
|
|
897
|
+
throw new CloudError("Use the original private-sync passphrase. Changing it here would strand encrypted memories.", "encryption-required", 409);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
const api = validateApi(input.api ?? existing?.api ?? DEFAULT_CLOUD_API);
|
|
901
|
+
const deviceId = String(input.deviceId ?? existing?.deviceId ?? this.defaultDeviceId()).trim();
|
|
902
|
+
if (!deviceId || deviceId.includes(":") || deviceId.length > 200) {
|
|
903
|
+
throw new CloudError("Invalid device name", "invalid");
|
|
904
|
+
}
|
|
905
|
+
await this.stopWorker();
|
|
906
|
+
if (existing?.enabled) saveCloudConfig(this.paths, { ...existing, enabled: false });
|
|
907
|
+
ensurePrivateDir(this.paths.cloudDir);
|
|
908
|
+
writePrivateFile(this.paths.tokenFile, token);
|
|
909
|
+
if (passphrase) writePrivateFile(this.paths.passphraseFile, passphrase);
|
|
910
|
+
const config = {
|
|
911
|
+
version: 1,
|
|
912
|
+
enabled: true,
|
|
913
|
+
...existing?.queryEnrichment === void 0 ? {} : {
|
|
914
|
+
queryEnrichment: existing.queryEnrichment
|
|
915
|
+
},
|
|
916
|
+
optInAt: this.now().toISOString(),
|
|
917
|
+
api,
|
|
918
|
+
deviceId,
|
|
919
|
+
deviceAliases: existing?.deviceAliases ?? {},
|
|
920
|
+
intervalSeconds: existing?.intervalSeconds ?? 300,
|
|
921
|
+
fullReconcileSeconds: existing?.fullReconcileSeconds ?? null,
|
|
922
|
+
statuses: existing?.statuses ?? null,
|
|
923
|
+
limit: existing?.limit ?? null,
|
|
924
|
+
rejectedRetentionDays: existing?.rejectedRetentionDays ?? null,
|
|
925
|
+
dbPath: existing?.dbPath ?? this.paths.dbFile,
|
|
926
|
+
stateFile: existing?.stateFile ?? this.paths.stateFile,
|
|
927
|
+
tokenFile: this.paths.tokenFile,
|
|
928
|
+
e2ee: passphrase !== null,
|
|
929
|
+
passphraseFile: passphrase ? this.paths.passphraseFile : null,
|
|
930
|
+
migratedFrom: existing?.migratedFrom ?? null,
|
|
931
|
+
migrationPending: false
|
|
932
|
+
};
|
|
933
|
+
requestFullReconcile(config);
|
|
934
|
+
saveCloudConfig(this.paths, config);
|
|
935
|
+
this.launchSafely(config);
|
|
936
|
+
return this.status();
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
/** Stops the worker first and reports success only once the child has exited. */
|
|
940
|
+
disconnect() {
|
|
941
|
+
return this.exclusive(async () => {
|
|
942
|
+
await this.stopWorker();
|
|
943
|
+
this.startError = null;
|
|
944
|
+
let existing = null;
|
|
945
|
+
try {
|
|
946
|
+
existing = loadCloudConfig(this.paths);
|
|
947
|
+
} catch {
|
|
948
|
+
existing = null;
|
|
949
|
+
}
|
|
950
|
+
if (existing) {
|
|
951
|
+
saveCloudConfig(this.paths, { ...existing, enabled: false, migrationPending: false });
|
|
952
|
+
const { cloudDir } = this.paths;
|
|
953
|
+
if (isInside(cloudDir, existing.tokenFile) && !this.legacy.plistExists()) removeFile(existing.tokenFile);
|
|
954
|
+
if (existing.passphraseFile && isInside(cloudDir, existing.passphraseFile)) removeFile(existing.passphraseFile);
|
|
955
|
+
}
|
|
956
|
+
return this.status();
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Explicit user action only. Stages the new config disabled, stops the legacy
|
|
961
|
+
* job and requires launchd to prove it is gone, retires its plist, and only
|
|
962
|
+
* then enables and starts the in-daemon worker. Any failure leaves the worker off.
|
|
963
|
+
*/
|
|
964
|
+
migrateLegacy(input) {
|
|
965
|
+
return this.exclusive(async () => {
|
|
966
|
+
this.assertAvailable();
|
|
967
|
+
if (input.optIn !== true) {
|
|
968
|
+
throw new CloudError("Confirm that you want to move sync into Recall first", "opt-in-required");
|
|
969
|
+
}
|
|
970
|
+
this.engineFn();
|
|
971
|
+
if (!this.legacy.plistExists()) {
|
|
972
|
+
throw new CloudError("No existing Recall Cloud Sync job was found on this Mac", "legacy-missing", 404);
|
|
973
|
+
}
|
|
974
|
+
await this.stopWorker();
|
|
975
|
+
const legacy = this.legacy.readSettings();
|
|
976
|
+
readPrivateSecret(legacy.tokenFile, "token");
|
|
977
|
+
let passphraseFile = null;
|
|
978
|
+
if (legacy.e2ee && legacy.passphrase) {
|
|
979
|
+
ensurePrivateDir(this.paths.cloudDir);
|
|
980
|
+
writePrivateFile(this.paths.passphraseFile, normalizePassphrase(legacy.passphrase));
|
|
981
|
+
passphraseFile = this.paths.passphraseFile;
|
|
982
|
+
}
|
|
983
|
+
const staged = {
|
|
984
|
+
version: 1,
|
|
985
|
+
enabled: false,
|
|
986
|
+
optInAt: null,
|
|
987
|
+
api: legacy.api,
|
|
988
|
+
deviceId: legacy.deviceId,
|
|
989
|
+
deviceAliases: legacy.deviceAliases,
|
|
990
|
+
intervalSeconds: legacy.intervalSeconds,
|
|
991
|
+
fullReconcileSeconds: legacy.fullReconcileSeconds,
|
|
992
|
+
statuses: legacy.statuses,
|
|
993
|
+
limit: legacy.limit,
|
|
994
|
+
rejectedRetentionDays: legacy.rejectedRetentionDays,
|
|
995
|
+
dbPath: legacy.dbPath,
|
|
996
|
+
stateFile: legacy.stateFile,
|
|
997
|
+
tokenFile: legacy.tokenFile,
|
|
998
|
+
e2ee: legacy.e2ee,
|
|
999
|
+
passphraseFile,
|
|
1000
|
+
migratedFrom: "legacy-launchd",
|
|
1001
|
+
migrationPending: true
|
|
1002
|
+
};
|
|
1003
|
+
saveCloudConfig(this.paths, staged);
|
|
1004
|
+
await this.legacy.bootoutAndProve();
|
|
1005
|
+
this.legacy.retirePlist();
|
|
1006
|
+
const final = { ...staged, enabled: true, optInAt: this.now().toISOString(), migrationPending: false };
|
|
1007
|
+
saveCloudConfig(this.paths, final);
|
|
1008
|
+
this.launchSafely(final);
|
|
1009
|
+
return this.status();
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
async shutdown() {
|
|
1013
|
+
await this.exclusive(async () => {
|
|
1014
|
+
try {
|
|
1015
|
+
await this.worker.stop();
|
|
1016
|
+
} catch {
|
|
1017
|
+
this.worker.killSync();
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
/** Synchronous last resort for the process 'exit' event. */
|
|
1022
|
+
killSync() {
|
|
1023
|
+
this.worker.killSync();
|
|
1024
|
+
}
|
|
1025
|
+
launchSafely(config) {
|
|
1026
|
+
try {
|
|
1027
|
+
this.startError = null;
|
|
1028
|
+
this.launch(config);
|
|
1029
|
+
} catch (e) {
|
|
1030
|
+
this.startError = safeMessage(e);
|
|
1031
|
+
this.log(`[recall-cloud] not started: ${this.startError}`);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
launch(config) {
|
|
1035
|
+
const engine = this.engineFn();
|
|
1036
|
+
this.assertNoLegacy();
|
|
1037
|
+
readPrivateSecret(config.tokenFile, "token");
|
|
1038
|
+
let passphrase = null;
|
|
1039
|
+
if (config.e2ee) {
|
|
1040
|
+
try {
|
|
1041
|
+
passphrase = readPrivatePassphrase(config.passphraseFile ?? "");
|
|
1042
|
+
} catch {
|
|
1043
|
+
throw new CloudError(
|
|
1044
|
+
"End-to-end encryption is on but its passphrase is unavailable, so sync was not started",
|
|
1045
|
+
"encryption-required",
|
|
1046
|
+
409
|
|
1047
|
+
);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
this.worker.start({
|
|
1051
|
+
command: this.nodePath,
|
|
1052
|
+
args: [engine.wrapper, ...buildEngineArgs(config, engine.engine)],
|
|
1053
|
+
env: buildChildEnv(this.env, passphrase)
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
/** Refuses to run beside the old separate job, so uploads can never be duplicated. */
|
|
1057
|
+
assertNoLegacy() {
|
|
1058
|
+
if (this.legacy.plistExists()) {
|
|
1059
|
+
throw new CloudError(
|
|
1060
|
+
"The old Recall Cloud Sync job is still installed. Use Move sync into Recall first.",
|
|
1061
|
+
"legacy-active",
|
|
1062
|
+
409
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1065
|
+
const loaded = this.legacy.loadedState();
|
|
1066
|
+
if (loaded === "loaded") {
|
|
1067
|
+
throw new CloudError(
|
|
1068
|
+
"The old Recall Cloud Sync job is still running. Use Move sync into Recall first.",
|
|
1069
|
+
"legacy-active",
|
|
1070
|
+
409
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
if (loaded === "unknown") {
|
|
1074
|
+
throw new CloudError(
|
|
1075
|
+
"Recall could not confirm that the old Recall Cloud Sync job is stopped, so sync was not started. Try again.",
|
|
1076
|
+
"legacy-active",
|
|
1077
|
+
409
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
assertAvailable() {
|
|
1082
|
+
if (!this.available()) {
|
|
1083
|
+
throw new CloudError("Recall Cloud sync is not available in this edition", "unavailable", 403);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
async stopWorker() {
|
|
1087
|
+
try {
|
|
1088
|
+
await this.worker.stop();
|
|
1089
|
+
} catch {
|
|
1090
|
+
throw new CloudError("The sync process did not stop. Nothing was changed; try again.", "unavailable", 503);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
defaultDeviceId() {
|
|
1094
|
+
return this.env.RECALL_CLOUD_DEVICE_ID ?? this.env.HOSTNAME ?? this.osHostname() ?? "local-device";
|
|
1095
|
+
}
|
|
1096
|
+
exclusive(fn) {
|
|
1097
|
+
const run = this.chain.then(fn, fn);
|
|
1098
|
+
this.chain = run.catch(() => void 0);
|
|
1099
|
+
return run;
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
// src/cloud/local-index.ts
|
|
1104
|
+
init_define_RECALL_BUILD_INFO();
|
|
1105
|
+
import { realpathSync } from "fs";
|
|
1106
|
+
|
|
1107
|
+
// src/embeddings/index-lock.ts
|
|
1108
|
+
init_define_RECALL_BUILD_INFO();
|
|
1109
|
+
var tails = /* @__PURE__ */ new WeakMap();
|
|
1110
|
+
async function withMemoryIndexLock(db2, operation) {
|
|
1111
|
+
const prior = tails.get(db2.$client) ?? Promise.resolve();
|
|
1112
|
+
let release;
|
|
1113
|
+
const current = new Promise((resolve4) => {
|
|
1114
|
+
release = resolve4;
|
|
1115
|
+
});
|
|
1116
|
+
tails.set(db2.$client, current);
|
|
1117
|
+
await prior;
|
|
1118
|
+
try {
|
|
1119
|
+
return await operation();
|
|
1120
|
+
} finally {
|
|
1121
|
+
release();
|
|
1122
|
+
if (tails.get(db2.$client) === current) tails.delete(db2.$client);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// src/cloud/local-index.ts
|
|
1127
|
+
function createCloudIndexRefresher(db2, onError = () => {
|
|
1128
|
+
}) {
|
|
1129
|
+
let pending = false;
|
|
1130
|
+
let running = null;
|
|
1131
|
+
return (dbPath) => {
|
|
1132
|
+
try {
|
|
1133
|
+
if (realpathSync(dbPath) !== realpathSync(db2.$client.name)) return Promise.resolve();
|
|
1134
|
+
} catch {
|
|
1135
|
+
return Promise.resolve();
|
|
1136
|
+
}
|
|
1137
|
+
pending = true;
|
|
1138
|
+
if (running) return running;
|
|
1139
|
+
running = (async () => {
|
|
1140
|
+
await new Promise((resolve4) => setImmediate(resolve4));
|
|
1141
|
+
do {
|
|
1142
|
+
pending = false;
|
|
1143
|
+
await withMemoryIndexLock(db2, async () => {
|
|
1144
|
+
if (verifyMemoryFtsIndex(db2).drift !== 0) await rebuildMemoryFtsIndexResponsive(db2);
|
|
1145
|
+
const config = loadEmbeddingConfigFromEnv();
|
|
1146
|
+
if (!config) return;
|
|
1147
|
+
const state = verifyEmbeddings(db2, config);
|
|
1148
|
+
if (state.stale > 0) await bootstrapEmbeddings(db2, config);
|
|
1149
|
+
else if (state.index_drift !== 0 || state.lexical_drift !== 0) {
|
|
1150
|
+
await rebuildEmbeddingIndexResponsive(db2, config);
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
} while (pending);
|
|
1154
|
+
})().catch(onError).finally(() => {
|
|
1155
|
+
running = null;
|
|
1156
|
+
});
|
|
1157
|
+
return running;
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// src/cloud/routes.ts
|
|
1162
|
+
init_define_RECALL_BUILD_INFO();
|
|
1163
|
+
|
|
1164
|
+
// src/daemon/body.ts
|
|
1165
|
+
init_define_RECALL_BUILD_INFO();
|
|
1166
|
+
var MAX_DAEMON_BODY_BYTES = 1024 * 1024;
|
|
1167
|
+
var JsonBodyError = class extends Error {
|
|
1168
|
+
constructor(message, status) {
|
|
1169
|
+
super(message);
|
|
1170
|
+
this.status = status;
|
|
1171
|
+
this.name = "JsonBodyError";
|
|
1172
|
+
}
|
|
1173
|
+
status;
|
|
1174
|
+
};
|
|
1175
|
+
async function parseJsonBody(req, maxBytes = MAX_DAEMON_BODY_BYTES) {
|
|
1176
|
+
const chunks = [];
|
|
1177
|
+
let total = 0;
|
|
1178
|
+
let tooLarge = false;
|
|
1179
|
+
for await (const chunk of req) {
|
|
1180
|
+
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
1181
|
+
total += bytes.byteLength;
|
|
1182
|
+
if (total > maxBytes) {
|
|
1183
|
+
tooLarge = true;
|
|
1184
|
+
chunks.length = 0;
|
|
1185
|
+
continue;
|
|
1186
|
+
}
|
|
1187
|
+
if (!tooLarge) chunks.push(bytes);
|
|
1188
|
+
}
|
|
1189
|
+
if (tooLarge) {
|
|
1190
|
+
throw new JsonBodyError("request body too large", 413);
|
|
1191
|
+
}
|
|
1192
|
+
if (total === 0) return {};
|
|
1193
|
+
try {
|
|
1194
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
1195
|
+
} catch {
|
|
1196
|
+
throw new JsonBodyError("invalid JSON body", 400);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
// src/cloud/routes.ts
|
|
1201
|
+
var MAX_CLOUD_BODY_BYTES = 16 * 1024;
|
|
1202
|
+
function send(res, status, data) {
|
|
1203
|
+
res.statusCode = status;
|
|
1204
|
+
res.setHeader("Content-Type", "application/json");
|
|
1205
|
+
res.end(JSON.stringify(data));
|
|
1206
|
+
}
|
|
1207
|
+
async function handleCloudRoute(service, req, res, path, method) {
|
|
1208
|
+
if (!path.startsWith("/cloud/")) return false;
|
|
1209
|
+
try {
|
|
1210
|
+
if (path === "/cloud/status" && method === "GET") {
|
|
1211
|
+
send(res, 200, service.status());
|
|
1212
|
+
return true;
|
|
1213
|
+
}
|
|
1214
|
+
if (method !== "POST" || !["/cloud/connect", "/cloud/disconnect", "/cloud/migrate", "/cloud/query"].includes(path)) {
|
|
1215
|
+
return false;
|
|
1216
|
+
}
|
|
1217
|
+
const body = await parseJsonBody(req, MAX_CLOUD_BODY_BYTES);
|
|
1218
|
+
const input = body && typeof body === "object" && !Array.isArray(body) ? body : {};
|
|
1219
|
+
if (path === "/cloud/connect") send(res, 200, await service.connect(input));
|
|
1220
|
+
else if (path === "/cloud/migrate") send(res, 200, await service.migrateLegacy(input));
|
|
1221
|
+
else if (path === "/cloud/query") send(res, 200, await service.setQueryEnrichment(input.enabled));
|
|
1222
|
+
else send(res, 200, await service.disconnect());
|
|
1223
|
+
return true;
|
|
1224
|
+
} catch (error) {
|
|
1225
|
+
if (error instanceof JsonBodyError) throw error;
|
|
1226
|
+
if (error instanceof CloudError) {
|
|
1227
|
+
send(res, error.status, { error: error.message, code: error.code });
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
send(res, 500, { error: "Cloud sync request failed", code: "internal" });
|
|
1231
|
+
return true;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// src/daemon.ts
|
|
1236
|
+
import { join as join5 } from "path";
|
|
1237
|
+
|
|
1238
|
+
// src/graph/reconcile.ts
|
|
1239
|
+
init_define_RECALL_BUILD_INFO();
|
|
1240
|
+
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
1241
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
203
1242
|
var GRAPH_EXTRACTOR_VERSION = 2;
|
|
204
1243
|
function reconcileGraph(db2) {
|
|
205
1244
|
clearGraph(db2);
|
|
@@ -214,7 +1253,7 @@ function reconcileGraph(db2) {
|
|
|
214
1253
|
return { memories: rows.length, entity_touches: entityTouches, relation_touches: relationTouches };
|
|
215
1254
|
}
|
|
216
1255
|
function reconcileGraphIfStale(db2, dataDir) {
|
|
217
|
-
const markerPath =
|
|
1256
|
+
const markerPath = join3(dataDir, ".graph-extractor-version");
|
|
218
1257
|
if (readMarker(markerPath) >= GRAPH_EXTRACTOR_VERSION) return null;
|
|
219
1258
|
const result = reconcileGraph(db2);
|
|
220
1259
|
writeMarker(markerPath, GRAPH_EXTRACTOR_VERSION);
|
|
@@ -222,8 +1261,8 @@ function reconcileGraphIfStale(db2, dataDir) {
|
|
|
222
1261
|
}
|
|
223
1262
|
function readMarker(path) {
|
|
224
1263
|
try {
|
|
225
|
-
if (!
|
|
226
|
-
const parsed = parseInt(
|
|
1264
|
+
if (!existsSync3(path)) return 0;
|
|
1265
|
+
const parsed = parseInt(readFileSync2(path, "utf8").trim(), 10);
|
|
227
1266
|
return Number.isFinite(parsed) ? parsed : 0;
|
|
228
1267
|
} catch {
|
|
229
1268
|
return 0;
|
|
@@ -231,7 +1270,7 @@ function readMarker(path) {
|
|
|
231
1270
|
}
|
|
232
1271
|
function writeMarker(path, version) {
|
|
233
1272
|
try {
|
|
234
|
-
mkdirSync(
|
|
1273
|
+
mkdirSync(dirname2(path), { recursive: true });
|
|
235
1274
|
writeFileSync(path, `${version}
|
|
236
1275
|
`, "utf8");
|
|
237
1276
|
} catch {
|
|
@@ -241,13 +1280,13 @@ function writeMarker(path, version) {
|
|
|
241
1280
|
// src/webui/server.ts
|
|
242
1281
|
init_define_RECALL_BUILD_INFO();
|
|
243
1282
|
import { createServer } from "http";
|
|
244
|
-
import { createReadStream, existsSync as
|
|
245
|
-
import { extname, join as
|
|
246
|
-
import { fileURLToPath } from "url";
|
|
1283
|
+
import { createReadStream, existsSync as existsSync4, readFileSync as readFileSync3, statSync } from "fs";
|
|
1284
|
+
import { extname, join as join4, normalize, resolve as resolve3, sep } from "path";
|
|
1285
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
247
1286
|
|
|
248
1287
|
// src/webui/ws.ts
|
|
249
1288
|
init_define_RECALL_BUILD_INFO();
|
|
250
|
-
import { createHash } from "crypto";
|
|
1289
|
+
import { createHash as createHash2 } from "crypto";
|
|
251
1290
|
var WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
252
1291
|
var clients = /* @__PURE__ */ new Set();
|
|
253
1292
|
var pingTimer = null;
|
|
@@ -266,7 +1305,7 @@ function handleUpgrade(req, socket) {
|
|
|
266
1305
|
socket.destroy();
|
|
267
1306
|
return;
|
|
268
1307
|
}
|
|
269
|
-
const accept =
|
|
1308
|
+
const accept = createHash2("sha1").update(key + WS_GUID).digest("base64");
|
|
270
1309
|
socket.write(
|
|
271
1310
|
[
|
|
272
1311
|
"HTTP/1.1 101 Switching Protocols",
|
|
@@ -405,17 +1444,17 @@ function serializeLifecycle(operation) {
|
|
|
405
1444
|
return result;
|
|
406
1445
|
}
|
|
407
1446
|
function defaultDistDir() {
|
|
408
|
-
const here =
|
|
1447
|
+
const here = fileURLToPath2(new URL(".", import.meta.url));
|
|
409
1448
|
let dir = here;
|
|
410
1449
|
for (let i = 0; i < 8; i++) {
|
|
411
|
-
if (
|
|
412
|
-
return
|
|
1450
|
+
if (existsSync4(join4(dir, "package.json"))) {
|
|
1451
|
+
return join4(dir, "dist", "webui");
|
|
413
1452
|
}
|
|
414
|
-
const parent =
|
|
1453
|
+
const parent = resolve3(dir, "..");
|
|
415
1454
|
if (parent === dir) break;
|
|
416
1455
|
dir = parent;
|
|
417
1456
|
}
|
|
418
|
-
return
|
|
1457
|
+
return join4(here, "..", "..", "dist", "webui");
|
|
419
1458
|
}
|
|
420
1459
|
function getStatus() {
|
|
421
1460
|
if (!active) {
|
|
@@ -427,7 +1466,7 @@ function getStatus() {
|
|
|
427
1466
|
url: null,
|
|
428
1467
|
client_count: 0,
|
|
429
1468
|
dist_dir: distDir,
|
|
430
|
-
dist_exists:
|
|
1469
|
+
dist_exists: existsSync4(distDir),
|
|
431
1470
|
started_at: null
|
|
432
1471
|
};
|
|
433
1472
|
}
|
|
@@ -438,7 +1477,7 @@ function getStatus() {
|
|
|
438
1477
|
url: `http://${active.host}:${active.port}`,
|
|
439
1478
|
client_count: clientCount(),
|
|
440
1479
|
dist_dir: active.distDir,
|
|
441
|
-
dist_exists:
|
|
1480
|
+
dist_exists: existsSync4(active.distDir),
|
|
442
1481
|
started_at: active.startedAt
|
|
443
1482
|
};
|
|
444
1483
|
}
|
|
@@ -458,11 +1497,11 @@ async function startListener(options) {
|
|
|
458
1497
|
socket.destroy();
|
|
459
1498
|
}
|
|
460
1499
|
});
|
|
461
|
-
await new Promise((
|
|
1500
|
+
await new Promise((resolve4, reject) => {
|
|
462
1501
|
server2.once("error", reject);
|
|
463
1502
|
server2.listen(port, host, () => {
|
|
464
1503
|
server2.off("error", reject);
|
|
465
|
-
|
|
1504
|
+
resolve4();
|
|
466
1505
|
});
|
|
467
1506
|
});
|
|
468
1507
|
active = { server: server2, port, host, distDir, startedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -476,8 +1515,8 @@ async function stopListener() {
|
|
|
476
1515
|
const a = active;
|
|
477
1516
|
active = null;
|
|
478
1517
|
shutdown();
|
|
479
|
-
await new Promise((
|
|
480
|
-
a.server.close(() =>
|
|
1518
|
+
await new Promise((resolve4) => {
|
|
1519
|
+
a.server.close(() => resolve4());
|
|
481
1520
|
a.server.closeAllConnections();
|
|
482
1521
|
});
|
|
483
1522
|
return getStatus();
|
|
@@ -511,15 +1550,15 @@ function handleHttp(req, res, distDir) {
|
|
|
511
1550
|
res.end();
|
|
512
1551
|
return;
|
|
513
1552
|
}
|
|
514
|
-
const
|
|
515
|
-
const fullPath = normalize(
|
|
1553
|
+
const relative2 = decoded === "/" ? "index.html" : decoded.replace(/^\/+/, "");
|
|
1554
|
+
const fullPath = normalize(join4(distDir, relative2));
|
|
516
1555
|
if (!fullPath.startsWith(distDir + sep) && fullPath !== distDir) {
|
|
517
1556
|
res.statusCode = 403;
|
|
518
1557
|
res.end();
|
|
519
1558
|
return;
|
|
520
1559
|
}
|
|
521
1560
|
if (!isReadableFileCandidate(fullPath)) {
|
|
522
|
-
const indexPath =
|
|
1561
|
+
const indexPath = join4(distDir, "index.html");
|
|
523
1562
|
if (isReadableFileCandidate(indexPath)) {
|
|
524
1563
|
serveFile(res, indexPath, req.method === "HEAD");
|
|
525
1564
|
} else {
|
|
@@ -557,7 +1596,7 @@ function serveFile(res, file, head = false) {
|
|
|
557
1596
|
const port = Number(process.env.RECALL_PORT);
|
|
558
1597
|
if (Number.isInteger(port) && port > 0 && port <= 65535) {
|
|
559
1598
|
try {
|
|
560
|
-
const html =
|
|
1599
|
+
const html = readFileSync3(file, "utf8");
|
|
561
1600
|
const meta = `<meta name="recall-daemon-url" content="http://127.0.0.1:${port}">`;
|
|
562
1601
|
res.end(html.replace(/<head(?:\s[^>]*)?>/i, (head2) => head2 + meta));
|
|
563
1602
|
} catch {
|
|
@@ -603,7 +1642,7 @@ function escapeHtml(s) {
|
|
|
603
1642
|
|
|
604
1643
|
// src/daemon.ts
|
|
605
1644
|
import { execFile, spawn } from "child_process";
|
|
606
|
-
import { fileURLToPath as
|
|
1645
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
607
1646
|
|
|
608
1647
|
// src/maintenance/lifecycle.ts
|
|
609
1648
|
init_define_RECALL_BUILD_INFO();
|
|
@@ -615,6 +1654,7 @@ function loadMaintenanceConfigFromEnv() {
|
|
|
615
1654
|
interval_seconds: parseInt(process.env.RECALL_MAINTENANCE_INTERVAL_SECONDS ?? "3600", 10),
|
|
616
1655
|
stale_days: parseInt(process.env.RECALL_MAINTENANCE_STALE_DAYS ?? "90", 10),
|
|
617
1656
|
candidate_unconfirmed_days: parseInt(process.env.RECALL_CANDIDATE_UNCONFIRMED_DAYS ?? "30", 10),
|
|
1657
|
+
candidate_max_age_days: parseInt(process.env.RECALL_CANDIDATE_MAX_AGE_DAYS ?? "60", 10),
|
|
618
1658
|
min_health_score: parseFloat(process.env.RECALL_MAINTENANCE_MIN_HEALTH_SCORE ?? "0.2"),
|
|
619
1659
|
activity_retention_days: parseInt(process.env.RECALL_ACTIVITY_RETENTION_DAYS ?? "30", 10),
|
|
620
1660
|
hook_call_retention_days: parseInt(process.env.RECALL_HOOK_CALL_RETENTION_DAYS ?? "30", 10),
|
|
@@ -655,6 +1695,7 @@ function loadMaintenanceConfigFromEnv() {
|
|
|
655
1695
|
async function runMaintenanceCycle(db2, config = loadMaintenanceConfigFromEnv()) {
|
|
656
1696
|
const prune = pruneMemories(db2, {
|
|
657
1697
|
candidate_unconfirmed_days: config.candidate_unconfirmed_days,
|
|
1698
|
+
candidate_max_age_days: config.candidate_max_age_days,
|
|
658
1699
|
stale_days: config.stale_days,
|
|
659
1700
|
min_health_score: config.min_health_score,
|
|
660
1701
|
rejected_retention_days: config.rejected_retention_days,
|
|
@@ -681,18 +1722,20 @@ async function runMaintenanceCycle(db2, config = loadMaintenanceConfigFromEnv())
|
|
|
681
1722
|
let history_lexical_drift = 0;
|
|
682
1723
|
const embeddingConfig = loadEmbeddingConfigFromEnv();
|
|
683
1724
|
if (embeddingConfig) {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
1725
|
+
await withMemoryIndexLock(db2, async () => {
|
|
1726
|
+
const verify = verifyEmbeddings(db2, embeddingConfig);
|
|
1727
|
+
embedding_stale = verify.stale;
|
|
1728
|
+
vector_drift = verify.index_drift;
|
|
1729
|
+
lexical_drift = verify.lexical_drift;
|
|
1730
|
+
if (embedding_stale > 0) {
|
|
1731
|
+
embeddings_refreshed = await bootstrapEmbeddings(db2, embeddingConfig);
|
|
1732
|
+
}
|
|
1733
|
+
if (vector_drift !== 0 || lexical_drift !== 0) {
|
|
1734
|
+
const rebuilt = await rebuildEmbeddingIndexResponsive(db2, embeddingConfig);
|
|
1735
|
+
vector_rows_rebuilt = rebuilt.vector_rows;
|
|
1736
|
+
lexical_rows_rebuilt = rebuilt.lexical_rows;
|
|
1737
|
+
}
|
|
1738
|
+
});
|
|
696
1739
|
const historyVerify = verifyHistoryEmbeddings(db2, embeddingConfig);
|
|
697
1740
|
history_vector_drift = historyVerify.index_drift;
|
|
698
1741
|
history_lexical_drift = historyVerify.lexical_drift;
|
|
@@ -1229,42 +2272,6 @@ function deny(res) {
|
|
|
1229
2272
|
res.end(JSON.stringify({ error: "local request required" }));
|
|
1230
2273
|
}
|
|
1231
2274
|
|
|
1232
|
-
// src/daemon/body.ts
|
|
1233
|
-
init_define_RECALL_BUILD_INFO();
|
|
1234
|
-
var MAX_DAEMON_BODY_BYTES = 1024 * 1024;
|
|
1235
|
-
var JsonBodyError = class extends Error {
|
|
1236
|
-
constructor(message, status) {
|
|
1237
|
-
super(message);
|
|
1238
|
-
this.status = status;
|
|
1239
|
-
this.name = "JsonBodyError";
|
|
1240
|
-
}
|
|
1241
|
-
status;
|
|
1242
|
-
};
|
|
1243
|
-
async function parseJsonBody(req, maxBytes = MAX_DAEMON_BODY_BYTES) {
|
|
1244
|
-
const chunks = [];
|
|
1245
|
-
let total = 0;
|
|
1246
|
-
let tooLarge = false;
|
|
1247
|
-
for await (const chunk of req) {
|
|
1248
|
-
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
1249
|
-
total += bytes.byteLength;
|
|
1250
|
-
if (total > maxBytes) {
|
|
1251
|
-
tooLarge = true;
|
|
1252
|
-
chunks.length = 0;
|
|
1253
|
-
continue;
|
|
1254
|
-
}
|
|
1255
|
-
if (!tooLarge) chunks.push(bytes);
|
|
1256
|
-
}
|
|
1257
|
-
if (tooLarge) {
|
|
1258
|
-
throw new JsonBodyError("request body too large", 413);
|
|
1259
|
-
}
|
|
1260
|
-
if (total === 0) return {};
|
|
1261
|
-
try {
|
|
1262
|
-
return JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
1263
|
-
} catch {
|
|
1264
|
-
throw new JsonBodyError("invalid JSON body", 400);
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
2275
|
// src/runtime/build.ts
|
|
1269
2276
|
init_define_RECALL_BUILD_INFO();
|
|
1270
2277
|
var fallback = {
|
|
@@ -1602,10 +2609,10 @@ function scheduleCleanupLoop() {
|
|
|
1602
2609
|
try {
|
|
1603
2610
|
const report = runDeterministicCleanup(db, { dryRun: false });
|
|
1604
2611
|
const c = report.counts;
|
|
1605
|
-
const total = c.dedupe_clusters + c.fragment_rejections + c.repeat_promotions + c.command_suppressions + c.globalizations + c.test_fixture_rejections + c.invalid_scope_rejections + c.generic_scanned_tooling_rejections;
|
|
2612
|
+
const total = c.dedupe_clusters + c.fragment_rejections + c.repeat_promotions + c.command_suppressions + c.globalizations + c.test_fixture_rejections + c.invalid_scope_rejections + c.generic_scanned_tooling_rejections + c.agent_authored_rejections;
|
|
1606
2613
|
if (total > 0) {
|
|
1607
2614
|
console.log(
|
|
1608
|
-
`[recall] cleanup run=${report.run_id.slice(0, 8)} merges=${c.dedupe_clusters}/${c.dedupe_losers} fragments=${c.fragment_rejections} promotions=${c.repeat_promotions} suppress=${c.command_suppressions} globalize=${c.globalizations}/${c.globalize_losers} test_repos=${c.test_fixture_rejections} invalid_scope=${c.invalid_scope_rejections} generic_tooling=${c.generic_scanned_tooling_rejections}`
|
|
2615
|
+
`[recall] cleanup run=${report.run_id.slice(0, 8)} merges=${c.dedupe_clusters}/${c.dedupe_losers} fragments=${c.fragment_rejections} promotions=${c.repeat_promotions} suppress=${c.command_suppressions} globalize=${c.globalizations}/${c.globalize_losers} test_repos=${c.test_fixture_rejections} invalid_scope=${c.invalid_scope_rejections} generic_tooling=${c.generic_scanned_tooling_rejections} agent_authored=${c.agent_authored_rejections}`
|
|
1609
2616
|
);
|
|
1610
2617
|
emit("cleanup.tick", {
|
|
1611
2618
|
run_id: report.run_id,
|
|
@@ -1705,19 +2712,19 @@ function scheduleReliabilityProbeLoop() {
|
|
|
1705
2712
|
timer.unref?.();
|
|
1706
2713
|
}
|
|
1707
2714
|
var lastReliabilityVerdict = null;
|
|
2715
|
+
var reliabilityVerdictNotify = false;
|
|
1708
2716
|
var reliabilityVerdictRunning = false;
|
|
1709
2717
|
function scheduleReliabilityVerdictLoop() {
|
|
1710
2718
|
const config = loadReliabilityVerdictConfigFromEnv();
|
|
1711
2719
|
const dataDir = reliabilityVerdictDataDir();
|
|
1712
2720
|
lastReliabilityVerdict = readReliabilityVerdict(dataDir);
|
|
2721
|
+
reliabilityVerdictNotify = config.enabled && config.notify;
|
|
1713
2722
|
if (!config.enabled) return;
|
|
1714
2723
|
const run = async () => {
|
|
1715
2724
|
if (reliabilityVerdictRunning) return;
|
|
1716
2725
|
reliabilityVerdictRunning = true;
|
|
1717
2726
|
try {
|
|
1718
|
-
lastReliabilityVerdict = await runReliabilityVerdictCycle(db, dataDir
|
|
1719
|
-
notify: config.notify ? notifyMacOS : void 0
|
|
1720
|
-
});
|
|
2727
|
+
lastReliabilityVerdict = await runReliabilityVerdictCycle(db, dataDir);
|
|
1721
2728
|
console.log(
|
|
1722
2729
|
`[recall] reliability verdict overall=${lastReliabilityVerdict.overall} fail_days=${lastReliabilityVerdict.consecutive_fail_days} sustained=${lastReliabilityVerdict.sustained_fail}`
|
|
1723
2730
|
);
|
|
@@ -1732,10 +2739,10 @@ function scheduleReliabilityVerdictLoop() {
|
|
|
1732
2739
|
timer.unref?.();
|
|
1733
2740
|
}
|
|
1734
2741
|
function runReliabilityProbeSubprocess(realEmbeddings) {
|
|
1735
|
-
const cliPath =
|
|
2742
|
+
const cliPath = fileURLToPath3(new URL("./cli.js", import.meta.url));
|
|
1736
2743
|
const args = [cliPath, "reliability", "--probe"];
|
|
1737
2744
|
if (realEmbeddings) args.push("--real-embeddings");
|
|
1738
|
-
return new Promise((
|
|
2745
|
+
return new Promise((resolve4, reject) => {
|
|
1739
2746
|
execFile(process.execPath, args, {
|
|
1740
2747
|
env: process.env,
|
|
1741
2748
|
timeout: 3e5,
|
|
@@ -1750,13 +2757,20 @@ function runReliabilityProbeSubprocess(realEmbeddings) {
|
|
|
1750
2757
|
if (typeof parsed.ok !== "boolean" || typeof parsed.database_integrity !== "boolean") {
|
|
1751
2758
|
throw new Error("missing reliability probe fields");
|
|
1752
2759
|
}
|
|
1753
|
-
|
|
2760
|
+
resolve4(parsed);
|
|
1754
2761
|
} catch {
|
|
1755
2762
|
reject(new Error("Reliability probe process returned invalid JSON"));
|
|
1756
2763
|
}
|
|
1757
2764
|
});
|
|
1758
2765
|
});
|
|
1759
2766
|
}
|
|
2767
|
+
var refreshCloudIndex;
|
|
2768
|
+
var cloudService = new CloudService({
|
|
2769
|
+
log: (message) => console.log(message),
|
|
2770
|
+
onPull: (dbPath) => {
|
|
2771
|
+
void refreshCloudIndex?.(dbPath);
|
|
2772
|
+
}
|
|
2773
|
+
});
|
|
1760
2774
|
var server = createServer2(async (req, res) => {
|
|
1761
2775
|
const url = new URL(req.url ?? "/", `http://localhost:${PORT}`);
|
|
1762
2776
|
const path = url.pathname;
|
|
@@ -1773,38 +2787,39 @@ var server = createServer2(async (req, res) => {
|
|
|
1773
2787
|
}
|
|
1774
2788
|
res.setHeader("Content-Type", "application/json");
|
|
1775
2789
|
if (path === "/health" && method === "GET") {
|
|
1776
|
-
return
|
|
2790
|
+
return send2(res, 200, {
|
|
1777
2791
|
status: "ok",
|
|
1778
2792
|
version: pkg.version,
|
|
1779
2793
|
instance_id: process.env.RECALL_INSTANCE_ID ?? null,
|
|
1780
2794
|
build: recallBuildInfo,
|
|
1781
2795
|
reliability_probe: lastReliabilityProbe,
|
|
1782
2796
|
reliability_verdict: lastReliabilityVerdict,
|
|
2797
|
+
reliability_verdict_notify: reliabilityVerdictNotify,
|
|
1783
2798
|
embeddings: getEmbeddingModelInfo(),
|
|
1784
2799
|
retrieval_mode: loadEmbeddingConfigFromEnv() ? "hybrid" : "lexical",
|
|
1785
2800
|
embedding_unavailable_reason: getEmbeddingUnavailableReason()
|
|
1786
2801
|
});
|
|
1787
2802
|
}
|
|
1788
2803
|
if (path === "/doctor" && method === "GET") {
|
|
1789
|
-
return
|
|
2804
|
+
return send2(res, 200, {
|
|
1790
2805
|
version: pkg.version,
|
|
1791
2806
|
...getDoctorStatusReport()
|
|
1792
2807
|
});
|
|
1793
2808
|
}
|
|
1794
2809
|
if (path === "/update" && method === "GET") {
|
|
1795
2810
|
if (process.env.RECALL_DISTRIBUTION === "mac-app-store") {
|
|
1796
|
-
return
|
|
2811
|
+
return send2(res, 200, {
|
|
1797
2812
|
current_version: pkg.version,
|
|
1798
2813
|
update_available: false,
|
|
1799
2814
|
managed_by: "mac-app-store"
|
|
1800
2815
|
});
|
|
1801
2816
|
}
|
|
1802
|
-
return
|
|
2817
|
+
return send2(res, 200, await releaseChecker.check(pkg.version, url.searchParams.get("refresh") === "1"));
|
|
1803
2818
|
}
|
|
1804
2819
|
if (path === "/store/memory" && method === "POST" && process.env.RECALL_DISTRIBUTION === "mac-app-store") {
|
|
1805
2820
|
const body = await parseBody(req);
|
|
1806
2821
|
if (typeof body.text !== "string" || !body.text.trim() || body.text.length > 8192) {
|
|
1807
|
-
return
|
|
2822
|
+
return send2(res, 400, { error: "A memory must contain 1 to 8192 characters." });
|
|
1808
2823
|
}
|
|
1809
2824
|
const repo = typeof body.repo === "string" && body.repo.trim() ? body.repo.trim() : null;
|
|
1810
2825
|
const id = createMemory(db, {
|
|
@@ -1817,31 +2832,31 @@ var server = createServer2(async (req, res) => {
|
|
|
1817
2832
|
});
|
|
1818
2833
|
safeIngestMemory(id);
|
|
1819
2834
|
emit("memory.created", { memory_id: id, repo, source: "manual" });
|
|
1820
|
-
return
|
|
2835
|
+
return send2(res, 201, { id });
|
|
1821
2836
|
}
|
|
1822
2837
|
if (path.startsWith("/hook/agent/") && method === "POST") {
|
|
1823
2838
|
const segments = path.split("/");
|
|
1824
2839
|
const agent = segments[3];
|
|
1825
2840
|
const event = segments[4];
|
|
1826
2841
|
if (segments.length !== 5 || agent !== "codex" && agent !== "claude-code" || !HTTP_HOOK_EVENTS.includes(event)) {
|
|
1827
|
-
return
|
|
2842
|
+
return send2(res, 400, { error: "unsupported agent or hook event" });
|
|
1828
2843
|
}
|
|
1829
2844
|
const body = await parseBody(req);
|
|
1830
2845
|
try {
|
|
1831
|
-
return
|
|
2846
|
+
return send2(res, 200, await handleAgentHttpHook(
|
|
1832
2847
|
db,
|
|
1833
2848
|
agent,
|
|
1834
2849
|
event,
|
|
1835
2850
|
body
|
|
1836
2851
|
));
|
|
1837
2852
|
} catch (error) {
|
|
1838
|
-
return
|
|
2853
|
+
return send2(res, 400, { error: error instanceof Error ? error.message : "invalid hook" });
|
|
1839
2854
|
}
|
|
1840
2855
|
}
|
|
1841
2856
|
if (path === "/compile" && method === "POST") {
|
|
1842
2857
|
const body = await parseBody(req);
|
|
1843
2858
|
const repo = resolveRepo(body);
|
|
1844
|
-
if (!repo) return
|
|
2859
|
+
if (!repo) return send2(res, 400, { error: "repo or repo_path required" });
|
|
1845
2860
|
const bootstrap = ensureRepoBootstrapped(db, {
|
|
1846
2861
|
repo,
|
|
1847
2862
|
repoPathHint: body.repo_path
|
|
@@ -1892,10 +2907,11 @@ var server = createServer2(async (req, res) => {
|
|
|
1892
2907
|
dropped: result.memories_dropped,
|
|
1893
2908
|
history_included: result.history_included,
|
|
1894
2909
|
token_estimate: result.token_estimate,
|
|
2910
|
+
...result.cloud_enrichment ? { cloud_enrichment: result.cloud_enrichment } : {},
|
|
1895
2911
|
repo_path: bootstrap.repo_path
|
|
1896
2912
|
}
|
|
1897
2913
|
});
|
|
1898
|
-
return
|
|
2914
|
+
return send2(res, 200, {
|
|
1899
2915
|
...result,
|
|
1900
2916
|
repo,
|
|
1901
2917
|
repo_path: bootstrap.repo_path ?? body.repo_path ?? null,
|
|
@@ -1905,7 +2921,7 @@ var server = createServer2(async (req, res) => {
|
|
|
1905
2921
|
if (path === "/session/start" && method === "POST") {
|
|
1906
2922
|
const body = await parseBody(req);
|
|
1907
2923
|
if (!body.session_id) {
|
|
1908
|
-
return
|
|
2924
|
+
return send2(res, 400, { error: "session_id required" });
|
|
1909
2925
|
}
|
|
1910
2926
|
const result = startSessionLifecycle(db, {
|
|
1911
2927
|
session_id: body.session_id,
|
|
@@ -1920,12 +2936,12 @@ var server = createServer2(async (req, res) => {
|
|
|
1920
2936
|
client: body.client ?? null,
|
|
1921
2937
|
repo: body.repo ?? null
|
|
1922
2938
|
});
|
|
1923
|
-
return
|
|
2939
|
+
return send2(res, 200, result);
|
|
1924
2940
|
}
|
|
1925
2941
|
if (path === "/session/event" && method === "POST") {
|
|
1926
2942
|
const body = await parseBody(req);
|
|
1927
2943
|
if (!body.session_id || !body.name) {
|
|
1928
|
-
return
|
|
2944
|
+
return send2(res, 400, { error: "session_id and name required" });
|
|
1929
2945
|
}
|
|
1930
2946
|
const result = recordSessionLifecycleEvent(db, {
|
|
1931
2947
|
session_id: body.session_id,
|
|
@@ -1937,12 +2953,12 @@ var server = createServer2(async (req, res) => {
|
|
|
1937
2953
|
name: body.name,
|
|
1938
2954
|
payload: body.payload ?? {}
|
|
1939
2955
|
});
|
|
1940
|
-
return
|
|
2956
|
+
return send2(res, 200, result);
|
|
1941
2957
|
}
|
|
1942
2958
|
if (path === "/session/end" && method === "POST") {
|
|
1943
2959
|
const body = await parseBody(req);
|
|
1944
2960
|
if (!body.session_id) {
|
|
1945
|
-
return
|
|
2961
|
+
return send2(res, 400, { error: "session_id required" });
|
|
1946
2962
|
}
|
|
1947
2963
|
const result = endSessionLifecycle(db, {
|
|
1948
2964
|
session_id: body.session_id,
|
|
@@ -1957,10 +2973,10 @@ var server = createServer2(async (req, res) => {
|
|
|
1957
2973
|
session_id: body.session_id,
|
|
1958
2974
|
repo: body.repo ?? null
|
|
1959
2975
|
});
|
|
1960
|
-
return
|
|
2976
|
+
return send2(res, 200, result);
|
|
1961
2977
|
}
|
|
1962
2978
|
if (path === "/graph/stats" && method === "GET") {
|
|
1963
|
-
return
|
|
2979
|
+
return send2(res, 200, {
|
|
1964
2980
|
entities: countEntities(db),
|
|
1965
2981
|
relations: countRelations(db)
|
|
1966
2982
|
});
|
|
@@ -1969,7 +2985,7 @@ var server = createServer2(async (req, res) => {
|
|
|
1969
2985
|
const repo = url.searchParams.get("repo") ?? void 0;
|
|
1970
2986
|
const limit = parseInt(url.searchParams.get("limit") ?? "2000", 10);
|
|
1971
2987
|
const rows = listAllRelations(db, { repo, limit });
|
|
1972
|
-
return
|
|
2988
|
+
return send2(res, 200, { count: rows.length, relations: rows });
|
|
1973
2989
|
}
|
|
1974
2990
|
if (path === "/graph/entities" && method === "GET") {
|
|
1975
2991
|
const repo = url.searchParams.get("repo") ?? void 0;
|
|
@@ -1982,7 +2998,7 @@ var server = createServer2(async (req, res) => {
|
|
|
1982
2998
|
search,
|
|
1983
2999
|
limit
|
|
1984
3000
|
});
|
|
1985
|
-
return
|
|
3001
|
+
return send2(res, 200, {
|
|
1986
3002
|
count: rows.length,
|
|
1987
3003
|
entities: rows
|
|
1988
3004
|
});
|
|
@@ -1990,7 +3006,7 @@ var server = createServer2(async (req, res) => {
|
|
|
1990
3006
|
if (path === "/graph/query" && method === "POST") {
|
|
1991
3007
|
const body = await parseBody(req);
|
|
1992
3008
|
if (!body.query || typeof body.query !== "string") {
|
|
1993
|
-
return
|
|
3009
|
+
return send2(res, 400, { error: "query (string) required" });
|
|
1994
3010
|
}
|
|
1995
3011
|
const embeddingConfig = loadEmbeddingConfigFromEnv();
|
|
1996
3012
|
const result = await graphQuery(db, body.query, embeddingConfig, {
|
|
@@ -1999,7 +3015,7 @@ var server = createServer2(async (req, res) => {
|
|
|
1999
3015
|
limit: typeof body.limit === "number" ? body.limit : void 0,
|
|
2000
3016
|
relationTypes: Array.isArray(body.relation_types) ? body.relation_types : void 0
|
|
2001
3017
|
});
|
|
2002
|
-
return
|
|
3018
|
+
return send2(res, 200, {
|
|
2003
3019
|
seed_count: result.seed_count,
|
|
2004
3020
|
expanded_entities: result.expanded_entities,
|
|
2005
3021
|
hits: result.hits.map((h) => ({
|
|
@@ -2019,8 +3035,8 @@ var server = createServer2(async (req, res) => {
|
|
|
2019
3035
|
if (path.startsWith("/graph/entity/") && method === "GET") {
|
|
2020
3036
|
const id = path.slice("/graph/entity/".length);
|
|
2021
3037
|
const ent = getEntity(db, id);
|
|
2022
|
-
if (!ent) return
|
|
2023
|
-
return
|
|
3038
|
+
if (!ent) return send2(res, 404, { error: "entity not found" });
|
|
3039
|
+
return send2(res, 200, {
|
|
2024
3040
|
entity: ent,
|
|
2025
3041
|
memories: listMemoryIdsForEntity(db, id)
|
|
2026
3042
|
});
|
|
@@ -2028,17 +3044,17 @@ var server = createServer2(async (req, res) => {
|
|
|
2028
3044
|
if (path === "/graph/neighbors" && method === "POST") {
|
|
2029
3045
|
const body = await parseBody(req);
|
|
2030
3046
|
if (!body.entity_id || typeof body.entity_id !== "string") {
|
|
2031
|
-
return
|
|
3047
|
+
return send2(res, 400, { error: "entity_id (string) required" });
|
|
2032
3048
|
}
|
|
2033
3049
|
const root = getEntity(db, body.entity_id);
|
|
2034
|
-
if (!root) return
|
|
3050
|
+
if (!root) return send2(res, 404, { error: "entity not found" });
|
|
2035
3051
|
const walk = neighborsOf(db, body.entity_id, {
|
|
2036
3052
|
hops: typeof body.hops === "number" ? body.hops : void 0,
|
|
2037
3053
|
relationTypes: Array.isArray(body.relation_types) ? body.relation_types : void 0
|
|
2038
3054
|
});
|
|
2039
3055
|
const includeMemories = body.include_memories !== false;
|
|
2040
3056
|
const memoriesByEntity = includeMemories ? Object.fromEntries(walk.entities.map((e) => [e.id, listMemoryIdsForEntity(db, e.id)])) : {};
|
|
2041
|
-
return
|
|
3057
|
+
return send2(res, 200, {
|
|
2042
3058
|
root,
|
|
2043
3059
|
entities: walk.entities,
|
|
2044
3060
|
relations: walk.relations,
|
|
@@ -2048,10 +3064,10 @@ var server = createServer2(async (req, res) => {
|
|
|
2048
3064
|
if (path.startsWith("/graph/memory/") && method === "GET") {
|
|
2049
3065
|
const memId = path.slice("/graph/memory/".length);
|
|
2050
3066
|
const ents = listEntitiesForMemory(db, memId);
|
|
2051
|
-
return
|
|
3067
|
+
return send2(res, 200, { memory_id: memId, entities: ents });
|
|
2052
3068
|
}
|
|
2053
3069
|
if (path === "/webui/status" && method === "GET") {
|
|
2054
|
-
return
|
|
3070
|
+
return send2(res, 200, getStatus());
|
|
2055
3071
|
}
|
|
2056
3072
|
if (path === "/webui/start" && method === "POST") {
|
|
2057
3073
|
const body = await parseBody(req).catch(() => ({}));
|
|
@@ -2061,70 +3077,70 @@ var server = createServer2(async (req, res) => {
|
|
|
2061
3077
|
if (body.open !== false && status.url) {
|
|
2062
3078
|
openInBrowser(status.url);
|
|
2063
3079
|
}
|
|
2064
|
-
return
|
|
3080
|
+
return send2(res, 200, status);
|
|
2065
3081
|
}
|
|
2066
3082
|
if (path === "/webui/stop" && method === "POST") {
|
|
2067
3083
|
const status = await stop();
|
|
2068
|
-
return
|
|
3084
|
+
return send2(res, 200, status);
|
|
2069
3085
|
}
|
|
2070
3086
|
if (path === "/dispatch/wake" && method === "POST") {
|
|
2071
3087
|
wakeDispatcherDebounced();
|
|
2072
|
-
return
|
|
3088
|
+
return send2(res, 202, { status: "queued", debounce_ms: DISPATCH_WAKE_DEBOUNCE_MS });
|
|
2073
3089
|
}
|
|
2074
3090
|
if (path === "/hook/prompt" && method === "POST") {
|
|
2075
3091
|
const body = await parseBody(req);
|
|
2076
3092
|
if (!body.text) {
|
|
2077
|
-
return
|
|
3093
|
+
return send2(res, 400, { error: "text required" });
|
|
2078
3094
|
}
|
|
2079
3095
|
const result = await handlePromptHook(body, {
|
|
2080
3096
|
db,
|
|
2081
3097
|
source: "daemon"
|
|
2082
3098
|
});
|
|
2083
|
-
return
|
|
3099
|
+
return send2(res, 200, { ...result, transport: "daemon" });
|
|
2084
3100
|
}
|
|
2085
3101
|
if (path === "/hook/tool" && method === "POST") {
|
|
2086
3102
|
const body = await parseBody(req);
|
|
2087
3103
|
if (!body.name || typeof body.exit_code !== "number") {
|
|
2088
|
-
return
|
|
3104
|
+
return send2(res, 400, { error: "name and numeric exit_code required" });
|
|
2089
3105
|
}
|
|
2090
3106
|
const result = await handleToolHook(body, {
|
|
2091
3107
|
db,
|
|
2092
3108
|
source: "daemon"
|
|
2093
3109
|
});
|
|
2094
|
-
return
|
|
3110
|
+
return send2(res, 200, { ...result, transport: "daemon" });
|
|
2095
3111
|
}
|
|
2096
3112
|
if (path === "/hook/assistant" && method === "POST") {
|
|
2097
3113
|
const body = await parseBody(req);
|
|
2098
3114
|
if (!body.text) {
|
|
2099
|
-
return
|
|
3115
|
+
return send2(res, 400, { error: "text required" });
|
|
2100
3116
|
}
|
|
2101
3117
|
const result = await handleAssistantCompletionHook(body, {
|
|
2102
3118
|
db,
|
|
2103
3119
|
source: "daemon"
|
|
2104
3120
|
});
|
|
2105
|
-
return
|
|
3121
|
+
return send2(res, 200, { ...result, transport: "daemon" });
|
|
2106
3122
|
}
|
|
2107
3123
|
if (path === "/hook/session-start" && method === "POST") {
|
|
2108
3124
|
const body = await parseBody(req);
|
|
2109
3125
|
if (!body.session_id || !body.agent) {
|
|
2110
|
-
return
|
|
3126
|
+
return send2(res, 400, { error: "session_id and agent required" });
|
|
2111
3127
|
}
|
|
2112
3128
|
const result = await handleSessionStartHook(body, {
|
|
2113
3129
|
db,
|
|
2114
3130
|
source: "daemon"
|
|
2115
3131
|
});
|
|
2116
|
-
return
|
|
3132
|
+
return send2(res, 200, { ...result, transport: "daemon" });
|
|
2117
3133
|
}
|
|
2118
3134
|
if (path === "/hook/session-end" && method === "POST") {
|
|
2119
3135
|
const body = await parseBody(req);
|
|
2120
3136
|
if (!body.session_id) {
|
|
2121
|
-
return
|
|
3137
|
+
return send2(res, 400, { error: "session_id required" });
|
|
2122
3138
|
}
|
|
2123
3139
|
const result = await handleSessionEndHook(body, {
|
|
2124
3140
|
db,
|
|
2125
3141
|
source: "daemon"
|
|
2126
3142
|
});
|
|
2127
|
-
return
|
|
3143
|
+
return send2(res, 200, { ...result, transport: "daemon" });
|
|
2128
3144
|
}
|
|
2129
3145
|
if (path === "/correct" && method === "POST") {
|
|
2130
3146
|
const body = await parseBody(req);
|
|
@@ -2153,7 +3169,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2153
3169
|
source: "correction"
|
|
2154
3170
|
});
|
|
2155
3171
|
}
|
|
2156
|
-
return
|
|
3172
|
+
return send2(res, 200, { created: ids, pending_task_id: pendingTaskId ?? null });
|
|
2157
3173
|
}
|
|
2158
3174
|
if (path === "/review" && method === "POST") {
|
|
2159
3175
|
const body = await parseBody(req);
|
|
@@ -2182,7 +3198,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2182
3198
|
source: "review"
|
|
2183
3199
|
});
|
|
2184
3200
|
}
|
|
2185
|
-
return
|
|
3201
|
+
return send2(res, 200, { created: ids });
|
|
2186
3202
|
}
|
|
2187
3203
|
if (path === "/confirm" && method === "POST") {
|
|
2188
3204
|
const body = await parseBody(req);
|
|
@@ -2194,7 +3210,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2194
3210
|
repo: mem?.repo ?? null
|
|
2195
3211
|
});
|
|
2196
3212
|
}
|
|
2197
|
-
return
|
|
3213
|
+
return send2(res, ok ? 200 : 404, { success: ok });
|
|
2198
3214
|
}
|
|
2199
3215
|
if (path === "/reject" && method === "POST") {
|
|
2200
3216
|
const body = await parseBody(req);
|
|
@@ -2217,7 +3233,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2217
3233
|
actor: "daemon:http"
|
|
2218
3234
|
});
|
|
2219
3235
|
}
|
|
2220
|
-
return
|
|
3236
|
+
return send2(res, ok ? 200 : 404, { success: ok });
|
|
2221
3237
|
}
|
|
2222
3238
|
if (path === "/feedback" && method === "POST") {
|
|
2223
3239
|
const body = await parseBody(req);
|
|
@@ -2233,7 +3249,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2233
3249
|
outcome: String(body.outcome ?? ""),
|
|
2234
3250
|
injected: Boolean(body.injected)
|
|
2235
3251
|
});
|
|
2236
|
-
return
|
|
3252
|
+
return send2(res, 200, { feedback_id: id });
|
|
2237
3253
|
}
|
|
2238
3254
|
if (path === "/memories" && method === "GET") {
|
|
2239
3255
|
const repo = url.searchParams.get("repo") ?? void 0;
|
|
@@ -2241,7 +3257,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2241
3257
|
const limit = parseInt(url.searchParams.get("limit") ?? "50", 10);
|
|
2242
3258
|
const offset = parseInt(url.searchParams.get("offset") ?? "0", 10);
|
|
2243
3259
|
const items = queryMemories(db, { repo, status, limit, offset });
|
|
2244
|
-
return
|
|
3260
|
+
return send2(res, 200, {
|
|
2245
3261
|
memories: items,
|
|
2246
3262
|
offset,
|
|
2247
3263
|
limit,
|
|
@@ -2251,8 +3267,8 @@ var server = createServer2(async (req, res) => {
|
|
|
2251
3267
|
if (path.startsWith("/memory/") && method === "GET") {
|
|
2252
3268
|
const id = path.slice("/memory/".length);
|
|
2253
3269
|
const mem = getMemory(db, id);
|
|
2254
|
-
if (!mem) return
|
|
2255
|
-
return
|
|
3270
|
+
if (!mem) return send2(res, 404, { error: "not found" });
|
|
3271
|
+
return send2(res, 200, mem);
|
|
2256
3272
|
}
|
|
2257
3273
|
if (path === "/scan" && method === "POST") {
|
|
2258
3274
|
const body = await parseBody(req);
|
|
@@ -2290,7 +3306,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2290
3306
|
type: m?.type
|
|
2291
3307
|
});
|
|
2292
3308
|
}
|
|
2293
|
-
return
|
|
3309
|
+
return send2(res, 200, {
|
|
2294
3310
|
created: ids,
|
|
2295
3311
|
count: ids.length,
|
|
2296
3312
|
artifact_path: artifact.output_path,
|
|
@@ -2301,22 +3317,22 @@ var server = createServer2(async (req, res) => {
|
|
|
2301
3317
|
const repo = url.searchParams.get("repo") ?? void 0;
|
|
2302
3318
|
const since = url.searchParams.get("since") ?? void 0;
|
|
2303
3319
|
const metrics = computeMetrics(db, { repo, since });
|
|
2304
|
-
return
|
|
3320
|
+
return send2(res, 200, metrics);
|
|
2305
3321
|
}
|
|
2306
3322
|
if (path === "/eval/start" && method === "POST") {
|
|
2307
3323
|
const body = await parseBody(req);
|
|
2308
3324
|
const id = startEvalSession(db, body.repo);
|
|
2309
|
-
return
|
|
3325
|
+
return send2(res, 200, { session_id: id });
|
|
2310
3326
|
}
|
|
2311
3327
|
if (path === "/eval/end" && method === "POST") {
|
|
2312
3328
|
const body = await parseBody(req);
|
|
2313
3329
|
endEvalSession(db, body.session_id);
|
|
2314
|
-
return
|
|
3330
|
+
return send2(res, 200, { success: true });
|
|
2315
3331
|
}
|
|
2316
3332
|
if (path === "/eval/increment" && method === "POST") {
|
|
2317
3333
|
const body = await parseBody(req);
|
|
2318
3334
|
incrementEvalCounter(db, body.session_id, body.field, body.amount ?? 1);
|
|
2319
|
-
return
|
|
3335
|
+
return send2(res, 200, { success: true });
|
|
2320
3336
|
}
|
|
2321
3337
|
if (path === "/signal" && method === "POST") {
|
|
2322
3338
|
const body = await parseBody(req);
|
|
@@ -2338,16 +3354,16 @@ var server = createServer2(async (req, res) => {
|
|
|
2338
3354
|
request: { signal_type: body.signal_type, context: body.context ?? null },
|
|
2339
3355
|
result: { signal_id: id }
|
|
2340
3356
|
});
|
|
2341
|
-
return
|
|
3357
|
+
return send2(res, 200, { signal_id: id });
|
|
2342
3358
|
}
|
|
2343
3359
|
if (path.startsWith("/signal/stats/") && method === "GET") {
|
|
2344
3360
|
const memId = path.slice("/signal/stats/".length);
|
|
2345
3361
|
const stats = getSignalStats(db, memId);
|
|
2346
|
-
return
|
|
3362
|
+
return send2(res, 200, stats);
|
|
2347
3363
|
}
|
|
2348
3364
|
if (path === "/quality" && method === "GET") {
|
|
2349
3365
|
const repo = url.searchParams.get("repo") ?? void 0;
|
|
2350
|
-
return
|
|
3366
|
+
return send2(res, 200, getRepoQualityProfile(db, repo));
|
|
2351
3367
|
}
|
|
2352
3368
|
if (path === "/activity" && method === "GET") {
|
|
2353
3369
|
const repo = url.searchParams.get("repo") ?? void 0;
|
|
@@ -2366,7 +3382,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2366
3382
|
limit,
|
|
2367
3383
|
offset
|
|
2368
3384
|
});
|
|
2369
|
-
return
|
|
3385
|
+
return send2(res, 200, { events, offset, limit, has_more: events.length === limit });
|
|
2370
3386
|
}
|
|
2371
3387
|
if (path === "/sessions" && method === "GET") {
|
|
2372
3388
|
const repo = url.searchParams.get("repo") ?? void 0;
|
|
@@ -2383,7 +3399,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2383
3399
|
limit: Math.max(limit + offset, 200)
|
|
2384
3400
|
});
|
|
2385
3401
|
const page = grouped.slice(offset, offset + limit);
|
|
2386
|
-
return
|
|
3402
|
+
return send2(res, 200, {
|
|
2387
3403
|
sessions: page,
|
|
2388
3404
|
offset,
|
|
2389
3405
|
limit,
|
|
@@ -2392,44 +3408,44 @@ var server = createServer2(async (req, res) => {
|
|
|
2392
3408
|
}
|
|
2393
3409
|
if (path === "/policy/list" && method === "GET") {
|
|
2394
3410
|
const orgId = url.searchParams.get("org_id") ?? "";
|
|
2395
|
-
return
|
|
3411
|
+
return send2(res, 200, { policies: listPolicies(db, orgId) });
|
|
2396
3412
|
}
|
|
2397
3413
|
if (path === "/policy" && method === "POST") {
|
|
2398
3414
|
const body = await parseBody(req);
|
|
2399
3415
|
const id = createPolicy(db, body.org_id, body.rule_type, body.config);
|
|
2400
|
-
return
|
|
3416
|
+
return send2(res, 200, { policy_id: id });
|
|
2401
3417
|
}
|
|
2402
3418
|
if (path === "/policy/check" && method === "POST") {
|
|
2403
3419
|
const body = await parseBody(req);
|
|
2404
3420
|
const mem = getMemory(db, body.memory_id);
|
|
2405
|
-
if (!mem) return
|
|
3421
|
+
if (!mem) return send2(res, 404, { error: "memory not found" });
|
|
2406
3422
|
const violations = evaluatePolicy(db, body.org_id, mem);
|
|
2407
|
-
return
|
|
3423
|
+
return send2(res, 200, { violations });
|
|
2408
3424
|
}
|
|
2409
3425
|
if (path === "/approval/request" && method === "POST") {
|
|
2410
3426
|
const body = await parseBody(req);
|
|
2411
3427
|
const id = requestApproval(db, body.memory_id, body.org_id, body.requested_by ?? "daemon");
|
|
2412
|
-
return
|
|
3428
|
+
return send2(res, 200, { approval_id: id });
|
|
2413
3429
|
}
|
|
2414
3430
|
if (path === "/approval/pending" && method === "GET") {
|
|
2415
3431
|
const orgId = url.searchParams.get("org_id") ?? "";
|
|
2416
|
-
return
|
|
3432
|
+
return send2(res, 200, { approvals: listPendingApprovals(db, orgId) });
|
|
2417
3433
|
}
|
|
2418
3434
|
if (path === "/approval/resolve" && method === "POST") {
|
|
2419
3435
|
const body = await parseBody(req);
|
|
2420
3436
|
const ok = resolveApproval(db, body.approval_id, body.status, body.reviewed_by ?? "daemon", body.reason);
|
|
2421
|
-
return
|
|
3437
|
+
return send2(res, ok ? 200 : 404, { success: ok });
|
|
2422
3438
|
}
|
|
2423
3439
|
if (path.startsWith("/health/") && method === "GET") {
|
|
2424
3440
|
const memId = path.slice("/health/".length);
|
|
2425
3441
|
const score = computeHealthScore(db, memId);
|
|
2426
|
-
if (!score) return
|
|
2427
|
-
return
|
|
3442
|
+
if (!score) return send2(res, 404, { error: "not found" });
|
|
3443
|
+
return send2(res, 200, score);
|
|
2428
3444
|
}
|
|
2429
3445
|
if (path === "/health" && method === "GET") {
|
|
2430
3446
|
const repo = url.searchParams.get("repo") ?? void 0;
|
|
2431
3447
|
const scores = computeAllHealthScores(db, repo);
|
|
2432
|
-
return
|
|
3448
|
+
return send2(res, 200, { scores });
|
|
2433
3449
|
}
|
|
2434
3450
|
if (path === "/contradictions/detect" && method === "POST") {
|
|
2435
3451
|
const body = await parseBody(req);
|
|
@@ -2442,7 +3458,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2442
3458
|
severity: c.severity
|
|
2443
3459
|
});
|
|
2444
3460
|
}
|
|
2445
|
-
return
|
|
3461
|
+
return send2(res, 200, { contradictions: found });
|
|
2446
3462
|
}
|
|
2447
3463
|
if (path === "/contradictions" && method === "GET") {
|
|
2448
3464
|
const resolved = url.searchParams.get("resolved");
|
|
@@ -2453,7 +3469,7 @@ var server = createServer2(async (req, res) => {
|
|
|
2453
3469
|
limit,
|
|
2454
3470
|
offset
|
|
2455
3471
|
});
|
|
2456
|
-
return
|
|
3472
|
+
return send2(res, 200, {
|
|
2457
3473
|
contradictions: items,
|
|
2458
3474
|
offset,
|
|
2459
3475
|
limit,
|
|
@@ -2469,43 +3485,44 @@ var server = createServer2(async (req, res) => {
|
|
|
2469
3485
|
keep_memory_id: body.keep_memory_id
|
|
2470
3486
|
});
|
|
2471
3487
|
}
|
|
2472
|
-
return
|
|
3488
|
+
return send2(res, ok ? 200 : 404, { success: ok });
|
|
2473
3489
|
}
|
|
2474
3490
|
if (path === "/contradictions/auto-resolve" && method === "POST") {
|
|
2475
3491
|
const body = await parseBody(req);
|
|
2476
3492
|
const count = autoResolveContradictions(db, body.repo);
|
|
2477
|
-
return
|
|
3493
|
+
return send2(res, 200, { resolved: count });
|
|
2478
3494
|
}
|
|
2479
3495
|
if (path === "/prune" && method === "POST") {
|
|
2480
3496
|
const body = await parseBody(req);
|
|
2481
3497
|
const result = pruneMemories(db, body.config);
|
|
2482
|
-
return
|
|
3498
|
+
return send2(res, 200, result);
|
|
2483
3499
|
}
|
|
2484
3500
|
if (path.startsWith("/audit/memory/") && method === "GET") {
|
|
2485
3501
|
const memId = path.slice("/audit/memory/".length);
|
|
2486
3502
|
const entries = getAuditTrail(db, memId);
|
|
2487
|
-
return
|
|
3503
|
+
return send2(res, 200, { entries });
|
|
2488
3504
|
}
|
|
2489
3505
|
if (path === "/audit/recent" && method === "GET") {
|
|
2490
3506
|
const limit = parseInt(url.searchParams.get("limit") ?? "50");
|
|
2491
3507
|
const entries = getRecentAudit(db, limit);
|
|
2492
|
-
return
|
|
3508
|
+
return send2(res, 200, { entries });
|
|
2493
3509
|
}
|
|
2494
3510
|
if (path === "/audit/rollback" && method === "POST") {
|
|
2495
3511
|
const body = await parseBody(req);
|
|
2496
3512
|
const ok = rollbackMemory(db, body.memory_id, body.audit_entry_id, body.actor ?? "daemon");
|
|
2497
|
-
return
|
|
3513
|
+
return send2(res, ok ? 200 : 404, { success: ok });
|
|
2498
3514
|
}
|
|
2499
|
-
|
|
3515
|
+
if (await handleCloudRoute(cloudService, req, res, path, method)) return;
|
|
3516
|
+
send2(res, 404, { error: "not found" });
|
|
2500
3517
|
} catch (err) {
|
|
2501
3518
|
if (err instanceof JsonBodyError) {
|
|
2502
|
-
return
|
|
3519
|
+
return send2(res, err.status, { error: err.message });
|
|
2503
3520
|
}
|
|
2504
3521
|
Sentry.captureException(err);
|
|
2505
|
-
|
|
3522
|
+
send2(res, 500, { error: "internal server error" });
|
|
2506
3523
|
}
|
|
2507
3524
|
});
|
|
2508
|
-
function
|
|
3525
|
+
function send2(res, status, data) {
|
|
2509
3526
|
res.statusCode = status;
|
|
2510
3527
|
res.end(JSON.stringify(data));
|
|
2511
3528
|
}
|
|
@@ -2529,6 +3546,7 @@ async function startDaemon() {
|
|
|
2529
3546
|
console.log(`[recall] backup created ${backup.created} (retained ${backup.retained.length})`);
|
|
2530
3547
|
}
|
|
2531
3548
|
db = initDb();
|
|
3549
|
+
refreshCloudIndex = createCloudIndexRefresher(db, () => console.error("[recall-cloud] local index refresh failed; maintenance will retry"));
|
|
2532
3550
|
if (!backup.created && backup.retained.length === 0) {
|
|
2533
3551
|
backup = ensureDailyBackup();
|
|
2534
3552
|
if (backup.created) {
|
|
@@ -2536,7 +3554,7 @@ async function startDaemon() {
|
|
|
2536
3554
|
}
|
|
2537
3555
|
}
|
|
2538
3556
|
try {
|
|
2539
|
-
const dataDir = process.env.RECALL_DATA_DIR ??
|
|
3557
|
+
const dataDir = process.env.RECALL_DATA_DIR ?? join5(homedir(), ".recall");
|
|
2540
3558
|
const reconciled = reconcileGraphIfStale(db, dataDir);
|
|
2541
3559
|
if (reconciled) {
|
|
2542
3560
|
console.log(
|
|
@@ -2554,7 +3572,14 @@ async function startDaemon() {
|
|
|
2554
3572
|
scheduleQualitySnapshotLoop();
|
|
2555
3573
|
scheduleReliabilityProbeLoop();
|
|
2556
3574
|
scheduleReliabilityVerdictLoop();
|
|
3575
|
+
void cloudService.startIfEnabled();
|
|
2557
3576
|
});
|
|
3577
|
+
for (const signal of ["SIGTERM", "SIGINT"]) {
|
|
3578
|
+
process.once(signal, () => {
|
|
3579
|
+
void cloudService.shutdown().finally(() => process.kill(process.pid, signal));
|
|
3580
|
+
});
|
|
3581
|
+
}
|
|
3582
|
+
process.on("exit", () => cloudService.killSync());
|
|
2558
3583
|
}
|
|
2559
3584
|
void startDaemon().catch((error) => {
|
|
2560
3585
|
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|