Skip to content

feat: add conversation storage with WatermelonDB - #4

Merged
Denis Fadeev (fadeev) merged 6 commits into
mainfrom
feat/conversation-storage
Mar 17, 2026
Merged

Denis Fadeev (fadeev) merged 6 commits into
mainfrom
feat/conversation-storage

Conversation

@fadeev

@fadeev Denis Fadeev (fadeev) commented Mar 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Store conversations and messages on disk using the SDK's WatermelonDB storage layer with a custom LokiJS filesystem adapter (~/.anuma/data/)
  • Lazy conversation creation — only persisted when the user sends their first message
  • Auto-generated conversation titles via postApiV1ChatCompletions (fire-and-forget, no storage pollution)
  • New slash commands: /history (resume or delete conversations), /new (start fresh), /model (switch models)
  • New CLI flags: --resume <id>, --reset (wipe all data)

Integration

Requires @nozbe/watermelondb as a new dependency. The SDK must export deleteConversationOp, createConversationOp, createMessageOp, getMessagesOp, getConversationsOp, getConversationOp, updateConversationTitleOp, and StoredConversation from @anuma/sdk/server.

Breaking Changes

None


Note

Medium Risk
Introduces local filesystem-backed persistence and new stateful chat flows (resume/delete/reset), which can affect data integrity and user experience if storage operations fail or schema expectations change.

Overview
Adds on-disk conversation persistence for the chat CLI using the SDK’s WatermelonDB storage layer, including storing user/assistant messages and auto-generating a short conversation title after the first message.

Extends the REPL with --resume/--reset flags and new /history (resume/delete) and /new commands, plus improves picker/error handling and updates docs and tooling (pnpm check, new @nozbe/watermelondb dependency).

Written by Cursor Bugbot for commit 5d32e24. This will update automatically on new commits. Configure here.

Store conversations and messages on disk using the SDK's WatermelonDB
storage layer with a LokiJS filesystem adapter persisting to ~/.anuma/data/.

- Lazy conversation creation (only on first message)
- Auto-generated titles via postApiV1ChatCompletions
- /history command with resume and delete actions
- /new command to start a fresh conversation
- /delete support within /history picker
- --resume flag to continue a conversation by ID
- --reset flag to wipe all stored data
- Ctrl+C handling for interactive prompts
- Fix assistant message content format (string, not blocks)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for all 3 issues found in the latest run.

  • ✅ Fixed: System prompt appended after restored messages on resume
    • The system prompt now uses unshift so it is always the first message even after restored messages are loaded.
  • ✅ Fixed: Title update captures conversationId by reference, causing race
    • The title-generation path now snapshots conversationId before the async call and updates the title using that captured ID.
  • ✅ Fixed: Deleting current conversation leaves stale state active
    • Deleting the active conversation now resets conversationId, clears messages, and reapplies the system prompt baseline to avoid stale writes.

Create PR

Or push these changes by commenting:

@cursor push 1a47b2aa1b
Preview (1a47b2aa1b)
diff --git a/src/commands/chat.ts b/src/commands/chat.ts
--- a/src/commands/chat.ts
+++ b/src/commands/chat.ts
@@ -180,7 +180,7 @@
     }
 
     if (opts.system) {
-      messages.push({ role: "system", content: [{ type: "text", text: opts.system }] });
+      messages.unshift({ role: "system", content: [{ type: "text", text: opts.system }] });
     }
 
     let model = opts.model;
@@ -226,6 +226,14 @@
           console.log(chalk.dim(`Switched to "${picked.conversation.title}" (${restored.length} messages)\n`));
         } else if (picked?.action === "delete") {
           await deleteConversationOp(ctx, picked.conversation.conversationId);
+          if (conversationId === picked.conversation.conversationId) {
+            conversationId = null;
+            isNewConversation = false;
+            messages.length = 0;
+            if (opts.system) {
+              messages.push({ role: "system", content: [{ type: "text", text: opts.system }] });
+            }
+          }
           console.log(chalk.dim(`Deleted "${picked.conversation.title}"\n`));
         }
         rl = createInterface({ input: process.stdin, output: process.stdout });
