mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-30 14:22:02 +00:00
All business logic has been migrated to the REST API server. This removes obsolete Electron IPC handlers and services that are no longer used: - Deleted electron/services/ directory (18 files) - Deleted electron/agent-service.js - Deleted electron/auto-mode-service.js - Renamed main-simplified.js → main.js - Renamed preload-simplified.js → preload.js - Removed unused dependencies from package.json The Electron layer now only handles native OS features (10 IPC handlers): - File dialogs, shell operations, and app info 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
9.2 KiB
9.2 KiB
Plan: Full Web Support for Automaker
Goal
Make the app work fully in web browsers while keeping Electron support. Web mode connects to a backend server (self-hosted or cloud). Electron embeds the same server locally.
Architecture
┌─────────────────────────────────────┐
│ Next.js Frontend │
│ (same code both modes) │
└───────────────┬─────────────────────┘
│
┌───────────┴───────────┐
│ │
[Web Mode] [Electron Mode]
│ │
HTTP/WebSocket HTTP/WebSocket
to remote server to localhost:3008
│ │
└───────────┬───────────┘
│
┌───────────────▼─────────────────────┐
│ Backend Server │
│ (apps/server) │
│ - Express + WebSocket │
│ - All services from electron/ │
│ - Claude Agent SDK │
│ - File ops, Git, PTY │
└─────────────────────────────────────┘
Key insight: Electron uses the same HTTP API - just connects to localhost instead of remote.
New Package: apps/server
apps/server/
├── package.json
├── src/
│ ├── index.ts # Express server entry
│ ├── routes/
│ │ ├── fs.ts # File system routes
│ │ ├── agent.ts # Agent routes
│ │ ├── sessions.ts # Session routes
│ │ ├── auto-mode.ts # Auto mode routes
│ │ ├── features.ts # Features routes
│ │ ├── worktree.ts # Git worktree routes
│ │ ├── setup.ts # Setup/config routes
│ │ └── suggestions.ts # Feature suggestions routes
│ ├── services/ # Moved from electron/services/
│ │ ├── agent-service.ts
│ │ ├── auto-mode-service.ts
│ │ ├── worktree-manager.ts
│ │ ├── feature-loader.ts
│ │ ├── feature-executor.ts
│ │ └── ...
│ └── lib/
│ ├── events.ts # Event emitter for streaming
│ └── security.ts # Path validation
Critical Files to Modify
| File | Change |
|---|---|
apps/app/src/lib/electron.ts |
Add HttpApiClient class that implements ElectronAPI using fetch/WebSocket |
apps/app/electron/main.js |
Simplify to: spawn server + create window (remove 1500+ lines of IPC handlers) |
apps/app/electron/preload.js |
Simplify to just expose isElectron flag |
apps/app/package.json |
Remove server-side deps (Claude SDK, pty) |
Root package.json |
Add apps/server workspace |
Implementation Phases
Phase 1: Create Server Package (Foundation)
- Create
apps/serverwith Express + TypeScript setup - Add health check endpoint:
GET /api/health - Copy one simple service (feature-loader) and create route
- Test with curl/Postman
Phase 2: File System API
- Create
POST /api/fs/read,POST /api/fs/write, etc. - Add path security (allowlist validation)
- Update
electron.tswithHttpApiClientfor fs operations - Test: file operations work in web mode
Phase 3: Agent API with Streaming
- Add WebSocket server for events (
/api/events) - Migrate
agent-service.jsto TypeScript - Create routes:
POST /api/agent/send, etc. - Events stream via WebSocket instead of IPC
- Test: chat works in web mode
Phase 4: Sessions & Features API
- Migrate session management routes
- Migrate features CRUD routes
- Test: project/feature management works
Phase 5: Auto Mode & Worktree
- Migrate
auto-mode-service.js(complex - has streaming) - Migrate
worktree-manager.js - Test: auto mode runs features in web
Phase 6: Remaining Services
- Spec regeneration
- Feature suggestions
- Setup/CLI detection
- Model provider checks
Phase 7: Simplify Electron
- Update
main.jsto spawn server process + create window - Remove all IPC handlers
- Electron app uses HTTP like web
- Test: Electron still works
Phase 8: Production Ready
- Add authentication (API key header)
- Configure CORS for production
- Add
ALLOWED_PROJECT_DIRSenv for security - Docker setup for deployment
- Update build scripts
API Design Pattern
Convert IPC handlers to REST:
IPC: dialog:openDirectory → Web: User types path, POST /api/fs/validate
IPC: fs:readFile → POST /api/fs/read { filePath }
IPC: agent:send → POST /api/agent/send { sessionId, message, ... }
IPC: auto-mode:start → POST /api/auto-mode/start { projectPath }
IPC: features:getAll → GET /api/projects/:path/features
Streaming via WebSocket:
ws://server/api/events
Events: agent:stream, auto-mode:event, suggestions:event
Web-Specific Handling
| Feature | Electron | Web |
|---|---|---|
| File picker | Native dialog | Text input + server validation |
| Open link | shell.openExternal | window.open() |
| Data directory | app.getPath('userData') | Server's DATA_DIR env |
Configuration
Server .env:
PORT=3008
DATA_DIR=/path/to/data
ANTHROPIC_API_KEY=xxx
ALLOWED_PROJECT_DIRS=/home/user/projects
Frontend .env.local:
NEXT_PUBLIC_SERVER_URL=http://localhost:3008
Estimated Scope
- New files: ~15-20 (server package)
- Modified files: ~5 (electron.ts, main.js, preload.js, package.jsons)
- Deleted lines: ~1500 (IPC handlers from main.js)
- Services to migrate: ~10
Implementation Status
✅ ALL PHASES COMPLETE
-
Phase 1: Server package foundation (
apps/server)- Express server with WebSocket support
- Event emitter for streaming
- Security module for path validation
- Health check endpoint
-
Phase 2: HttpApiClient in frontend
apps/app/src/lib/http-api-client.ts- full implementation- Modified
electron.tsto use HTTP client when not in Electron - No mocks - all calls go through HTTP
-
Phase 3: Agent API with streaming
apps/server/src/services/agent-service.tsapps/server/src/routes/agent.ts- WebSocket streaming for responses
-
Phase 4: Sessions & Features API
apps/server/src/routes/sessions.tsapps/server/src/services/feature-loader.tsapps/server/src/routes/features.ts
-
Phase 5: Auto Mode & Worktree
apps/server/src/services/auto-mode-service.ts- full implementation with Claude SDKapps/server/src/routes/auto-mode.tsapps/server/src/routes/worktree.tsapps/server/src/routes/git.ts
-
Phase 6: Remaining services
apps/server/src/routes/setup.ts- CLI detection, API keys, platform infoapps/server/src/routes/suggestions.ts- AI-powered feature suggestionsapps/server/src/routes/spec-regeneration.ts- spec generation from overviewapps/server/src/routes/models.ts- model providers and availabilityapps/server/src/routes/running-agents.ts- active agent tracking
-
Phase 7: Simplify Electron
apps/app/electron/main.js- spawns server, minimal IPC (10 handlers for native features only)apps/app/electron/preload.js- only native features exposed- Updated
electron.tsto detect simplified mode - Updated
http-api-client.tsto use native dialogs when available - Removed ~13,000 lines of dead code (obsolete services, agent-service.js, auto-mode-service.js)
-
Phase 8: Production ready
apps/server/src/lib/auth.ts- API key authentication middlewareapps/server/Dockerfile- multi-stage Docker builddocker-compose.yml- easy deployment configurationapps/server/.env.example- documented configuration
Additional Fixes Applied
State Persistence
- Features now cached in localStorage via Zustand persist middleware
- Board view properly handles API failures by keeping cached data
- Theme and UI state properly persisted across refreshes
Authentication Display
- Server now returns proper auth method names:
oauth_token_env,oauth_token,api_key_env,api_key - Settings view displays correct auth source (OAuth token, API key, subscription, etc.)
- Added support for Codex subscription detection
- Fixed "Unknown method" display issue
Bug Fixes
- Fixed board-view.tsx crash when feature status is unknown (defaults to backlog)
- Removed "Mock IPC" label from web mode indicator
- Fixed unused imports and dependency warnings
- Updated API key authentication header support in HTTP client
Summary
The architecture is simple: one backend server, two ways to access it (web browser or Electron shell).
- Web users: Connect browser to your cloud-hosted server
- Electron users: App spawns server locally, connects to localhost
- Same codebase: Frontend code unchanged, backend services extracted to standalone server