diff options
Diffstat (limited to 'dist/main/db')
| -rw-r--r-- | dist/main/db/index.js | 33 | ||||
| -rw-r--r-- | dist/main/db/projects.js | 28 | ||||
| -rw-r--r-- | dist/main/db/schema.js | 36 | ||||
| -rw-r--r-- | dist/main/db/sessions.js | 72 |
4 files changed, 169 insertions, 0 deletions
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 @@ | |||
| 1 | "use strict"; | ||
| 2 | var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| 4 | }; | ||
| 5 | Object.defineProperty(exports, "__esModule", { value: true }); | ||
| 6 | exports.getDb = getDb; | ||
| 7 | exports.closeDb = closeDb; | ||
| 8 | const better_sqlite3_1 = __importDefault(require("better-sqlite3")); | ||
| 9 | const electron_1 = require("electron"); | ||
| 10 | const node_path_1 = __importDefault(require("node:path")); | ||
| 11 | const node_fs_1 = __importDefault(require("node:fs")); | ||
| 12 | const schema_1 = require("./schema"); | ||
| 13 | let db = null; | ||
| 14 | function getDb() { | ||
| 15 | if (db) | ||
| 16 | return db; | ||
| 17 | const dbDir = electron_1.app.getPath("userData"); | ||
| 18 | if (!node_fs_1.default.existsSync(dbDir)) { | ||
| 19 | node_fs_1.default.mkdirSync(dbDir, { recursive: true }); | ||
| 20 | } | ||
| 21 | const dbPath = node_path_1.default.join(dbDir, "claude-flow.db"); | ||
| 22 | db = new better_sqlite3_1.default(dbPath); | ||
| 23 | db.pragma("journal_mode = WAL"); | ||
| 24 | db.pragma("foreign_keys = ON"); | ||
| 25 | (0, schema_1.initSchema)(db); | ||
| 26 | return db; | ||
| 27 | } | ||
| 28 | function closeDb() { | ||
| 29 | if (db) { | ||
| 30 | db.close(); | ||
| 31 | db = null; | ||
| 32 | } | ||
| 33 | } | ||
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 @@ | |||
| 1 | "use strict"; | ||
| 2 | Object.defineProperty(exports, "__esModule", { value: true }); | ||
| 3 | exports.listProjects = listProjects; | ||
| 4 | exports.getProject = getProject; | ||
| 5 | exports.createProject = createProject; | ||
| 6 | exports.deleteProject = deleteProject; | ||
| 7 | const index_1 = require("./index"); | ||
| 8 | const uuid_1 = require("uuid"); | ||
| 9 | function listProjects() { | ||
| 10 | return (0, index_1.getDb)() | ||
| 11 | .prepare("SELECT * FROM projects ORDER BY updated_at DESC") | ||
| 12 | .all(); | ||
| 13 | } | ||
| 14 | function getProject(id) { | ||
| 15 | return (0, index_1.getDb)() | ||
| 16 | .prepare("SELECT * FROM projects WHERE id = ?") | ||
| 17 | .get(id); | ||
| 18 | } | ||
| 19 | function createProject(name, projectPath) { | ||
| 20 | const db = (0, index_1.getDb)(); | ||
| 21 | const id = (0, uuid_1.v4)(); | ||
| 22 | const now = Math.floor(Date.now() / 1000); | ||
| 23 | db.prepare("INSERT INTO projects (id, name, path, created_at, updated_at) VALUES (?, ?, ?, ?, ?)").run(id, name, projectPath, now, now); | ||
| 24 | return { id, name, path: projectPath, created_at: now, updated_at: now }; | ||
| 25 | } | ||
| 26 | function deleteProject(id) { | ||
| 27 | (0, index_1.getDb)().prepare("DELETE FROM projects WHERE id = ?").run(id); | ||
| 28 | } | ||
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 @@ | |||
| 1 | "use strict"; | ||
| 2 | Object.defineProperty(exports, "__esModule", { value: true }); | ||
| 3 | exports.initSchema = initSchema; | ||
| 4 | function initSchema(db) { | ||
| 5 | db.exec(` | ||
| 6 | CREATE TABLE IF NOT EXISTS projects ( | ||
| 7 | id TEXT PRIMARY KEY, | ||
| 8 | name TEXT NOT NULL, | ||
| 9 | path TEXT NOT NULL, | ||
| 10 | created_at INTEGER NOT NULL DEFAULT (unixepoch()), | ||
| 11 | updated_at INTEGER NOT NULL DEFAULT (unixepoch()) | ||
| 12 | ); | ||
| 13 | |||
| 14 | CREATE TABLE IF NOT EXISTS sessions ( | ||
| 15 | id TEXT PRIMARY KEY, | ||
| 16 | project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE, | ||
| 17 | name TEXT NOT NULL, | ||
| 18 | phase TEXT NOT NULL DEFAULT 'research', | ||
| 19 | claude_session_id TEXT, | ||
| 20 | permission_mode TEXT NOT NULL DEFAULT 'acceptEdits', | ||
| 21 | created_at INTEGER NOT NULL DEFAULT (unixepoch()), | ||
| 22 | updated_at INTEGER NOT NULL DEFAULT (unixepoch()) | ||
| 23 | ); | ||
| 24 | |||
| 25 | CREATE TABLE IF NOT EXISTS messages ( | ||
| 26 | id TEXT PRIMARY KEY, | ||
| 27 | session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE, | ||
| 28 | role TEXT NOT NULL, | ||
| 29 | content TEXT NOT NULL, | ||
| 30 | created_at INTEGER NOT NULL DEFAULT (unixepoch()) | ||
| 31 | ); | ||
| 32 | |||
| 33 | CREATE INDEX IF NOT EXISTS idx_sessions_project ON sessions(project_id); | ||
| 34 | CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id); | ||
| 35 | `); | ||
| 36 | } | ||
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 @@ | |||
| 1 | "use strict"; | ||
| 2 | Object.defineProperty(exports, "__esModule", { value: true }); | ||
| 3 | exports.listSessions = listSessions; | ||
| 4 | exports.getSession = getSession; | ||
| 5 | exports.createSession = createSession; | ||
| 6 | exports.updateSession = updateSession; | ||
| 7 | exports.deleteSession = deleteSession; | ||
| 8 | exports.listMessages = listMessages; | ||
| 9 | exports.addMessage = addMessage; | ||
| 10 | const index_1 = require("./index"); | ||
| 11 | const uuid_1 = require("uuid"); | ||
| 12 | function listSessions(projectId) { | ||
| 13 | return (0, index_1.getDb)() | ||
| 14 | .prepare("SELECT * FROM sessions WHERE project_id = ? ORDER BY updated_at DESC") | ||
| 15 | .all(projectId); | ||
| 16 | } | ||
| 17 | function getSession(id) { | ||
| 18 | return (0, index_1.getDb)() | ||
| 19 | .prepare("SELECT * FROM sessions WHERE id = ?") | ||
| 20 | .get(id); | ||
| 21 | } | ||
| 22 | function createSession(projectId, name) { | ||
| 23 | const db = (0, index_1.getDb)(); | ||
| 24 | const id = (0, uuid_1.v4)(); | ||
| 25 | const now = Math.floor(Date.now() / 1000); | ||
| 26 | db.prepare(`INSERT INTO sessions (id, project_id, name, phase, permission_mode, created_at, updated_at) | ||
| 27 | VALUES (?, ?, ?, 'research', 'acceptEdits', ?, ?)`).run(id, projectId, name, now, now); | ||
| 28 | return { | ||
| 29 | id, | ||
| 30 | project_id: projectId, | ||
| 31 | name, | ||
| 32 | phase: "research", | ||
| 33 | claude_session_id: null, | ||
| 34 | permission_mode: "acceptEdits", | ||
| 35 | created_at: now, | ||
| 36 | updated_at: now, | ||
| 37 | }; | ||
| 38 | } | ||
| 39 | function updateSession(id, updates) { | ||
| 40 | const db = (0, index_1.getDb)(); | ||
| 41 | const sets = []; | ||
| 42 | const values = []; | ||
| 43 | for (const [key, value] of Object.entries(updates)) { | ||
| 44 | if (value !== undefined) { | ||
| 45 | sets.push(`${key} = ?`); | ||
| 46 | values.push(value); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | if (sets.length > 0) { | ||
| 50 | sets.push("updated_at = ?"); | ||
| 51 | values.push(Math.floor(Date.now() / 1000)); | ||
| 52 | values.push(id); | ||
| 53 | db.prepare(`UPDATE sessions SET ${sets.join(", ")} WHERE id = ?`).run(...values); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | function deleteSession(id) { | ||
| 57 | (0, index_1.getDb)().prepare("DELETE FROM sessions WHERE id = ?").run(id); | ||
| 58 | } | ||
| 59 | // Messages | ||
| 60 | function listMessages(sessionId) { | ||
| 61 | return (0, index_1.getDb)() | ||
| 62 | .prepare("SELECT * FROM messages WHERE session_id = ? ORDER BY created_at ASC") | ||
| 63 | .all(sessionId); | ||
| 64 | } | ||
| 65 | function addMessage(sessionId, role, content) { | ||
| 66 | const db = (0, index_1.getDb)(); | ||
| 67 | const id = (0, uuid_1.v4)(); | ||
| 68 | const now = Math.floor(Date.now() / 1000); | ||
| 69 | db.prepare("INSERT INTO messages (id, session_id, role, content, created_at) VALUES (?, ?, ?, ?, ?)").run(id, sessionId, role, content, now); | ||
| 70 | db.prepare("UPDATE sessions SET updated_at = ? WHERE id = ?").run(now, sessionId); | ||
| 71 | return { id, session_id: sessionId, role, content, created_at: now }; | ||
| 72 | } | ||
