mirror of
https://github.com/bendtherules/opencode-multi-model.git
synced 2026-08-18 13:42:21 +00:00
plan: Use runCommand with array input
This commit is contained in:
@@ -127,7 +127,13 @@ export interface CloseSessionResult {
|
||||
// src/core/utils.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.$
|
||||
}
|
||||
|
||||
@@ -180,7 +186,7 @@ export interface WorktreeInfo {
|
||||
|
||||
export async function getWorktreesForSession(sessionName: string): Promise<WorktreeInfo[]> {
|
||||
// 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 homedir = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
||||
@@ -292,8 +298,7 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
|
||||
|
||||
try {
|
||||
// Check if session exists
|
||||
const { exitCode } = await runCommand(`tmux has-session -t ${options.sessionName} 2>/dev/null`);
|
||||
const sessionExists = exitCode === 0;
|
||||
const { ok: sessionExists } = await runCommand(["tmux", "has-session", "-t", options.sessionName]);
|
||||
|
||||
// Get list of worktrees for this session before killing tmux
|
||||
const worktrees = await getWorktreesForSession(options.sessionName);
|
||||
@@ -315,7 +320,7 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
|
||||
|
||||
// Kill tmux session if it exists
|
||||
if (sessionExists) {
|
||||
await runCommand(`tmux kill-session -t ${options.sessionName}`);
|
||||
await runCommand(["tmux", "kill-session", "-t", options.sessionName]);
|
||||
}
|
||||
|
||||
let cleanupPerformed = false;
|
||||
@@ -325,10 +330,10 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
|
||||
for (const worktree of worktrees) {
|
||||
try {
|
||||
// Remove worktree
|
||||
await runCommand(`git worktree remove -f ${worktree.path}`);
|
||||
await runCommand(["git", "worktree", "remove", "-f", worktree.path]);
|
||||
worktreesRemoved.push(worktree.path);
|
||||
|
||||
await runCommand(`git branch -D ${worktree.branch}`);
|
||||
await runCommand(["git", "branch", "-D", worktree.branch]);
|
||||
branchesDeleted.push(worktree.branch);
|
||||
} catch (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
|
||||
const worktreeBase = `~/.local/share/opencode/multi-model/${options.sessionName}`;
|
||||
try {
|
||||
await runCommand(`rmdir ${worktreeBase} 2>/dev/null || true`);
|
||||
await runCommand(["rmdir", worktreeBase]);
|
||||
} catch {
|
||||
// Ignore errors if directory not empty
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user