name: fantasia-electron-preload description: >- Extends or fixes renderer-facing Electron APIs exposed through the preload script and contextBridge. Use when adding IPC-like surface area, typing window.faContentBridgeAPIs, editing src-electron/contentBridgeAPIs, or extending shared IPC channel names in electron-ipc-bridge.ts.
Fantasia Archive — preload and content bridge
Architecture
- JSDoc/comments in
src-electron/: AGENTS.md comment rules — no Markdown emphasis; single quotes for refs - Preload:
electron-preload.ts→contextBridge.exposeInMainWorld('faContentBridgeAPIs', apiObject) - Renderer:
window.faContentBridgeAPIs—src/globals.d.ts - Implementations:
contentBridgeAPIs/*.tsper API (window control, keybinds, project management,projectContentAPI, …)
Main ↔ preload IPC (electron-ipc-bridge)
- Async first:
ipcRenderer.invoke+ipcMain.handle.sendSynclast resort only - Registry:
electron-ipc-bridge.ts—FA_*_IPCconstants; never duplicate string literals - Main:
register*Ipc.tswired fromstartApp() - Preload: import constants in
contentBridgeAPIs/*.ts
Adding a new API surface
- Contract in
types/I_<Name>.ts - Channels in
electron-ipc-bridge.ts+register*Ipc.ts+ startup - Implement
contentBridgeAPIs/<name>.ts - Add to
apiObjectinelectron-preload.ts - Extend
globals.d.ts - Vitest:
contentBridgeAPIs/_tests/,ipcManagement/_tests/—yarn testbatch:verifyenforces 99% onsrc-electron
Security and boundaries
- Narrow explicit methods — no raw Node/Electron objects to renderer
- No broad
nodeIntegrationin renderer - Sandboxed preload → IPC to main for
shell, paths, etc. - Privileged calls via
invoke— no@electron/remotewithout documented reason - No
neverthrowin preload —Promisechains; see neverthrow.mdc - Structured IPC args validated in main with Zod — fantasia-electron-main
Related skills
Types
Shared types → types/. See types-folder.mdc.