cc-haha/desktop/scripts/prepare-node-pty.ts
程序员阿江(Relakkes) 386a41e606 feat(desktop): enable Electron migration path
Introduce the Electron desktop shell alongside the existing React renderer and local Bun server boundary. The migration keeps the DesktopHost contract explicit across Tauri, Electron, and browser runtimes while adding Electron main/preload services for dialogs, shell, notifications, updates, tray/window lifecycle, terminal, preview WebContentsView, app mode, and release/package validation.

The commit also carries the latest local main desktop command updates, including agent slash entries and hidden-by-default markdown thinking details, so the packaged Electron build matches the current main UX surface.

Constraint: React renderer, local Bun server, REST/WebSocket, and sidecar boundaries must remain reusable during the migration
Constraint: macOS dev packages are ad-hoc signed and cannot prove Developer ID notarization or Gatekeeper release launch
Rejected: Browser-only smoke validation | it cannot exercise native dialogs, keychain prompts, notification behavior, or packaged app startup
Confidence: medium
Scope-risk: broad
Directive: Do not remove Tauri host support until signed Electron release artifacts pass native OS smoke on macOS, Windows, and Linux
Tested: bun run check:desktop
Tested: cd desktop && bun run check:electron
Tested: CSC_IDENTITY_AUTO_DISCOVERY=false bun run electron📦dir
Tested: bun run test:package-smoke --platform macos --package-kind dir --artifacts-dir desktop/build-artifacts/electron
Tested: Computer Use read packaged Electron app window at desktop/build-artifacts/electron/mac-arm64/Claude Code Haha.app
Not-tested: Developer ID signed/notarized Gatekeeper launch
Not-tested: Real OS notification click-to-session action
Not-tested: Windows and Linux packaged app smoke on real hosts
2026-06-01 22:43:16 +08:00

42 lines
1.2 KiB
TypeScript

import fs from 'node:fs'
import path from 'node:path'
const desktopDir = path.resolve(import.meta.dirname, '..')
const prebuildsDir = path.join(desktopDir, 'node_modules', 'node-pty', 'prebuilds')
function ensureExecutable(filePath: string): boolean {
const stat = fs.statSync(filePath)
if (!stat.isFile()) return false
const executableMode = stat.mode | 0o755
if ((stat.mode & 0o777) !== (executableMode & 0o777)) {
fs.chmodSync(filePath, executableMode)
return true
}
return false
}
if (!fs.existsSync(prebuildsDir)) {
throw new Error(`node-pty prebuilds directory is missing: ${prebuildsDir}`)
}
let helpersSeen = 0
let helpersChanged = 0
for (const platformDir of fs.readdirSync(prebuildsDir)) {
const helperPath = path.join(prebuildsDir, platformDir, 'spawn-helper')
if (!fs.existsSync(helperPath)) continue
helpersSeen += 1
if (ensureExecutable(helperPath)) {
helpersChanged += 1
}
}
if (process.platform === 'darwin' && helpersSeen === 0) {
throw new Error(`node-pty spawn-helper is missing under ${prebuildsDir}`)
}
console.log(`[prepare-node-pty] spawn-helper executable bits verified (${helpersChanged}/${helpersSeen} updated)`)