From 519d6b850e07a0387511a8f024dc394250b1a241 Mon Sep 17 00:00:00 2001 From: Clawd Date: Sat, 28 Feb 2026 15:26:02 -0800 Subject: Clear artifacts when creating new session Each new session now starts with empty research.md and plan.md files, preventing stale content from previous sessions appearing. --- dist/main/db/index.js | 33 ++++++++++++++++++++++ dist/main/db/projects.js | 28 +++++++++++++++++++ dist/main/db/schema.js | 36 ++++++++++++++++++++++++ dist/main/db/sessions.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 169 insertions(+) create mode 100644 dist/main/db/index.js create mode 100644 dist/main/db/projects.js create mode 100644 dist/main/db/schema.js create mode 100644 dist/main/db/sessions.js (limited to 'dist/main/db') diff --git a/dist/main/db/index.js b/dist/main/db/index.js new file mode 100644 index 0000000..652d189 --- /dev/null +++ b/dist/main/db/index.js @@ -0,0 +1,33 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getDb = getDb; +exports.closeDb = closeDb; +const better_sqlite3_1 = __importDefault(require("better-sqlite3")); +const electron_1 = require("electron"); +const node_path_1 = __importDefault(require("node:path")); +const node_fs_1 = __importDefault(require("node:fs")); +const schema_1 = require("./schema"); +let db = null; +function getDb() { + if (db) + return db; + const dbDir = electron_1.app.getPath("userData"); + if (!node_fs_1.default.existsSync(dbDir)) { + node_fs_1.default.mkdirSync(dbDir, { recursive: true }); + } + const dbPath = node_path_1.default.join(dbDir, "claude-flow.db"); + db = new better_sqlite3_1.default(dbPath); + db.pragma("journal_mode = WAL"); + db.pragma("foreign_keys = ON"); + (0, schema_1.initSchema)(db); + return db; +} +function closeDb() { + if (db) { + db.close(); + db = null; + } +} diff --git a/dist/main/db/projects.js b/dist/main/db/projects.js new file mode 100644 index 0000000..af36cc0 --- /dev/null +++ b/dist/main/db/projects.js @@ -0,0 +1,28 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.listProjects = listProjects; +exports.getProject = getProject; +exports.createProject = createProject; +exports.deleteProject = deleteProject; +const index_1 = require("./index"); +const uuid_1 = require("uuid"); +function listProjects() { + return (0, index_1.getDb)() + .prepare("SELECT * FROM projects ORDER BY updated_at DESC") + .all(); +} +function getProject(id) { + return (0, index_1.getDb)() + .prepare("SELECT * FROM projects WHERE id = ?") + .get(id); +} +function createProject(name, projectPath) { + const db = (0, index_1.getDb)(); + const id = (0, uuid_1.v4)(); + const now = Math.floor(Date.now() / 1000); + db.prepare("INSERT INTO projects (id, name, path, created_at, updated_at) VALUES (?, ?, ?, ?, ?)").run(id, name, projectPath, now, now); + return { id, name, path: projectPath, created_at: now, updated_at: now }; +} +function deleteProject(id) { + (0, index_1.getDb)().prepare("DELETE FROM projects WHERE id = ?").run(id); +} diff --git a/dist/main/db/schema.js b/dist/main/db/schema.js new file mode 100644 index 0000000..974e593 --- /dev/null +++ b/dist/main/db/schema.js @@ -0,0 +1,36 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.initSchema = initSchema; +function initSchema(db) { + db.exec(` + CREATE TABLE IF NOT EXISTS projects ( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + path TEXT NOT NULL, + created_at INTEGER NOT NULL DEFAULT (unixepoch()), + updated_at INTEGER NOT NULL DEFAULT (unixepoch()) + ); + + CREATE TABLE IF NOT EXISTS sessions ( + id TEXT PRIMARY KEY, + project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE, + name TEXT NOT NULL, + phase TEXT NOT NULL DEFAULT 'research', + claude_session_id TEXT, + permission_mode TEXT NOT NULL DEFAULT 'acceptEdits', + created_at INTEGER NOT NULL DEFAULT (unixepoch()), + updated_at INTEGER NOT NULL DEFAULT (unixepoch()) + ); + + CREATE TABLE IF NOT EXISTS messages ( + id TEXT PRIMARY KEY, + session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE, + role TEXT NOT NULL, + content TEXT NOT NULL, + created_at INTEGER NOT NULL DEFAULT (unixepoch()) + ); + + CREATE INDEX IF NOT EXISTS idx_sessions_project ON sessions(project_id); + CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id); + `); +} diff --git a/dist/main/db/sessions.js b/dist/main/db/sessions.js new file mode 100644 index 0000000..b554898 --- /dev/null +++ b/dist/main/db/sessions.js @@ -0,0 +1,72 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.listSessions = listSessions; +exports.getSession = getSession; +exports.createSession = createSession; +exports.updateSession = updateSession; +exports.deleteSession = deleteSession; +exports.listMessages = listMessages; +exports.addMessage = addMessage; +const index_1 = require("./index"); +const uuid_1 = require("uuid"); +function listSessions(projectId) { + return (0, index_1.getDb)() + .prepare("SELECT * FROM sessions WHERE project_id = ? ORDER BY updated_at DESC") + .all(projectId); +} +function getSession(id) { + return (0, index_1.getDb)() + .prepare("SELECT * FROM sessions WHERE id = ?") + .get(id); +} +function createSession(projectId, name) { + const db = (0, index_1.getDb)(); + const id = (0, uuid_1.v4)(); + const now = Math.floor(Date.now() / 1000); + db.prepare(`INSERT INTO sessions (id, project_id, name, phase, permission_mode, created_at, updated_at) + VALUES (?, ?, ?, 'research', 'acceptEdits', ?, ?)`).run(id, projectId, name, now, now); + return { + id, + project_id: projectId, + name, + phase: "research", + claude_session_id: null, + permission_mode: "acceptEdits", + created_at: now, + updated_at: now, + }; +} +function updateSession(id, updates) { + const db = (0, index_1.getDb)(); + const sets = []; + const values = []; + for (const [key, value] of Object.entries(updates)) { + if (value !== undefined) { + sets.push(`${key} = ?`); + values.push(value); + } + } + if (sets.length > 0) { + sets.push("updated_at = ?"); + values.push(Math.floor(Date.now() / 1000)); + values.push(id); + db.prepare(`UPDATE sessions SET ${sets.join(", ")} WHERE id = ?`).run(...values); + } +} +function deleteSession(id) { + (0, index_1.getDb)().prepare("DELETE FROM sessions WHERE id = ?").run(id); +} +// Messages +function listMessages(sessionId) { + return (0, index_1.getDb)() + .prepare("SELECT * FROM messages WHERE session_id = ? ORDER BY created_at ASC") + .all(sessionId); +} +function addMessage(sessionId, role, content) { + const db = (0, index_1.getDb)(); + const id = (0, uuid_1.v4)(); + const now = Math.floor(Date.now() / 1000); + db.prepare("INSERT INTO messages (id, session_id, role, content, created_at) VALUES (?, ?, ?, ?, ?)").run(id, sessionId, role, content, now); + db.prepare("UPDATE sessions SET updated_at = ? WHERE id = ?").run(now, sessionId); + return { id, session_id: sessionId, role, content, created_at: now }; +} -- cgit v1.2.3