summaryrefslogtreecommitdiffhomepage
path: root/packages/core/src/db
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-03 15:29:45 +0900
committerAdam Malczewski <[email protected]>2026-06-03 15:30:38 +0900
commit5af9bd021c206b9e4330ab6a549dc8d013d91537 (patch)
tree667dca977d6eb78e09006c5553523230daa2b73f /packages/core/src/db
parentbcc449a5cba183c7358ab48ed4f2140bb1a3238c (diff)
parentbc3ecbe7b72f6da6ed36d0cea5a66de1c440269a (diff)
downloaddispatch-5af9bd021c206b9e4330ab6a549dc8d013d91537.tar.gz
dispatch-5af9bd021c206b9e4330ab6a549dc8d013d91537.zip
Merge branch 'dev' into warm/prompt-cache-warming
# Conflicts: # packages/api/src/agent-manager.ts # packages/api/tests/agent-manager.test.ts # packages/frontend/src/lib/tabs.svelte.ts
Diffstat (limited to 'packages/core/src/db')
-rw-r--r--packages/core/src/db/chunks.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/packages/core/src/db/chunks.ts b/packages/core/src/db/chunks.ts
index e0aadf3..b434a47 100644
--- a/packages/core/src/db/chunks.ts
+++ b/packages/core/src/db/chunks.ts
@@ -225,3 +225,22 @@ export function clearChunksForTab(tabId: string): void {
const db = getDatabase();
db.query("DELETE FROM chunks WHERE tab_id = $tabId").run({ $tabId: tabId });
}
+
+/**
+ * Relocate every chunk row from one tab to another (compaction backup path).
+ *
+ * Used by conversation compaction to move the FULL pre-compaction history off
+ * the canonical tab id (`fromTabId`) onto a freshly-created backup tab id
+ * (`toTabId`), leaving the canonical id free to be re-seeded with the summary +
+ * preserved tail. `seq` values are preserved (they remain per-tab monotonic for
+ * the destination since it starts empty), as are turn ids, so the relocated
+ * history groups identically under its new tab. Returns the number of rows
+ * moved.
+ */
+export function rekeyChunks(fromTabId: string, toTabId: string): number {
+ const db = getDatabase();
+ const result = db
+ .query("UPDATE chunks SET tab_id = $to WHERE tab_id = $from")
+ .run({ $from: fromTabId, $to: toTabId });
+ return Number(result.changes ?? 0);
+}