0aafe20a85
Eliminates 19 unguarded `Bun.*` runtime call sites in the plugin bundle that crashed with `ReferenceError: Bun is not defined` under Electron. Per-tool-call hot paths (executed on every Read/Edit): - src/tools/hashline-edit/hash-computation.ts: Bun.hash.xxHash32 → bunHashXxh32 - src/tools/hashline-edit/hashline-edit-executor.ts: 8 sites via bunFile/bunWrite - src/hooks/hashline-read-enhancer/hook.ts: Bun.file → bunFile - src/hooks/hashline-edit-diff-enhancer/hook.ts: 2 sites via bunFile Plugin-load paths: - src/hooks/claude-code-hooks/config.ts and config-loader.ts: Bun.file → bunFile - src/features/claude-code-mcp-loader/loader.ts: Bun.file → bunFile - src/features/claude-code-plugin-loader/mcp-server-loader.ts: Bun.file → bunFile - src/features/team-mode/deps.ts: Bun.spawn → spawn shim - src/hooks/session-notification-utils.ts: Bun.which → bunWhich, also drops the bare `declare const Bun` ambient declaration - src/shared/binary-downloader.ts: Bun.write → bunWrite Pure mechanical API swaps. No control-flow or signature changes.
82 lines
2.6 KiB
TypeScript
82 lines
2.6 KiB
TypeScript
import { log } from "../shared/logger"
|
|
import { bunWhich } from "../shared/bun-which-shim"
|
|
|
|
type Platform = "darwin" | "linux" | "win32" | "unsupported"
|
|
|
|
async function findCommand(commandName: string): Promise<string | null> {
|
|
try {
|
|
return bunWhich(commandName)
|
|
} catch (error) {
|
|
log("[session-notification] failed to resolve command path", {
|
|
commandName,
|
|
error: error instanceof Error ? error.message : String(error),
|
|
})
|
|
return null
|
|
}
|
|
}
|
|
|
|
function logBackgroundCheckError(commandName: string, error: unknown): void {
|
|
log("[session-notification] background command check failed", {
|
|
commandName,
|
|
error: error instanceof Error ? error.message : String(error),
|
|
})
|
|
}
|
|
|
|
function createCommandFinder(commandName: string): () => Promise<string | null> {
|
|
let cachedPath: string | null = null
|
|
let pending: Promise<string | null> | null = null
|
|
|
|
return async () => {
|
|
if (cachedPath !== null) return cachedPath
|
|
if (pending) return pending
|
|
|
|
pending = (async () => {
|
|
const path = await findCommand(commandName)
|
|
cachedPath = path
|
|
return path
|
|
})()
|
|
|
|
return pending
|
|
}
|
|
}
|
|
|
|
export const getNotifySendPath = createCommandFinder("notify-send")
|
|
export const getOsascriptPath = createCommandFinder("osascript")
|
|
export const getPowershellPath = createCommandFinder("powershell")
|
|
export const getAfplayPath = createCommandFinder("afplay")
|
|
export const getPaplayPath = createCommandFinder("paplay")
|
|
export const getAplayPath = createCommandFinder("aplay")
|
|
export const getTerminalNotifierPath = createCommandFinder("terminal-notifier")
|
|
export const getCmuxPath = createCommandFinder("cmux")
|
|
|
|
export function startBackgroundCheck(platform: Platform): void {
|
|
if (platform === "darwin") {
|
|
getCmuxPath().catch((error) => {
|
|
logBackgroundCheckError("cmux", error)
|
|
})
|
|
getOsascriptPath().catch((error) => {
|
|
logBackgroundCheckError("osascript", error)
|
|
})
|
|
getAfplayPath().catch((error) => {
|
|
logBackgroundCheckError("afplay", error)
|
|
})
|
|
getTerminalNotifierPath().catch((error) => {
|
|
logBackgroundCheckError("terminal-notifier", error)
|
|
})
|
|
} else if (platform === "linux") {
|
|
getNotifySendPath().catch((error) => {
|
|
logBackgroundCheckError("notify-send", error)
|
|
})
|
|
getPaplayPath().catch((error) => {
|
|
logBackgroundCheckError("paplay", error)
|
|
})
|
|
getAplayPath().catch((error) => {
|
|
logBackgroundCheckError("aplay", error)
|
|
})
|
|
} else if (platform === "win32") {
|
|
getPowershellPath().catch((error) => {
|
|
logBackgroundCheckError("powershell", error)
|
|
})
|
|
}
|
|
}
|