Repository navigation
feat: add conversation storage with WatermelonDB - #4
Conversation
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>
There was a problem hiding this comment.
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
unshiftso it is always the first message even after restored messages are loaded.
- The system prompt now uses
- ✅ Fixed: Title update captures conversationId by reference, causing race
- The title-generation path now snapshots
conversationIdbefore the async call and updates the title using that captured ID.
- The title-generation path now snapshots
- ✅ 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.
- Deleting the active conversation now resets
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(() => {});
}There was a problem hiding this comment.
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
/historyresumes a conversation, it now re-addsopts.systemafter clearing messages so the system prompt is preserved consistently.
- When
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`));There was a problem hiding this comment.
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
onErrorcallback- Updated
onErrorto accept the error object, stop the spinner as before, and immediately log the error message so streaming-level failures remain visible.
- Updated
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| if (firstToken) { | ||
| spinner.stop(); | ||
| firstToken = false; | ||
| } |
There was a problem hiding this comment.
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.
| 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); }; |
There was a problem hiding this comment.
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.



Summary
~/.anuma/data/)postApiV1ChatCompletions(fire-and-forget, no storage pollution)/history(resume or delete conversations),/new(start fresh),/model(switch models)--resume <id>,--reset(wipe all data)Integration
Requires
@nozbe/watermelondbas a new dependency. The SDK must exportdeleteConversationOp,createConversationOp,createMessageOp,getMessagesOp,getConversationsOp,getConversationOp,updateConversationTitleOp, andStoredConversationfrom@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
chatCLI 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/--resetflags and new/history(resume/delete) and/newcommands, plus improves picker/error handling and updates docs and tooling (pnpm check, new@nozbe/watermelondbdependency).Written by Cursor Bugbot for commit 5d32e24. This will update automatically on new commits. Configure here.