diff --git a/electron/.electron-build-summary.md b/electron/.electron-build-summary.md deleted file mode 100644 index fac5050e..00000000 --- a/electron/.electron-build-summary.md +++ /dev/null @@ -1,228 +0,0 @@ -# โœ… Electron Build Setup Complete - -## ๐ŸŽ‰ What Was Created - -The Shakespeare project now has a complete Electron desktop application build system, with all files organized in the `electron/` directory to keep the existing codebase untouched. - -### ๐Ÿ“ Files Created - -``` -electron/ -โ”œโ”€โ”€ ๐Ÿ“„ main.js # Main Electron process (ESM) -โ”œโ”€โ”€ ๐Ÿ“„ preload.js # Secure IPC bridge (ESM) -โ”œโ”€โ”€ ๐Ÿ“„ builder.config.js # Build configuration (ESM) -โ”œโ”€โ”€ ๐Ÿ“„ electron.d.ts # TypeScript definitions -โ”œโ”€โ”€ ๐Ÿ”ง generate-icons.sh # Icon generation script -โ”œโ”€โ”€ ๐Ÿ”ง test-config.js # Configuration validator (ESM) -โ”œโ”€โ”€ ๐Ÿ“– INDEX.md # Documentation index -โ”œโ”€โ”€ ๐Ÿ“– README.md # Technical documentation -โ”œโ”€โ”€ ๐Ÿ“– QUICKSTART.md # Quick start guide -โ”œโ”€โ”€ ๐Ÿ“– INTEGRATION.md # Developer integration guide -โ”œโ”€โ”€ ๐Ÿ“– TROUBLESHOOTING.md # Troubleshooting guide -โ”œโ”€โ”€ ๐Ÿ“– CHANGELOG.md # Version history -โ””โ”€โ”€ ๐Ÿ“ resources/ # Icon resources directory - โ””โ”€โ”€ .gitkeep -``` - -### ๐Ÿ”ง Package.json Scripts Added - -```json -{ - "electron:dev": "Run in development mode", - "electron:build": "Build for current platform", - "electron:build:mac": "Build for macOS", - "electron:build:win": "Build for Windows", - "electron:build:linux": "Build for Linux", - "electron:build:all": "Build for all platforms", - "electron:icons": "Generate platform icons" -} -``` - -### ๐Ÿ“ฆ Dependencies Added - -- `electron` - Desktop application framework -- `electron-builder` - Multi-platform build tool -- `concurrently` - Run multiple commands -- `wait-on` - Wait for dev server -- `cross-env` - Cross-platform environment variables - -### ๐Ÿ“ Configuration Updates - -- โœ… `package.json` - Added main entry point and scripts -- โœ… `tsconfig.json` - Added Electron type definitions -- โœ… `.gitignore` - Added electron-dist directory -- โœ… `README.md` - Added Desktop App section - -## ๐Ÿš€ How to Use - -### Development Mode -```bash -npm run electron:dev -``` -Opens Shakespeare in an Electron window with hot-reload and DevTools. - -### Build for Distribution -```bash -# Build for your current platform -npm run electron:build - -# Or build for specific platforms -npm run electron:build:mac # macOS (DMG + ZIP) -npm run electron:build:win # Windows (NSIS + Portable) -npm run electron:build:linux # Linux (AppImage + DEB + RPM) -npm run electron:build:all # All platforms -``` - -### Generate Icons (Optional) -```bash -npm run electron:icons -``` -Requires ImageMagick. Creates platform-specific icons from `public/shakespeare-512x512.png`. - -## ๐ŸŽฏ Platform Support - -### macOS -- โœ… Intel (x64) builds -- โœ… Apple Silicon (arm64) builds -- ๐Ÿ“ฆ DMG installer -- ๐Ÿ“ฆ ZIP archive - -### Windows -- โœ… x64 builds -- โœ… ARM64 builds -- ๐Ÿ“ฆ NSIS installer -- ๐Ÿ“ฆ Portable executable - -### Linux -- โœ… x64 builds -- โœ… ARM64 builds -- ๐Ÿ“ฆ AppImage -- ๐Ÿ“ฆ DEB package -- ๐Ÿ“ฆ RPM package - -## ๐Ÿ”’ Security Features - -- โœ… Context isolation enabled (primary security boundary) -- โš ๏ธ Sandbox mode disabled (required for ESM preload scripts) -- โœ… Node integration disabled -- โœ… Minimal IPC API surface -- โœ… Navigation restrictions -- โœ… Secure window opening - -## ๐Ÿ“š Documentation - -Comprehensive documentation has been created: - -1. **[INDEX.md](INDEX.md)** - Start here for documentation overview -2. **[QUICKSTART.md](QUICKSTART.md)** - Quick start guide for users -3. **[INTEGRATION.md](INTEGRATION.md)** - Developer integration guide -4. **[TROUBLESHOOTING.md](TROUBLESHOOTING.md)** - Common issues and solutions -5. **[README.md](README.md)** - Complete technical reference -6. **[CHANGELOG.md](CHANGELOG.md)** - Version history - -## ๐ŸŽจ Icons - -**No setup required!** The build automatically uses `public/shakespeare-512x512.png` and converts it to the appropriate format for each platform (icns for macOS, ico for Windows, png for Linux). - -If you want custom icons, you can optionally: -```bash -npm run electron:icons # Requires ImageMagick -``` - -Or manually place custom icons in `electron/resources/` and update `builder.config.js`. - -## โœจ Key Features - -### Current Features -- Platform detection API -- App version information -- Secure IPC communication -- External link handling -- Native window management -- Hot-reload development mode - -### Potential Future Features -- Auto-updates -- Native application menus -- System tray integration -- File type associations -- Native dialogs -- Custom URL schemes -- Multiple windows -- Keyboard shortcuts - -## ๐Ÿงช Testing Status - -- โœ… TypeScript compilation passes -- โœ… All existing tests pass (877 tests) -- โœ… Web build works unchanged -- โœ… No breaking changes to existing code - -## ๐Ÿ“ฆ Build Output - -Built applications will be in `electron-dist/`: - -``` -electron-dist/ -โ”œโ”€โ”€ mac/ -โ”‚ โ”œโ”€โ”€ Shakespeare.app -โ”‚ โ””โ”€โ”€ Shakespeare.dmg -โ”œโ”€โ”€ win-unpacked/ -โ”‚ โ””โ”€โ”€ Shakespeare.exe -โ”œโ”€โ”€ Shakespeare Setup.exe -โ”œโ”€โ”€ Shakespeare Portable.exe -โ””โ”€โ”€ shakespeare-*.AppImage -``` - -## ๐ŸŽ“ Next Steps - -1. **Try it out:** - ```bash - npm run electron:dev - ``` - -2. **Generate icons:** - ```bash - npm run electron:icons - ``` - -3. **Build for your platform:** - ```bash - npm run electron:build - ``` - -4. **Read the documentation:** - - Start with `electron/QUICKSTART.md` - - Check `electron/INDEX.md` for full documentation index - -5. **Customize as needed:** - - Window size/appearance: `electron/main.js` - - Build settings: `electron/builder.config.js` - - Add features: See `electron/INTEGRATION.md` - -## ๐Ÿ’ก Important Notes - -- โœ… **Existing codebase is untouched** - All Electron code is in `electron/` -- โœ… **Web version still works** - No dependencies on Electron -- โœ… **Progressive enhancement** - Electron features are optional -- โœ… **Type-safe** - Full TypeScript support -- โœ… **Secure** - Follows Electron security best practices -- โœ… **Well-documented** - Comprehensive guides for users and developers - -## ๐Ÿ†˜ Need Help? - -1. Check `electron/TROUBLESHOOTING.md` for common issues -2. Read the relevant documentation in `electron/` -3. Search existing issues on GitLab -4. Create a new issue with details - -## ๐ŸŽ‰ Success! - -Your Shakespeare project now has a complete Electron build system that: -- Keeps the existing codebase untouched -- Provides native desktop apps for all major platforms -- Includes comprehensive documentation -- Follows security best practices -- Is ready to use immediately - -**Try it now:** `npm run electron:dev` diff --git a/electron/ARCHITECTURE.md b/electron/ARCHITECTURE.md deleted file mode 100644 index f0ef1f90..00000000 --- a/electron/ARCHITECTURE.md +++ /dev/null @@ -1,456 +0,0 @@ -# Electron Architecture - -This document describes the architecture of Shakespeare's Electron implementation, focusing on the real terminal feature. - -## Overview - -Shakespeare's Electron app uses a standard Electron architecture with a main process, renderer process, and preload script for secure IPC communication. - -## Process Architecture - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Electron App โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Main Process โ”‚ โ”‚ -โ”‚ โ”‚ (Node.js/Electron) โ”‚ โ”‚ -โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข File System Operations (fs module) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Shell Execution (child_process.spawn) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข IPC Handlers (ipcMain) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Window Management โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Working Directory: ~/shakespeare โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ IPC Bridge โ”‚ -โ”‚ โ”‚ (contextBridge) โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Preload Script โ”‚ โ”‚ -โ”‚ โ”‚ (Secure IPC Bridge - ESM) โ”‚ โ”‚ -โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Exposes to Renderer: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข window.electron.isElectron โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข window.electron.platform() โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข window.electron.version() โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข window.electron.fs.* โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข window.electron.shell.exec() โ† NEW โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ window.electron API โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Renderer Process โ”‚ โ”‚ -โ”‚ โ”‚ (React/TypeScript) โ”‚ โ”‚ -โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ Terminal Component โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Detects window.electron.shell โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Routes to real shell if available โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Falls back to virtual shell in browser โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ ShellTool (AI) โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Detects window.electron.shell โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Routes to real shell if available โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Falls back to virtual commands in browser โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ ElectronFSAdapter โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Implements JSRuntimeFS interface โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Routes to window.electron.fs.* โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## Shell Execution Flow - -### Browser Mode (Virtual Shell) - -``` -User Input: "ls -la" - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Terminal.tsx โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ ShellTool โ”‚ -โ”‚ (Virtual) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ LsCommand โ”‚ -โ”‚ (JavaScript) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ LightningFS โ”‚ -โ”‚ (IndexedDB) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - Result -``` - -### Electron Mode (Real Shell) - -``` -User Input: "ls -la" - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Terminal.tsx โ”‚ -โ”‚ (Renderer Process) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”‚ Detects window.electron.shell - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ window.electron โ”‚ -โ”‚ .shell.exec() โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”‚ IPC Call - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Preload Script โ”‚ -โ”‚ (IPC Bridge) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”‚ Secure IPC - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Main Process โ”‚ -โ”‚ shell:exec โ”‚ -โ”‚ IPC Handler โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ child_process โ”‚ -โ”‚ .spawn() โ”‚ -โ”‚ /bin/sh or cmd.exe โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ OS Shell โ”‚ -โ”‚ (Real Terminal) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ ~/shakespeare/ โ”‚ -โ”‚ (OS Filesystem) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - Result - { stdout, stderr, exitCode } -``` - -## Filesystem Architecture - -### Browser Mode - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Browser Storage โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ”‚ -โ”‚ IndexedDB โ”‚ -โ”‚ โ”œโ”€โ”€ /projects/ โ”‚ -โ”‚ โ”‚ โ”œโ”€โ”€ project-1/ โ”‚ -โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ package.json โ”‚ -โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ src/ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€ project-2/ โ”‚ -โ”‚ โ”œโ”€โ”€ /config/ โ”‚ -โ”‚ โ””โ”€โ”€ /tmp/ โ”‚ -โ”‚ โ”‚ -โ”‚ Accessed via: โ”‚ -โ”‚ โ€ข LightningFS โ”‚ -โ”‚ โ€ข LightningFSAdapter โ”‚ -โ”‚ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -### Electron Mode - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ OS Filesystem โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ”‚ -โ”‚ ~/shakespeare/ โ”‚ -โ”‚ โ”œโ”€โ”€ projects/ โ”‚ -โ”‚ โ”‚ โ”œโ”€โ”€ project-1/ โ”‚ -โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ package.json โ”‚ -โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ src/ โ”‚ -โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ node_modules/ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€ project-2/ โ”‚ -โ”‚ โ”œโ”€โ”€ config/ โ”‚ -โ”‚ โ””โ”€โ”€ tmp/ โ”‚ -โ”‚ โ”‚ -โ”‚ Accessed via: โ”‚ -โ”‚ โ€ข Node.js fs module (main) โ”‚ -โ”‚ โ€ข IPC calls (renderer) โ”‚ -โ”‚ โ€ข ElectronFSAdapter โ”‚ -โ”‚ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## Security Boundaries - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Security Layers โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ”‚ -โ”‚ 1. Context Isolation (PRIMARY BOUNDARY) โ”‚ -โ”‚ โœ“ Renderer cannot access Node.js/Electron APIs โ”‚ -โ”‚ โœ“ Only window.electron is exposed โ”‚ -โ”‚ โ”‚ -โ”‚ 2. Preload Script (CONTROLLED BRIDGE) โ”‚ -โ”‚ โœ“ Only specific APIs exposed via contextBridge โ”‚ -โ”‚ โœ“ No direct Node.js access from renderer โ”‚ -โ”‚ โ”‚ -โ”‚ 3. IPC Handlers (VALIDATION LAYER) โ”‚ -โ”‚ โœ“ Validate all inputs โ”‚ -โ”‚ โœ“ Path resolution and sanitization โ”‚ -โ”‚ โœ“ Error handling and code preservation โ”‚ -โ”‚ โ”‚ -โ”‚ 4. Filesystem Restrictions โ”‚ -โ”‚ โœ“ All operations relative to ~/shakespeare โ”‚ -โ”‚ โœ“ No access outside this directory โ”‚ -โ”‚ โ”‚ -โ”‚ 5. Shell Execution โ”‚ -โ”‚ โœ“ Commands run with user's permissions โ”‚ -โ”‚ โœ“ Working directory: ~/shakespeare/projects/{id} โ”‚ -โ”‚ โœ“ No elevation or sudo access โ”‚ -โ”‚ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## API Surface - -### Exposed to Renderer - -```typescript -interface window.electron { - // Platform info - isElectron: boolean; - platform(): Promise; - version(): Promise; - - // Filesystem API - fs: { - readFile(path: string, encoding?: string): Promise; - writeFile(path: string, data: string | number[], encoding?: string): Promise; - readdir(path: string, withFileTypes?: boolean): Promise; - mkdir(path: string, recursive?: boolean): Promise; - stat(path: string): Promise; - lstat(path: string): Promise; - unlink(path: string): Promise; - rmdir(path: string): Promise; - rename(oldPath: string, newPath: string): Promise; - readlink(path: string): Promise; - symlink(target: string, path: string): Promise; - }; - - // Shell API (NEW) - shell: { - exec(command: string, cwd?: string): Promise<{ - stdout: string; - stderr: string; - exitCode: number; - }>; - }; -} -``` - -## Component Integration - -### Terminal Component - -```typescript -// Automatic detection and routing -const executeCommand = async (command: string) => { - if (window.electron?.shell) { - // Use real OS shell - const result = await window.electron.shell.exec(command, relativeCwd); - // Display result - } else { - // Use virtual shell - const result = await shellTool.execute({ command }); - // Display result - } -}; -``` - -### ShellTool (AI) - -```typescript -// Automatic detection and routing -async execute(args: ShellToolParams): Promise { - if (window.electron?.shell) { - // Use real OS shell - return this.executeRealShell(args.command); - } - - // Use virtual commands - return this.executeVirtualShell(args.command); -} -``` - -## Path Resolution - -### Virtual to OS Path Conversion - -The `projectsPath` is configurable (default: `/projects`), so path conversion respects the configured value: - -``` -VFS Path: {projectsPath}/my-app/src/index.ts - โ†“ -Extract: my-app/src/index.ts - โ†“ -Resolve: ~/shakespeare/{projectsPath}/my-app/src/index.ts - โ†“ -OS Path: /Users/username/shakespeare/projects/my-app/src/index.ts -``` - -### Working Directory - -``` -Project ID: abc123 -VFS CWD: {projectsPath}/abc123 -Relative CWD: abc123 -OS CWD: ~/shakespeare/{projectsPath}/abc123 -Shell CWD: /Users/username/shakespeare/projects/abc123 -``` - -**Note**: The `projectsPath` is configurable via the app settings and defaults to `/projects`. - -## Error Handling - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Error Flow โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ”‚ -โ”‚ OS Error (e.g., ENOENT) โ”‚ -โ”‚ โ†“ โ”‚ -โ”‚ Main Process Handler โ”‚ -โ”‚ โ†“ โ”‚ -โ”‚ Preserve Error Code โ”‚ -โ”‚ โ†“ โ”‚ -โ”‚ IPC Serialization โ”‚ -โ”‚ โ†“ โ”‚ -โ”‚ Preload Script โ”‚ -โ”‚ โ†“ โ”‚ -โ”‚ Renderer Process โ”‚ -โ”‚ โ†“ โ”‚ -โ”‚ ElectronFSAdapter.unwrapError() โ”‚ -โ”‚ โ†“ โ”‚ -โ”‚ Restore Original Error Code โ”‚ -โ”‚ โ†“ โ”‚ -โ”‚ Application Logic โ”‚ -โ”‚ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## Performance Considerations - -### Browser Mode -- **Filesystem**: IndexedDB queries (slower for large files) -- **Commands**: JavaScript execution (interpreted) -- **Git**: isomorphic-git (JavaScript implementation) - -### Electron Mode -- **Filesystem**: Native fs module (much faster) -- **Commands**: Native OS shell (compiled binaries) -- **Git**: isomorphic-git (same as browser)* - -\* Future: Could use native Git CLI for even better performance - -## Deployment - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Build Process โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ”‚ -โ”‚ 1. npm run build โ”‚ -โ”‚ โ€ข Vite builds React app โ†’ dist/ โ”‚ -โ”‚ โ”‚ -โ”‚ 2. npm run electron:build โ”‚ -โ”‚ โ€ข electron-builder packages: โ”‚ -โ”‚ - Main process (main.js) โ”‚ -โ”‚ - Preload script (preload.js) โ”‚ -โ”‚ - Built React app (dist/) โ”‚ -โ”‚ - Icons and resources โ”‚ -โ”‚ โ”‚ -โ”‚ 3. Platform-specific installers created: โ”‚ -โ”‚ โ€ข macOS: .dmg, .app โ”‚ -โ”‚ โ€ข Windows: .exe (NSIS installer) โ”‚ -โ”‚ โ€ข Linux: .AppImage, .deb, .rpm โ”‚ -โ”‚ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## Future Architecture Enhancements - -### Planned Improvements - -1. **Native Git CLI Integration** - - Replace isomorphic-git with native Git commands - - Faster operations, better compatibility - - Leverage existing Git installations - -2. **Multiple Windows** - - Support multiple project windows - - Shared state management - - Inter-window communication - -3. **Enhanced Terminal** - - Persistent shell sessions - - Terminal tabs and splits - - Custom shell configuration - -4. **Auto-Update** - - electron-updater integration - - Automatic update downloads - - User-controlled update installation - -5. **System Integration** - - System tray icon - - Native menus - - File associations - - Protocol handlers - -## References - -- [Electron Security](https://www.electronjs.org/docs/latest/tutorial/security) -- [Context Isolation](https://www.electronjs.org/docs/latest/tutorial/context-isolation) -- [IPC Communication](https://www.electronjs.org/docs/latest/tutorial/ipc) -- [Process Model](https://www.electronjs.org/docs/latest/tutorial/process-model) diff --git a/electron/BUGFIX-ERROR-CODES.md b/electron/BUGFIX-ERROR-CODES.md deleted file mode 100644 index 335cbea5..00000000 --- a/electron/BUGFIX-ERROR-CODES.md +++ /dev/null @@ -1,118 +0,0 @@ -# Electron Filesystem Error Code Preservation Fix - -## Problem - -When creating projects in the Electron app, the filesystem operations were failing because error codes (like `ENOENT`) were not being preserved during IPC communication between the renderer and main processes. - -### Root Cause - -The Shakespeare codebase relies on checking `error.code === 'ENOENT'` in multiple places to handle file-not-found scenarios gracefully: - -- `ProjectsManager.readFile()` -- `ProjectsManager.readFileBytes()` -- `ProjectsManager.listFiles()` -- `ProjectsManager.fileExists()` - -When errors are thrown from Node.js filesystem operations in the Electron main process and sent via IPC to the renderer process, the `code` property was being lost during serialization. This is because error properties are typically non-enumerable and don't survive the IPC boundary. - -### Symptoms - -``` -Error occurred in handler for 'fs:stat': Error: Failed to stat /tmp: ENOENT: no such file or directory -Error occurred in handler for 'fs:stat': Error: Failed to stat /projects/untitled: ENOENT: no such file or directory -``` - -The error messages contained "ENOENT", but the `error.code` property was `undefined`, causing code that checks `error.code === 'ENOENT'` to fail. - -## Solution - -The fix required changes in two places: - -### 1. Electron Main Process (`electron/main.js`) - -Updated all filesystem IPC handlers to explicitly preserve the error `code` property using `Object.defineProperty()` with `enumerable: true`: - -```javascript -catch (error) { - const err = new Error(`Failed to stat ${filePath}: ${error.message}`); - if (error.code) { - Object.defineProperty(err, 'code', { - value: error.code, - enumerable: true, // Critical: makes property survive IPC serialization - writable: true, - configurable: true, - }); - } - throw err; -} -``` - -**Updated IPC Handlers:** -- `fs:readFile` -- `fs:writeFile` -- `fs:readdir` -- `fs:mkdir` -- `fs:stat` -- `fs:lstat` -- `fs:unlink` -- `fs:rmdir` -- `fs:rename` -- `fs:readlink` -- `fs:symlink` - -### 2. Electron FS Adapter (`src/lib/ElectronFSAdapter.ts`) - -Added error unwrapping in the renderer process to handle Electron's IPC error wrapping. When errors cross the IPC boundary, Electron wraps them in messages like "Error invoking remote method 'fs:stat': ...". The adapter now: - -1. **Catches all errors** from IPC calls -2. **Extracts the error code** from either: - - The `code` property (if preserved from main process) - - The error message via regex matching (fallback) -3. **Re-throws a clean error** with the proper `code` property - -```typescript -private unwrapElectronError(error: unknown): Error { - if (!(error instanceof Error)) { - return error as Error; - } - - // Extract error code from the error object if it exists - const code = (error as NodeJS.ErrnoException).code; - - // If there's already a code, preserve it - if (code) { - const err = new Error(error.message); - (err as NodeJS.ErrnoException).code = code; - return err; - } - - // If no code property, try to extract from the message - const match = error.message.match(/:\s*(E[A-Z]+):/); - if (match) { - const err = new Error(error.message); - (err as NodeJS.ErrnoException).code = match[1]; - return err; - } - - return error; -} -``` - -All filesystem methods in `ElectronFSAdapter` now wrap their calls in try-catch blocks and use `unwrapElectronError()` to ensure error codes are properly preserved. - -## Difference from LightningFS - -**LightningFS** runs entirely in the renderer process (browser context), so errors never cross the IPC boundary. Error objects maintain all their properties, including the `code` property. - -**ElectronFS** uses IPC to communicate between renderer and main processes. Without explicitly making the `code` property enumerable, it gets lost during serialization. - -## Testing - -After this fix, project creation in the Electron app should work identically to the browser version: - -1. Creating new projects from templates -2. Importing projects from ZIP files -3. Git operations on non-existent paths -4. File existence checks - -All operations that rely on `ENOENT` detection should now function correctly. diff --git a/electron/CHANGELOG.md b/electron/CHANGELOG.md deleted file mode 100644 index a6b77172..00000000 --- a/electron/CHANGELOG.md +++ /dev/null @@ -1,73 +0,0 @@ -# Electron Build Changelog - -All notable changes to the Shakespeare Electron build will be documented in this file. - -## [Unreleased] - -### Added -- Initial Electron build support -- Main process with secure window management (`main.js`) -- Preload script with minimal API exposure (`preload.js`) -- electron-builder configuration for multi-platform builds (`builder.config.js`) -- TypeScript definitions for Electron API (`electron.d.ts`) -- Icon generation script (`generate-icons.sh`) -- Comprehensive documentation: - - `INDEX.md` - Documentation index - - `README.md` - Technical documentation - - `QUICKSTART.md` - Quick start guide - - `INTEGRATION.md` - Developer integration guide - - `TROUBLESHOOTING.md` - Troubleshooting guide -- NPM scripts for development and building: - - `electron:dev` - Development mode - - `electron:build` - Build for current platform - - `electron:build:mac` - Build for macOS - - `electron:build:win` - Build for Windows - - `electron:build:linux` - Build for Linux - - `electron:build:all` - Build for all platforms - - `electron:icons` - Generate platform icons - -### Security -- Enabled context isolation -- Enabled sandbox mode -- Disabled node integration -- Implemented navigation restrictions -- Configured secure window opening behavior -- Minimal IPC API surface through preload script - -### Platform Support -- macOS (Intel and Apple Silicon) - - DMG installer - - ZIP archive -- Windows (x64 and ARM64) - - NSIS installer - - Portable executable -- Linux (x64 and ARM64) - - AppImage - - DEB package - - RPM package - -### API -- `window.electron.isElectron` - Detect Electron environment -- `window.electron.platform()` - Get platform information -- `window.electron.version()` - Get app version - -## Future Enhancements - -Planned features for future releases: - -- [ ] Auto-update support -- [ ] Native application menu -- [ ] System tray integration -- [ ] File type associations -- [ ] Custom URL scheme handling -- [ ] Native file dialogs -- [ ] Enhanced offline capabilities -- [ ] Keyboard shortcuts/accelerators -- [ ] Window state persistence -- [ ] Multiple window support -- [ ] Native notifications -- [ ] Deep linking support - -## Notes - -The Electron build is designed to keep the existing web codebase untouched. All Electron-specific code is contained in the `electron/` directory, and the web version continues to work independently. diff --git a/electron/COMPLETE_FIX_SUMMARY.md b/electron/COMPLETE_FIX_SUMMARY.md deleted file mode 100644 index 9ec3197a..00000000 --- a/electron/COMPLETE_FIX_SUMMARY.md +++ /dev/null @@ -1,198 +0,0 @@ -# Complete Electron Filesystem Fix Summary - -This document summarizes all fixes applied to enable project creation in the Electron app. - -## Problems Encountered - -### Problem 1: Error Codes Not Preserved Across IPC -**Symptom**: isomorphic-git's `FileSystem.exists()` method was throwing "Unhandled error" instead of returning `false` for non-existent files. - -**Root Cause**: Error `code` properties (like `ENOENT`) were being lost during IPC serialization because they are non-enumerable by default. - -**Impact**: Code that checks `error.code === 'ENOENT'` failed, breaking file existence checks throughout the codebase. - -### Problem 2: Missing fs.Stats Methods -**Symptom**: `TypeError: h.isSymbolicLink is not a function` - -**Root Cause**: The `stat()` and `lstat()` methods only returned `isDirectory()` and `isFile()`, but isomorphic-git requires the complete fs.Stats interface including `isSymbolicLink()`. - -**Impact**: isomorphic-git operations failed when checking file types during Git operations. - -## Solutions Implemented - -### Fix 1: Error Code Preservation (Two-Part Fix) - -#### Part A: Main Process (`electron/main.js`) -Made error codes enumerable so they survive IPC serialization: - -```javascript -catch (error) { - const err = new Error(`Failed to stat ${filePath}: ${error.message}`); - if (error.code) { - Object.defineProperty(err, 'code', { - value: error.code, - enumerable: true, // โ† Critical for IPC serialization - writable: true, - configurable: true, - }); - } - throw err; -} -``` - -Applied to all 11 IPC handlers: -- `fs:readFile` -- `fs:writeFile` -- `fs:readdir` -- `fs:mkdir` -- `fs:stat` -- `fs:lstat` -- `fs:unlink` -- `fs:rmdir` -- `fs:rename` -- `fs:readlink` -- `fs:symlink` - -#### Part B: Renderer Process (`src/lib/ElectronFSAdapter.ts`) -Added error unwrapping to handle Electron's IPC error wrapping: - -```typescript -private unwrapElectronError(error: unknown): Error { - if (!(error instanceof Error)) { - return error as Error; - } - - // Extract error code from the error object if it exists - const code = (error as NodeJS.ErrnoException).code; - - // If there's already a code, preserve it - if (code) { - const err = new Error(error.message); - (err as NodeJS.ErrnoException).code = code; - return err; - } - - // If no code property, try to extract from the message - const match = error.message.match(/:\s*(E[A-Z]+):/); - if (match) { - const err = new Error(error.message); - (err as NodeJS.ErrnoException).code = match[1]; - return err; - } - - return error; -} -``` - -All filesystem methods now wrap IPC calls in try-catch and use `unwrapElectronError()`. - -### Fix 2: Complete fs.Stats Interface - -Added all fs.Stats methods to `stat()` and `lstat()` in both main process and adapter: - -**Main Process (`electron/main.js`):** -```javascript -return { - isDirectory: stats.isDirectory(), - isFile: stats.isFile(), - isBlockDevice: stats.isBlockDevice(), - isCharacterDevice: stats.isCharacterDevice(), - isSymbolicLink: stats.isSymbolicLink(), // โ† Critical for isomorphic-git - isFIFO: stats.isFIFO(), - isSocket: stats.isSocket(), - size: stats.size, - mtimeMs: stats.mtimeMs, -}; -``` - -**Renderer Process (`src/lib/ElectronFSAdapter.ts`):** -```typescript -return { - isDirectory: () => result.isDirectory, - isFile: () => result.isFile, - isBlockDevice: () => result.isBlockDevice, - isCharacterDevice: () => result.isCharacterDevice, - isSymbolicLink: () => result.isSymbolicLink, - isFIFO: () => result.isFIFO, - isSocket: () => result.isSocket, - size: result.size, - mtimeMs: result.mtimeMs, -}; -``` - -**TypeScript Definitions (`electron/electron.d.ts`):** -```typescript -interface StatResult { - isDirectory: boolean; - isFile: boolean; - isBlockDevice: boolean; - isCharacterDevice: boolean; - isSymbolicLink: boolean; - isFIFO: boolean; - isSocket: boolean; - size?: number; - mtimeMs?: number; -} -``` - -## Files Modified - -1. **`electron/main.js`** - - Added error code preservation to all IPC handlers - - Added complete fs.Stats methods to `stat()` and `lstat()` - -2. **`src/lib/ElectronFSAdapter.ts`** - - Added `unwrapElectronError()` helper method - - Updated all filesystem methods to use error unwrapping - - Added complete fs.Stats methods to `stat()` and `lstat()` - -3. **`electron/electron.d.ts`** - - Updated `StatResult` interface with all fs.Stats methods - -4. **Documentation** - - `electron/BUGFIX-ERROR-CODES.md` - - `ELECTRON_ERROR_FIX_SUMMARY.md` - - `electron/ERROR-CODE-FLOW.md` - - `electron/COMPLETE_FIX_SUMMARY.md` (this file) - -## Validation - -โœ… **TypeScript compilation**: Passes without errors -โœ… **Test suite**: All 877 tests pass (106 test files) -โœ… **Error codes preserved**: Both in main and renderer processes -โœ… **isomorphic-git compatibility**: Full fs.Stats interface provided -โœ… **Project creation**: Should now work in Electron app - -## Why Both Fixes Were Necessary - -1. **Error Code Fix**: Required for isomorphic-git to determine if files exist -2. **fs.Stats Methods Fix**: Required for isomorphic-git to check file types during Git operations - -Both fixes work together to provide complete filesystem compatibility with isomorphic-git in the Electron environment. - -## Differences from LightningFS - -**LightningFS** (browser): -- Runs in renderer process - no IPC boundary -- Error properties preserved automatically -- May have incomplete fs.Stats interface (but isomorphic-git handles gracefully) - -**ElectronFS** (desktop): -- Uses IPC - requires explicit error code preservation -- Requires complete fs.Stats interface for isomorphic-git compatibility -- Must unwrap Electron's IPC error wrapping - -## Testing in Electron App - -To verify the fixes work: - -1. Build the Electron app: `npm run electron:build` -2. Run the app -3. Try creating a new project -4. Project creation should complete successfully without errors - -Expected behavior: -- No "Unhandled error in FileSystem.exists()" errors -- No "isSymbolicLink is not a function" errors -- Project files created successfully -- Git repository initialized properly diff --git a/electron/ERROR-CODE-FLOW.md b/electron/ERROR-CODE-FLOW.md deleted file mode 100644 index f385ba4f..00000000 --- a/electron/ERROR-CODE-FLOW.md +++ /dev/null @@ -1,127 +0,0 @@ -# Error Code Preservation Flow - -## Before the Fix โŒ - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ RENDERER PROCESS โ”‚ -โ”‚ โ”‚ -โ”‚ ElectronFSAdapter.stat('/projects/untitled') โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ IPC Call: fs:stat โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”‚ IPC Channel - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ MAIN PROCESS โ”‚ -โ”‚ โ”‚ -โ”‚ IPC Handler receives: '/projects/untitled' โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ fs.stat('/home/user/shakespeare/projects/...')โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ–ผ โ”‚ -โ”‚ โŒ ENOENT Error โ”‚ -โ”‚ { โ”‚ -โ”‚ message: "ENOENT: no such file...", โ”‚ -โ”‚ code: 'ENOENT' โ† Non-enumerable! โ”‚ -โ”‚ } โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Throw error โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”‚ IPC Serialization (loses code!) - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ RENDERER PROCESS โ”‚ -โ”‚ โ”‚ -โ”‚ Error received: โ”‚ -โ”‚ { โ”‚ -โ”‚ message: "Error invoking remote method 'fs:stat': ...", โ”‚ -โ”‚ code: undefined โ† LOST! โ”‚ -โ”‚ } โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ isomorphic-git checks: err.code === 'ENOENT' โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ–ผ โ”‚ -โ”‚ โŒ FALSE (code is undefined) โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Throws unhandled error โ”‚ -โ”‚ ๐Ÿ’ฅ PROJECT CREATION FAILS โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## After the Fix โœ… - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ RENDERER PROCESS โ”‚ -โ”‚ โ”‚ -โ”‚ ElectronFSAdapter.stat('/projects/untitled') โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ IPC Call: fs:stat โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”‚ IPC Channel - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ MAIN PROCESS โ”‚ -โ”‚ โ”‚ -โ”‚ IPC Handler receives: '/projects/untitled' โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ fs.stat('/home/user/shakespeare/projects/...')โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ–ผ โ”‚ -โ”‚ โŒ ENOENT Error โ”‚ -โ”‚ { โ”‚ -โ”‚ message: "ENOENT: no such file...", โ”‚ -โ”‚ code: 'ENOENT' โ”‚ -โ”‚ } โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Catch & Re-throw โ”‚ -โ”‚ โ”‚ -โ”‚ โœ… FIX #1: Make code enumerable โ”‚ -โ”‚ Object.defineProperty(err, 'code', { โ”‚ -โ”‚ value: error.code, โ”‚ -โ”‚ enumerable: true โ† Survives IPC! โ”‚ -โ”‚ }) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”‚ IPC Serialization (preserves code!) - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ RENDERER PROCESS โ”‚ -โ”‚ โ”‚ -โ”‚ Error received: โ”‚ -โ”‚ { โ”‚ -โ”‚ message: "Error invoking remote method 'fs:stat': ...", โ”‚ -โ”‚ code: 'ENOENT' โ† PRESERVED! โœ… โ”‚ -โ”‚ } โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ โœ… FIX #2: unwrapElectronError() โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ–ผ โ”‚ -โ”‚ Extract code from error โ”‚ -โ”‚ Create new error with code property โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Return to caller โ”‚ -โ”‚ โ”‚ -โ”‚ isomorphic-git checks: err.code === 'ENOENT' โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ–ผ โ”‚ -โ”‚ โœ… TRUE (code preserved!) โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Returns false โ”‚ -โ”‚ โœ… PROJECT CREATION SUCCEEDS โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## Key Points - -1. **Problem**: Error `code` property is non-enumerable by default and gets lost during IPC serialization - -2. **Fix #1 (Main Process)**: Use `Object.defineProperty()` with `enumerable: true` to make the code property survive IPC - -3. **Fix #2 (Renderer Process)**: Unwrap Electron's error wrapping and extract the code property (or parse from message as fallback) - -4. **Result**: isomorphic-git's `FileSystem.exists()` method can properly detect ENOENT errors and return `false` instead of throwing diff --git a/electron/INDEX.md b/electron/INDEX.md deleted file mode 100644 index 97551ea4..00000000 --- a/electron/INDEX.md +++ /dev/null @@ -1,201 +0,0 @@ -# Electron Build Documentation - -Welcome to the Shakespeare Electron build documentation! This directory contains everything needed to build and run Shakespeare as a native desktop application. - -## ๐Ÿ“š Documentation Index - -### Getting Started -- **[QUICKSTART.md](QUICKSTART.md)** - Quick start guide for building and running Electron builds - - Development mode setup - - Building for distribution - - Platform-specific instructions - - Icon generation - -### Features -- **[FEATURES.md](FEATURES.md)** - Overview of Electron-specific features - - Real OS filesystem - - Real OS terminal - - Native window management - - Performance benefits - - Browser vs Electron comparison -- **[REAL_TERMINAL.md](REAL_TERMINAL.md)** - Real terminal feature documentation - - How it works - - Usage examples - - Security considerations - - AI integration - - Troubleshooting -- **[FILESYSTEM.md](FILESYSTEM.md)** - Filesystem configuration details - - Storage location - - Directory structure - - File access patterns - -### Integration -- **[INTEGRATION.md](INTEGRATION.md)** - Guide for integrating Electron features into Shakespeare - - Detecting Electron environment - - Using the Electron API - - Adding new features - - Security best practices - - Code examples - -### Troubleshooting -- **[TROUBLESHOOTING.md](TROUBLESHOOTING.md)** - Solutions to common issues - - Development issues - - Build issues - - Runtime issues - - Platform-specific problems - -### Technical Reference -- **[ARCHITECTURE.md](ARCHITECTURE.md)** - System architecture and design - - Process architecture - - Shell execution flow - - Filesystem architecture - - Security boundaries - - Component integration - - Performance considerations -- **[README.md](README.md)** - Complete technical documentation - - File structure - - Build configuration - - Security implementation - - Customization options -- **[ESM.md](ESM.md)** - Why we use ES Modules (ESM) instead of CommonJS - - Benefits and rationale - - Examples and patterns - - Migration guide - -## ๐Ÿ—‚๏ธ File Structure - -``` -electron/ -โ”œโ”€โ”€ INDEX.md # This file - documentation index -โ”œโ”€โ”€ README.md # Complete technical documentation -โ”œโ”€โ”€ QUICKSTART.md # Quick start guide -โ”œโ”€โ”€ INTEGRATION.md # Integration guide for developers -โ”œโ”€โ”€ TROUBLESHOOTING.md # Troubleshooting guide -โ”œโ”€โ”€ main.js # Electron main process (ESM) -โ”œโ”€โ”€ preload.js # Preload script (ESM) -โ”œโ”€โ”€ builder.config.js # electron-builder configuration (ESM) -โ”œโ”€โ”€ electron.d.ts # TypeScript definitions for Electron API -โ”œโ”€โ”€ generate-icons.sh # Script to generate platform icons -โ”œโ”€โ”€ test-config.js # Configuration validation script (ESM) -โ””โ”€โ”€ resources/ # Build resources (icons, etc.) - โ””โ”€โ”€ .gitkeep -``` - -## ๐Ÿš€ Quick Commands - -```bash -# Development -npm run electron:dev # Run in development mode - -# Building -npm run electron:build # Build for current platform -npm run electron:build:mac # Build for macOS -npm run electron:build:win # Build for Windows -npm run electron:build:linux # Build for Linux -npm run electron:build:all # Build for all platforms - -# Utilities -npm run electron:icons # Generate icons from Shakespeare logo -``` - -## ๐ŸŽฏ What You Need to Know - -### For Users -1. Read [QUICKSTART.md](QUICKSTART.md) to build and run the app -2. Check [TROUBLESHOOTING.md](TROUBLESHOOTING.md) if you encounter issues - -### For Developers -1. Start with [QUICKSTART.md](QUICKSTART.md) for basic setup -2. Read [INTEGRATION.md](INTEGRATION.md) to add Electron features -3. Refer to [README.md](README.md) for technical details -4. Use [TROUBLESHOOTING.md](TROUBLESHOOTING.md) when debugging - -## ๐Ÿ”’ Security - -The Electron build implements security best practices: -- Context isolation enabled (primary security boundary) -- Sandbox mode disabled (required for ESM preload scripts) -- Node integration disabled -- Minimal API surface through preload script -- Navigation and window opening restrictions - -See [README.md](README.md) for complete security details. - -## ๐ŸŽจ Icons - -Before building for distribution, generate platform-specific icons: - -```bash -npm run electron:icons -``` - -This requires ImageMagick. Alternatively, use online tools or electron-icon-builder. - -See [QUICKSTART.md](QUICKSTART.md) for details. - -## ๐Ÿ“ฆ Build Output - -Built applications are placed in `electron-dist/`: -- macOS: `.dmg` installer and `.app` bundle -- Windows: NSIS installer and portable `.exe` -- Linux: AppImage, `.deb`, and `.rpm` packages - -## ๐Ÿ†˜ Need Help? - -1. Check the documentation files in order: - - [QUICKSTART.md](QUICKSTART.md) - - [TROUBLESHOOTING.md](TROUBLESHOOTING.md) - - [INTEGRATION.md](INTEGRATION.md) - - [README.md](README.md) - -2. Search existing issues on GitLab - -3. Create a new issue with: - - OS and version - - Steps to reproduce - - Error messages - - Relevant logs - -## ๐Ÿ”„ Updating - -When updating the Electron build: - -1. Update Electron version: `npm install electron@latest --save-dev` -2. Update electron-builder: `npm install electron-builder@latest --save-dev` -3. Test thoroughly on all target platforms -4. Update documentation if APIs change - -## ๐ŸŒŸ Features - -Current Electron features: -- โœ… **Real OS filesystem** - Projects stored at `~/shakespeare` -- โœ… **Real OS terminal** - Execute any system command -- โœ… Platform detection -- โœ… App version info -- โœ… Secure IPC bridge -- โœ… External link handling -- โœ… Native window management - -See [FEATURES.md](FEATURES.md) for detailed feature documentation. - -Potential future features (see [README.md](README.md)): -- Auto-updates -- Native menus -- System tray -- File associations -- Native dialogs -- Native Git CLI integration - -## ๐Ÿ“ Contributing - -When contributing to the Electron build: - -1. Keep the web version working - it should not depend on Electron -2. Use progressive enhancement - Electron features should be optional -3. Follow security best practices -4. Update documentation -5. Test on all platforms if possible - -## ๐Ÿ“„ License - -The Electron build is part of Shakespeare and is licensed under GNU AGPLv3.