aboutsummaryrefslogtreecommitdiffstats
path: root/dist/main/db
diff options
context:
space:
mode:
authorClawd <ai@clawd.bot>2026-02-28 15:26:02 -0800
committerClawd <ai@clawd.bot>2026-02-28 15:26:02 -0800
commit519d6b850e07a0387511a8f024dc394250b1a241 (patch)
tree5ee0a1bbbd7410f93a770e8129c88e29b5a5e5fb /dist/main/db
parentbebbffa890c38f12f04b6fafad4c5c5e46e051a8 (diff)
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.
Diffstat (limited to 'dist/main/db')
-rw-r--r--dist/main/db/index.js33
-rw-r--r--dist/main/db/projects.js28
-rw-r--r--dist/main/db/schema.js36
-rw-r--r--dist/main/db/sessions.js72
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";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.getDb = getDb;
7exports.closeDb = closeDb;
8const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
9const electron_1 = require("electron");
10const node_path_1 = __importDefault(require("node:path"));
11const node_fs_1 = __importDefault(require("node:fs"));
12const schema_1 = require("./schema");
13let db = null;
14function 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}
28function 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";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.listProjects = listProjects;
4exports.getProject = getProject;
5exports.createProject = createProject;
6exports.deleteProject = deleteProject;
7const index_1 = require("./index");
8const uuid_1 = require("uuid");
9function listProjects() {
10 return (0, index_1.getDb)()
11 .prepare("SELECT * FROM projects ORDER BY updated_at DESC")
12 .all();
13}
14function getProject(id) {
15 return (0, index_1.getDb)()
16 .prepare("SELECT * FROM projects WHERE id = ?")
17 .get(id);
18}
19function 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}
26function 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";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.initSchema = initSchema;
4function 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";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.listSessions = listSessions;
4exports.getSession = getSession;
5exports.createSession = createSession;
6exports.updateSession = updateSession;
7exports.deleteSession = deleteSession;
8exports.listMessages = listMessages;
9exports.addMessage = addMessage;
10const index_1 = require("./index");
11const uuid_1 = require("uuid");
12function 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}
17function getSession(id) {
18 return (0, index_1.getDb)()
19 .prepare("SELECT * FROM sessions WHERE id = ?")
20 .get(id);
21}
22function 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}
39function 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}
56function deleteSession(id) {
57 (0, index_1.getDb)().prepare("DELETE FROM sessions WHERE id = ?").run(id);
58}
59// Messages
60function 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}
65function 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}