@edihasaj/recall 0.6.6 → 0.7.1
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 +57 -1
- package/dist/chunk-37K4DPRI.js +17 -0
- package/dist/chunk-37K4DPRI.js.map +1 -0
- package/dist/chunk-AKODTKWM.js +123 -0
- package/dist/chunk-AKODTKWM.js.map +1 -0
- package/dist/{chunk-4P3NKEIJ.js → chunk-CPOANMKD.js} +18 -9
- package/dist/{chunk-4P3NKEIJ.js.map → chunk-CPOANMKD.js.map} +1 -1
- package/dist/{chunk-AJAAK4FK.js → chunk-GNXTOM5K.js} +159 -9
- package/dist/chunk-GNXTOM5K.js.map +1 -0
- package/dist/chunk-JRIM7VBY.js +2346 -0
- package/dist/chunk-JRIM7VBY.js.map +1 -0
- package/dist/chunk-PG2ZVVAT.js +6525 -0
- package/dist/chunk-PG2ZVVAT.js.map +1 -0
- package/dist/{chunk-LFWG3CBM.js → chunk-PH6YNVHR.js} +206 -2381
- package/dist/chunk-PH6YNVHR.js.map +1 -0
- package/dist/chunk-QDA5M3AJ.js +2617 -0
- package/dist/chunk-QDA5M3AJ.js.map +1 -0
- package/dist/chunk-QSJKGEID.js +235 -0
- package/dist/chunk-QSJKGEID.js.map +1 -0
- package/dist/chunk-UBPGOOAN.js +462 -0
- package/dist/chunk-UBPGOOAN.js.map +1 -0
- package/dist/{chunk-XUM7JEJU.js → chunk-YL23MKB3.js} +10 -4
- package/dist/{chunk-XUM7JEJU.js.map → chunk-YL23MKB3.js.map} +1 -1
- package/dist/chunk-Z6RT5BUO.js +282 -0
- package/dist/chunk-Z6RT5BUO.js.map +1 -0
- package/dist/{cleanup-JM3CGHUV.js → cleanup-YGHZIYLJ.js} +6 -3
- package/dist/cli.js +160 -26
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +662 -42
- package/dist/daemon.js.map +1 -1
- package/dist/{dispatcher-C5S7SYY6.js → dispatcher-5MDL3QQT.js} +6 -3
- package/dist/embeddings-GKNH2E3N.js +48 -0
- package/dist/ingest-JWXX22QX.js +19 -0
- package/dist/mcp.js +9 -4
- package/dist/mcp.js.map +1 -1
- package/dist/{quality-YTQKAEY6.js → quality-2JOLSIC3.js} +4 -3
- package/dist/quality-2JOLSIC3.js.map +1 -0
- package/dist/retrieval-GLAEYWGA.js +13 -0
- package/dist/retrieval-GLAEYWGA.js.map +1 -0
- package/dist/store-2BPQPOOZ.js +31 -0
- package/dist/store-2BPQPOOZ.js.map +1 -0
- package/dist/{tasks-KHLJT7MP.js → tasks-6J3LULYO.js} +6 -3
- package/dist/tasks-6J3LULYO.js.map +1 -0
- package/dist/{usage-DU4TKVJH.js → usage-YBS74UEU.js} +8 -4
- package/dist/{usage-DU4TKVJH.js.map → usage-YBS74UEU.js.map} +1 -1
- package/dist/webui/assets/index-BJt1Lf-q.css +1 -0
- package/dist/webui/assets/index-Bfhwll2B.js +5224 -0
- package/dist/webui/assets/index-Bfhwll2B.js.map +1 -0
- package/dist/webui/index.html +15 -0
- package/dist/webui/recall-icon.png +0 -0
- package/drizzle/0008_premium_red_hulk.sql +44 -0
- package/drizzle/meta/0008_snapshot.json +2491 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +8 -3
- package/dist/chunk-A6XEULA4.js +0 -470
- package/dist/chunk-A6XEULA4.js.map +0 -1
- package/dist/chunk-AJAAK4FK.js.map +0 -1
- package/dist/chunk-DSNYEUZW.js +0 -2993
- package/dist/chunk-DSNYEUZW.js.map +0 -1
- package/dist/chunk-LFWG3CBM.js.map +0 -1
- /package/dist/{cleanup-JM3CGHUV.js.map → cleanup-YGHZIYLJ.js.map} +0 -0
- /package/dist/{dispatcher-C5S7SYY6.js.map → dispatcher-5MDL3QQT.js.map} +0 -0
- /package/dist/{quality-YTQKAEY6.js.map → embeddings-GKNH2E3N.js.map} +0 -0
- /package/dist/{tasks-KHLJT7MP.js.map → ingest-JWXX22QX.js.map} +0 -0
package/dist/daemon.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
safeIngestMemoryById
|
|
3
|
+
} from "./chunk-QSJKGEID.js";
|
|
1
4
|
import {
|
|
2
5
|
computeQualityReport,
|
|
3
6
|
listQualitySnapshots,
|
|
4
7
|
recordQualitySnapshot
|
|
5
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YL23MKB3.js";
|
|
6
9
|
import {
|
|
7
10
|
ensureDailyBackup,
|
|
8
11
|
handlePromptHook,
|
|
9
12
|
handleSessionEndHook,
|
|
10
13
|
handleSessionStartHook,
|
|
11
14
|
handleToolHook
|
|
12
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-CPOANMKD.js";
|
|
13
16
|
import {
|
|
14
17
|
createRecallMcpServer
|
|
15
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-GNXTOM5K.js";
|
|
19
|
+
import {
|
|
20
|
+
graphQuery
|
|
21
|
+
} from "./chunk-AKODTKWM.js";
|
|
22
|
+
import {
|
|
23
|
+
countEntities,
|
|
24
|
+
countRelations,
|
|
25
|
+
getEntity,
|
|
26
|
+
listAllRelations,
|
|
27
|
+
listEntities,
|
|
28
|
+
listEntitiesForMemory,
|
|
29
|
+
listMemoryIdsForEntity,
|
|
30
|
+
neighborsOf
|
|
31
|
+
} from "./chunk-Z6RT5BUO.js";
|
|
16
32
|
import {
|
|
17
33
|
bootstrapHistoryEmbeddings,
|
|
18
34
|
compileContext,
|
|
@@ -53,49 +69,56 @@ import {
|
|
|
53
69
|
updateHistorySnippet,
|
|
54
70
|
verifyHistoryEmbeddings,
|
|
55
71
|
writeRepoContextArtifact
|
|
56
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-PG2ZVVAT.js";
|
|
57
73
|
import {
|
|
58
74
|
DEFAULT_ENQUEUE_CONFIG,
|
|
59
75
|
autoResolveContradictions,
|
|
60
|
-
bootstrapEmbeddings,
|
|
61
76
|
computeAllHealthScores,
|
|
62
77
|
computeHealthScore,
|
|
63
|
-
confirmMemory,
|
|
64
78
|
detectContradictions,
|
|
65
79
|
detectCorrections,
|
|
66
80
|
dispatchPendingTasks,
|
|
67
81
|
enqueueMaintenanceTasks,
|
|
68
|
-
ensureEmbeddingProviderReady,
|
|
69
82
|
getAuditTrail,
|
|
70
|
-
getEmbeddingModelInfo,
|
|
71
|
-
getMemory,
|
|
72
83
|
getRecentAudit,
|
|
73
84
|
getRepoQualityProfile,
|
|
74
85
|
listContradictions,
|
|
75
|
-
loadEmbeddingConfigFromEnv,
|
|
76
86
|
processCorrection,
|
|
77
87
|
processReviewFeedback,
|
|
78
|
-
promoteMemory,
|
|
79
|
-
queryMemories,
|
|
80
|
-
queueMemoryEmbeddingSync,
|
|
81
|
-
rebuildEmbeddingIndex,
|
|
82
88
|
recordAudit,
|
|
83
89
|
recordAuditWithSnapshot,
|
|
84
|
-
recordFeedback,
|
|
85
|
-
rejectMemory,
|
|
86
90
|
resolveContradiction,
|
|
87
91
|
rollbackMemory,
|
|
88
|
-
runDeterministicCleanup
|
|
89
|
-
|
|
92
|
+
runDeterministicCleanup
|
|
93
|
+
} from "./chunk-PH6YNVHR.js";
|
|
94
|
+
import {
|
|
95
|
+
confirmMemory,
|
|
96
|
+
getMemory,
|
|
97
|
+
promoteMemory,
|
|
98
|
+
queryMemories,
|
|
99
|
+
recordFeedback,
|
|
100
|
+
rejectMemory,
|
|
101
|
+
statusFromConfidence
|
|
102
|
+
} from "./chunk-UBPGOOAN.js";
|
|
103
|
+
import "./chunk-37K4DPRI.js";
|
|
104
|
+
import {
|
|
105
|
+
bootstrapEmbeddings,
|
|
106
|
+
ensureEmbeddingProviderReady,
|
|
107
|
+
getEmbeddingModelInfo,
|
|
108
|
+
loadEmbeddingConfigFromEnv,
|
|
109
|
+
queueMemoryEmbeddingSync,
|
|
110
|
+
rebuildEmbeddingIndex,
|
|
90
111
|
verifyEmbeddings
|
|
91
|
-
} from "./chunk-
|
|
112
|
+
} from "./chunk-JRIM7VBY.js";
|
|
92
113
|
import {
|
|
93
114
|
activityEvents,
|
|
115
|
+
eq,
|
|
94
116
|
feedbackEvents,
|
|
95
117
|
historySnippets,
|
|
96
118
|
implicitSignals,
|
|
119
|
+
lt,
|
|
97
120
|
memories
|
|
98
|
-
} from "./chunk-
|
|
121
|
+
} from "./chunk-QDA5M3AJ.js";
|
|
99
122
|
import {
|
|
100
123
|
hasProviderConfigured,
|
|
101
124
|
init_keychain
|
|
@@ -103,12 +126,356 @@ import {
|
|
|
103
126
|
import "./chunk-4CV4JOE5.js";
|
|
104
127
|
|
|
105
128
|
// src/daemon.ts
|
|
106
|
-
import { createServer } from "http";
|
|
129
|
+
import { createServer as createServer2 } from "http";
|
|
107
130
|
import { createRequire } from "module";
|
|
108
131
|
|
|
132
|
+
// src/daemon/events.ts
|
|
133
|
+
var handlers = /* @__PURE__ */ new Map();
|
|
134
|
+
var anyHandlers = /* @__PURE__ */ new Set();
|
|
135
|
+
function onAny(handler) {
|
|
136
|
+
anyHandlers.add(handler);
|
|
137
|
+
return () => {
|
|
138
|
+
anyHandlers.delete(handler);
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function emit(name, payload) {
|
|
142
|
+
const envelope = {
|
|
143
|
+
name,
|
|
144
|
+
payload,
|
|
145
|
+
ts: (/* @__PURE__ */ new Date()).toISOString()
|
|
146
|
+
};
|
|
147
|
+
const set = handlers.get(name);
|
|
148
|
+
if (set) {
|
|
149
|
+
for (const h of set) {
|
|
150
|
+
try {
|
|
151
|
+
h(envelope);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
console.error(`[recall] event handler for ${name} threw:`, err);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (const h of anyHandlers) {
|
|
158
|
+
try {
|
|
159
|
+
h(envelope);
|
|
160
|
+
} catch (err) {
|
|
161
|
+
console.error(`[recall] any-event handler threw:`, err);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/webui/server.ts
|
|
167
|
+
import { createServer } from "http";
|
|
168
|
+
import { createReadStream, existsSync, statSync } from "fs";
|
|
169
|
+
import { extname, join, normalize, resolve, sep } from "path";
|
|
170
|
+
import { fileURLToPath } from "url";
|
|
171
|
+
|
|
172
|
+
// src/webui/ws.ts
|
|
173
|
+
import { createHash } from "crypto";
|
|
174
|
+
var WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
175
|
+
var clients = /* @__PURE__ */ new Set();
|
|
176
|
+
var pingTimer = null;
|
|
177
|
+
var busUnsubscribe = null;
|
|
178
|
+
function isLocalRequest(req) {
|
|
179
|
+
const addr = req.socket.remoteAddress ?? "";
|
|
180
|
+
return addr === "127.0.0.1" || addr === "::1" || addr === "::ffff:127.0.0.1" || addr === "localhost";
|
|
181
|
+
}
|
|
182
|
+
function handleUpgrade(req, socket) {
|
|
183
|
+
if (!isLocalRequest(req)) {
|
|
184
|
+
socket.destroy();
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const key = req.headers["sec-websocket-key"];
|
|
188
|
+
if (typeof key !== "string") {
|
|
189
|
+
socket.destroy();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const accept = createHash("sha1").update(key + WS_GUID).digest("base64");
|
|
193
|
+
socket.write(
|
|
194
|
+
[
|
|
195
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
196
|
+
"Upgrade: websocket",
|
|
197
|
+
"Connection: Upgrade",
|
|
198
|
+
`Sec-WebSocket-Accept: ${accept}`,
|
|
199
|
+
"\r\n"
|
|
200
|
+
].join("\r\n")
|
|
201
|
+
);
|
|
202
|
+
const client = { socket, alive: true };
|
|
203
|
+
clients.add(client);
|
|
204
|
+
socket.on("close", () => {
|
|
205
|
+
clients.delete(client);
|
|
206
|
+
});
|
|
207
|
+
socket.on("error", () => {
|
|
208
|
+
clients.delete(client);
|
|
209
|
+
socket.destroy();
|
|
210
|
+
});
|
|
211
|
+
socket.on("data", (chunk) => {
|
|
212
|
+
if (chunk.length < 2) return;
|
|
213
|
+
const opcode = chunk[0] & 15;
|
|
214
|
+
if (opcode === 8) {
|
|
215
|
+
writeFrame(socket, 8, Buffer.alloc(0));
|
|
216
|
+
socket.end();
|
|
217
|
+
clients.delete(client);
|
|
218
|
+
} else if (opcode === 10) {
|
|
219
|
+
client.alive = true;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
writeText(
|
|
223
|
+
socket,
|
|
224
|
+
JSON.stringify({ name: "hello", payload: { version: 1 }, ts: (/* @__PURE__ */ new Date()).toISOString() })
|
|
225
|
+
);
|
|
226
|
+
ensurePingLoop();
|
|
227
|
+
ensureBusBridge();
|
|
228
|
+
}
|
|
229
|
+
function ensureBusBridge() {
|
|
230
|
+
if (busUnsubscribe) return;
|
|
231
|
+
busUnsubscribe = onAny((envelope) => {
|
|
232
|
+
if (clients.size === 0) return;
|
|
233
|
+
const json = JSON.stringify(envelope);
|
|
234
|
+
for (const c of clients) {
|
|
235
|
+
writeText(c.socket, json);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function ensurePingLoop() {
|
|
240
|
+
if (pingTimer) return;
|
|
241
|
+
pingTimer = setInterval(() => {
|
|
242
|
+
if (clients.size === 0) return;
|
|
243
|
+
for (const c of clients) {
|
|
244
|
+
if (!c.alive) {
|
|
245
|
+
c.socket.destroy();
|
|
246
|
+
clients.delete(c);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
c.alive = false;
|
|
250
|
+
try {
|
|
251
|
+
writeFrame(c.socket, 9, Buffer.alloc(0));
|
|
252
|
+
} catch {
|
|
253
|
+
clients.delete(c);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}, 3e4);
|
|
257
|
+
pingTimer.unref?.();
|
|
258
|
+
}
|
|
259
|
+
function writeText(socket, text) {
|
|
260
|
+
try {
|
|
261
|
+
writeFrame(socket, 1, Buffer.from(text, "utf8"));
|
|
262
|
+
} catch {
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function writeFrame(socket, opcode, payload) {
|
|
266
|
+
const len = payload.length;
|
|
267
|
+
let header;
|
|
268
|
+
if (len < 126) {
|
|
269
|
+
header = Buffer.alloc(2);
|
|
270
|
+
header[0] = 128 | opcode & 15;
|
|
271
|
+
header[1] = len;
|
|
272
|
+
} else if (len < 65536) {
|
|
273
|
+
header = Buffer.alloc(4);
|
|
274
|
+
header[0] = 128 | opcode & 15;
|
|
275
|
+
header[1] = 126;
|
|
276
|
+
header.writeUInt16BE(len, 2);
|
|
277
|
+
} else {
|
|
278
|
+
header = Buffer.alloc(10);
|
|
279
|
+
header[0] = 128 | opcode & 15;
|
|
280
|
+
header[1] = 127;
|
|
281
|
+
header.writeBigUInt64BE(BigInt(len), 2);
|
|
282
|
+
}
|
|
283
|
+
socket.write(Buffer.concat([header, payload]));
|
|
284
|
+
}
|
|
285
|
+
function clientCount() {
|
|
286
|
+
return clients.size;
|
|
287
|
+
}
|
|
288
|
+
function shutdown() {
|
|
289
|
+
if (pingTimer) {
|
|
290
|
+
clearInterval(pingTimer);
|
|
291
|
+
pingTimer = null;
|
|
292
|
+
}
|
|
293
|
+
busUnsubscribe?.();
|
|
294
|
+
busUnsubscribe = null;
|
|
295
|
+
for (const c of clients) {
|
|
296
|
+
try {
|
|
297
|
+
writeFrame(c.socket, 8, Buffer.alloc(0));
|
|
298
|
+
c.socket.end();
|
|
299
|
+
} catch {
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
clients.clear();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// src/webui/server.ts
|
|
306
|
+
var MIME = {
|
|
307
|
+
".html": "text/html; charset=utf-8",
|
|
308
|
+
".js": "text/javascript; charset=utf-8",
|
|
309
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
310
|
+
".css": "text/css; charset=utf-8",
|
|
311
|
+
".json": "application/json; charset=utf-8",
|
|
312
|
+
".svg": "image/svg+xml",
|
|
313
|
+
".png": "image/png",
|
|
314
|
+
".jpg": "image/jpeg",
|
|
315
|
+
".jpeg": "image/jpeg",
|
|
316
|
+
".webp": "image/webp",
|
|
317
|
+
".ico": "image/x-icon",
|
|
318
|
+
".woff2": "font/woff2",
|
|
319
|
+
".woff": "font/woff",
|
|
320
|
+
".map": "application/json"
|
|
321
|
+
};
|
|
322
|
+
var active = null;
|
|
323
|
+
function defaultDistDir() {
|
|
324
|
+
const here = fileURLToPath(new URL(".", import.meta.url));
|
|
325
|
+
let dir = here;
|
|
326
|
+
for (let i = 0; i < 8; i++) {
|
|
327
|
+
if (existsSync(join(dir, "package.json"))) {
|
|
328
|
+
return join(dir, "dist", "webui");
|
|
329
|
+
}
|
|
330
|
+
const parent = resolve(dir, "..");
|
|
331
|
+
if (parent === dir) break;
|
|
332
|
+
dir = parent;
|
|
333
|
+
}
|
|
334
|
+
return join(here, "..", "..", "dist", "webui");
|
|
335
|
+
}
|
|
336
|
+
function getStatus() {
|
|
337
|
+
if (!active) {
|
|
338
|
+
const distDir = defaultDistDir();
|
|
339
|
+
return {
|
|
340
|
+
running: false,
|
|
341
|
+
port: null,
|
|
342
|
+
host: null,
|
|
343
|
+
url: null,
|
|
344
|
+
client_count: 0,
|
|
345
|
+
dist_dir: distDir,
|
|
346
|
+
dist_exists: existsSync(distDir),
|
|
347
|
+
started_at: null
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
return {
|
|
351
|
+
running: true,
|
|
352
|
+
port: active.port,
|
|
353
|
+
host: active.host,
|
|
354
|
+
url: `http://${active.host}:${active.port}`,
|
|
355
|
+
client_count: clientCount(),
|
|
356
|
+
dist_dir: active.distDir,
|
|
357
|
+
dist_exists: existsSync(active.distDir),
|
|
358
|
+
started_at: active.startedAt
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
async function start(options = {}) {
|
|
362
|
+
if (active) return getStatus();
|
|
363
|
+
const port = options.port ?? parseInt(process.env.RECALL_WEBUI_PORT ?? "7891", 10);
|
|
364
|
+
const host = options.host ?? "127.0.0.1";
|
|
365
|
+
const distDir = options.distDir ?? defaultDistDir();
|
|
366
|
+
const server2 = createServer((req, res) => handleHttp(req, res, distDir));
|
|
367
|
+
server2.on("upgrade", (req, socket) => {
|
|
368
|
+
if (req.url === "/ws") {
|
|
369
|
+
handleUpgrade(req, socket);
|
|
370
|
+
} else {
|
|
371
|
+
socket.destroy();
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
await new Promise((resolve2, reject) => {
|
|
375
|
+
server2.once("error", reject);
|
|
376
|
+
server2.listen(port, host, () => {
|
|
377
|
+
server2.off("error", reject);
|
|
378
|
+
resolve2();
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
active = { server: server2, port, host, distDir, startedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
382
|
+
return getStatus();
|
|
383
|
+
}
|
|
384
|
+
async function stop() {
|
|
385
|
+
if (!active) return getStatus();
|
|
386
|
+
const a = active;
|
|
387
|
+
active = null;
|
|
388
|
+
shutdown();
|
|
389
|
+
await new Promise((resolve2) => {
|
|
390
|
+
a.server.close(() => resolve2());
|
|
391
|
+
});
|
|
392
|
+
return getStatus();
|
|
393
|
+
}
|
|
394
|
+
function isRunning() {
|
|
395
|
+
return active !== null;
|
|
396
|
+
}
|
|
397
|
+
function handleHttp(req, res, distDir) {
|
|
398
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
399
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
400
|
+
if (req.method === "GET" && req.url === "/__webui/status") {
|
|
401
|
+
res.statusCode = 200;
|
|
402
|
+
res.setHeader("Content-Type", "application/json");
|
|
403
|
+
res.end(JSON.stringify(getStatus()));
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (!isLocalRequest(req)) {
|
|
407
|
+
res.statusCode = 403;
|
|
408
|
+
res.end();
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
412
|
+
res.statusCode = 405;
|
|
413
|
+
res.end();
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const rawPath = (req.url ?? "/").split("?")[0];
|
|
417
|
+
const decoded = safeDecode(rawPath);
|
|
418
|
+
if (decoded === null) {
|
|
419
|
+
res.statusCode = 400;
|
|
420
|
+
res.end();
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const relative = decoded === "/" ? "index.html" : decoded.replace(/^\/+/, "");
|
|
424
|
+
const fullPath = normalize(join(distDir, relative));
|
|
425
|
+
if (!fullPath.startsWith(distDir + sep) && fullPath !== distDir) {
|
|
426
|
+
res.statusCode = 403;
|
|
427
|
+
res.end();
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (!existsSync(fullPath) || !statSync(fullPath).isFile()) {
|
|
431
|
+
const indexPath = join(distDir, "index.html");
|
|
432
|
+
if (existsSync(indexPath)) {
|
|
433
|
+
serveFile(res, indexPath);
|
|
434
|
+
} else {
|
|
435
|
+
res.statusCode = 503;
|
|
436
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
437
|
+
res.end(missingBundleHtml(distDir));
|
|
438
|
+
}
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
serveFile(res, fullPath);
|
|
442
|
+
}
|
|
443
|
+
function safeDecode(p) {
|
|
444
|
+
try {
|
|
445
|
+
return decodeURIComponent(p);
|
|
446
|
+
} catch {
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function serveFile(res, file) {
|
|
451
|
+
const mime = MIME[extname(file).toLowerCase()] ?? "application/octet-stream";
|
|
452
|
+
res.statusCode = 200;
|
|
453
|
+
res.setHeader("Content-Type", mime);
|
|
454
|
+
createReadStream(file).pipe(res);
|
|
455
|
+
}
|
|
456
|
+
function missingBundleHtml(distDir) {
|
|
457
|
+
return `<!doctype html>
|
|
458
|
+
<html><head><meta charset="utf-8"><title>Recall WebUI \u2014 bundle missing</title>
|
|
459
|
+
<style>body{font-family:system-ui;max-width:560px;margin:80px auto;color:#222;padding:0 16px}code{background:#f4f4f4;padding:2px 4px;border-radius:3px}</style>
|
|
460
|
+
</head><body>
|
|
461
|
+
<h1>WebUI bundle not built</h1>
|
|
462
|
+
<p>The Recall daemon is running and the WebUI port is open, but the static SPA bundle was not found at:</p>
|
|
463
|
+
<pre><code>${escapeHtml(distDir)}</code></pre>
|
|
464
|
+
<p>Run <code>npm run webui:build</code> (or the wrapping <code>npm run build</code>) and reload this page.</p>
|
|
465
|
+
</body></html>`;
|
|
466
|
+
}
|
|
467
|
+
function escapeHtml(s) {
|
|
468
|
+
return s.replace(
|
|
469
|
+
/[&<>"']/g,
|
|
470
|
+
(c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c] ?? c
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// src/daemon.ts
|
|
475
|
+
import { spawn } from "child_process";
|
|
476
|
+
|
|
109
477
|
// src/maintenance/lifecycle.ts
|
|
110
|
-
import { statSync } from "fs";
|
|
111
|
-
import { eq, lt } from "drizzle-orm";
|
|
478
|
+
import { statSync as statSync2 } from "fs";
|
|
112
479
|
var DAY_MS = 864e5;
|
|
113
480
|
function loadMaintenanceConfigFromEnv() {
|
|
114
481
|
return {
|
|
@@ -119,6 +486,8 @@ function loadMaintenanceConfigFromEnv() {
|
|
|
119
486
|
activity_retention_days: parseInt(process.env.RECALL_ACTIVITY_RETENTION_DAYS ?? "90", 10),
|
|
120
487
|
feedback_retention_days: parseInt(process.env.RECALL_FEEDBACK_RETENTION_DAYS ?? "180", 10),
|
|
121
488
|
signal_retention_days: parseInt(process.env.RECALL_SIGNAL_RETENTION_DAYS ?? "180", 10),
|
|
489
|
+
rejected_retention_days: parseInt(process.env.RECALL_REJECTED_RETENTION_DAYS ?? "90", 10),
|
|
490
|
+
transient_retention_days: parseInt(process.env.RECALL_TRANSIENT_RETENTION_DAYS ?? "7", 10),
|
|
122
491
|
history_session_retention_days: parseInt(process.env.RECALL_HISTORY_SESSION_RETENTION_DAYS ?? "30", 10),
|
|
123
492
|
sqlite_analyze_enabled: process.env.RECALL_SQLITE_ANALYZE_ENABLED !== "false",
|
|
124
493
|
sqlite_optimize_enabled: process.env.RECALL_SQLITE_OPTIMIZE_ENABLED !== "false",
|
|
@@ -146,7 +515,9 @@ function loadMaintenanceConfigFromEnv() {
|
|
|
146
515
|
async function runMaintenanceCycle(db2, config = loadMaintenanceConfigFromEnv()) {
|
|
147
516
|
const prune = pruneMemories(db2, {
|
|
148
517
|
stale_days: config.stale_days,
|
|
149
|
-
min_health_score: config.min_health_score
|
|
518
|
+
min_health_score: config.min_health_score,
|
|
519
|
+
rejected_retention_days: config.rejected_retention_days,
|
|
520
|
+
transient_retention_days: config.transient_retention_days
|
|
150
521
|
});
|
|
151
522
|
const scannedMemoryCleanup = reconcileScannedMemories(db2);
|
|
152
523
|
const candidates_promoted = promoteRepetitionCandidates(db2);
|
|
@@ -331,7 +702,7 @@ function runSqliteMaintenance(db2, config) {
|
|
|
331
702
|
function shouldTruncateWal(sqlite, thresholdBytes) {
|
|
332
703
|
if (!Number.isFinite(thresholdBytes) || thresholdBytes <= 0) return false;
|
|
333
704
|
try {
|
|
334
|
-
return
|
|
705
|
+
return statSync2(`${sqlite.name}-wal`).size >= thresholdBytes;
|
|
335
706
|
} catch {
|
|
336
707
|
return false;
|
|
337
708
|
}
|
|
@@ -634,6 +1005,9 @@ function sendJsonRpcError(res, status, code, message) {
|
|
|
634
1005
|
}
|
|
635
1006
|
|
|
636
1007
|
// src/daemon.ts
|
|
1008
|
+
function safeIngestMemory(memoryId) {
|
|
1009
|
+
safeIngestMemoryById(db, memoryId);
|
|
1010
|
+
}
|
|
637
1011
|
var db;
|
|
638
1012
|
var PORT = parseInt(process.env.RECALL_PORT ?? "7890", 10);
|
|
639
1013
|
var requireFromHere = createRequire(import.meta.url);
|
|
@@ -657,14 +1031,14 @@ var qualitySnapshotConfig = {
|
|
|
657
1031
|
};
|
|
658
1032
|
var qualitySnapshotRunning = false;
|
|
659
1033
|
function parseBody(req) {
|
|
660
|
-
return new Promise((
|
|
1034
|
+
return new Promise((resolve2, reject) => {
|
|
661
1035
|
const chunks = [];
|
|
662
1036
|
req.on("data", (c) => chunks.push(c));
|
|
663
1037
|
req.on("end", () => {
|
|
664
1038
|
try {
|
|
665
|
-
|
|
1039
|
+
resolve2(JSON.parse(Buffer.concat(chunks).toString()));
|
|
666
1040
|
} catch {
|
|
667
|
-
|
|
1041
|
+
resolve2({});
|
|
668
1042
|
}
|
|
669
1043
|
});
|
|
670
1044
|
req.on("error", reject);
|
|
@@ -718,6 +1092,12 @@ async function runDispatcherOnce() {
|
|
|
718
1092
|
console.log(
|
|
719
1093
|
`[recall] dispatcher ${report.provider}: attempted=${report.attempted} applied=${report.applied} rejected=${report.rejected} released=${report.released}`
|
|
720
1094
|
);
|
|
1095
|
+
emit("dispatcher.tick", {
|
|
1096
|
+
provider: report.provider ?? "unknown",
|
|
1097
|
+
attempted: report.attempted,
|
|
1098
|
+
applied: report.applied,
|
|
1099
|
+
rejected: report.rejected
|
|
1100
|
+
});
|
|
721
1101
|
}
|
|
722
1102
|
} catch (error) {
|
|
723
1103
|
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
@@ -757,6 +1137,12 @@ function scheduleCleanupLoop() {
|
|
|
757
1137
|
console.log(
|
|
758
1138
|
`[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}`
|
|
759
1139
|
);
|
|
1140
|
+
emit("cleanup.tick", {
|
|
1141
|
+
run_id: report.run_id,
|
|
1142
|
+
merges: c.dedupe_clusters,
|
|
1143
|
+
promotions: c.repeat_promotions,
|
|
1144
|
+
suppressions: c.command_suppressions
|
|
1145
|
+
});
|
|
760
1146
|
}
|
|
761
1147
|
const newContradictions = detectContradictions(db);
|
|
762
1148
|
if (newContradictions.length > 0) {
|
|
@@ -766,6 +1152,14 @@ function scheduleCleanupLoop() {
|
|
|
766
1152
|
for (const c2 of newContradictions.slice(0, 5)) {
|
|
767
1153
|
console.log(` [${c2.severity}] ${c2.contradiction_type}: ${c2.description.slice(0, 120)}`);
|
|
768
1154
|
}
|
|
1155
|
+
for (const c2 of newContradictions) {
|
|
1156
|
+
emit("contradiction.detected", {
|
|
1157
|
+
contradiction_id: c2.id,
|
|
1158
|
+
memory_a: c2.memory_a_id,
|
|
1159
|
+
memory_b: c2.memory_b_id,
|
|
1160
|
+
severity: c2.severity
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
769
1163
|
}
|
|
770
1164
|
} catch (error) {
|
|
771
1165
|
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
@@ -808,7 +1202,7 @@ function scheduleQualitySnapshotLoop() {
|
|
|
808
1202
|
const timer = setInterval(run, 3600 * 1e3);
|
|
809
1203
|
timer.unref?.();
|
|
810
1204
|
}
|
|
811
|
-
var server =
|
|
1205
|
+
var server = createServer2(async (req, res) => {
|
|
812
1206
|
const url = new URL(req.url ?? "/", `http://localhost:${PORT}`);
|
|
813
1207
|
const path = url.pathname;
|
|
814
1208
|
const method = req.method ?? "GET";
|
|
@@ -912,6 +1306,11 @@ var server = createServer(async (req, res) => {
|
|
|
912
1306
|
path: body.path ?? null,
|
|
913
1307
|
meta: body.meta ?? {}
|
|
914
1308
|
});
|
|
1309
|
+
emit("session.started", {
|
|
1310
|
+
session_id: body.session_id,
|
|
1311
|
+
client: body.client ?? null,
|
|
1312
|
+
repo: body.repo ?? null
|
|
1313
|
+
});
|
|
915
1314
|
return send(res, 200, result);
|
|
916
1315
|
}
|
|
917
1316
|
if (path === "/session/event" && method === "POST") {
|
|
@@ -945,8 +1344,120 @@ var server = createServer(async (req, res) => {
|
|
|
945
1344
|
meta: body.meta ?? {},
|
|
946
1345
|
payload: body.payload ?? {}
|
|
947
1346
|
});
|
|
1347
|
+
emit("session.ended", {
|
|
1348
|
+
session_id: body.session_id,
|
|
1349
|
+
repo: body.repo ?? null
|
|
1350
|
+
});
|
|
948
1351
|
return send(res, 200, result);
|
|
949
1352
|
}
|
|
1353
|
+
if (path === "/graph/stats" && method === "GET") {
|
|
1354
|
+
return send(res, 200, {
|
|
1355
|
+
entities: countEntities(db),
|
|
1356
|
+
relations: countRelations(db)
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
if (path === "/graph/relations" && method === "GET") {
|
|
1360
|
+
const repo = url.searchParams.get("repo") ?? void 0;
|
|
1361
|
+
const limit = parseInt(url.searchParams.get("limit") ?? "2000", 10);
|
|
1362
|
+
const rows = listAllRelations(db, { repo, limit });
|
|
1363
|
+
return send(res, 200, { count: rows.length, relations: rows });
|
|
1364
|
+
}
|
|
1365
|
+
if (path === "/graph/entities" && method === "GET") {
|
|
1366
|
+
const repo = url.searchParams.get("repo") ?? void 0;
|
|
1367
|
+
const kind = url.searchParams.get("kind");
|
|
1368
|
+
const search = url.searchParams.get("search") ?? void 0;
|
|
1369
|
+
const limit = parseInt(url.searchParams.get("limit") ?? "100", 10);
|
|
1370
|
+
const rows = listEntities(db, {
|
|
1371
|
+
repo,
|
|
1372
|
+
kind: kind ?? void 0,
|
|
1373
|
+
search,
|
|
1374
|
+
limit
|
|
1375
|
+
});
|
|
1376
|
+
return send(res, 200, {
|
|
1377
|
+
count: rows.length,
|
|
1378
|
+
entities: rows
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
if (path === "/graph/query" && method === "POST") {
|
|
1382
|
+
const body = await parseBody(req);
|
|
1383
|
+
if (!body.query || typeof body.query !== "string") {
|
|
1384
|
+
return send(res, 400, { error: "query (string) required" });
|
|
1385
|
+
}
|
|
1386
|
+
const embeddingConfig = loadEmbeddingConfigFromEnv();
|
|
1387
|
+
const result = await graphQuery(db, body.query, embeddingConfig, {
|
|
1388
|
+
repo: body.repo,
|
|
1389
|
+
hops: typeof body.hops === "number" ? body.hops : void 0,
|
|
1390
|
+
limit: typeof body.limit === "number" ? body.limit : void 0,
|
|
1391
|
+
relationTypes: Array.isArray(body.relation_types) ? body.relation_types : void 0
|
|
1392
|
+
});
|
|
1393
|
+
return send(res, 200, {
|
|
1394
|
+
seed_count: result.seed_count,
|
|
1395
|
+
expanded_entities: result.expanded_entities,
|
|
1396
|
+
hits: result.hits.map((h) => ({
|
|
1397
|
+
memory_id: h.memory.id,
|
|
1398
|
+
text: h.memory.text,
|
|
1399
|
+
repo: h.memory.repo,
|
|
1400
|
+
scope: h.memory.scope,
|
|
1401
|
+
status: h.memory.status,
|
|
1402
|
+
via: h.via,
|
|
1403
|
+
score: h.score,
|
|
1404
|
+
hops: h.hops,
|
|
1405
|
+
shared_entities: h.shared_entities
|
|
1406
|
+
})),
|
|
1407
|
+
entities: result.entities
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
if (path.startsWith("/graph/entity/") && method === "GET") {
|
|
1411
|
+
const id = path.slice("/graph/entity/".length);
|
|
1412
|
+
const ent = getEntity(db, id);
|
|
1413
|
+
if (!ent) return send(res, 404, { error: "entity not found" });
|
|
1414
|
+
return send(res, 200, {
|
|
1415
|
+
entity: ent,
|
|
1416
|
+
memories: listMemoryIdsForEntity(db, id)
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
if (path === "/graph/neighbors" && method === "POST") {
|
|
1420
|
+
const body = await parseBody(req);
|
|
1421
|
+
if (!body.entity_id || typeof body.entity_id !== "string") {
|
|
1422
|
+
return send(res, 400, { error: "entity_id (string) required" });
|
|
1423
|
+
}
|
|
1424
|
+
const root = getEntity(db, body.entity_id);
|
|
1425
|
+
if (!root) return send(res, 404, { error: "entity not found" });
|
|
1426
|
+
const walk = neighborsOf(db, body.entity_id, {
|
|
1427
|
+
hops: typeof body.hops === "number" ? body.hops : void 0,
|
|
1428
|
+
relationTypes: Array.isArray(body.relation_types) ? body.relation_types : void 0
|
|
1429
|
+
});
|
|
1430
|
+
const includeMemories = body.include_memories !== false;
|
|
1431
|
+
const memoriesByEntity = includeMemories ? Object.fromEntries(walk.entities.map((e) => [e.id, listMemoryIdsForEntity(db, e.id)])) : {};
|
|
1432
|
+
return send(res, 200, {
|
|
1433
|
+
root,
|
|
1434
|
+
entities: walk.entities,
|
|
1435
|
+
relations: walk.relations,
|
|
1436
|
+
memories_by_entity: memoriesByEntity
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
if (path.startsWith("/graph/memory/") && method === "GET") {
|
|
1440
|
+
const memId = path.slice("/graph/memory/".length);
|
|
1441
|
+
const ents = listEntitiesForMemory(db, memId);
|
|
1442
|
+
return send(res, 200, { memory_id: memId, entities: ents });
|
|
1443
|
+
}
|
|
1444
|
+
if (path === "/webui/status" && method === "GET") {
|
|
1445
|
+
return send(res, 200, getStatus());
|
|
1446
|
+
}
|
|
1447
|
+
if (path === "/webui/start" && method === "POST") {
|
|
1448
|
+
const body = await parseBody(req).catch(() => ({}));
|
|
1449
|
+
const status = await start({
|
|
1450
|
+
port: typeof body.port === "number" ? body.port : void 0
|
|
1451
|
+
});
|
|
1452
|
+
if (body.open !== false && status.url) {
|
|
1453
|
+
openInBrowser(status.url);
|
|
1454
|
+
}
|
|
1455
|
+
return send(res, 200, status);
|
|
1456
|
+
}
|
|
1457
|
+
if (path === "/webui/stop" && method === "POST") {
|
|
1458
|
+
const status = await stop();
|
|
1459
|
+
return send(res, 200, status);
|
|
1460
|
+
}
|
|
950
1461
|
if (path === "/dispatch/wake" && method === "POST") {
|
|
951
1462
|
wakeDispatcherDebounced();
|
|
952
1463
|
return send(res, 202, { status: "queued", debounce_ms: DISPATCH_WAKE_DEBOUNCE_MS });
|
|
@@ -1013,6 +1524,14 @@ var server = createServer(async (req, res) => {
|
|
|
1013
1524
|
request: { text: body.text },
|
|
1014
1525
|
result: { created: ids }
|
|
1015
1526
|
});
|
|
1527
|
+
for (const id of ids) {
|
|
1528
|
+
safeIngestMemory(id);
|
|
1529
|
+
emit("memory.created", {
|
|
1530
|
+
memory_id: id,
|
|
1531
|
+
repo: repo ?? null,
|
|
1532
|
+
source: "correction"
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1016
1535
|
return send(res, 200, { created: ids });
|
|
1017
1536
|
}
|
|
1018
1537
|
if (path === "/review" && method === "POST") {
|
|
@@ -1034,11 +1553,26 @@ var server = createServer(async (req, res) => {
|
|
|
1034
1553
|
request: { feedback: body.feedback, reviewer: body.reviewer ?? null },
|
|
1035
1554
|
result: { created: ids }
|
|
1036
1555
|
});
|
|
1556
|
+
for (const id of ids) {
|
|
1557
|
+
safeIngestMemory(id);
|
|
1558
|
+
emit("memory.created", {
|
|
1559
|
+
memory_id: id,
|
|
1560
|
+
repo: repo ?? null,
|
|
1561
|
+
source: "review"
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1037
1564
|
return send(res, 200, { created: ids });
|
|
1038
1565
|
}
|
|
1039
1566
|
if (path === "/confirm" && method === "POST") {
|
|
1040
1567
|
const body = await parseBody(req);
|
|
1041
1568
|
const ok = confirmMemory(db, body.memory_id);
|
|
1569
|
+
if (ok) {
|
|
1570
|
+
const mem = getMemory(db, body.memory_id);
|
|
1571
|
+
emit("memory.confirmed", {
|
|
1572
|
+
memory_id: body.memory_id,
|
|
1573
|
+
repo: mem?.repo ?? null
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1042
1576
|
return send(res, ok ? 200 : 404, { success: ok });
|
|
1043
1577
|
}
|
|
1044
1578
|
if (path === "/reject" && method === "POST") {
|
|
@@ -1056,6 +1590,11 @@ var server = createServer(async (req, res) => {
|
|
|
1056
1590
|
before ? JSON.stringify(before) : null,
|
|
1057
1591
|
after ? JSON.stringify(after) : null
|
|
1058
1592
|
);
|
|
1593
|
+
emit("memory.rejected", {
|
|
1594
|
+
memory_id: body.memory_id,
|
|
1595
|
+
repo: before?.repo ?? null,
|
|
1596
|
+
actor: "daemon:http"
|
|
1597
|
+
});
|
|
1059
1598
|
}
|
|
1060
1599
|
return send(res, ok ? 200 : 404, { success: ok });
|
|
1061
1600
|
}
|
|
@@ -1076,20 +1615,26 @@ var server = createServer(async (req, res) => {
|
|
|
1076
1615
|
request: { injected: body.injected, outcome: body.outcome },
|
|
1077
1616
|
result: { feedback_id: id }
|
|
1078
1617
|
});
|
|
1618
|
+
emit("feedback.recorded", {
|
|
1619
|
+
memory_id: body.memory_id,
|
|
1620
|
+
session_id: body.session_id,
|
|
1621
|
+
outcome: String(body.outcome ?? ""),
|
|
1622
|
+
injected: Boolean(body.injected)
|
|
1623
|
+
});
|
|
1079
1624
|
return send(res, 200, { feedback_id: id });
|
|
1080
1625
|
}
|
|
1081
1626
|
if (path === "/memories" && method === "GET") {
|
|
1082
1627
|
const repo = url.searchParams.get("repo") ?? void 0;
|
|
1083
1628
|
const status = url.searchParams.get("status");
|
|
1084
|
-
const limit = url.searchParams.get("limit");
|
|
1085
|
-
const offset = url.searchParams.get("offset");
|
|
1086
|
-
const items = queryMemories(db, {
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1629
|
+
const limit = parseInt(url.searchParams.get("limit") ?? "50", 10);
|
|
1630
|
+
const offset = parseInt(url.searchParams.get("offset") ?? "0", 10);
|
|
1631
|
+
const items = queryMemories(db, { repo, status, limit, offset });
|
|
1632
|
+
return send(res, 200, {
|
|
1633
|
+
memories: items,
|
|
1634
|
+
offset,
|
|
1635
|
+
limit,
|
|
1636
|
+
has_more: items.length === limit
|
|
1091
1637
|
});
|
|
1092
|
-
return send(res, 200, { memories: items });
|
|
1093
1638
|
}
|
|
1094
1639
|
if (path.startsWith("/memory/") && method === "GET") {
|
|
1095
1640
|
const id = path.slice("/memory/".length);
|
|
@@ -1118,6 +1663,21 @@ var server = createServer(async (req, res) => {
|
|
|
1118
1663
|
artifact_written: artifact.written
|
|
1119
1664
|
}
|
|
1120
1665
|
});
|
|
1666
|
+
emit("scan.completed", {
|
|
1667
|
+
repo: mem?.repo ?? null,
|
|
1668
|
+
created: ids.length,
|
|
1669
|
+
repo_path: body.repo_path
|
|
1670
|
+
});
|
|
1671
|
+
for (const id of ids) {
|
|
1672
|
+
safeIngestMemory(id);
|
|
1673
|
+
const m = getMemory(db, id);
|
|
1674
|
+
emit("memory.created", {
|
|
1675
|
+
memory_id: id,
|
|
1676
|
+
repo: m?.repo ?? null,
|
|
1677
|
+
source: "scan",
|
|
1678
|
+
type: m?.type
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1121
1681
|
return send(res, 200, {
|
|
1122
1682
|
created: ids,
|
|
1123
1683
|
count: ids.length,
|
|
@@ -1199,9 +1759,17 @@ var server = createServer(async (req, res) => {
|
|
|
1199
1759
|
const event_type = url.searchParams.get("event_type");
|
|
1200
1760
|
const since = url.searchParams.get("since") ?? void 0;
|
|
1201
1761
|
const limit = parseInt(url.searchParams.get("limit") ?? "20", 10);
|
|
1202
|
-
|
|
1203
|
-
|
|
1762
|
+
const offset = parseInt(url.searchParams.get("offset") ?? "0", 10);
|
|
1763
|
+
const events = listActivityEvents(db, {
|
|
1764
|
+
repo,
|
|
1765
|
+
session_id,
|
|
1766
|
+
source,
|
|
1767
|
+
event_type,
|
|
1768
|
+
since,
|
|
1769
|
+
limit,
|
|
1770
|
+
offset
|
|
1204
1771
|
});
|
|
1772
|
+
return send(res, 200, { events, offset, limit, has_more: events.length === limit });
|
|
1205
1773
|
}
|
|
1206
1774
|
if (path === "/sessions" && method === "GET") {
|
|
1207
1775
|
const repo = url.searchParams.get("repo") ?? void 0;
|
|
@@ -1209,8 +1777,20 @@ var server = createServer(async (req, res) => {
|
|
|
1209
1777
|
const event_type = url.searchParams.get("event_type");
|
|
1210
1778
|
const since = url.searchParams.get("since") ?? void 0;
|
|
1211
1779
|
const limit = parseInt(url.searchParams.get("limit") ?? "20", 10);
|
|
1780
|
+
const offset = parseInt(url.searchParams.get("offset") ?? "0", 10);
|
|
1781
|
+
const grouped = listActivitySessions(db, {
|
|
1782
|
+
repo,
|
|
1783
|
+
source,
|
|
1784
|
+
event_type,
|
|
1785
|
+
since,
|
|
1786
|
+
limit: Math.max(limit + offset, 200)
|
|
1787
|
+
});
|
|
1788
|
+
const page = grouped.slice(offset, offset + limit);
|
|
1212
1789
|
return send(res, 200, {
|
|
1213
|
-
sessions:
|
|
1790
|
+
sessions: page,
|
|
1791
|
+
offset,
|
|
1792
|
+
limit,
|
|
1793
|
+
has_more: grouped.length > offset + limit
|
|
1214
1794
|
});
|
|
1215
1795
|
}
|
|
1216
1796
|
if (path === "/policy/list" && method === "GET") {
|
|
@@ -1257,18 +1837,41 @@ var server = createServer(async (req, res) => {
|
|
|
1257
1837
|
if (path === "/contradictions/detect" && method === "POST") {
|
|
1258
1838
|
const body = await parseBody(req);
|
|
1259
1839
|
const found = detectContradictions(db, body.repo);
|
|
1840
|
+
for (const c of found) {
|
|
1841
|
+
emit("contradiction.detected", {
|
|
1842
|
+
contradiction_id: c.id,
|
|
1843
|
+
memory_a: c.memory_a_id,
|
|
1844
|
+
memory_b: c.memory_b_id,
|
|
1845
|
+
severity: c.severity
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1260
1848
|
return send(res, 200, { contradictions: found });
|
|
1261
1849
|
}
|
|
1262
1850
|
if (path === "/contradictions" && method === "GET") {
|
|
1263
1851
|
const resolved = url.searchParams.get("resolved");
|
|
1852
|
+
const limit = parseInt(url.searchParams.get("limit") ?? "50", 10);
|
|
1853
|
+
const offset = parseInt(url.searchParams.get("offset") ?? "0", 10);
|
|
1264
1854
|
const items = listContradictions(db, {
|
|
1265
|
-
resolved: resolved === "true" ? true : resolved === "false" ? false : void 0
|
|
1855
|
+
resolved: resolved === "true" ? true : resolved === "false" ? false : void 0,
|
|
1856
|
+
limit,
|
|
1857
|
+
offset
|
|
1858
|
+
});
|
|
1859
|
+
return send(res, 200, {
|
|
1860
|
+
contradictions: items,
|
|
1861
|
+
offset,
|
|
1862
|
+
limit,
|
|
1863
|
+
has_more: items.length === limit
|
|
1266
1864
|
});
|
|
1267
|
-
return send(res, 200, { contradictions: items });
|
|
1268
1865
|
}
|
|
1269
1866
|
if (path === "/contradictions/resolve" && method === "POST") {
|
|
1270
1867
|
const body = await parseBody(req);
|
|
1271
1868
|
const ok = resolveContradiction(db, body.contradiction_id, body.keep_memory_id, body.actor ?? "daemon", body.resolution);
|
|
1869
|
+
if (ok) {
|
|
1870
|
+
emit("contradiction.resolved", {
|
|
1871
|
+
contradiction_id: body.contradiction_id,
|
|
1872
|
+
keep_memory_id: body.keep_memory_id
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1272
1875
|
return send(res, ok ? 200 : 404, { success: ok });
|
|
1273
1876
|
}
|
|
1274
1877
|
if (path === "/contradictions/auto-resolve" && method === "POST") {
|
|
@@ -1305,6 +1908,20 @@ function send(res, status, data) {
|
|
|
1305
1908
|
res.statusCode = status;
|
|
1306
1909
|
res.end(JSON.stringify(data));
|
|
1307
1910
|
}
|
|
1911
|
+
function openInBrowser(url) {
|
|
1912
|
+
const platform = process.platform;
|
|
1913
|
+
try {
|
|
1914
|
+
if (platform === "darwin") {
|
|
1915
|
+
spawn("open", [url], { detached: true, stdio: "ignore" }).unref();
|
|
1916
|
+
} else if (platform === "win32") {
|
|
1917
|
+
spawn("cmd", ["/c", "start", "", url], { detached: true, stdio: "ignore" }).unref();
|
|
1918
|
+
} else {
|
|
1919
|
+
spawn("xdg-open", [url], { detached: true, stdio: "ignore" }).unref();
|
|
1920
|
+
}
|
|
1921
|
+
} catch (err) {
|
|
1922
|
+
console.error(`[recall] failed to open browser for ${url}:`, err);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1308
1925
|
async function startDaemon() {
|
|
1309
1926
|
const backup = ensureDailyBackup();
|
|
1310
1927
|
if (backup.created) {
|
|
@@ -1337,4 +1954,7 @@ void startDaemon().catch((error) => {
|
|
|
1337
1954
|
console.error(`[recall] daemon startup failed: ${message}`);
|
|
1338
1955
|
process.exit(1);
|
|
1339
1956
|
});
|
|
1957
|
+
export {
|
|
1958
|
+
isRunning as webUiIsRunning
|
|
1959
|
+
};
|
|
1340
1960
|
//# sourceMappingURL=daemon.js.map
|