diff --git a/.memory/design-mode.md b/.memory/design-mode.md index b6802a84d..e45103faf 100644 --- a/.memory/design-mode.md +++ b/.memory/design-mode.md @@ -1,6 +1,6 @@ # Design mode -v2 (2026-11-23): owner approved the live app canvas spec `docs/superpowers/specs/2026-11-23-design-mode-live-app-design.md` (live dev-server routes as frames, localhost-only, one canvas per workspace with a page per chat, Aiden-controlled dev server, Inspect tool X, DESIGN.md as the design-system source, React mock apps for non-web React projects). Pre-build checks are in spec §11 (`@google/design.md` 0.4.0: Apache-2.0, `/linter` `lint(content)` offline; v1 `design-system*.ts` removed in 3d (S6), except the scanner, which moved to `design-md/style-scan.ts` (S37); no default-session `webRequest` listener exists; E2E fixture symlinks root `node_modules`). The PR split was revised in §8: 1a must move every `activePageId` reader at once (tools, placement, focus with `pageId`, renderer view store), and 1b only writes `chatPages` and handles lifecycle. Phase 1a plan: `docs/superpowers/plans/2026-11-23-design-mode-v2-p1a-workspace-canvas.md`, built 2026-11-23 on `t3/design-mode-live-app-plan`, PR #894 opened 2026-11-23 after code review fixes (main `d5b1b14e9`, renderer `f78a6b0ef`); see "v2 Phase 1a" below. Key 1a decisions: `DesignChatCanvases` adapter (chat → workspace) so callers keep chat ids; a `.layout-v3` marker in `design-canvases/` triggers the one-time wipe; `designCanvas:updated` carries `workspaceId`; each No workspace chat has its own hidden workspace and so its own canvas (only legacy chats with no `workspaceId` share `default`). An adversarial plan review on 2026-11-23 added amendments A1–A12 to the 1a plan (origin `chatId` on updates, comment tray filtered by chat in 1a, per-window ordered views, Aiden's page change applied in main at once, attach merges the hidden canvas). An adversarial spec review the same day added §12 S1–S15: subframe `will-redirect` fix, a per-workspace start consent with a script-text hash plus a read-only refusal, a fail-closed null-frame rule, `file://` cookie handling, a narrowed network guarantee, a `design` job owner, an install stamp, a permission dispatcher shared with Gemini Live, no `allow-modals`, untrusted bridge output, Vite-client HMR, loopback binding, and 2b–5 behind `AIDEN_EXPERIMENTAL_DESIGN_LIVE` until Phase 7. Phase 2a (app detection: `node-toolchain.ts` lift, `detectWebApp`, `resolveAppToolchain`; no caller until 2b) built 2026-11-24 on `t3/design-mode-v2-p2a`, stacked on PR #908; see "v2 Phase 2a" below and spec S19–S24. +v2 (2026-11-23): owner approved the live app canvas spec `docs/superpowers/specs/2026-11-23-design-mode-live-app-design.md` (live dev-server routes as frames, localhost-only, one canvas per workspace with a page per chat, Aiden-controlled dev server, Inspect tool X, DESIGN.md as the design-system source, React mock apps for non-web React projects). Pre-build checks are in spec §11 (`@google/design.md` 0.4.0: Apache-2.0, `/linter` `lint(content)` offline; v1 `design-system*.ts` removed in 3d (S6), except the scanner, which moved to `design-md/style-scan.ts` (S37); no default-session `webRequest` listener exists; E2E fixture symlinks root `node_modules`). The PR split was revised in §8: 1a must move every `activePageId` reader at once (tools, placement, focus with `pageId`, renderer view store), and 1b only writes `chatPages` and handles lifecycle. Phase 1a plan: `docs/superpowers/plans/2026-11-23-design-mode-v2-p1a-workspace-canvas.md`, built 2026-11-23 on `t3/design-mode-live-app-plan`, PR #894 opened 2026-11-23 after code review fixes (main `d5b1b14e9`, renderer `f78a6b0ef`); see "v2 Phase 1a" below. Key 1a decisions: `DesignChatCanvases` adapter (chat → workspace) so callers keep chat ids; a `.layout-v3` marker in `design-canvases/` triggers the one-time wipe; `designCanvas:updated` carries `workspaceId`; each No workspace chat has its own hidden workspace and so its own canvas (only legacy chats with no `workspaceId` share `default`). An adversarial plan review on 2026-11-23 added amendments A1–A12 to the 1a plan (origin `chatId` on updates, comment tray filtered by chat in 1a, per-window ordered views, Aiden's page change applied in main at once, attach merges the hidden canvas). An adversarial spec review the same day added §12 S1–S15: subframe `will-redirect` fix, a per-workspace start consent with a script-text hash plus a read-only refusal, a fail-closed null-frame rule, `file://` cookie handling, a narrowed network guarantee, a `design` job owner, an install stamp, a permission dispatcher shared with Gemini Live, no `allow-modals`, untrusted bridge output, Vite-client HMR, loopback binding, and 2b–5 behind `AIDEN_EXPERIMENTAL_DESIGN_LIVE` until Phase 7. Phase 2a (app detection: `node-toolchain.ts` lift, `detectWebApp`, `resolveAppToolchain`; no caller until 2b) built 2026-11-24 on `t3/design-mode-v2-p2a`, stacked on PR #908; see "v2 Phase 2a" below and spec S19–S24. Phase 2b (the dev server: `DesignAppServers`, the run-app card, `design_app`, `designApp:*` IPC) built 2026-11-24 on `t3/design-mode-v2-p2b`, stacked on DM, behind the live flag; see "v2 Phase 2b" below and spec S25–S32. Status: active. P0 (retire Studio), P1 (layout shell) and P2 (canvas and frames, Tasks 1–7) are done. The Mac Studio work was pushed as `claude/design-mode-deep-dive` on 2026-11-05, then merged with `origin/main` on `claude/project-thread-29fzrr` (the PR branch). P3 (Aiden on the canvas) is done (2026-11-05, P3a–P3d, on the PR #778 branch), plan `docs/superpowers/plans/2026-11-05-design-mode-p3-aiden-on-canvas.md`. P3a (canvas tools) is done: `main/services/design-canvas/canvas-tools.ts` (four tools, 20 calls per turn at the time, 60 now, `designCanvasToolsAllowed` gate, `DESIGN_MODE_PROMPT_SECTION`), wired in `llm-client.ts` as the `aiden.design-canvas` runtime extension (static prompt section; since 2026-11-18 the `canvasPromptLine` counts go to the transcript as a `design-canvas-status` section note via `withCanvasStatusNote`, only when they changed, instead of a volatile system prompt line). P3b (artifact frames) is done: `artifact-frames.ts` places committed `render_artifact` visuals after `generativeUiArtifactStore.commit` (never on a failed turn), same-title Aiden frames swap `mediaId` and keep their box; `ArtifactNode` keys its loaded src by mediaId. P3c (skill) is done: `design-canvas/skill.ts` (`aiden-design`, `DESIGN_CANVAS_SKILLS`), registered in `skill-registry-main.ts` only when the flag is on, dropped by `withoutSkills` unless `designCanvasOffered` in llm-client, and from Remote and Telegram catalogs. P3d is done: `design-mode-tool.ts` (`DesignModeConsent`, `design_mode`, on-demand), `canvas-snapshots.ts`, card `renderer/design/design-mode-consent.tsx`, focus store `renderer/design/canvas-focus-requests.ts`; canvas tools held back and added by `withEnteredCanvasTools` after Enter; new tests must also go in `scripts/ci-test-registry.json` or `npm test` fails its registry check. P4 plan (owner chose everything in their reference screenshots): `docs/superpowers/plans/2026-11-05-design-mode-p4-full-canvas.md`; P4a built 2026-11-05, P4e, P4b, P4c, P4d, P4f, P4g and P4h built 2026-11-06, P5 (launch) built 2026-11-06. Placement moved to `renderer/shared/design-canvas/placement.ts`; summaries in `canvas-summary.ts`. P4–P5 plans are written before each phase. @@ -406,3 +406,18 @@ Branch `t3/design-mode-v2-dm`, stacked on PR #911 (2a). Lands before 2b. Plan `d - Events: `design_md_linted` (once per new content per run, never for content lints or the IPC) and `design_md_drafted {source: "app"}` (a drafted target that exists at a delivered turn's end). - IPC `designCanvas:designSystem {chatId, appRoot?}`: read only, no event, needs the live flag, not design mode; `designCanvasApi.designSystem` has no UI yet (Phase 5). - Packaging: `build.files` drops the CLI `dist/index.js`, top-level `dist/spec.md` and `dist/spec-config.yaml`, `dist/linter/spec.md` and the nested `node_modules/`, and (after code review) the 18 packages only `@google/design.md` reaches (`DESIGN_MD_ONLY_DEPENDENCIES`; a lockfile-walk test fails if another production dependency needs one). `verifyPackagedDesignMdLinter` (macOS and Linux package checks) requires the worker and linter as packed files, the trimmed files absent, and lints a fixture with the extracted linter. `npm run test:design-md:packaged` launches the release app and reads DESIGN.md over the IPC (release workflow). A local unsigned `--dir` build passed the check; the linter adds about 0.7 MB to the asar. No PR workflow packages macOS, so the packaged acceptance runs only at release. `canvas-config.ts` also exports `configuredRoots` (R2 step 1, for 2b) and `readCanvasConfigText` returns a reason (`missing | link | too-large | unreadable`) or `ok` text; `studioCapabilities()` has `designLive`. + +## v2 Phase 2b: dev server (2026-11-24) + +Branch `t3/design-mode-v2-p2b`, stacked on DM (`t3/design-mode-v2-dm`). Plan `docs/superpowers/plans/2026-11-24-design-mode-v2-p2b-dev-server.md` (its "As built" lists every deviation); spec S25–S32; guide `docs/design-mode.md` "Live apps (experimental)". Behind `designLiveEnabled()` (DM's flag); macOS and Linux only (relies on `backgroundJobs`). +- Layout under `main/services/design-canvas/app-server/`: `app-detect.ts`, `app-toolchain.ts`, `app-server-core.ts` (2a); `app-launch-core.ts` (pure: launch plan and flags, env scrub `launchEnvironment`, `providerKeyNames`, install decision, readiness port pick, `isAddressInUse`, `missingModuleHint`, `lastLines`); `app-fingerprint.ts` (`readLaunchSurface`: hashed scripts, rc/workspace/lockfile/config files, refuses links, special files and scripts over 4 000 chars); `app-records.ts` (`userData/design-apps.json`: approved fingerprint, `installShown`, Aiden's install stamp, sticky port); `app-ports.ts` (`chooseAppPort`, `defaultOsPort`, loopback only); `app-consent.ts` (`DesignAppConsent`, one card per key, 16 waiting, 2 min, owner-checked answers); `app-server-main.ts` (`DesignAppServers`); `app-tool.ts` (`design_app`). Contract for 2c and 3a: `renderer/shared/design-app.ts` (status, problems, consent union, fixed messages, `consentDisplayText`). +- Jobs: background jobs' `design` owner (cap 8, argv spawn, 25 MB rotating log keeping 50 MB, byte-offset `readDesignLog`, `designSockets` via `follow-through/listening-ports.ts`, failing closed; `onDesignChange` on start, end and port changes only, never output). `stopDesign` also signals setsid descendants found by parent pid before any signal. +- Consent: before every spawn, detection, toolchain and fingerprint run again and the argv is rebuilt; `approveShown` must match what the card showed. The fingerprint (v3) includes `checkout`, the workspace folder's realpath, so a re-pointed or moved checkout asks again. Reasons `first | changed | install | choose`. Every app start for a chat (designApp:* channels, the Design toggle, the design-mode card's Enter) goes through `chatRunsDesignApps` (no `botId`, no `owner`). Toolchain problems answer before any card. Aiden's request for a declined key gets no second card; the person's always asks. +- Install: only for a missing `node_modules`, an unfinished or stale Aiden install, or on request; never over the person's own install; never when the lockfile is outside the workspace. +- Origin `http://127.0.0.1:`. Readiness needs an IPv4 loopback port the job's tree holds (2 min of quiet, 10 min cap; output resets quiet at the next poll). One shared poller (500 ms starting, 2 s running, no overlapping ticks) checks every socket is loopback; 3 failed reads or one wildcard listener stops the server (`exposed` / `exposure-unknown`). Address-in-use retries once on an OS port. +- Presence: `designCanvasViews.visible(workspaceId)` counts visible canvases (pane shown and document visible, reported by `use-design-view.ts`); 60 s after none (E2E knob `AIDEN_E2E_DESIGN_APP_GRACE_MS`, unpackaged only, 1–60 s) the server stops. Each attempt holds a `workspaceMutationGate` admission; a folder or access change stops it. +- Wiring: `design-canvas/main.ts` builds `designAppServers` and `designAppConsent`; `main/index.ts` connects `backgroundJobs`/`onDesignJobChange` (`connectDesignAppJobs`, because llm-client loads follow-through lazily) and `designAppRecoveryDone(processRecoveryReady)`. Turning design mode on (toggle, ⇧⌘L, `/design`, or Enter on Aiden's card) calls `designModeEntered` with the window's owner. Workspace removal forgets its apps (`createDesignWorkspaceCleanup` `apps`). +- IPC (`main/handlers/design-app.ts`, prefix `designApp:`, all through `rendererDocumentOwner`, attended desktop chats with a folder): `status:get`, `start`, `stop`, `restart`, `choose`, `logs`, `consentAnswer`; notifications `designApp:status` (snapshot per workspace), `designApp:consent`, `designApp:consentClosed`. Renderer: `designAppApi` in `renderer/lib/ipc.ts`; card `renderer/design/design-app-consent.tsx` (mounted in `chat-pane.tsx`), problem toasts for person-started apps (`DesignAppProblemToasts` in `app.tsx`). +- Tool: `design_app` joins the canvas tools when the flag and follow-through are available; `REVIEWED_CARDLESS_TOOLS` in `workspace-tool-approval.ts` skips its per-call card (hooks and rules still apply, never judged); 4 starts per turn; waits for the card then 90 s; abort ends the wait only. +- Event `design_app_started {framework, manager?, outcome}`. +- Tests: `app-*.test.ts` (core-git lane), `app-server-process.test.ts` (macos lane; real processes, fixtures in `tests/fixtures/design-app-server/`, the repo's Vite), `main/handlers/design-app.test.ts`, `renderer/design/design-app-consent.test.tsx` (renderer-other), all in `test:design-mode`; E2E `tests/e2e/design-app-server.spec.ts`. diff --git a/PRODUCT.md b/PRODUCT.md index af49e71b4..cfb1562d4 100644 --- a/PRODUCT.md +++ b/PRODUCT.md @@ -66,7 +66,7 @@ First-run setup and Settings → Providers share an account, API key and local-m - Settings → Storage shows how much disk Aiden uses on this computer, split into chats, logs, artifacts, browser data, voice models, Bot computers, saved work from removed worktrees, other app data and worktrees, with the largest worktrees and chats listed. Cleanup offers unused worktrees, one chat at a time, the browser cache (sign-ins kept) and logs behind a review that names what will be removed and how much it frees; voice models and Bot computers link to their own settings. Worktrees with uncommitted or unpushed work, a chat or terminal using them or a scheduled task in them are never removed, and cleanup re-checks that right before deleting. See [docs/storage.md](docs/storage.md). - A provider's usage limit makes a reply wait, never switch to another model; limits that last days and billing problems fail at once with the reset time. Spending limits are the owner's: each chat, each Bot's month and each routine run can stop at a dollar amount counted from API-key requests only, and only the person can allow more (on the Mac or a paired phone). See [docs/usage-limits-and-spending.md](docs/usage-limits-and-spending.md). - In chats with Web Search on, the agent can read a public web page. Opt-in extract mode, set up with the person's own Cloudflare account, returns only the named values it asks for, each with supporting page text; a value that is not on the page comes back as a guess, never as read. -- Design mode (desktop, on by default; `AIDEN_DESIGN_MODE=0` turns it off) puts a workspace chat beside an infinite design canvas. Design mode keeps one canvas per workspace, shared by its chats; each chat remembers its own page and view, so a pan, a zoom or a page switch in one chat never moves another. Opening design mode gives the chat a page of its own: the page on screen when no other chat is using it, otherwise a new page named after the chat, which follows the chat's title until someone renames the page. Aiden can switch the chat to another page. Deleting a page moves its chats to the first page, and Aiden won't delete a page another chat uses unless the person asks; the page picker shows how many chats use each page, never which. Deleting a chat removes its comments, its page claim, and the images and visuals it sent from the chat (artifact frames); workspace images, its page, notes and page frames stay. Canvases from earlier versions are cleared on first start; files under `design/` are untouched. Removing a workspace deletes its canvas, and a No workspace chat attached to a workspace with its files copied brings its canvas pages along, named after the chat, and uses the first of them as its page (attaching without copying the files leaves the canvas behind). Pages stay workspace HTML files served only to the canvas in a sandbox with no network; Aiden changes the canvas only in attended desktop turns, through its canvas tools or by an HTML page it writes, edits or makes with a command under the workspace's `design/` folder landing as a frame (and, when the person opens design mode, the pages the chat's earlier replies wrote landing on the chat's page), and a comment or an in-place word edit the person makes goes to Aiden only with their next message, while plain word edits are written into the page's file and can be undone. The first time design mode is on in a workspace with no `design/tokens.css`, Aiden reads a few of its style files on the device and offers in chat to write a tokens file and a specimen page from the colours and fonts it found; it writes them only after the person agrees, and asks once per workspace. With `AIDEN_EXPERIMENTAL_DESIGN_LIVE`, a DESIGN.md draft offer replaces it ([docs/design-mode.md](docs/design-mode.md)). +- Design mode (desktop, on by default; `AIDEN_DESIGN_MODE=0` turns it off) puts a workspace chat beside an infinite design canvas. Design mode keeps one canvas per workspace, shared by its chats; each chat remembers its own page and view, so a pan, a zoom or a page switch in one chat never moves another. Opening design mode gives the chat a page of its own: the page on screen when no other chat is using it, otherwise a new page named after the chat, which follows the chat's title until someone renames the page. Aiden can switch the chat to another page. Deleting a page moves its chats to the first page, and Aiden won't delete a page another chat uses unless the person asks; the page picker shows how many chats use each page, never which. Deleting a chat removes its comments, its page claim, and the images and visuals it sent from the chat (artifact frames); workspace images, its page, notes and page frames stay. Canvases from earlier versions are cleared on first start; files under `design/` are untouched. Removing a workspace deletes its canvas, and a No workspace chat attached to a workspace with its files copied brings its canvas pages along, named after the chat, and uses the first of them as its page (attaching without copying the files leaves the canvas behind). Pages stay workspace HTML files served only to the canvas in a sandbox with no network; Aiden changes the canvas only in attended desktop turns, through its canvas tools or by an HTML page it writes, edits or makes with a command under the workspace's `design/` folder landing as a frame (and, when the person opens design mode, the pages the chat's earlier replies wrote landing on the chat's page), and a comment or an in-place word edit the person makes goes to Aiden only with their next message, while plain word edits are written into the page's file and can be undone. The first time design mode is on in a workspace with no `design/tokens.css`, Aiden reads a few of its style files on the device and offers in chat to write a tokens file and a specimen page from the colours and fonts it found; it writes them only after the person agrees, and asks once per workspace. With `AIDEN_EXPERIMENTAL_DESIGN_LIVE`, a DESIGN.md draft offer replaces it ([docs/design-mode.md](docs/design-mode.md)). The same flag (macOS and Linux) lets design mode run the workspace's own web app dev server, only after the person chooses Allow on a **Run app?** card that shows the command, any install and every script it runs. The server listens only on this computer, gets no AI provider keys, and stops 60 seconds after no canvas for its workspace is on screen ([live apps](docs/design-mode.md#live-apps-experimental)). - Bot computers (Apple silicon): an opt-in macOS VM per Bot, which the Bot sees and uses with its own `computer` tool (screenshots and clicks, each step with a stated intent the rules read) and `computer_shell` tool, on routine runs too. The Bot panel's Computer tab shows it live with the Bot's avatar where it last pointed; the person's first click or key, or Take over, stops the Bot's current action until Give back, and Float over chat keeps the screen in view. Element control (Aiden's pinned cua-driver in the base computer, allowed once for Accessibility and Screen Recording and inherited by every Bot computer made from it) lets the Bot read an app's buttons and fields and click them by number, and the rules then also read the element acted on; skipping it keeps screen-only Bots. A Bot can ask the person to sign in on its own computer: Open hands the person the computer with Safari at the site, the Bot's computer tools wait, and the password never reaches the model. The onboarding tour introduces Bot computers only where they exist. See [docs/bot-computers.md](docs/bot-computers.md). - On iPhone, an `svg` code block in a reply has View, which draws it with no scripts and no network. A workspace `.html` file opens on a themed Preview, with no network and a Source switch, and tapping a "File written" line in a workspace chat opens that file. diff --git a/docs/analytics.md b/docs/analytics.md index 1c9bd24d8..6a12a0ab1 100644 --- a/docs/analytics.md +++ b/docs/analytics.md @@ -53,6 +53,7 @@ Feature events fire once, at the moment the action succeeded, from the service t | `design_comments_sent` | A desktop message carried design-canvas comments for Aiden | `count_bucket`: how many comments. Their notes, pages, files and elements stay on your device. | | `design_md_linted` | Design mode checked an app's DESIGN.md (once per change in a run) | `errors_bucket`, `warnings_bucket`: how many errors and warnings. The file, its tokens and its findings stay on your device. | | `design_md_drafted` | Aiden drafted an app's DESIGN.md and it was written in the same turn | `source`: app (from the app's own styles). The file and its contents stay on your device. | +| `design_app_started` | A design-mode attempt to run a workspace's web app settled: it ran, its server stopped before it was ready, or it failed (install, toolchain, exposure or readiness). A Not now, or a card nobody answered, is not counted. | `framework`: which framework detection found (`next`, `react-router`, `remix`, `remix-3`, `tanstack-start`, `nuxt`, `angular`, `astro`, `gatsby`, `create-react-app`, `tanstack-router` or `vite`); `manager`: `npm`, `pnpm`, `yarn` or `bun`, when known; `outcome`: `running`, `crashed` or `failed`. The app's folder, scripts, port and output stay on your device. | | `goal_started` | A keep-going goal was set in a chat | `source`: `slash`, `menu`, `proposal`, `phone` or `until`. The objective stays on your device. | | `goal_settled` | A keep-going goal stopped: done, needs you, paused or cleared | `outcome`: `done`, `needs_you`, `paused` or `cleared`; `rounds`: how many rounds it ran, as `1`, `2-5`, `6-10`, `11-20`, `21-49` or `50`. The objective and the reviewer's reasons stay on your device. | | `floating_chat_opened` | The floating Quick Chat window opened | `source`: hotkey (global shortcut) or command (command palette or in-app command) | diff --git a/docs/design-mode.md b/docs/design-mode.md index 945f1ad93..8ba79ccf2 100644 --- a/docs/design-mode.md +++ b/docs/design-mode.md @@ -25,3 +25,25 @@ Files outside the workspace, including symlinks that point out of it, are refuse **What the checks cover.** Aiden bundles `@google/design.md` 0.4.0 and runs its linter offline, in a separate worker, with a 2-second limit per check. A check that runs out of time is tried again after five minutes; if the linter can't load within 10 seconds, Aiden stops trying until it restarts. The canvas note waits at most 3 seconds for these checks and otherwise goes without the `DESIGN.md` line. Files over 64 KiB aren't checked, and an export over 64 KiB isn't shown. Version 0.4.0 doesn't know a `motion` token group or the Motion and Voice & Content Strategy sections, and doesn't resolve `@file#fragment` references. Aiden adds two warnings of its own: a section that appears twice, and a token reference to a group that doesn't resolve. **Privacy.** The file, its tokens and its findings stay on your device. Nothing is sent anywhere. Usage data records only that a check ran (with bucketed error and warning counts) and that a draft was written, never the file or its contents. See [analytics](analytics.md). + +## Live apps (experimental) + +With live apps, design mode runs your workspace's own web app so the canvas can show it. This first part (Phase 2b) runs the dev server; showing the app on the canvas comes with the next phases. + +**Turning it on.** Start Aiden with `AIDEN_EXPERIMENTAL_DESIGN_LIVE=1`. Live apps run on macOS and Linux only. With the flag off, nothing here runs. + +**Starting the app.** When you turn design mode on in a chat, Aiden finds the workspace's web app (Next.js, React Router, Remix, TanStack Start, Nuxt, Angular, Astro, Gatsby, Create React App, TanStack Router or Vite) and shows a **Run app?** card above the composer. The card shows the exact command, the install command when one will run, the text of every script that runs, and the names of the config, rc and workspace files the start reads. Every line break in a script is marked with ↵, and a run of blank lines or spaces shows as its count, so no line hides below another. When the details are long they scroll inside the card, and **Allow** and **Not now** stay on screen. When several apps ask at once, each gets its own card. Nothing runs until you choose **Allow**. **Not now** starts nothing. Aiden can also start, stop, restart or read the app's output with its `design_app` tool, which asks on the same card. It runs only the app's own dev script, and at most four starts per reply. A chat without write access to the workspace can't start it. When design mode turns on with several chosen apps, they start together. + +**When the card comes back.** Aiden remembers what you approved, for that folder on disk. The card comes back, as **Run app again?**, when a script, an install lifecycle script, the package manager, a lockfile, an rc or workspace file, or a framework config changes, when the workspace points at another folder (another checkout, even one with the same files) or its folder moved, and before an install that wasn't approved yet. + +**Installs.** When the app has no `node_modules`, or Aiden's own last install didn't finish or is out of date, Aiden installs the dependencies first with the app's package manager (npm, pnpm, Yarn or Bun) from your package registry. Installing runs your dependencies' install scripts, which the card says. Aiden never installs over dependencies you installed yourself, and never installs in a parent folder: when the lockfile is outside the workspace, install there yourself, then start the app again. When the app has no lockfile, the install writes one. That lockfile is the only change, so the card doesn't come back for it. + +**Only on this computer.** The app runs at `http://127.0.0.1:`. Aiden checks every socket the server's processes open, and stops a server that listens beyond this computer. To fix that, remove `--host` from the dev script. Remix 3's starter ignores the host and port Aiden passes: make its `server.ts` listen on `process.env.PORT` at `process.env.HOST`. + +**Environment.** The server runs with your shell's environment, minus your AI provider keys, Aiden's own `AIDEN_*` variables, npm's `npm_*` and `npm_config_*` variables, `NODE_ENV`, `ELECTRON_*` and `INIT_CWD`. An app that needs a key reads it from its own `.env`. Aiden also turns off framework telemetry (`NEXT_TELEMETRY_DISABLED`, `ASTRO_TELEMETRY_DISABLED`, `NUXT_TELEMETRY_DISABLED`, `GATSBY_TELEMETRY_DISABLED`, `NG_CLI_ANALYTICS=false` and `DO_NOT_TRACK`) unless you set those yourself. + +**When it stops.** The server stops 60 seconds after no canvas for its workspace is on screen: you left design mode, the stacked layout shows the Chat pane, or the window is minimized or hidden. A window behind other windows still counts as on screen. It also stops when the workspace's folder or access changes, when it doesn't start listening within two minutes of quiet (ten minutes at most), and when it listens beyond this computer. Aiden never restarts it on its own; a crash shows a short notice and the server's own output stays in its log. When the server stops or crashes, Aiden also stops the processes it started, including ones that left its process group. After Aiden quits unexpectedly, the next launch stops what the last run left behind, found by a marker in each process's environment. On macOS, `ps` can't read that marker for Apple's own programs (such as `sleep`), so one of those left behind by a crash keeps running. + +**Monorepos.** In a workspace with several web apps, you (or Aiden, through the same card) choose which app runs. The choice is saved as `script` in `.aiden/canvas.json`'s `apps`, for example `{"version": 1, "apps": [{"root": "apps/web", "script": "dev"}]}`, so you choose once. If Aiden can't save the choice (the file is a link, unreadable, or written by a newer Aiden), the app doesn't start. Choosing an app that is already running restarts it through the choose card. + +**Privacy.** The app's folder, scripts, port and output stay on your device. Usage data records only which framework and package manager an app used and whether it ran. See [analytics](analytics.md). diff --git a/docs/plans/README.md b/docs/plans/README.md index dd0bac08a..6fcf77add 100644 --- a/docs/plans/README.md +++ b/docs/plans/README.md @@ -63,7 +63,7 @@ Research addition 2026-10-03 against `main` at `3f86d41af` (0.52.0): [all-PR inv - [Design mode Tweaks panel](design-mode-tweaks-panel-plan.md) — Built 2026-11-18 on `claude/project-thread-m755wc`, in review (owner answered 1a 2a 3a+b). DialKit-style Tweaks: folders, typed number values, a 2D pad, words and buttons as page controls; saved versions with in-memory pictures and Show all; Shuffle, Send to Aiden, Copy and Make default with Undo; and the same controls floating over a page you are inside. -- [Design mode v2: the live app canvas](../superpowers/specs/2026-11-23-design-mode-live-app-design.md) — Approved 2026-11-23. The workspace's real dev-server routes as live, interactive frames (localhost-only network), one canvas per workspace with a page per chat, Aiden-controlled dev server, Inspect tool (X) with measure and drift checks, element chips into the composer, change toasts, error frames with Fix with Aiden, live directions with Adopt, a Styles frame, the app's design system kept in Google's open `DESIGN.md` format (read, linted and drafted by Aiden), React mock apps for non-web React projects such as Electron apps, and later `*.canvas.tsx` component cards. Pre-build checks done and the PR split revised (1a, 1b, 2a–2c, 3a–3d, DM, 4, 5, 7, 6) on 2026-11-23; Phase 1a (workspace canvas document) built 2026-11-23 on `t3/design-mode-live-app-plan`, in review as [PR #894](https://github.com/sambitcreate/aiden-agent/pull/894), plan [p1a](../superpowers/plans/2026-11-23-design-mode-v2-p1a-workspace-canvas.md). Phase 1b (chat pages) built 2026-11-24 on `t3/design-mode-v2-p1b`, in review as [PR #908](https://github.com/sambitcreate/aiden-agent/pull/908), stacked on PR #894, plan [p1b](../superpowers/plans/2026-11-23-design-mode-v2-p1b-chat-pages.md). Phase 2a (app detection) planned and built 2026-11-24 on `t3/design-mode-v2-p2a`, in review as [PR #911](https://github.com/sambitcreate/aiden-agent/pull/911), stacked on PR #908, plan [p2a](../superpowers/plans/2026-11-24-design-mode-v2-p2a-app-detection.md). Phase DM (DESIGN.md) planned and built 2026-11-24 on `t3/design-mode-v2-dm`, behind `AIDEN_EXPERIMENTAL_DESIGN_LIVE`, in review as [PR #915](https://github.com/sambitcreate/aiden-agent/pull/915), stacked on PR #911, plan [dm](../superpowers/plans/2026-11-24-design-mode-v2-dm-design-md.md). +- [Design mode v2: the live app canvas](../superpowers/specs/2026-11-23-design-mode-live-app-design.md) — Approved 2026-11-23. The workspace's real dev-server routes as live, interactive frames (localhost-only network), one canvas per workspace with a page per chat, Aiden-controlled dev server, Inspect tool (X) with measure and drift checks, element chips into the composer, change toasts, error frames with Fix with Aiden, live directions with Adopt, a Styles frame, the app's design system kept in Google's open `DESIGN.md` format (read, linted and drafted by Aiden), React mock apps for non-web React projects such as Electron apps, and later `*.canvas.tsx` component cards. Pre-build checks done and the PR split revised (1a, 1b, 2a–2c, 3a–3d, DM, 4, 5, 7, 6) on 2026-11-23; Phase 1a (workspace canvas document) built 2026-11-23 on `t3/design-mode-live-app-plan`, in review as [PR #894](https://github.com/sambitcreate/aiden-agent/pull/894), plan [p1a](../superpowers/plans/2026-11-23-design-mode-v2-p1a-workspace-canvas.md). Phase 1b (chat pages) built 2026-11-24 on `t3/design-mode-v2-p1b`, in review as [PR #908](https://github.com/sambitcreate/aiden-agent/pull/908), stacked on PR #894, plan [p1b](../superpowers/plans/2026-11-23-design-mode-v2-p1b-chat-pages.md). Phase 2a (app detection) planned and built 2026-11-24 on `t3/design-mode-v2-p2a`, in review as [PR #911](https://github.com/sambitcreate/aiden-agent/pull/911), stacked on PR #908, plan [p2a](../superpowers/plans/2026-11-24-design-mode-v2-p2a-app-detection.md). Phase DM (DESIGN.md) planned and built 2026-11-24 on `t3/design-mode-v2-dm`, behind `AIDEN_EXPERIMENTAL_DESIGN_LIVE`, in review as [PR #915](https://github.com/sambitcreate/aiden-agent/pull/915), stacked on PR #911, plan [dm](../superpowers/plans/2026-11-24-design-mode-v2-dm-design-md.md). Phase 2b (the dev server process) planned and built 2026-11-24 on `t3/design-mode-v2-p2b`, behind the same flag, in review as [PR #916](https://github.com/sambitcreate/aiden-agent/pull/916), stacked on PR #915, plan [p2b](../superpowers/plans/2026-11-24-design-mode-v2-p2b-dev-server.md). - [Design Studio + Create Images rebuild](design-studio-create-images-rebuild-plan.md) — Active (Create Images only; Design Studio superseded 2026-10-31). Track F (Studio Foundation) merged in [#375](https://github.com/sambitcreate/aiden-agent/pull/375) and [#376](https://github.com/sambitcreate/aiden-agent/pull/376). Create Images CI-1 merged in [#382](https://github.com/sambitcreate/aiden-agent/pull/382) (headless core) and [#383](https://github.com/sambitcreate/aiden-agent/pull/383) (UI and Playwright); CI-1.10 live OpenRouter acceptance passed (owner, 2026-10-08). Design Studio DS-1a (headless core: projects, design runs, partial publish + Resume, preview resolver, IPC) merged in [#385](https://github.com/sambitcreate/aiden-agent/pull/385) (2026-10-08, shipped in 0.55.0); DS-1b was never started. The Design Studio half was superseded 2026-10-31 by [Design mode](../superpowers/specs/2026-10-31-design-mode-design.md); Studio code removed in P0, and `AIDEN_EXPERIMENTAL_DESIGN_STUDIO` no longer does anything. Create Images continues under this plan behind `AIDEN_EXPERIMENTAL_CREATE_IMAGES` (default off). Haiku-built tasks were independently audited on Opus 5.5 and fixed before merge. Create Images viewer, editor History tab, All Images library and always-on auto-save to Pictures merged in [#689](https://github.com/sambitcreate/aiden-agent/pull/689) (2026-11-02, stacked on [#686](https://github.com/sambitcreate/aiden-agent/pull/686)) and shipped in 0.64.0. - [On-device speech engine foundation (STT sub-project 1)](stt-engine-foundation-spec.md) — Merged in [PR #436](https://github.com/sambitcreate/aiden-agent/pull/436), with hardening in #439; shipped in 0.56.0. Plan: [implementation plan](../superpowers/plans/2026-10-09-stt-engine-foundation.md); the smoke run, packaging check and native client tests are recorded in its Progress section and `.memory/stt-engine-foundation.md`. The onboarding voice step is deferred to sub-project 4. First of four Handy-informed speech-to-text sub-projects (engine foundation, live and accuracy, dictation UX, consistency and onboarding). It stays on sherpa-onnx (pinned 1.13.8) and covers: diff --git a/docs/superpowers/plans/2026-11-24-design-mode-v2-p2b-dev-server.md b/docs/superpowers/plans/2026-11-24-design-mode-v2-p2b-dev-server.md new file mode 100644 index 000000000..b52adfabd --- /dev/null +++ b/docs/superpowers/plans/2026-11-24-design-mode-v2-p2b-dev-server.md @@ -0,0 +1,1394 @@ +# Design mode v2 — Phase 2b: the dev server process — Implementation Plan + +> **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. + +**Goal:** Design mode can run the workspace's web app, safely and only when the person has agreed to it. +- `DesignAppServers` starts, installs, stops and restarts one dev server per workspace and app root, on top of `backgroundJobs`, with a `design` job owner that no chat owns (S7). +- Before the first start, and whenever the launch surface changes, the person sees one consent card naming the commands and the script text. Main keeps a hash of what they approved (S2). +- The server binds to loopback only (S14). Its origin is `http://127.0.0.1:`, and it counts as ready only on a socket its own processes hold. An exposure check that fails closed watches it for as long as it runs. +- A server stops 60 s after no window shows that workspace's canvas, when the workspace changes or goes away, and when Aiden quits (S6). +- Aiden gets a `design_app` tool, recorded as a reviewed approval exception. 2c and 3a get a fixed status, consent and origin contract, so they don't change 2b's types. + +**Architecture:** +- **Shared contract.** `renderer/shared/design-app.ts` holds the status, problem and consent types, the fixed problem messages, the display escaping and the IPC payload shapes. 2c's chip and 3a's frames read only these. +- **Pure core.** `main/services/design-canvas/app-server/app-launch-core.ts` takes a detected app, the scripts and a port, and returns the argv and environment. It also holds: + - the readiness choice and the exposure check; + - the install decision; + - the fingerprint's canonical form. + + It does no I/O. +- **Disk and network edges.** + - `app-fingerprint.ts` hashes the launch surface with bounded, no-follow reads. + - `app-records.ts` keeps consents, install stamps and sticky ports in one userData file, and fails closed. + - `app-ports.ts` picks a free loopback port. + - DM's `canvas-config.ts` (extended here with `script` and `saveCanvasConfigApp`) reads and writes `.aiden/canvas.json`. +- **Process layer.** `backgroundJobs` gains: + - a `design` owner; + - argv spawning without a shell; + - a rotating log; + - its own running cap; + - `designSockets(jobIds)`, which lists every listening socket of each job's process group and descendants, from one `ps` and one `lsof` call for all jobs, and fails closed. +- **Service.** `app-server-main.ts` holds `DesignAppServers`, one per process. It owns the per-app state machine and serialises actions per key. It holds a workspace admission per attempt, drives consent through `DesignAppConsent` (`app-consent.ts`), and watches visible-canvas presence from `DesignCanvasViews`. +- **Surfaces.** + - the `design_app` tool (`app-tool.ts`); + - the `designApp:*` IPC handlers; + - a hook on the person's design-mode toggle; + - one renderer card (`renderer/design/design-app-consent.tsx`). + + There's no status chip: that's 2c. + +**Tech Stack:** TypeScript (ESM), Electron 43 main, React renderer, `tsx --test` for unit and integration tests, Playwright for one E2E (Cua Space and host). + +**Spec:** `docs/superpowers/specs/2026-11-23-design-mode-live-app-design.md`: +- §3 anti-goals 2 and 4, §4, §5.2; +- §6.2.1 (the Choose apps rule), §6.2.2 (the launch environment), §6.2.3, §6.2.4, §6.8 (the Node-missing and install-failed states); +- §6.10 (`design_app_started`), §6.11, §7 (main services), §8 (row 2b), §10; +- §12 S2, S5, S6, S7, S8, S14, S15 (the consent half: 2c reuses S2's card for a repo URL) and S19–S22. + +**Stacking.** DM lands first (cross-phase decision 1). 2b's branch stacks on DM's branch, which stacks on PR #911 (Phase 2a), which is stacked on PR #908 (Phase 1b) and PR #894 (Phase 1a). 2b builds on these DM modules, which must exist on its base: +- `main/services/design-canvas/canvas-config.ts`: `CANVAS_CONFIG_PATH`, `CANVAS_CONFIG_MAX_BYTES`, `CanvasConfigApp` (already carrying `script?: string`, checked with 2a's `isSafeScriptName`), `CanvasConfig`, `parseCanvasConfig`, `parseCanvasConfigObject`, `readCanvasConfigText`, `readCanvasConfig`, `inspectCanvasConfig`, `configuredRoots(config, detected)`, `describedRoots(config, detected)` and `isSafeWorkspaceRelativePath` (a root of exactly `"."` allowed, any other `.` segment refused). DM's `version` rule: a missing `version` or `1` is known; anything else is unknown, and `parseCanvasConfig` returns `null`, which callers can tell apart from an empty config; +- `designLiveEnabled(env)` and `DESIGN_LIVE_FEATURE_FLAG` in `main/services/studio/feature-flags.ts`; +- `const designLive = designLiveEnabled()` in `llm-client.ts`'s canvas-tools block; +- `docs/design-mode.md` with DM's "DESIGN.md (experimental)" section; +- the S33–S44 amendments block in the spec. + +2b's amendments are S25–S32 (cross-phase decision 4). + +## Scope + +In scope: +- reusing DM's flag helper and DM's `studioCapabilities().designLive` for 2c's renderer; +- `backgroundJobs` changes (S7): + - the `design` owner and argv spawning; + - the rotating log with byte-offset reads; + - the design cap; + - `designSockets`; + - the owner guards in `scanPorts` and `forgetOldFinished`; +- address-aware listening sockets with a reader that fails closed (S14); +- the launch plan: argv, environment, port and host per framework (S14, S19); +- port choice with a sticky port per app root, and readiness from sockets the job owns; +- the launch fingerprint, the consent records, the consent card, its IPC, the read-only refusal and the desktop-only refusal (S2); +- the install decision with a completion stamp (S8, refined by D6); +- `DesignAppServers`: + - start, stop, restart, logs and choose; + - crashes and the exposure watch; + - the workspace gate; + - the 60 s visible-presence rule (S6); + - workspace removal and access loss; + - quit and crash recovery; +- the `design_app` tool with its gates, its per-turn budget and its reviewed approval exception; +- the person's toggle (button, ⇧⌘L, `/design`, Enter on Aiden's `design_mode` card) starting the target app; +- `saveCanvasConfigApp`, which saves the monorepo choice (`script`, which DM's parser already reads) through the consent card; +- the `designApp:*` IPC that 2c builds on: status get and broadcast, person start, stop, restart and choose, logs, and consent. Every call goes through `rendererDocumentOwner`; +- the `design_app_started` event (§6.10); +- a "Live apps (experimental)" section appended to `docs/design-mode.md`, plus `docs/analytics.md`, the S25–S32 amendments, memory and the plan index. + +Out of scope: +- **2c:** the status chip, its menu, the logs drawer, Connect running server, attaching a server by URL, and the browser-panel listing. 2b already defines `source: "attached"`, the `attach` consent request and the attach problems, so 2c adds no type; +- **3a:** app frames, the bridge, the network and permission dispatchers, and the iframe CSP. 2b gives 3a `appForOrigin`, `isAppOrigin` and `onOriginsChanged`; +- **other `.aiden/canvas.json` fields:** `routes`, `params`, `mock` and `url` (3b, 3d, 2c). DM owns the parser (including `script` and the `version` rule), `describedRoots` and `designMd`; 2b adds only the writer, which keeps every other field; +- **prompt and skill text.** 3b rewrites them. 2b's only model-facing text is the `design_app` tool's description and results; +- mock apps and scaffolding (3d); +- **Windows.** `hostPlatformCapabilities().backgroundJobs` is false there, so 2b reports `unavailable` and offers no tool; +- **Remote, iOS, Android and the CLI:** + - Remote turns can't start a server (D5); + - design jobs never reach Remote's `chat:jobs`; + - the shared `BackgroundJobView` and `BackgroundJobEndReason` types don't change, so the mobile clients don't either; +- automatic restart after a crash (D10). + +**Feature flag.** Everything that can start a process or show the card is behind DM's `designLiveEnabled()`, which is true when `designModeEnabled(env)` holds and `AIDEN_EXPERIMENTAL_DESIGN_LIVE` is `1`, `true`, `yes` or `on`, trimmed and case-insensitive. Off means: +- the `design_app` tool isn't offered; +- turning design mode on starts nothing; +- every `designApp:*` handler refuses with "Live apps are not available."; +- `DesignAppServers` is never asked to do anything, so no design job, record file, port probe or fingerprint read happens. + +Unflagged and inert while the flag is off: +- `backgroundJobs`' design owner, argv mode, rotating log and `designSockets` (no caller without the flag); +- the address-aware socket reader; +- `DesignCanvasViews.onPresence` and the `visible` field in the view report (a listener with no subscriber); +- the reviewed-exception row in `workspace-tool-approval.ts` (it names a tool that isn't offered); +- `saveCanvasConfigApp` (no caller); +- the `design_app_started` registry row and its docs row. + +## What exists today (checked against the code at `19b464fb9`) + +| Item | Today | 2b action | +|---|---|---| +| `BackgroundJobs.start` (`main/services/follow-through/background-jobs.ts:323`) | `spawn(command, { shell: true, detached: true })` in its own process group, marker env `AIDEN_BACKGROUND_JOB=`, stdin ignored. Per-chat cap 10, global cap 20. | Gains `startDesign` with owner `{ kind: "design", workspaceId, appRoot }` and `argv: { file, args }` (no shell). Design jobs have their own cap and don't count toward the chat caps (Task 2). | +| `list`, `get`, `read`, `settle`, `stop`, `stopChat`, `hasSettleStoppable`, `stopSettled`, `runningCount` | Keyed by `view.chatId`. | Answer only for chat-owned jobs. Design jobs get `getDesign`, `readDesignLog`, `stopDesign`, `listDesign`. | +| `scanPorts` (`:838`, `onChange(view.chatId)` at `:871`) and `forgetOldFinished` (`:931`, `onChange` at `:967-969`) | Call `onChange` with the job's chat id. | Never call `onChange` for a design job; `onDesignChange` instead (Task 2). | +| `listAll()` | Every job; only keep-awake reads it. `backgroundJobKeepAwakeInput` (`keep-awake/keep-awake-inputs.ts:106`) already skips jobs with ports. | Unchanged. A design install keeps the Mac awake while it runs; a listening server doesn't (Q6). | +| `stopWorkspace(workspaceId)`, `shutdown()`, `reapPreviousLaunch()` | Filter by `view.workspaceId`, stop everything, and reap from `running.json`. | Unchanged. They already cover design jobs, because design views keep `workspaceId` and `writeRecord` lists every running job. | +| `capture` (`:880`) | Past 50 MB of output the job is stopped with `output-limit`. | A design job's log rotates instead (D13). A dev server that logs every HMR update must not die after hours. | +| `onEnded`, `onChange(chatId)` (`follow-through-main.ts:191`, the `backgroundJobs` constructor) | `onEnded` posts a notice that wakes the chat; `onChange` broadcasts `chats:follow-through-changed` and feeds `chatSettlement`. | Never called for design jobs. A new `onDesignChange(view)` goes to `DesignAppServers` through a listener set. | +| `listening-ports.ts` | `parseLsofListening` and `parseProcNetTcp` keep ports only. Failures return nothing. | Address-aware siblings, plus `designSockets`, whose reader reports failure instead of nothing (Task 3). | +| `browserLocalServers(output)` (`main/services/browser/core.ts:299`) | Finds loopback URLs in terminal text; maps `0.0.0.0` to `localhost`. | Reused to read the printed port only. Loopback is decided by socket addresses, never by text. | +| `agentShellCommandEnvironment()` (`main/services/agent-command-environment.ts`) | Drops only secret-named `AIDEN_*` variables; keeps tooling tokens and provider keys. | The base of the launch environment, then scrubbed further (D7). | +| pi-ai `findEnvKeys(provider, env)` (`node_modules/@earendil-works/pi-ai/dist/env-api-keys.js:121`, pi-ai 1.5.2) | Exported from `@earendil-works/pi-ai/compat` (which re-exports `env-api-keys`), not from the main entry; returns the provider key variables present in `env`. The name table itself isn't exported. `compat` also exports `getProviders`. | `providerKeyNames(env)` imports both from `@earendil-works/pi-ai/compat`, calls `findEnvKeys` for every provider, and deletes what it finds. | +| `nodeCommandEnvironment`, `resolveAppToolchain`, `toolchainProblemMessage`, `clearAppToolchainCache`, `detectWebApp`, `designTarget`, `installCommand`, `runScriptCommand`, `FRAMEWORKS` (2a) | No caller yet. | First caller. `FRAMEWORKS[].devCommands` tells whether a script runs the framework's own CLI. | +| `DesignCanvasViews.mounted(workspaceId)` (`views.ts:177`) | A count, with no events. `report`, `unmount` and `unmountAll` set `mounted`. The renderer (`renderer/design/use-design-view.ts:102`) reports views; the stacked layout's visible pane is in `renderer/design/design-layout.tsx:48-67`. | The report gains `visible`, and the views gain `visible(workspaceId)` and `onPresence` (Task 7). | +| `chats:setDesignMode` (`main/handlers/chat-renderer-mutations.ts:140`) | Knows `wasOn` and the source; reports `design_mode_entered`. Its event parameter is unused. | On a false → true change with the flag on, it calls `designModeEntered` with `rendererDocumentOwner(event, …)` as the card's owner. | +| `designCanvas:consentAnswer` (`main/handlers/design-canvas-main.ts:35`) | Enter on Aiden's card turns design mode on. | Same hook, with that window as owner. | +| `rendererDocumentOwner(event, invalid)` (`main/services/renderer-document-owner.ts:85`) | Throws unless the sender is the current main frame; the owner can `send` and `onInvalidated`. | Every `designApp:*` handler and the toggle hook use it. | +| `DesignModeConsent` (`design-mode-tool.ts:35`), `renderer/design/design-mode-consent.tsx` | One pending card per chat, owner checks, 2-minute timeout, answers only from the card's window. | The pattern `DesignAppConsent` and its card follow. | +| `createMcpStdioApprovalStore` (`mcp-stdio-approvals.ts`) | Serialised writes, fail closed on an unreadable file, `approveShown`. | The pattern for the records file. | +| `workspaceMutationGate` (`main/services/workspace-mutation-gate.ts`) | `admit(id)` gives a signal that `begin(id)` aborts. Workspace `update` and `remove` call `begin` (`workspace-application-service.ts:381`, `:515`), then `closeForWorkspace` stops the workspace's jobs. Managed worktrees go through `beginWorkspaceMutation` (`workspace-worktree-application-service-main.ts:148`). | Each attempt holds an admission (D11). Because `begin` already aborts admissions, and every workspace change already stops the jobs, 2b adds no separate `pauseWorkspace`. | +| `processRecoveryReady` (`main/index.ts:2588`) | The result of reaping the last launch's jobs; `:2739` refuses work until it's true. | `start` waits for it (D3). | +| `designCanvasWorkspaceCleanup` (`design-canvas/main.ts:97`), `removeDesignCanvasWorkspace` (`:107`) | Called on workspace remove (`main/index.ts:2759`) and on managed-worktree delete (`workspace-worktree-application-service-main.ts:145`). | Also calls `designAppServers.forgetWorkspace`. | +| Remote turns (`main/services/aiden-remote-chats.ts:1420`) | Run with `usageSource: "chat"`, so they pass `followThroughAvailable`. Their owner has `kind: "remote"`. | `start`, `restart` and `choose` refuse them (D5). | +| `write_file`'s confined write (`coding-tools.ts`: `pinWorkspaceRoot` `:369`, `verifyWorkspaceRoot` `:394`, `resolveWritableInRoot` `:563`, `commitPinnedWrite` `:866`, `readReplacedFile` `:909`) | Module-private. Creates parent folders without following links and commits through the pinned writer. `assertAgentMayWriteConfigPath` protects only `.aiden/hooks.json` and `.aiden/hooks/` under `.aiden`. | A new exported `writeConfinedWorkspaceText(root, relPath, text, { expectedSha256?, signal })` reuses that path for `saveCanvasConfigApp` (Task 5). `writeWorkspaceFile` (the Files panel) can't create, and `writeWorkspaceBinaryFile` refuses hidden folders, so neither fits. | +| `AIDEN_ANALYTICS_DEBUG` (`analytics-main.ts:51`) | Read only when `!app.isPackaged`. | The pattern for the E2E grace knob (Q8). | +| `scripts/ci-test-registry.json` lanes | `core-git`, `runtime-subagents`, `renderer-other`, `macos`. | Main tests in `core-git`, renderer tests in `renderer-other`, `app-server-process.test.ts` in `macos`. | +| `scripts/ci-e2e-spec-map.json` | `design-canvas.spec.ts` maps to `main/services/design-canvas/` and `main/handlers/design-canvas`. | A row for `design-app-server.spec.ts`. | + +## Decisions + +These settle the rules the spec leaves open. Task 14 records the ones that change the spec as S25–S32. + +**D1. Owner.** A design job's owner is `{ kind: "design", workspaceId, appRoot }`. It has no chat. +- It never wakes a chat. +- It never appears in `background_job`, Remote's `chat:jobs`, the goal check's `jobsRunning` or chat settlement. +- It isn't stopped by a chat delete. +- It never triggers `chats:follow-through-changed`, including from `scanPorts` and `forgetOldFinished`. + +Its lifetime is visible presence, the workspace and quit (S7). + +**D2. One server per app root.** The key is `workspaceId + "\0" + appRoot`, where `appRoot` is 2a's POSIX relative root. Every action on a key runs through one per-key queue. +- A start while running answers `running`. +- A start while consent, install or start is pending joins that attempt, so the consent broker never shows a second card for a key. +- Two chats in one workspace share the server. +- Two workspace records on the same folder are two keys. Next.js refuses a second dev server in one folder, which then shows as a crash (Risk 12). + +**D3. What starts a server.** Only these: +- the person turning design mode on in a chat of the workspace (false → true), from a desktop window's main frame, with the flag on; +- `design_app start`, `restart` or `choose`; +- `designApp:start`, `restart` or `choose` from a window (2c's chip and 3a's "Start app" overlay). + +Every start first waits for `processRecoveryReady`. If recovery failed, the start ends with `recovery-failed`. Launching Aiden, restoring design-mode chats, opening a canvas, switching chats, moving a chat to another workspace (it isn't a false → true change), Remote, the CLI and background work never start a server, install, probe a port or read a fingerprint. + +**D4. What the toggle starts.** From `designTarget(detectWebApp(root))` and `readCanvasConfig(root)`: +- **configured roots:** DM's `configuredRoots(config, detected)` (cross-phase decision 2): the scripted entries detection sees as web candidates, `[]` for a `null` or unsupported config. 2b doesn't restate or re-implement its rule. When it returns any, they decide, whatever the target. (DM's `describedRoots` adds a detection fallback for DESIGN.md lookup; 2b never uses it to decide what starts); +- otherwise `single`: that app; +- otherwise `choose`: nothing starts, and the snapshot target is `choose`; +- `react-nonweb` and `none`: nothing. + +Each app gets its own card when consent is needed, shown one after another. A config with an unknown `version` (`parseCanvasConfig` returns `null`) describes no roots. + +**D5. Consent (S2).** +- **Fingerprint.** SHA-256 of a canonical JSON object (`launchFingerprintInput`), built from detection and toolchain resolution run now. It holds: + - `v: 2`, `appRoot`, `installRoot`, `lockfileLevelsUp`, the manager name and Yarn flavour, and the script name; + - script texts (absent recorded as `null`): + - the app root's `