codemem 0.30.0-alpha.1 → 0.30.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +45 -6
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -3118,11 +3118,22 @@ cmd$1.action((inputFile, opts) => {
|
|
|
3118
3118
|
`Prompts: ${payload.user_prompts.length.toLocaleString()}`
|
|
3119
3119
|
].join("\n"));
|
|
3120
3120
|
}
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3121
|
+
let result;
|
|
3122
|
+
try {
|
|
3123
|
+
result = importMemories(payload, {
|
|
3124
|
+
dbPath: resolveDbPath(resolveDbOpt(opts)),
|
|
3125
|
+
remapProject: opts.remapProject,
|
|
3126
|
+
dryRun: opts.dryRun
|
|
3127
|
+
});
|
|
3128
|
+
} catch (error) {
|
|
3129
|
+
const message = error instanceof Error ? error.message : "Import failed";
|
|
3130
|
+
if (opts.json) emitJsonError("import_failed", message);
|
|
3131
|
+
else {
|
|
3132
|
+
p.log.error(message);
|
|
3133
|
+
process.exitCode = 1;
|
|
3134
|
+
}
|
|
3135
|
+
return;
|
|
3136
|
+
}
|
|
3126
3137
|
if (opts.json) {
|
|
3127
3138
|
console.log(JSON.stringify({
|
|
3128
3139
|
sessions: result.sessions,
|
|
@@ -3343,6 +3354,14 @@ function forgetMemoryAction(idStr, opts) {
|
|
|
3343
3354
|
}
|
|
3344
3355
|
const store = new MemoryStore(resolveDbPath(resolveDbOpt(opts)));
|
|
3345
3356
|
try {
|
|
3357
|
+
if (!store.get(memoryId)) {
|
|
3358
|
+
if (opts.json) emitJsonError("not_found", `Memory ${memoryId} not found`);
|
|
3359
|
+
else {
|
|
3360
|
+
p.log.error(`Memory ${memoryId} not found`);
|
|
3361
|
+
process.exitCode = 1;
|
|
3362
|
+
}
|
|
3363
|
+
return;
|
|
3364
|
+
}
|
|
3346
3365
|
store.forget(memoryId);
|
|
3347
3366
|
if (opts.json) console.log(JSON.stringify({
|
|
3348
3367
|
id: memoryId,
|
|
@@ -3353,6 +3372,19 @@ function forgetMemoryAction(idStr, opts) {
|
|
|
3353
3372
|
store.close();
|
|
3354
3373
|
}
|
|
3355
3374
|
}
|
|
3375
|
+
function rollbackManualMemory(store, sessionId, memoryId) {
|
|
3376
|
+
store.db.transaction(() => {
|
|
3377
|
+
const row = store.db.prepare("SELECT import_key FROM memory_items WHERE id = ?").get(memoryId);
|
|
3378
|
+
store.db.prepare("DELETE FROM memory_vectors WHERE memory_id = ?").run(memoryId);
|
|
3379
|
+
store.db.prepare("DELETE FROM memory_file_refs WHERE memory_id = ?").run(memoryId);
|
|
3380
|
+
store.db.prepare("DELETE FROM memory_concept_refs WHERE memory_id = ?").run(memoryId);
|
|
3381
|
+
store.db.prepare("DELETE FROM replication_ops WHERE entity_type = 'memory_item' AND (entity_id = ? OR entity_id = ?)").run(row?.import_key ?? "", String(memoryId));
|
|
3382
|
+
store.db.prepare("DELETE FROM memory_items WHERE id = ?").run(memoryId);
|
|
3383
|
+
store.db.prepare(`DELETE FROM sessions
|
|
3384
|
+
WHERE id = ?
|
|
3385
|
+
AND NOT EXISTS (SELECT 1 FROM memory_items WHERE session_id = ?)`).run(sessionId, sessionId);
|
|
3386
|
+
})();
|
|
3387
|
+
}
|
|
3356
3388
|
async function rememberMemoryAction(opts) {
|
|
3357
3389
|
const store = new MemoryStore(resolveDbPath(resolveDbOpt(opts)));
|
|
3358
3390
|
let sessionId = null;
|
|
@@ -3366,8 +3398,14 @@ async function rememberMemoryAction(opts) {
|
|
|
3366
3398
|
metadata: { manual: true }
|
|
3367
3399
|
});
|
|
3368
3400
|
const memId = store.remember(sessionId, opts.kind, opts.title, opts.body, .5, opts.tags);
|
|
3369
|
-
|
|
3401
|
+
if (!store.get(memId)) {
|
|
3402
|
+
await store.flushPendingVectorWrites();
|
|
3403
|
+
rollbackManualMemory(store, sessionId, memId);
|
|
3404
|
+
sessionId = null;
|
|
3405
|
+
throw new Error("unauthorized_scope");
|
|
3406
|
+
}
|
|
3370
3407
|
store.endSession(sessionId, { manual: true });
|
|
3408
|
+
await store.flushPendingVectorWrites();
|
|
3371
3409
|
if (opts.json) console.log(JSON.stringify({ id: memId }));
|
|
3372
3410
|
else p.log.success(`Stored memory ${memId}`);
|
|
3373
3411
|
} catch (err) {
|
|
@@ -4638,6 +4676,7 @@ async function startForegroundViewer(invocation) {
|
|
|
4638
4676
|
host: syncConfig.syncHost,
|
|
4639
4677
|
port: syncConfig.syncPort,
|
|
4640
4678
|
signal: syncAbort.signal,
|
|
4679
|
+
scanner: store.scanner,
|
|
4641
4680
|
onPhaseChange: (phase) => {
|
|
4642
4681
|
if (phase === "running") {
|
|
4643
4682
|
syncRuntimeStatus.phase = null;
|