plan: Use runCommand with array input

This commit is contained in:
2026-03-19 18:11:39 +05:30
parent 0f35f0a66d
commit d016023a14
+13 -8
View File
@@ -127,7 +127,13 @@ export interface CloseSessionResult {
// src/core/utils.ts // src/core/utils.ts
// All helper functions extracted from current multi-model.ts // All helper functions extracted from current multi-model.ts
export function runCommand(command: string): Promise<{ stdout: string; stderr: string; exitCode: number }> { export type CommandResult = {
ok: boolean;
stdout: string;
stderr: string;
};
export async function runCommand(parts: string[]): Promise<CommandResult> {
// Implementation using Bun.$ // Implementation using Bun.$
} }
@@ -180,7 +186,7 @@ export interface WorktreeInfo {
export async function getWorktreesForSession(sessionName: string): Promise<WorktreeInfo[]> { export async function getWorktreesForSession(sessionName: string): Promise<WorktreeInfo[]> {
// Get all worktrees and filter for this session // Get all worktrees and filter for this session
const { stdout } = await runCommand("git worktree list --porcelain"); const { stdout } = await runCommand(["git", "worktree", "list", "--porcelain"]);
const worktrees: WorktreeInfo[] = []; const worktrees: WorktreeInfo[] = [];
const homedir = process.env.HOME || process.env.USERPROFILE || "/tmp"; const homedir = process.env.HOME || process.env.USERPROFILE || "/tmp";
@@ -292,8 +298,7 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
try { try {
// Check if session exists // Check if session exists
const { exitCode } = await runCommand(`tmux has-session -t ${options.sessionName} 2>/dev/null`); const { ok: sessionExists } = await runCommand(["tmux", "has-session", "-t", options.sessionName]);
const sessionExists = exitCode === 0;
// Get list of worktrees for this session before killing tmux // Get list of worktrees for this session before killing tmux
const worktrees = await getWorktreesForSession(options.sessionName); const worktrees = await getWorktreesForSession(options.sessionName);
@@ -315,7 +320,7 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
// Kill tmux session if it exists // Kill tmux session if it exists
if (sessionExists) { if (sessionExists) {
await runCommand(`tmux kill-session -t ${options.sessionName}`); await runCommand(["tmux", "kill-session", "-t", options.sessionName]);
} }
let cleanupPerformed = false; let cleanupPerformed = false;
@@ -325,10 +330,10 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
for (const worktree of worktrees) { for (const worktree of worktrees) {
try { try {
// Remove worktree // Remove worktree
await runCommand(`git worktree remove -f ${worktree.path}`); await runCommand(["git", "worktree", "remove", "-f", worktree.path]);
worktreesRemoved.push(worktree.path); worktreesRemoved.push(worktree.path);
await runCommand(`git branch -D ${worktree.branch}`); await runCommand(["git", "branch", "-D", worktree.branch]);
branchesDeleted.push(worktree.branch); branchesDeleted.push(worktree.branch);
} catch (err) { } catch (err) {
console.warn(`Warning: Failed to cleanup worktree ${worktree.path}: ${err}`); console.warn(`Warning: Failed to cleanup worktree ${worktree.path}: ${err}`);
@@ -338,7 +343,7 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
// Also remove the base directory if empty // Also remove the base directory if empty
const worktreeBase = `~/.local/share/opencode/multi-model/${options.sessionName}`; const worktreeBase = `~/.local/share/opencode/multi-model/${options.sessionName}`;
try { try {
await runCommand(`rmdir ${worktreeBase} 2>/dev/null || true`); await runCommand(["rmdir", worktreeBase]);
} catch { } catch {
// Ignore errors if directory not empty // Ignore errors if directory not empty
} }