Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/core/src/types/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export interface Session {
archived?: boolean;
claudeSessionId?: string;
executionMode?: 'plan' | 'execute';
currentBranch?: string;
ownerRepo?: string; // Main repo (upstream in fork, origin otherwise)
isFork?: boolean;
originOwnerRepo?: string; // Origin repo (only for fork workflow)
}

export interface SessionUpdate {
Expand All @@ -50,6 +54,10 @@ export interface SessionUpdate {
skipContinueNext?: boolean;
toolType?: 'claude' | 'codex' | 'gemini' | 'none';
executionMode?: 'plan' | 'execute';
currentBranch?: string;
ownerRepo?: string;
isFork?: boolean;
originOwnerRepo?: string;
}

export interface GitStatus {
Expand Down
62 changes: 62 additions & 0 deletions packages/desktop/src/infrastructure/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class DatabaseService {

const migrations: Migration[] = [
{ version: 1, name: 'add_execution_mode', run: () => this.migrate_001_add_execution_mode() },
{ version: 2, name: 'add_repo_info_cache', run: () => this.migrate_002_add_repo_info_cache() },
// Future migrations go here
];

Expand Down Expand Up @@ -187,6 +188,35 @@ export class DatabaseService {
this.db.prepare("ALTER TABLE sessions ADD COLUMN execution_mode TEXT DEFAULT 'execute'").run();
}
}

// Migration 002: Add repo info cache columns to sessions table
private migrate_002_add_repo_info_cache(): void {
interface SqliteTableInfo {
cid: number;
name: string;
type: string;
notnull: number;
dflt_value: unknown;
pk: number;
}

const tableInfo = this.db.prepare("PRAGMA table_info(sessions)").all() as SqliteTableInfo[];
const existingColumns = new Set(tableInfo.map((col: SqliteTableInfo) => col.name));

if (!existingColumns.has('current_branch')) {
this.db.prepare("ALTER TABLE sessions ADD COLUMN current_branch TEXT").run();
}
if (!existingColumns.has('owner_repo')) {
this.db.prepare("ALTER TABLE sessions ADD COLUMN owner_repo TEXT").run();
}
if (!existingColumns.has('is_fork')) {
this.db.prepare("ALTER TABLE sessions ADD COLUMN is_fork BOOLEAN DEFAULT 0").run();
}
if (!existingColumns.has('origin_owner_repo')) {
this.db.prepare("ALTER TABLE sessions ADD COLUMN origin_owner_repo TEXT").run();
}
}

private ensureSessionsTableColumns(): void {
interface SqliteTableInfo {
cid: number;
Expand Down Expand Up @@ -221,6 +251,22 @@ export class DatabaseService {
if (!existing.has('execution_mode')) {
addColumnBestEffort("ALTER TABLE sessions ADD COLUMN execution_mode TEXT DEFAULT 'execute'", 'execution_mode');
}

if (!existing.has('current_branch')) {
addColumnBestEffort("ALTER TABLE sessions ADD COLUMN current_branch TEXT", 'current_branch');
}

if (!existing.has('owner_repo')) {
addColumnBestEffort("ALTER TABLE sessions ADD COLUMN owner_repo TEXT", 'owner_repo');
}

if (!existing.has('is_fork')) {
addColumnBestEffort("ALTER TABLE sessions ADD COLUMN is_fork BOOLEAN DEFAULT 0", 'is_fork');
}

if (!existing.has('origin_owner_repo')) {
addColumnBestEffort("ALTER TABLE sessions ADD COLUMN origin_owner_repo TEXT", 'origin_owner_repo');
}
}

private migrateTimelineMaskedPrompts(): void {
Expand Down Expand Up @@ -866,6 +912,22 @@ export class DatabaseService {
updates.push('execution_mode = ?');
values.push(data.execution_mode);
}
if (data.current_branch !== undefined) {
updates.push('current_branch = ?');
values.push(data.current_branch);
}
if (data.owner_repo !== undefined) {
updates.push('owner_repo = ?');
values.push(data.owner_repo);
}
if (data.is_fork !== undefined) {
updates.push('is_fork = ?');
values.push(data.is_fork ? 1 : 0);
}
if (data.origin_owner_repo !== undefined) {
updates.push('origin_owner_repo = ?');
values.push(data.origin_owner_repo);
}

if (updates.length === 0) {
return this.getSession(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Add repo info cache fields to sessions table
ALTER TABLE sessions ADD COLUMN current_branch TEXT;
ALTER TABLE sessions ADD COLUMN owner_repo TEXT;
ALTER TABLE sessions ADD COLUMN is_fork BOOLEAN DEFAULT 0;
ALTER TABLE sessions ADD COLUMN origin_owner_repo TEXT;
8 changes: 8 additions & 0 deletions packages/desktop/src/infrastructure/database/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export interface Session {
skip_continue_next?: boolean | null;
archived?: boolean | null;
execution_mode?: 'plan' | 'execute' | null;
current_branch?: string | null;
owner_repo?: string | null;
is_fork?: boolean | null;
origin_owner_repo?: string | null;
}

export interface Project {
Expand Down Expand Up @@ -127,6 +131,10 @@ export interface UpdateSessionData {
base_branch?: string | null;
archived?: boolean;
execution_mode?: 'plan' | 'execute';
current_branch?: string | null;
owner_repo?: string | null;
is_fork?: boolean | null;
origin_owner_repo?: string | null;
}

export interface PromptMarker {
Expand Down
Loading
Loading