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
}
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 {
// Worktree path generation
const homedir = process.env.HOME || process.env.USERPROFILE || "/tmp";
return `${homedir}/.local/share/opencode/multi-model/${sessionName}/${windowName}`;
return `${getSessionPath(sessionName)}/${windowName}`;
}
export interface WorktreeInfo {
@@ -189,8 +193,7 @@ export async function getWorktreesForSession(sessionName: string): Promise<Workt
const { stdout } = await runCommand(["git", "worktree", "list", "--porcelain"]);
const worktrees: WorktreeInfo[] = [];
const homedir = process.env.HOME || process.env.USERPROFILE || "/tmp";
const sessionPath = `${homedir}/.local/share/opencode/multi-model/${sessionName}`;
const sessionPath = getSessionPath(sessionName);
let currentWorktree: Partial<WorktreeInfo> = {};
@@ -236,7 +239,7 @@ import type { MultiModelOptions, MultiModelResult } from "../types";
import {
runCommand, shellQuote, normalizeModels, findDuplicates,
createWindowPlans, suggestModels, formatInvalidModelError,
sanitizeName, getWorktreePath, undoWorktree, getBinaryName
sanitizeName, getWorktreePath, getSessionPath, undoWorktree, getBinaryName
} from "./utils";
export async function launchMultiModel(options: MultiModelOptions): Promise<MultiModelResult> {
@@ -263,7 +266,7 @@ To close the session and cleanup:
Or manually:
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}/*')
`
};
@@ -275,7 +278,7 @@ Or manually:
```typescript
// src/core/close.ts
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";
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
const worktreeBase = `~/.local/share/opencode/multi-model/${options.sessionName}`;
const worktreeBase = getSessionPath(options.sessionName);
try {
await runCommand(["rmdir", worktreeBase]);
} catch {