Skip to content

Commit 8d59fb0

Browse files
author
StackMemory Bot (CLI)
committed
fix(sync): resolve correct DB path + ensure sync tables before force push
- getDbPath() now checks context.db first (where CLI/MCP write frames) - ensureSyncTables() called at start of push/pull (not just in helpers) - Fixes crash on `push --force` when cloud_sync_state table doesn't exist - Skip missing tables (trace_events, entity_states) gracefully - Removed stale PROVENANT_API_KEY from .env (env var precedence bug) - Successfully synced 651 entities to Provenant cloud
1 parent 1db4de1 commit 8d59fb0

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/cli/commands/sync.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,16 @@ function buildConfig(
7777
}
7878

7979
function getDbPath(projectDir: string): string {
80-
// Check project-local first, then ~/.stackmemory/
80+
// Project-local context.db (primary — where CLI/MCP write frames)
81+
const contextDb = join(projectDir, '.stackmemory', 'context.db');
82+
if (existsSync(contextDb)) return contextDb;
83+
// Legacy stackmemory.db in project dir
8184
const localDb = join(projectDir, '.stackmemory', 'stackmemory.db');
8285
if (existsSync(localDb)) return localDb;
83-
return join(homedir(), '.stackmemory', 'stackmemory.db');
86+
// Global fallback
87+
const globalDb = join(homedir(), '.stackmemory', 'stackmemory.db');
88+
if (existsSync(globalDb)) return globalDb;
89+
return contextDb; // Return expected path for error messages
8490
}
8591

8692
export function createLoginCommand(): Command {

src/core/storage/cloud-sync.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export class CloudSyncEngine {
180180
async push(force = false): Promise<CloudSyncPushResult> {
181181
return this.mutex.withLock(async () => {
182182
try {
183+
this.ensureSyncTables();
183184
if (force) {
184185
// Reset all sync state — re-push everything
185186
this.db.prepare(`DELETE FROM cloud_sync_state`).run();
@@ -281,6 +282,7 @@ export class CloudSyncEngine {
281282
async pull(tables?: SyncTable[]): Promise<CloudSyncPullResult> {
282283
return this.mutex.withLock(async () => {
283284
try {
285+
this.ensureSyncTables();
284286
let totalPulled = 0;
285287
let totalApplied = 0;
286288
let totalConflicts = 0;

0 commit comments

Comments
 (0)