Skip to content
20 changes: 11 additions & 9 deletions src/main/ipc/githubIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GitHubService } from '../services/GitHubService';
import { worktreeService } from '../services/WorktreeService';
import { githubCLIInstaller } from '../services/GitHubCLIInstaller';
import { databaseService } from '../services/DatabaseService';
import { exec } from 'child_process';
import { exec, execFile } from 'child_process';
import { promisify } from 'util';
import * as path from 'path';
import * as fs from 'fs';
Expand All @@ -13,6 +13,7 @@ import { homedir } from 'os';
import { quoteShellArg } from '../utils/shellEscape';

const execAsync = promisify(exec);
const execFileAsync = promisify(execFile);
const githubService = new GitHubService();

const slugify = (name: string) =>
Expand Down Expand Up @@ -380,7 +381,7 @@ export function registerGithubIpc() {
// Find the project root from the worktree path
let projectRoot: string;
try {
const { stdout } = await execAsync('git rev-parse --show-toplevel', {
const { stdout } = await execFileAsync('git', ['rev-parse', '--show-toplevel'], {
cwd: worktreePath,
});
projectRoot = stdout.trim();
Expand All @@ -398,7 +399,7 @@ export function registerGithubIpc() {

// Fetch the base branch to ensure we have the latest
try {
await execAsync(`git fetch origin ${quoteShellArg(baseRefName)}`, { cwd: worktreePath });
await execFileAsync('git', ['fetch', 'origin', baseRefName], { cwd: worktreePath });
} catch {
// Best effort — base ref may already be available locally
}
Expand All @@ -409,16 +410,17 @@ export function registerGithubIpc() {
let diff: string;
try {
// Three-dot diff: changes introduced by the PR relative to the merge base
const { stdout } = await execAsync(
`git diff ${quoteShellArg(`origin/${baseRefName}`)}...HEAD`,
{ cwd: worktreePath, maxBuffer: 10 * 1024 * 1024 }
);
const { stdout } = await execFileAsync('git', ['diff', `origin/${baseRefName}...HEAD`], {
cwd: worktreePath,
maxBuffer: 10 * 1024 * 1024,
});
diff = stdout;
} catch {
// Fallback: two-dot diff
try {
const { stdout } = await execAsync(
`git diff ${quoteShellArg(`origin/${baseRefName}`)} HEAD`,
const { stdout } = await execFileAsync(
'git',
['diff', `origin/${baseRefName}`, 'HEAD'],
{ cwd: worktreePath, maxBuffer: 10 * 1024 * 1024 }
);
diff = stdout;
Expand Down
7 changes: 4 additions & 3 deletions src/main/services/DatabaseService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type sqlite3Type from 'sqlite3';
import * as crypto from 'crypto';
import { and, asc, desc, eq, inArray, isNull, ne, or, sql } from 'drizzle-orm';
import { readMigrationFiles } from 'drizzle-orm/migrator';
import { resolveDatabasePath, resolveMigrationsPath } from '../db/path';
Expand Down Expand Up @@ -626,7 +627,7 @@ export class DatabaseService {
.where(eq(conversationsTable.taskId, taskId));

// Create the new conversation
const conversationId = `conv_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
const conversationId = `conv_${crypto.randomUUID()}`;
const newConversation = {
id: conversationId,
taskId,
Expand Down Expand Up @@ -710,7 +711,7 @@ export class DatabaseService {
input: Omit<LineCommentInsert, 'id' | 'createdAt' | 'updatedAt'>
): Promise<string> {
if (this.disabled) return '';
const id = `comment-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
const id = `comment-${crypto.randomUUID()}`;
const { db } = await getDrizzleClient();
await db.insert(lineCommentsTable).values({
id,
Expand Down Expand Up @@ -795,7 +796,7 @@ export class DatabaseService {
}
const { db } = await getDrizzleClient();

const id = connection.id ?? `ssh_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
const id = connection.id ?? `ssh_${crypto.randomUUID()}`;
const now = new Date().toISOString();

const result = await db
Expand Down
Loading