|
| 1 | +# Wails Native Desktop Runtime Implementation Plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | +
|
| 5 | +**Goal:** Turn the existing browser-only React desktop UI into a native Wails desktop app, add tests for the native runtime wiring, and verify backend/frontend tests and builds pass. |
| 6 | + |
| 7 | +**Architecture:** Keep the existing CLI and `internal/desktop` services intact. Add a Wails v2 native entrypoint in `cmd/cam-desktop` that binds the existing service structs, embeds the Vite production bundle when available, and falls back to a small embedded diagnostic page when the bundle has not been built. Configure Vite to emit the desktop bundle into the Go entrypoint's embedded asset tree, and configure `wails.json`/`install.sh` to prefer Wails native builds when the Wails CLI is installed while preserving the existing lightweight Go fallback. |
| 8 | + |
| 9 | +**Tech Stack:** Go, Wails v2, React, TypeScript, Vite, Vitest, Go `testing`, PowerShell validation commands. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Files |
| 14 | + |
| 15 | +### Create |
| 16 | +- `cmd/cam-desktop/assets.go` — embeds desktop web assets and selects built UI or fallback UI. |
| 17 | +- `cmd/cam-desktop/assets_test.go` — verifies the fallback asset filesystem works without a frontend build. |
| 18 | +- `cmd/cam-desktop/webui/fallback/index.html` — diagnostic fallback page embedded in the native binary. |
| 19 | +- `wails.json` — Wails project configuration for native dev/build commands. |
| 20 | + |
| 21 | +### Modify |
| 22 | +- `cmd/cam-desktop/main.go` — run a native Wails app by default, keep `--services` smoke mode. |
| 23 | +- `cmd/cam-desktop/main_test.go` — add service-list tests if needed. |
| 24 | +- `frontend/vite.config.ts` — emit production assets into `cmd/cam-desktop/webui/dist` for embedding. |
| 25 | +- `.gitignore` — ignore generated Wails/Vite asset output, keep fallback assets trackable. |
| 26 | +- `go.mod` / `go.sum` — add Wails v2 dependency. |
| 27 | +- `install.sh` — prefer `wails build` when available, then `wails3 build`, then Go fallback. |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Task 1: Add Wails dependency and native app entrypoint |
| 32 | + |
| 33 | +**Files:** |
| 34 | +- Modify: `go.mod` |
| 35 | +- Modify: `go.sum` |
| 36 | +- Modify: `cmd/cam-desktop/main.go` |
| 37 | + |
| 38 | +- [ ] Add Wails v2 with `go get github.com/wailsapp/wails/v2@latest`. |
| 39 | +- [ ] Replace the print-only default path in `cmd/cam-desktop/main.go` with a `runDesktopApp()` function using `app.Run(&options.App{...})`. |
| 40 | +- [ ] Bind the existing services: `services.App`, `services.Providers`, `services.MCP`, `services.Entities`, `services.Tools`, `services.Doctor`, `services.Config`, and `services.Launch`. |
| 41 | +- [ ] Keep `--services` as a non-GUI smoke command that prints the service names as JSON. |
| 42 | +- [ ] Keep `--version` as a non-GUI smoke command that prints the desktop version. |
| 43 | +- [ ] Verify compilation with `go test ./cmd/cam-desktop`. |
| 44 | + |
| 45 | +## Task 2: Embed frontend assets with fallback |
| 46 | + |
| 47 | +**Files:** |
| 48 | +- Create: `cmd/cam-desktop/assets.go` |
| 49 | +- Create: `cmd/cam-desktop/assets_test.go` |
| 50 | +- Create: `cmd/cam-desktop/webui/fallback/index.html` |
| 51 | +- Modify: `.gitignore` |
| 52 | + |
| 53 | +- [ ] Add `//go:embed all:webui` to embed everything under `cmd/cam-desktop/webui`. |
| 54 | +- [ ] Implement `desktopAssets()` so it returns `webui/dist` when `index.html` exists, otherwise `webui/fallback`. |
| 55 | +- [ ] Add a fallback page that clearly says the native shell is running and instructs developers to run `npm --prefix frontend run build` for the full React UI. |
| 56 | +- [ ] Ignore generated `cmd/cam-desktop/webui/dist/` and Wails build output. |
| 57 | +- [ ] Test that `desktopAssets()` can open `index.html` without a frontend build. |
| 58 | +- [ ] Verify with `go test ./cmd/cam-desktop -run TestDesktopAssets`. |
| 59 | + |
| 60 | +## Task 3: Connect Vite build output to Wails embed tree |
| 61 | + |
| 62 | +**Files:** |
| 63 | +- Modify: `frontend/vite.config.ts` |
| 64 | + |
| 65 | +- [ ] Add `build.outDir = '../cmd/cam-desktop/webui/dist'`. |
| 66 | +- [ ] Add `build.emptyOutDir = true`. |
| 67 | +- [ ] Keep the existing Vitest settings unchanged. |
| 68 | +- [ ] Verify with `npm --prefix frontend run build`. |
| 69 | +- [ ] Verify the generated file exists at `cmd/cam-desktop/webui/dist/index.html`. |
| 70 | + |
| 71 | +## Task 4: Add Wails project config and installer support |
| 72 | + |
| 73 | +**Files:** |
| 74 | +- Create: `wails.json` |
| 75 | +- Modify: `install.sh` |
| 76 | + |
| 77 | +- [ ] Add Wails v2 config with project name `cam-desktop`, output filename `cam-desktop`, frontend build command `npm --prefix frontend run build`, and dev server URL `http://127.0.0.1:5173`. |
| 78 | +- [ ] Update `install.sh` desktop build logic to run `wails build` when available and `wails3 build` as a fallback. |
| 79 | +- [ ] Preserve the existing `go build ./cmd/cam-desktop` fallback when no Wails CLI exists. |
| 80 | +- [ ] Verify Go-side behavior with `go test ./cmd/cam-desktop ./internal/desktop`. |
| 81 | + |
| 82 | +## Task 5: Frontend binding compatibility tests |
| 83 | + |
| 84 | +**Files:** |
| 85 | +- Modify: `frontend/src/services/api.test.ts` |
| 86 | +- Modify: `frontend/src/services/api.ts` only if tests reveal binding-name incompatibility. |
| 87 | + |
| 88 | +- [ ] Add tests proving the adapter uses Wails-style service bindings when `window.go.desktop` is present. |
| 89 | +- [ ] Keep mock fallback behavior for browser-only dev mode. |
| 90 | +- [ ] If Wails exposes `AppService`/`ProviderService` names, support both the existing short aliases and service-struct names. |
| 91 | +- [ ] Verify with `npm --prefix frontend test -- --run src/services/api.test.ts`. |
| 92 | + |
| 93 | +## Task 6: Full verification |
| 94 | + |
| 95 | +**Files:** all changed files. |
| 96 | + |
| 97 | +- [ ] Run `go test ./cmd/cam-desktop ./internal/desktop`. |
| 98 | +- [ ] Run `go test ./...`. |
| 99 | +- [ ] Run `npm --prefix frontend test -- --run`. |
| 100 | +- [ ] Run `npm --prefix frontend run build`. |
| 101 | +- [ ] Run `go build ./cmd/cam-desktop` after the frontend build so embedded React assets are compiled into the native app. |
| 102 | +- [ ] Run `go run ./cmd/cam-desktop --services` and verify the JSON service list. |
| 103 | +- [ ] If Wails CLI is installed, run `wails build`; if it is not installed, record that native packaging could not be executed in this environment while the Wails app source compiles. |
| 104 | + |
| 105 | +## Self-Review |
| 106 | + |
| 107 | +- Spec coverage: native Wails runtime, frontend embedding, Wails config, installer support, binding compatibility, backend/frontend verification are covered. |
| 108 | +- Placeholder scan: no TBD/TODO placeholders remain. |
| 109 | +- Type consistency: service names match the existing `internal/desktop.Services` fields and frontend adapter methods. |
0 commit comments