openpencil/server/utils/resolve-claude-cli.ts
Kayshen-X 543e64245c feat(electron): integrate Electron framework for desktop application support
- Add Electron configuration and main process setup for building a desktop application.
- Implement IPC communication for file operations (open, save) between the renderer and main processes.
- Create a preload script to expose Electron APIs to the renderer.
- Update package.json to include Electron and related dependencies.
- Enhance the build process with electron-builder for packaging the application.
- Introduce a new electron-builder.yml configuration file for build settings.
- Modify Vite configuration to support Electron-specific builds.
- Update UI components to accommodate Electron's window management and drag regions.
2026-02-20 20:19:06 +08:00

37 lines
1.1 KiB
TypeScript

import { execSync } from 'node:child_process'
import { existsSync } from 'node:fs'
import { homedir } from 'node:os'
import { join } from 'node:path'
/**
* Resolve the absolute path to the standalone `claude` binary.
*
* When Nitro bundles @anthropic-ai/claude-agent-sdk, the SDK's internal
* `import.meta.url`-based resolution to find its own `cli.js` breaks.
* Instead we locate the standalone native binary and pass it via
* `pathToClaudeCodeExecutable` — the SDK detects non-.js paths as native
* binaries and spawns them directly (no `node` wrapper needed).
*/
export function resolveClaudeCli(): string | undefined {
// 1. Try `which claude` (works when PATH is correctly set)
try {
const p = execSync('which claude 2>/dev/null', {
encoding: 'utf-8',
timeout: 3000,
}).trim()
if (p && existsSync(p)) return p
} catch { /* not in PATH */ }
// 2. Common install locations
const candidates = [
join(homedir(), '.local', 'bin', 'claude'),
'/usr/local/bin/claude',
'/opt/homebrew/bin/claude',
]
for (const c of candidates) {
if (existsSync(c)) return c
}
return undefined
}