@@ -281,6 +289,7 @@
       // Generate a proper title in the background after the first message.
       if (isNewConversation) {
         isNewConversation = false;
+        const titleConversationId = conversationId;
 
         postApiV1ChatCompletions({
           baseUrl,
@@ -294,8 +303,8 @@
           },
         }).then(async (res) => {
           const title = (res.data as any)?.choices?.[0]?.message?.content?.trim();
-          if (title) {
-            await updateConversationTitleOp(ctx, conversationId!, title);
+          if (title && titleConversationId) {
+            await updateConversationTitleOp(ctx, titleConversationId, title);
           }
         }).catch(() => {});
       }

Comment thread src/commands/chat.ts Resolved
Comment thread src/commands/chat.ts Resolved
Comment thread src/commands/chat.ts Resolved

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: System prompt lost when resuming via /history
    • When /history resumes a conversation, it now re-adds opts.system after clearing messages so the system prompt is preserved consistently.

Create PR

Or push these changes by commenting:

@cursor push 19eeea1709
Preview (19eeea1709)
diff --git a/src/commands/chat.ts b/src/commands/chat.ts
--- a/src/commands/chat.ts
+++ b/src/commands/chat.ts
@@ -221,6 +221,9 @@
         if (picked?.action === "resume") {
           conversationId = picked.conversation.conversationId;
           messages.length = 0;
+          if (opts.system) {
+            messages.push({ role: "system", content: [{ type: "text", text: opts.system }] });
+          }
           const restored = await loadConversation(conversationId);
           messages.push(...restored);
           console.log(chalk.dim(`Switched to "${picked.conversation.title}" (${restored.length} messages)\n`));

Comment thread src/commands/chat.ts Resolved

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Streaming errors silently swallowed in onError callback
    • Updated onError to accept the error object, stop the spinner as before, and immediately log the error message so streaming-level failures remain visible.

Create PR

Or push these changes by commenting:

@cursor push 8e163d1cb7
Preview (8e163d1cb7)
diff --git a/src/commands/chat.ts b/src/commands/chat.ts
--- a/src/commands/chat.ts
+++ b/src/commands/chat.ts
@@ -338,11 +338,13 @@
             }
             process.stdout.write(chunk);
           },
-          onError: () => {
+          onError: (err: unknown) => {
             if (firstToken) {
               spinner.stop();
               firstToken = false;
             }
+            const message = err instanceof Error ? err.message : String(err);
+            console.error(chalk.red(`Error: ${message}`));
           },
         });
         // #endregion runToolLoop

Comment thread src/commands/chat.ts
if (firstToken) {
spinner.stop();
firstToken = false;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streaming errors silently swallowed in onError callback

Medium Severity

The onError callback no longer captures or logs the error object — its parameter was completely removed. The old code logged errors immediately via console.error. Now, if runToolLoop fires onError for a streaming-level error that doesn't propagate to result.error or cause a throw (e.g., a transient SSE parsing issue), that error becomes entirely invisible to the user. The error details are discarded, making debugging streaming failures much harder.

Fix in Cursor Fix in Web

Comment thread src/db.ts
const _log = console.log;
const _warn = console.warn;
console.log = (...args: any[]) => { if (typeof args[0] === "string" && args[0].includes("[🍉]")) return; _log(...args); };
console.warn = (...args: any[]) => { if (typeof args[0] === "string" && args[0].includes("[🍉]")) return; _warn(...args); };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global console monkey-patching as module import side effect

Low Severity

console.log and console.warn are permanently overridden at module import time to filter WatermelonDB [🍉] messages. This process-wide side effect applies to all code, not just WatermelonDB, and can silently mask important log messages from any library or user code that happens to include that substring. It also makes the behavior surprising for anyone importing db.ts and can interfere with test frameworks.

Fix in Cursor Fix in Web

@fadeev
Denis Fadeev (fadeev) merged commit eb423e2 into main Mar 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant