plan: use path helpers in close

This commit is contained in:
2026-03-19 18:12:40 +05:30
parent d016023a14
commit b39b7c95a8
+11 -8
View File
@@ -173,10 +173,14 @@ export function sanitizeName(name: string): string {
// Session name sanitization // Session name sanitization
} }
export function getSessionPath(sessionName: string): string {
const homedir = process.env.HOME || process.env.USERPROFILE || "/tmp";
return `${homedir}/.local/share/opencode/multi-model/${sessionName}`;
}
export function getWorktreePath(sessionName: string, windowName: string): string { export function getWorktreePath(sessionName: string, windowName: string): string {
// Worktree path generation // Worktree path generation
const homedir = process.env.HOME || process.env.USERPROFILE || "/tmp"; return `${getSessionPath(sessionName)}/${windowName}`;
return `${homedir}/.local/share/opencode/multi-model/${sessionName}/${windowName}`;
} }
export interface WorktreeInfo { export interface WorktreeInfo {
@@ -189,8 +193,7 @@ export async function getWorktreesForSession(sessionName: string): Promise<Workt
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 sessionPath = getSessionPath(sessionName);
const sessionPath = `${homedir}/.local/share/opencode/multi-model/${sessionName}`;
let currentWorktree: Partial<WorktreeInfo> = {}; let currentWorktree: Partial<WorktreeInfo> = {};
@@ -236,7 +239,7 @@ import type { MultiModelOptions, MultiModelResult } from "../types";
import { import {
runCommand, shellQuote, normalizeModels, findDuplicates, runCommand, shellQuote, normalizeModels, findDuplicates,
createWindowPlans, suggestModels, formatInvalidModelError, createWindowPlans, suggestModels, formatInvalidModelError,
sanitizeName, getWorktreePath, undoWorktree, getBinaryName sanitizeName, getWorktreePath, getSessionPath, undoWorktree, getBinaryName
} from "./utils"; } from "./utils";
export async function launchMultiModel(options: MultiModelOptions): Promise<MultiModelResult> { export async function launchMultiModel(options: MultiModelOptions): Promise<MultiModelResult> {
@@ -263,7 +266,7 @@ To close the session and cleanup:
Or manually: Or manually:
tmux kill-session -t ${options.sessionName} tmux kill-session -t ${options.sessionName}
rm -rf ~/.local/share/opencode/multi-model/${safeSessionName} && git worktree prune rm -rf ${getSessionPath(safeSessionName)} && git worktree prune
git branch -D $(git branch --format='%(refname:short)' --list 'opencode/${safeSessionName}/*') git branch -D $(git branch --format='%(refname:short)' --list 'opencode/${safeSessionName}/*')
` `
}; };
@@ -275,7 +278,7 @@ Or manually:
```typescript ```typescript
// src/core/close.ts // src/core/close.ts
import type { CloseSessionOptions, CloseSessionResult } from "../types"; import type { CloseSessionOptions, CloseSessionResult } from "../types";
import { runCommand, getWorktreePath, getWorktreesForSession, sanitizeName } from "./utils"; import { runCommand, getSessionPath, getWorktreesForSession, sanitizeName } from "./utils";
import * as readline from "readline"; import * as readline from "readline";
async function promptUser(question: string): Promise<string> { async function promptUser(question: string): Promise<string> {
@@ -341,7 +344,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 = getSessionPath(options.sessionName);
try { try {
await runCommand(["rmdir", worktreeBase]); await runCommand(["rmdir", worktreeBase]);
} catch { } catch {