refactor: route raw Bun.file/write/hash/which/spawn through runtime shims

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.
This commit is contained in:
YeonGyu-Kim
2026-05-12 12:46:31 +09:00
parent 4394f34225
commit 0aafe20a85
11 changed files with 30 additions and 23 deletions
@@ -11,6 +11,7 @@ import type {
import { transformMcpServer } from "./transformer"
import { log } from "../../shared/logger"
import { shouldLoadMcpServer } from "./scope-filter"
import { bunFile } from "../../shared/bun-file-shim"
interface McpConfigPath {
path: string
@@ -37,7 +38,7 @@ async function loadMcpConfigFile(
}
try {
const content = await Bun.file(filePath).text()
const content = await bunFile(filePath).text()
return JSON.parse(content) as ClaudeCodeMcpConfig
} catch (error) {
log(`Failed to load MCP config from ${filePath}`, error)
@@ -7,6 +7,7 @@ import type { ClaudeCodeMcpConfig } from "../claude-code-mcp-loader/types"
import { log } from "../../shared/logger"
import type { LoadedPlugin } from "./types"
import { resolvePluginPaths } from "./plugin-path-resolver"
import { bunFile } from "../../shared/bun-file-shim"
export async function loadPluginMcpServers(
plugins: LoadedPlugin[],
@@ -18,7 +19,7 @@ export async function loadPluginMcpServers(
if (!plugin.mcpPath || !existsSync(plugin.mcpPath)) continue
try {
const content = await Bun.file(plugin.mcpPath).text()
const content = await bunFile(plugin.mcpPath).text()
let config = JSON.parse(content) as ClaudeCodeMcpConfig
config = resolvePluginPaths(config, plugin.installPath)
+2 -1
View File
@@ -1,4 +1,5 @@
import type { TeamModeConfig } from "../../config/schema/team-mode"
import { spawn } from "../../shared/bun-spawn-shim"
export interface TeamModeDependencyReport {
tmuxAvailable: boolean
@@ -20,7 +21,7 @@ export async function checkTeamModeDependencies(
async function probeBinary(cmd: string, args: string[]): Promise<boolean> {
try {
const proc = Bun.spawn({ cmd: [cmd, ...args], stdout: "pipe", stderr: "pipe" })
const proc = spawn({ cmd: [cmd, ...args], stdout: "pipe", stderr: "pipe" })
const code = await proc.exited
return code === 0
} catch {