2026-04-18 19:31:22 +09:00
|
|
|
export async function killTmuxSessionIfExists(sessionName: string): Promise<boolean> {
|
2026-04-28 10:45:09 +09:00
|
|
|
const [{ log }, { isInsideTmux }, { getTmuxPath }, { runTmuxCommand }] = await Promise.all([
|
2026-04-18 19:31:22 +09:00
|
|
|
import("../../logger"),
|
|
|
|
|
import("./environment"),
|
|
|
|
|
import("../../../tools/interactive-bash/tmux-path-resolver"),
|
2026-04-28 10:45:09 +09:00
|
|
|
import("../runner"),
|
2026-04-18 19:31:22 +09:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
if (!isInsideTmux()) {
|
|
|
|
|
log("[killTmuxSessionIfExists] SKIP: not inside tmux", { sessionName })
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tmux = await getTmuxPath()
|
|
|
|
|
if (!tmux) {
|
|
|
|
|
log("[killTmuxSessionIfExists] SKIP: tmux not found", { sessionName })
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 10:45:09 +09:00
|
|
|
const hasSessionResult = await runTmuxCommand(tmux, ["has-session", "-t", sessionName])
|
2026-04-18 19:31:22 +09:00
|
|
|
|
2026-04-28 10:45:09 +09:00
|
|
|
if (hasSessionResult.exitCode !== 0) {
|
2026-04-18 19:31:22 +09:00
|
|
|
log("[killTmuxSessionIfExists] SKIP: session not found", { sessionName })
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 10:45:09 +09:00
|
|
|
const killSessionResult = await runTmuxCommand(tmux, ["kill-session", "-t", sessionName])
|
2026-04-18 19:31:22 +09:00
|
|
|
|
2026-04-28 10:45:09 +09:00
|
|
|
if (killSessionResult.exitCode !== 0) {
|
|
|
|
|
log("[killTmuxSessionIfExists] FAILED", {
|
|
|
|
|
sessionName,
|
|
|
|
|
exitCode: killSessionResult.exitCode,
|
|
|
|
|
stderr: killSessionResult.stderr.trim(),
|
|
|
|
|
})
|
2026-04-18 19:31:22 +09:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log("[killTmuxSessionIfExists] SUCCESS", { sessionName })
|
|
|
|
|
return true
|
|
|
|
|
}
|