feat: 添加 Windows Terminal swarm 后端及 swarm 增强

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
unraid
2026-04-22 22:38:09 +08:00
parent c4775fff58
commit 59f8675fa3
17 changed files with 1298 additions and 86 deletions

View File

@@ -24,6 +24,9 @@ let isInsideTmuxCached: boolean | null = null
/** Cached result for isInITerm2 */
let isInITerm2Cached: boolean | null = null
/** Cached result for isInWindowsTerminal */
let isInWindowsTerminalCached: boolean | null = null
/**
* Checks if we're currently running inside a tmux session (synchronous version).
* Uses the original TMUX value captured at module load, not process.env.TMUX,
@@ -75,6 +78,20 @@ export async function isTmuxAvailable(): Promise<boolean> {
return result.code === 0
}
/**
* Checks if wt.exe is available without executing it.
* Do NOT run `wt.exe --version` — wt.exe is a UWP app bridge that opens
* the Windows Terminal GUI to render version info, producing a phantom
* "Windows 终端 1.24.x" window every time availability is checked.
*/
export async function isWindowsTerminalAvailable(): Promise<boolean> {
if (process.env.WT_SESSION) {
return true
}
const result = await execFileNoThrow('where.exe', ['wt.exe'])
return result.code === 0
}
/**
* Checks if we're currently running inside iTerm2.
* Uses multiple detection methods:
@@ -103,6 +120,18 @@ export function isInITerm2(): boolean {
return isInITerm2Cached
}
/**
* Checks if we're currently running inside Windows Terminal.
* Windows Terminal sets WT_SESSION for child processes.
*/
export function isInWindowsTerminal(): boolean {
if (isInWindowsTerminalCached !== null) {
return isInWindowsTerminalCached
}
isInWindowsTerminalCached = !!process.env.WT_SESSION
return isInWindowsTerminalCached
}
/**
* The it2 CLI command name.
*/
@@ -125,4 +154,5 @@ export async function isIt2CliAvailable(): Promise<boolean> {
export function resetDetectionCache(): void {
isInsideTmuxCached = null
isInITerm2Cached = null
isInWindowsTerminalCached = null
}