unforgit 0.11.1 → 0.11.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/{chunk-O7I6JQSJ.js → chunk-IYCICAXZ.js} +110 -26
- package/dist/chunk-IYCICAXZ.js.map +1 -0
- package/dist/index.js +59 -13
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-O7I6JQSJ.js.map +0 -1
|
@@ -2922,26 +2922,54 @@ var LocalStore = class {
|
|
|
2922
2922
|
return stats;
|
|
2923
2923
|
}
|
|
2924
2924
|
deprecate(id, reason) {
|
|
2925
|
-
const
|
|
2926
|
-
const result = this.db.prepare(
|
|
2927
|
-
"UPDATE memories SET status = 'deprecated', updated_at = ? WHERE id = ?"
|
|
2928
|
-
).run(now, id);
|
|
2929
|
-
if (reason && result.changes > 0) {
|
|
2925
|
+
const transaction = this.db.transaction(() => {
|
|
2930
2926
|
const mem = this.getById(id);
|
|
2931
|
-
if (mem)
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2927
|
+
if (!mem) return false;
|
|
2928
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2929
|
+
const refs = { ...mem.sourceRefs ?? {} };
|
|
2930
|
+
if (reason) refs.deprecation_reason = reason;
|
|
2931
|
+
const result = this.db.prepare(`
|
|
2932
|
+
UPDATE memories
|
|
2933
|
+
SET status = 'deprecated', source_refs = ?, version = version + 1, updated_at = ?
|
|
2934
|
+
WHERE id = ?
|
|
2935
|
+
`).run(Object.keys(refs).length > 0 ? JSON.stringify(refs) : null, now, id);
|
|
2936
|
+
if (result.changes > 0) {
|
|
2937
|
+
this.db.prepare(`
|
|
2938
|
+
UPDATE sync_state
|
|
2939
|
+
SET local_version = (SELECT version FROM memories WHERE id = ?),
|
|
2940
|
+
sync_status = CASE
|
|
2941
|
+
WHEN remote_version IS NULL AND last_pushed_at IS NULL AND last_pulled_at IS NULL
|
|
2942
|
+
THEN 'synced'
|
|
2943
|
+
ELSE 'pending_push'
|
|
2944
|
+
END
|
|
2945
|
+
WHERE memory_id = ?
|
|
2946
|
+
`).run(id, id);
|
|
2935
2947
|
}
|
|
2936
|
-
|
|
2937
|
-
|
|
2948
|
+
return result.changes > 0;
|
|
2949
|
+
});
|
|
2950
|
+
return transaction.immediate();
|
|
2938
2951
|
}
|
|
2939
2952
|
supersede(oldId, newId) {
|
|
2940
|
-
const
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2953
|
+
const transaction = this.db.transaction(() => {
|
|
2954
|
+
const memory = this.getById(oldId);
|
|
2955
|
+
if (!memory) return false;
|
|
2956
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2957
|
+
const result = this.db.prepare(`
|
|
2958
|
+
UPDATE memories
|
|
2959
|
+
SET status = 'superseded', supersedes_id = ?, version = version + 1, updated_at = ?
|
|
2960
|
+
WHERE id = ?
|
|
2961
|
+
`).run(newId, now, oldId);
|
|
2962
|
+
if (result.changes > 0) {
|
|
2963
|
+
this.db.prepare(`
|
|
2964
|
+
UPDATE sync_state
|
|
2965
|
+
SET local_version = (SELECT version FROM memories WHERE id = ?),
|
|
2966
|
+
sync_status = 'pending_push'
|
|
2967
|
+
WHERE memory_id = ?
|
|
2968
|
+
`).run(oldId, oldId);
|
|
2969
|
+
}
|
|
2970
|
+
return result.changes > 0;
|
|
2971
|
+
});
|
|
2972
|
+
return transaction.immediate();
|
|
2945
2973
|
}
|
|
2946
2974
|
updateVisibility(id, visibility) {
|
|
2947
2975
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -3501,13 +3529,38 @@ var LocalStore = class {
|
|
|
3501
3529
|
state.syncStatus
|
|
3502
3530
|
);
|
|
3503
3531
|
}
|
|
3504
|
-
markAsPushed(memoryId, remoteVersion) {
|
|
3505
|
-
const
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3532
|
+
markAsPushed(memoryId, remoteVersion, expectedVersion) {
|
|
3533
|
+
const transaction = this.db.transaction(() => {
|
|
3534
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3535
|
+
if (expectedVersion === void 0) {
|
|
3536
|
+
const result2 = this.db.prepare(`
|
|
3537
|
+
UPDATE sync_state
|
|
3538
|
+
SET sync_status = 'synced', remote_version = ?, last_pushed_at = ?
|
|
3539
|
+
WHERE memory_id = ?
|
|
3540
|
+
`).run(remoteVersion, now, memoryId);
|
|
3541
|
+
return result2.changes > 0;
|
|
3542
|
+
}
|
|
3543
|
+
const result = this.db.prepare(`
|
|
3544
|
+
UPDATE sync_state
|
|
3545
|
+
SET remote_version = MAX(COALESCE(remote_version, 0), ?),
|
|
3546
|
+
last_pushed_at = ?,
|
|
3547
|
+
sync_status = CASE
|
|
3548
|
+
WHEN local_version = ?
|
|
3549
|
+
AND sync_status = 'pending_push'
|
|
3550
|
+
AND EXISTS (
|
|
3551
|
+
SELECT 1 FROM memories WHERE id = ? AND version = ?
|
|
3552
|
+
)
|
|
3553
|
+
THEN 'synced'
|
|
3554
|
+
WHEN sync_status IN ('conflict', 'pending_pull') THEN sync_status
|
|
3555
|
+
ELSE 'pending_push'
|
|
3556
|
+
END
|
|
3557
|
+
WHERE memory_id = ?
|
|
3558
|
+
`).run(remoteVersion, now, expectedVersion, memoryId, expectedVersion, memoryId);
|
|
3559
|
+
if (result.changes === 0) return false;
|
|
3560
|
+
const state = this.getSyncState(memoryId);
|
|
3561
|
+
return state?.syncStatus === "synced" && state.localVersion === expectedVersion;
|
|
3562
|
+
});
|
|
3563
|
+
return transaction.immediate();
|
|
3511
3564
|
}
|
|
3512
3565
|
markAsPulled(memoryId, localVersion) {
|
|
3513
3566
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -3592,6 +3645,25 @@ var LocalStore = class {
|
|
|
3592
3645
|
newId: row.supersedes_id
|
|
3593
3646
|
}));
|
|
3594
3647
|
}
|
|
3648
|
+
getDeprecatedMemoriesToSync(orgId, repoId) {
|
|
3649
|
+
const rows = this.db.prepare(`
|
|
3650
|
+
SELECT m.*
|
|
3651
|
+
FROM memories m
|
|
3652
|
+
LEFT JOIN sync_state s ON s.memory_id = m.id
|
|
3653
|
+
WHERE m.org_id = ?
|
|
3654
|
+
AND m.repo_id = ?
|
|
3655
|
+
AND m.status = 'deprecated'
|
|
3656
|
+
AND (s.remote_version IS NOT NULL OR s.last_pushed_at IS NOT NULL OR s.last_pulled_at IS NOT NULL)
|
|
3657
|
+
AND (
|
|
3658
|
+
s.sync_status = 'pending_push'
|
|
3659
|
+
OR (
|
|
3660
|
+
s.sync_status = 'synced'
|
|
3661
|
+
AND MAX(COALESCE(s.last_pushed_at, ''), COALESCE(s.last_pulled_at, '')) < m.updated_at
|
|
3662
|
+
)
|
|
3663
|
+
)
|
|
3664
|
+
`).all(orgId, repoId);
|
|
3665
|
+
return rows.map(rowToMemory);
|
|
3666
|
+
}
|
|
3595
3667
|
getLinksToSync(orgId, repoId) {
|
|
3596
3668
|
const rows = this.db.prepare(`
|
|
3597
3669
|
SELECT l.*, ms.id as source_mem_id, mt.id as target_mem_id
|
|
@@ -3612,9 +3684,21 @@ var LocalStore = class {
|
|
|
3612
3684
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3613
3685
|
this.db.prepare(`INSERT OR IGNORE INTO synced_links (link_id, synced_at) VALUES (?, ?)`).run(linkId, now);
|
|
3614
3686
|
}
|
|
3615
|
-
markStatusSynced(memoryId) {
|
|
3687
|
+
markStatusSynced(memoryId, expectedVersion) {
|
|
3616
3688
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3617
|
-
this.db.prepare(`
|
|
3689
|
+
const result = this.db.prepare(`
|
|
3690
|
+
UPDATE sync_state
|
|
3691
|
+
SET last_pushed_at = ?,
|
|
3692
|
+
local_version = ?,
|
|
3693
|
+
sync_status = 'synced'
|
|
3694
|
+
WHERE memory_id = ?
|
|
3695
|
+
AND local_version = ?
|
|
3696
|
+
AND sync_status IN ('pending_push', 'synced')
|
|
3697
|
+
AND EXISTS (
|
|
3698
|
+
SELECT 1 FROM memories WHERE id = ? AND version = ?
|
|
3699
|
+
)
|
|
3700
|
+
`).run(now, expectedVersion, memoryId, expectedVersion, memoryId, expectedVersion);
|
|
3701
|
+
return result.changes > 0;
|
|
3618
3702
|
}
|
|
3619
3703
|
unconsolidate(consolidationId) {
|
|
3620
3704
|
const memory = this.getById(consolidationId);
|
|
@@ -4152,4 +4236,4 @@ export {
|
|
|
4152
4236
|
RemoteClient,
|
|
4153
4237
|
LocalStore
|
|
4154
4238
|
};
|
|
4155
|
-
//# sourceMappingURL=chunk-
|
|
4239
|
+
//# sourceMappingURL=chunk-IYCICAXZ.js.map
|