diff --git a/src/main/coworkStore.ts b/src/main/coworkStore.ts index 212c0ad728..9a3b0aec3a 100644 --- a/src/main/coworkStore.ts +++ b/src/main/coworkStore.ts @@ -565,15 +565,17 @@ export class CoworkStore { systemPrompt: string = '', executionMode: CoworkExecutionMode = 'local', activeSkillIds: string[] = [], - agentId: string = 'main' + agentId: string = 'main', + options?: { hidden?: boolean } ): CoworkSession { const id = uuidv4(); const now = Date.now(); + const hidden = options?.hidden ? 1 : 0; this.db.run(` - INSERT INTO cowork_sessions (id, title, claude_session_id, status, cwd, system_prompt, execution_mode, active_skill_ids, agent_id, pinned, created_at, updated_at) - VALUES (?, ?, NULL, 'idle', ?, ?, ?, ?, ?, 0, ?, ?) - `, [id, title, cwd, systemPrompt, executionMode, JSON.stringify(activeSkillIds), agentId, now, now]); + INSERT INTO cowork_sessions (id, title, claude_session_id, status, cwd, system_prompt, execution_mode, active_skill_ids, agent_id, pinned, hidden, created_at, updated_at) + VALUES (?, ?, NULL, 'idle', ?, ?, ?, ?, ?, 0, ?, ?, ?) + `, [id, title, cwd, systemPrompt, executionMode, JSON.stringify(activeSkillIds), agentId, hidden, now, now]); this.saveDb(); @@ -728,13 +730,14 @@ export class CoworkStore { rows = this.getAll(` SELECT id, title, status, pinned, agent_id, created_at, updated_at FROM cowork_sessions - WHERE agent_id = ? + WHERE agent_id = ? AND COALESCE(hidden, 0) = 0 ORDER BY pinned DESC, updated_at DESC `, [agentId]); } else { rows = this.getAll(` SELECT id, title, status, pinned, agent_id, created_at, updated_at FROM cowork_sessions + WHERE COALESCE(hidden, 0) = 0 ORDER BY pinned DESC, updated_at DESC `); } @@ -1575,6 +1578,7 @@ export class CoworkStore { const clauses: string[] = [ "m.type IN ('user', 'assistant')", `(${likeClauses.join(' OR ')})`, + 'COALESCE(s.hidden, 0) = 0', ]; const params: Array = terms.map((term) => `%${term}%`); @@ -1656,7 +1660,7 @@ export class CoworkStore { const beforeMs = parseTimeToMs(options.before); const afterMs = parseTimeToMs(options.after); - const clauses: string[] = []; + const clauses: string[] = ['COALESCE(hidden, 0) = 0']; const params: Array = []; if (beforeMs !== null) { @@ -1668,7 +1672,7 @@ export class CoworkStore { params.push(afterMs); } - const whereClause = clauses.length ? `WHERE ${clauses.join(' AND ')}` : ''; + const whereClause = `WHERE ${clauses.join(' AND ')}`; const rows = this.getAll<{ id: string; diff --git a/src/main/libs/openclawChannelSessionSync.ts b/src/main/libs/openclawChannelSessionSync.ts index c83863502a..a8038ce0c2 100644 --- a/src/main/libs/openclawChannelSessionSync.ts +++ b/src/main/libs/openclawChannelSessionSync.ts @@ -408,7 +408,7 @@ export class OpenClawChannelSessionSync { const cwd = this.getDefaultCwd(); console.log('[ChannelSessionSync] creating main agent session: key=', sessionKey, 'cwd=', cwd); - const session = this.coworkStore.createSession('[OpenClaw]', cwd, '', 'local'); + const session = this.coworkStore.createSession('[OpenClaw]', cwd, '', 'local', [], 'main', { hidden: true }); console.log('[ChannelSessionSync] created main agent session:', session.id); this.syncedSessionKeys.set(sessionKey, session.id); diff --git a/src/main/sqliteStore.ts b/src/main/sqliteStore.ts index 8edc44f994..412fb3dad4 100644 --- a/src/main/sqliteStore.ts +++ b/src/main/sqliteStore.ts @@ -260,6 +260,19 @@ export class SqliteStore { // Column already exists or migration not needed. } + // Migration: Add hidden column to cowork_sessions + try { + const sessionCols2 = this.db.exec("PRAGMA table_info(cowork_sessions);"); + const sessionColNames2 = sessionCols2[0]?.values.map((row) => row[1]) || []; + if (!sessionColNames2.includes('hidden')) { + this.db.run('ALTER TABLE cowork_sessions ADD COLUMN hidden INTEGER NOT NULL DEFAULT 0;'); + this.db.run("UPDATE cowork_sessions SET hidden = 1 WHERE title = '[OpenClaw]';"); + this.save(); + } + } catch { + // Column already exists or migration not needed. + } + // Migration: Ensure default 'main' agent exists try { const mainAgent = this.db.exec("SELECT id FROM agents WHERE id = 'main'");