diff --git a/.memory/design-mode.md b/.memory/design-mode.md index 7db39a11f7..8c76022a5b 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` used only by `main.ts`, deleted in 3b; 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. +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` used only by `main.ts`, deleted in 3b; 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. 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. @@ -379,3 +379,17 @@ Branch `t3/design-mode-v2-p1b`, stacked on PR #894. Plan `docs/superpowers/plans - Lifecycle: `forgetChat(chatId, workspaceId, scope)`: `comments` before a delete commits, `all` (claim, `namedFor`, artifact frames) after; `move` for `moveEmptyToWorkspace` (also deletes an empty page made for the chat). Startup recovery uses `recoverDeletedChatCanvas` (cleanup.ts); when the chat's metadata is already gone (crash after the remove) it runs `all` on every canvas (`DesignCanvasStore.workspaceIds`), because the pending-deletion marker lives in the subagent run stores' strict V1 format and can't carry a workspace id. Attaching from a shared legacy No workspace canvas runs `move` on it. Attach carry claims the first carried page; at a full `chatPages` it asks liveness and evicts gone chats, else skips only the claim. - Picker (`design-toolbar.tsx`): trailing tertiary label "This chat", "This chat · N more", "1 chat", "N chats"; accessible name "Page 1, This chat". Counts only, from the doc. Only entry, `canvas_page use` and `canvas_page delete` drop leftover claims and `namedFor` marks of chats that are not live; other `canvas_page` actions and other writes don't. - E2E: `tests/e2e/design-canvas.spec.ts` "two chats on one workspace…" (screenshot `1440-canvas-two-chats-{light,dark}.png` in the test's output folder). + +## v2 Phase 2a: app detection (2026-11-24) + +Branch `t3/design-mode-v2-p2a`, stacked on PR #908. Plan `docs/superpowers/plans/2026-11-24-design-mode-v2-p2a-app-detection.md`; spec S19–S24. +- Layout: `main/services/node-toolchain.ts` (shared lookup: PATH, then `$SHELL -ilc "command -v "`, then Homebrew; fixed `ToolCommand` union checked at runtime; optional `ExecutableCache` of validated login-shell answers; `isStandaloneNodeExecutable(…, { minMajor })`; `prependPathEntries`, `nodeCommandEnvironment(env, binDirs)`). `main/services/design-canvas/app-server/`: `app-server-core.ts` (pure R2–R5, R8, R10 and pattern helpers), `app-detect.ts` (`readBounded`, `detectWebApp`, the only disk reader), `app-toolchain.ts` (`resolveAppToolchain`, `defaultAppToolchainDeps`, `toolchainProblemMessage`). +- Devices: Task 1 (own commit) made `deviceNodeEnvironment`, `androidSdkEnv` and `createNpmRunner` drop empty PATH entries. The lift kept every `device-toolchain.ts` export as a wrapper (Node 22, npm lookup with Node's default buffer, Node lookup at 16 KiB, no cache). The oracle was the existing device tests unedited plus Task 1's cases and two argv guards. +- R3: `dev`, `start`, `serve`; a script running the framework's dev command wins; otherwise the first that isn't a build, production run, Storybook or workspace runner. Word matching on script text, not a shell parser. +- R4 order: invalid package.json; desktop shell (Electron, Tauri) with React → `react-nonweb desktop`, without → `none desktop`; framework + script → `web`; runner script or `nx.json`/`turbo.json`/`lerna.json` → `workspace-runner`; React Native/Expo; framework with no dev/start/serve and no Storybook → `no-dev-script`; usable script, no framework → `unknown-framework`; React → `react-nonweb`; else `none`. +- R5: field wins only with no lockfile or its own (else conflict with `field` set); two managers' lockfiles conflict; a single install marker in `node_modules` settles a conflict (`source: "installed"`, conflict kept); `pnpm-workspace.yaml` → pnpm; Deno → `unsupported`; nothing → npm `none`. Yarn flavour: field major, else `.yarnrc.yml`, `.pnp.cjs` or `__metadata:` in the 512-byte lock head. +- R6: members without their own lockfile install at `.`; a candidate with its own lockfile is its own install root. The enclosing walk runs only when the root has no lockfile, field, `pnpm-workspace.yaml`, Deno marker or `.git`; it stops at `.git`, home, `stopAt` (after realpath) and five levels, and reports only `lockfileLevelsUp`. +- Remix 3 (checked against `remix@3.3.0`): dev command `node --watch`, port 44100. TanStack Start's starter uses port 3000. Only npm gets `--` before extra script arguments (pnpm 12 and Yarn 4 pass a bare `--` through). +- Node 22 for design, the same as devices. No corepack fallback; 2b sets `COREPACK_ENABLE_DOWNLOAD_PROMPT=0` (S19). +- Nothing calls the design modules until 2b. Tests: `node-toolchain.test.ts` (in `test:devices`), `app-server-core.test.ts`, `app-detect.test.ts`, `app-toolchain.test.ts` (in `test:design-mode`). +- Code review fixes (2026-11-24): the agent-device launcher and `run`'s no-Node branch also drop empty PATH entries (plan Q7 settled). Follow-up: `ssh-device-script.ts:26` builds the remote PATH as `…:$PATH`. Detection: the enclosing walk's signal counts only when that folder's `workspaces`/`pnpm-workspace.yaml` lists the workspace; hand-off root scripts (`-w`/`--workspace`/`--prefix`/`--dir` next to a package manager, `yarn workspace`, `pnpm -C`, `concurrently`, `npm-run-all`, `run-p`) are runners; a workspace root is `web` only through the framework's own dev command; a framework app with only production scripts is `no-dev-script`; `clearAppToolchainCache()` for 2c's Retry; conflict messages say how to fix, with plural wording for 3+ managers. diff --git a/.memory/devices-ssh-hosts-toolchain.md b/.memory/devices-ssh-hosts-toolchain.md index 6f8f5fa2be..d7f674f2fe 100644 --- a/.memory/devices-ssh-hosts-toolchain.md +++ b/.memory/devices-ssh-hosts-toolchain.md @@ -62,3 +62,7 @@ This is sibling C of the devices-parity effort (six parallel implementers). It p - No protocol, mobile DTO, release fuse, provider, or startup network changes. Packaged runtime smoke and PR validation results are recorded in the PR. - Local validation: device suite 598/598; simulator stream + agent Electron E2E 2/2; type-check, E2E type-check, ESLint and production build passed. An isolated ASAR Electron 43.1.1 app with RunAsNode disabled launched the actual installed expo-device-hub 0.12.0 through standalone Node and received readyz HTTP 200. This is runtime smoke evidence, not a notarized Aiden release or physical-device acceptance. - PR #447 review follow-up: Node discovery is best effort during daemon shutdown so missing Node cannot block consent revocation, token-config deletion, tool removal or proxy closure. Missing Node uses a recoverable setup error, preserving Settings' existing Retry action. Tests exercise real service removal/revocation and the service-produced Settings error followed by successful Retry. Device suite now passes 600/600. + +## Shared Node toolchain and PATH fix (2026-11-24) +- Node and npm resolution now lives in `main/services/node-toolchain.ts`, shared with design mode's live app (v2 Phase 2a). `device-toolchain.ts` keeps the same exports (`resolveNpm`, `defaultNpmResolutionDeps`, `resolveDeviceNode`, `defaultDeviceNodeResolutionDeps`, `isDeviceNodeExecutable`, `deviceNodeEnvironment`, `NpmResolutionDeps`) as wrappers with the device settings: Node 22+, no cache, npm lookup with Node's default buffer, Node lookup at 16 KiB. +- `deviceNodeEnvironment`, `androidSdkEnv` and `createNpmRunner` build PATH through `prependPathEntries`, which drops every empty entry (an empty entry means the working folder). The generated agent-device launcher does the same in its own text, and `run` drops inherited empty entries for commands that start before Node is resolved (an unset PATH stays unset). Follow-up: `ssh-device-script.ts:26` (remote `…:$PATH`). diff --git a/docs/plans/README.md b/docs/plans/README.md index 879ff4f73f..4c4243c7a9 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). +- [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). - [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-p2a-app-detection.md b/docs/superpowers/plans/2026-11-24-design-mode-v2-p2a-app-detection.md new file mode 100644 index 0000000000..b5b374de49 --- /dev/null +++ b/docs/superpowers/plans/2026-11-24-design-mode-v2-p2a-app-detection.md @@ -0,0 +1,766 @@ +# Design mode v2 — Phase 2a: app detection — 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:** Give design mode a tested way to find a workspace's web app and the tools to run it, before anything runs. +- The device helpers stop putting an empty entry on PATH. That is a small safety fix, with its own commit, made before the lift. +- The Node and package-manager lookup that devices use moves into a shared `main/services/node-toolchain.ts`. Devices behave as they do after that fix. +- `detectWebApp(root)` finds the workspace's app candidates and classifies each as `web`, `react-nonweb` or `none`. For each it gives the framework, dev script, package manager, install root and install state. +- Lockfile and package-manager rules are pure functions, and so are the fixed install and run commands built from them. +- `resolveAppToolchain` turns a missing Node or package manager into a typed reason that 2b and 2c can show. + +**Architecture:** +- **Shared toolchain.** `node-toolchain.ts` holds: + - the generic resolver (PATH, then the login shell, then Homebrew), with an optional cache of validated paths; + - the standalone-Node check; + - the PATH and environment helpers. + + `devices/device-toolchain.ts` keeps every export it has today, as thin wrappers that pass the device's own settings (Node 22, `npm` and `node` only, no cache). Device callers don't change. +- **Pure core.** `main/services/design-canvas/app-server/app-server-core.ts` takes parsed inputs (a package.json object, lockfile names, a few existence flags) and returns the classification. It does no I/O. +- **Reader.** `app-detect.ts` reads the disk with bounded, no-follow reads and feeds the core. It is the only 2a file that touches the filesystem for detection. The spec put `detectWebApp` in `app-server-core.ts`; S23 records the move. +- **Toolchain join.** `app-toolchain.ts` combines a detected app with `node-toolchain.ts` and returns either the resolved binaries or a typed problem. + +Nothing in the running app calls the new design modules in 2a. 2b is their first caller. + +**Tech Stack:** TypeScript (ESM), Electron 43 main, `tsx --test` for unit tests. No renderer or E2E changes. + +**Spec:** `docs/superpowers/specs/2026-11-23-design-mode-live-app-design.md`: +- §4 (constraints), §5.2; +- §6.2.1 (detection), §6.2.2 (Node toolchain), §6.2.3 (the install rule; 2a uses it only for the command table); +- §6.8 (non-web React projects, missing Node); +- §7 (pure-core tests), §8 (row 2a), §10 (builder's choices), §11 item 3 (E2E fixture); +- §12 S2, S6, S8 and S14, which 2b builds on top of this. + +Stacked on PR #908 (Phase 1b), which is stacked on PR #894 (Phase 1a). + +## Scope + +In scope: +- the device PATH fix: `deviceNodeEnvironment`, `androidSdkEnv` and `createNpmRunner` stop adding empty PATH entries (Task 1); +- lifting `resolveExecutable`, the login-shell lookup, the standalone-Node check and the environment helpers out of `device-toolchain.ts` into `node-toolchain.ts`. They're generalised to a fixed set of commands (`node`, `npm`, `pnpm`, `yarn`, `bun`), and devices don't change; +- an optional cache of validated login-shell answers, which only design callers use (§6.2.2 "with a cache"); +- `detectWebApp(root)`: candidates at the root, in the spec's fixed folders and in declared workspace patterns, each classified (§6.2.1); +- package-manager and lockfile detection, covering: + - conflicting lockfiles and the `packageManager` field; + - `pnpm-workspace.yaml` as a pnpm signal, and Deno markers; + - workspace members; + - a workspace folder that sits inside a larger repo; +- the fixed install and run-script argv for each manager (§6.2.3 "Install", S2 "the resolved command"); +- `designTarget(detection)`: what design mode should do with a detection (start one app, ask which, offer mocks, or nothing); +- `resolveAppToolchain(app)`: Node and the package manager resolved, or a typed reason with a short message; +- the spec amendments recording 2a's decisions, the memory files and the plan index. + +Out of scope: +- starting, stopping or installing anything: `DesignAppServers`, `backgroundJobs` changes, the `design` job owner, consent and the install stamp (2b: S2, S7, S8); +- the dev-server command environment: `agentShellCommandEnvironment()`, `BROWSER=none`, `FORCE_COLOR=0`, `PORT`, `COREPACK_ENABLE_DOWNLOAD_PROMPT=0` and the loopback host flags (S14). §8 lists §6.2.2 under 2a, but these are launch facts with no caller until 2b, so they land there with the process (S19). 2a settles the signatures 2b needs (`nodeCommandEnvironment(env, binDirs)`, `runScriptCommand(info, script, extraArgs)`) so 2b doesn't change them; +- `.aiden/canvas.json`: reading `apps`, `mock`, a project naming itself `react-nonweb`, and saving the monorepo choice (3b for the file, 2b for the saved choice); +- the monorepo question card, the status chip and any message shown to the person (2b, 2c); +- route discovery (3b), mock apps and the scaffold questions (3d); +- a corepack fallback for a missing `pnpm` or `yarn` (settled: none); +- running Deno projects (reported as `unsupported-manager`); +- Windows. Design live needs `backgroundJobs`, which `hostPlatformCapabilities()` gives only on darwin and linux. 2a makes no platform claim and changes nothing in `host-platform-capabilities.ts`; +- analytics. `design_app_started` belongs to 2b (§6.10). + +**Feature flag.** 2a ships without `AIDEN_EXPERIMENTAL_DESIGN_LIVE`. It has no user-facing surface: no IPC channel, no tool, no UI and no new process. The flag starts in 2b (S6), the first phase that calls these modules. The device fix and lift aren't design work; they stay under the devices' own flag, as today. + +## What exists today (checked against the code at `e88271d63`) + +| Item | Today | 2a action | +|---|---|---| +| `resolveExecutable(command: "npm" \| "node", deps)` (`device-toolchain.ts:197`) | PATH entries (absolute only), then the `$SHELL -ilc` output (last absolute line, checked with `isExecutable`), then `/opt/homebrew/bin` and `/usr/local/bin`. Not exported. | Moves to `node-toolchain.ts`, exported, with a wider command union and an optional `cache` dependency (Task 2). | +| `NpmResolutionDeps` (`:185`) | `{ env, isExecutable(path), loginShellLookup(shell) }`. The lookup has its command baked in. | Becomes an alias of `ExecutableResolutionDeps`, whose lookup takes `(shell, command)`. A one-argument function still fits the type, so device code and tests compile unchanged. | +| `resolveNpm` (`:193`), `defaultNpmResolutionDeps` (`:219`) | npm: a plain `X_OK` check. The lookup runs `command -v npm` with `env: process.env`, a 5 s timeout and the default `maxBuffer`. Used by `main/handlers/devices.ts:53` and `scripts/devices-acceptance.mjs:56`. | Stay in `device-toolchain.ts` as wrappers, with the same argv, timeout, env and buffer. A guard test pins the argv before the lift. | +| `resolveDeviceNode` (`:284`), `defaultDeviceNodeResolutionDeps` (`:322`) | Node is checked with the `isDeviceNodeExecutable` probe. The lookup runs `command -v node` with the given env and `maxBuffer: 16384`. No cache. Used by `local-device-host.ts:850`. | Wrappers over `resolveExecutable` and `isStandaloneNodeExecutable(…, { minMajor: 22 })`. A guard test pins the argv and buffer. | +| `isDeviceNodeExecutable` (`:295`) | Rejects the app binary by realpath and inode, then runs `-p` and wants `electron === false` and major ≥ 22. It probes with `deviceNodeEnvironment`. Defaults: `process.execPath`, `!!process.versions.electron`. | Wrapper over `isStandaloneNodeExecutable` with `minMajor: 22`, keeping both defaults. | +| `deviceNodeEnvironment` (`:288`) | PATH = `[dirname(node), env.PATH ?? ""].join(path.delimiter)`, then deletes `ELECTRON_RUN_AS_NODE`. With PATH unset or `""` it leaves a trailing `:`, and it keeps any empty entry in the inherited PATH. An empty entry puts the working folder on PATH. Used by `local-device-host.ts` (`:315`, `:358`, `:363`) and `device-tool-maintenance.ts:168`. | **Task 1 fixes it:** no empty entries, by the rule `nodeCommandEnvironment` uses. Task 2 makes it a wrapper over `nodeCommandEnvironment(env, [dirname(node)])`. | +| `androidSdkEnv` (`local-device-host.ts:264`, PATH built at `:274`) | Joins the SDK folders with `env.PATH ?? ""`, which gives the same trailing `:`. No direct test; `local-device-host.test.ts:769` and `:800` test the SDK lookup around it. | Task 1 fixes it, with a new test next to `:800`. | +| `createNpmRunner` (`device-toolchain.ts:243`) | `[dirname(npm), env.PATH].filter(Boolean)` drops a missing PATH, but keeps empty entries inside the inherited PATH. | Task 1 uses the same helper here (see Review amendments, B-M1 note). | +| `NODE_REQUIRED_REASON`, `DeviceNodeUnavailableError`, tool specs and installs | Device-only. | No change. | +| Device tests | `device-toolchain.test.ts` covers npm and Node resolution order, app-binary rejection, old runtimes and the environment (`:294-301`). It is in `test:devices` and the `runtime-subagents` registry lane. | Task 1 extends `:294-301` with three PATH cases. After that, the lift's oracle is the existing device tests unedited, plus Task 1's cases and Task 2's two argv guards. | +| `packages/cli` | Bundles no `devices/` or `design-canvas/` module (`grep` over `packages/cli/src` finds neither). | `npm run cli:build` is a guard only. | +| Lockfile or framework detection | None in `main/` or `renderer/`. Only CI scripts mention lockfiles. | New. | +| `tests/fixtures/design-live-app/` (§7, §11 item 3) | Doesn't exist yet; 3a adds it. | 2a's tests build their own trees in temp folders. One case copies the fixture's shape (Vite + React, `node_modules` as a symlink). | +| `yaml` | Runtime dependency, `2.9.0`. | Used to read `pnpm-workspace.yaml`. | + +## Review amendments (2026-11-24) + +Two adversarial reviews (A: detection rules; B: lift safety and tests) were accepted in full. The decision file named minor findings without ids, so this table numbers them B-m1… and A-m1… in the order given. + +| Id | Decision | Where the plan handles it | +|---|---|---| +| B-M1 | Device PATH fix first, own commit; fix `androidSdkEnv`; three cases in `device-toolchain.test.ts:294-301` and one in `local-device-host.test.ts`; drop `probeEnv`; new lift oracle | Task 1; "What exists today"; Interfaces (no `probeEnv`); Task 2 Step 4; Risk 1; S24. Also applied to `createNpmRunner`, which keeps empty entries from the inherited PATH (same file, same rule). | +| B-M2 | Explicit lookup limits: `timeoutMs` defaults to 5000, `maxBuffer` only when defined; > 1 MiB test; real `defaultNpmResolutionDeps` argv test | Interfaces (`loginShellCommandLookup`); Task 2 Step 1 (both tests, plus the same guard for the Node lookup) | +| B-M3 | Cache only validated paths, inside `resolveExecutable` through a `cache` dependency; drop stale entries | R9; Interfaces (`ExecutableCache`); Task 2 Step 1 tests; Risk 4 | +| B-M4 | `lockfileLevelsUp: number` | R8 type; R6; Task 5 enclosing test | +| B-M5 | `runScriptCommand(info, script, extraArgs?)` with per-manager `--`; `nodeCommandEnvironment(env, binDirs[])` | R10; Interfaces; Task 2 and Task 4 tests | +| B-m1 | Line references fixed against HEAD | "What exists today" (checked at `e88271d63`) | +| B-m2 | `isStandaloneNodeExecutable` keeps the defaults `process.execPath` and `!!process.versions.electron` | Interfaces | +| B-m3 | S-amendments for the `detectWebApp` move and the PATH fix | Task 7 (S23, S24) | +| B-m4 | Docs: `.memory/devices-ssh-hosts-toolchain.md:59`; wider docs search | Task 7 Steps 3–4 | +| B-m5 | Tests: a dangling `node_modules` symlink, and a symlinked `node_modules` at the enclosing root | Task 5 Step 1 | +| B-m6 | Drop the framework-table loop test | Task 3 (removed) | +| A-M1 | Dev-script choice prefers the framework's dev command and skips builds, production runs and workspace runners | R3; Task 3 tests; Risk 10 settled | +| A-M2 | Angular, Nuxt, `@tanstack/start`, `remix@3`; reason `unknown-framework` | R2; R4 rule 8; Task 3; S22 | +| A-M3 | Tauri is desktop, like Electron | R4 rules 2–3, reason `desktop` plus `desktopShell`; Task 3 | +| A-M4 | Node 22 for design, the same as devices | R9; message text; Q2 settled; the old S22 (Node 20) dropped | +| A-M5 | The field wins only with no lockfile or its own; `pnpm-workspace.yaml` means pnpm; Deno gives `unsupported-manager` | R5; R6; R9; Task 4 tests; S20 | +| A-M6 | `O_NOFOLLOW \| O_NONBLOCK`, `fstat().isFile()`, cap+1 reads; `lstat` containers and pattern parents; drop absolute and `..` patterns; FIFO and `packages → /` tests | Global Constraints ("Bounded reads"); R1; Task 5 | +| A-m1 | No upward walk when the workspace root holds `.git`; compare `stopAt` and home after `realpath` | R6; Task 5 tests | +| A-m2 | A conflict with exactly one manager's `node_modules` marker picks it (`source: "installed"`) and still lists the conflict | R5 step 5; Task 4 and Task 5 tests; Q3 settled | +| A-m3 | npm is resolved first from `dirname(resolvedNode)` | R9 step 3; Task 6 test | +| A-m4 | Yarn flavour: the field's major, else `.yarnrc.yml`, `.pnp.cjs` or a non-v1 `yarn.lock` | R5 "Yarn flavour"; Task 4 and Task 5 tests | +| A-m5 | No corepack fallback; S19 says 2b always sets `COREPACK_ENABLE_DOWNLOAD_PROMPT=0` | Scope; Task 7 (S19); Q1 settled | +| A-m6 | Q5 agreed, with `binDirs` | Scope; Interfaces; Q5 settled | +| A-m7 | `@react-router/dev` before `@remix-run/dev` | R2 order; Task 3 test | +| A-m8 | Edge tests: no `scripts`, array `scripts`, `dev: 42` and `dev: null`, a Storybook-only repo, an Nx integrated repo with no member `package.json`; none may give a misleading "add a dev script" | R4 (`no-dev-script` narrowed, `workspace-runner`); Task 3 and Task 5 tests | + +## Global Constraints + +- **Device behaviour.** After Task 1, devices behave exactly as before, except that they never put an empty entry on PATH. Every export of `device-toolchain.ts` keeps its name and signature. The existing tests in `device-toolchain.test.ts`, `local-device-host.test.ts`, `android-device-features.test.ts` and `renderer/components/settings/simulator-settings.test.tsx` pass without edits. Only Task 1's new cases and Task 2's guards are added. If an existing test needs an edit, the change is wrong. +- **Fixed commands only.** `resolveExecutable` and the login-shell lookup accept only the `ToolCommand` union. The lookup also checks at runtime, so a string from a package.json can never reach `command -v`. +- **Pure core.** `app-server-core.ts` imports nothing from `node:fs`, `node:child_process` or Electron. +- **Bounded reads** (A-M6). Every file `detectWebApp` reads (`package.json`, `pnpm-workspace.yaml`, the head of `yarn.lock`) goes through one `readBounded(path, cap)`: + - it opens with `O_RDONLY | O_NOFOLLOW | O_NONBLOCK`; + - it checks `fstat().isFile()`; + - it reads at most `cap + 1` bytes, and over the cap counts as unreadable; + - a symlink, FIFO, socket, device or folder is unreadable, never followed or waited on. + + Caps: + - 512 KiB per `package.json`, 64 KiB for `pnpm-workspace.yaml`, 512 bytes of `yarn.lock`; + - 200 entries per scanned folder; + - 100 candidates in total (then `truncated: true`). + + Containers (`apps/`, `packages/`) and every parent folder of a workspace pattern are checked with `lstat` and skipped when they're a symlink or not a folder. Candidate folders that are symlinks are skipped. `node_modules` and dot folders are never entered. Existence checks for lockfiles and markers use `lstat` and never read. Nothing throws for a bad file: a bad candidate gets a reason. +- **Relative output.** Every path in a detection is POSIX and relative to the workspace root (`.` for the root). Absolute paths stay inside main and never go into a result. Enclosing folders show up only as `lockfileLevelsUp`. +- **Script names.** A script name is used only when its value is a string, it is at most 100 characters, it has no control characters, and it doesn't start with `-`. So a script name can never be read as a manager option. Extra run arguments must have no control characters. +- **AGENTS.md:** + - no source-grep tests; + - each new test file goes in `scripts/ci-test-registry.json` and a `package.json` script, then `npm run test:ci-policy` runs; + - docs change in this PR; + - platform claims match `host-platform-capabilities.ts` (2a makes none). +- **Each task stands alone.** Every task ends with its own tests, `npx tsc --noEmit -p .` and `npm run test:ci-policy` passing, and one commit. +- **Tests.** Detection tests use real temp folders and call the real functions. Toolchain tests use injected `isExecutable` and lookup fakes, plus temp-folder executables and shells where the real behaviour matters. A test that can't fail before its task's change is marked **(guard)**. + +## Detection rules + +**R1. Candidates** (§6.2.1, §10). `detectWebApp(root)` looks at: +1. the root itself; +2. each folder directly inside `apps/` and `packages/`, and the folders `web/`, `frontend/` and `site/` (the spec's fixed list); +3. the root's declared workspace patterns: `workspaces` in `package.json` (an array, or `{ packages: [...] }`) and `packages:` in `pnpm-workspace.yaml`. + +A folder is a candidate when it has a `package.json`. Supported pattern forms: +- `a`, `a/b`, `a/b/c` (exact); +- `a/*`, `a/b/*` (one level); +- `a/*-app` (a `*` inside the last segment); +- a leading `./` is stripped, and `**` counts as `*`, so `packages/**` searches one level, per §6.2.1 and §10; +- `!pattern` removes matches. + +Patterns that are absolute or contain a `..` segment are dropped. Other forms (braces, deeper wildcards, more than three segments) are ignored. Every parent folder of a pattern is checked with `lstat`, so a symlinked `packages/` pointing at `/` is never listed. Candidates are deduplicated and sorted: root first, then by path. + +**R2. Framework** (§6.2.1; widened by S22). Read from `dependencies` and `devDependencies`, never `peerDependencies`. The first match in this order wins. Later entries also appear inside earlier frameworks' apps: Remix, React Router, TanStack Start and SvelteKit apps all list `vite`, and migrated React Router apps may still list `@remix-run/dev`. + +| Dependency | `framework` | Label | Default port | Dev commands (R3) | +|---|---|---|---|---| +| `next` | `next` | Next.js | 3000 | `next dev` | +| `@react-router/dev` | `react-router` | React Router | 5173 | `react-router dev` | +| `@remix-run/dev` | `remix` | Remix | 5173 | `remix vite:dev`, `remix dev` | +| `remix` at major 3 or later | `remix-3` | Remix | 44100 | `node --watch` | +| `@tanstack/react-start` | `tanstack-start` | TanStack Start | 3000 | `vite`, `vinxi dev` | +| `@tanstack/start` | `tanstack-start` | TanStack Start | 3000 | `vinxi dev`, `vite` | +| `nuxt` | `nuxt` | Nuxt | 3000 | `nuxt dev`, `nuxi dev` | +| `@angular/build`, `@angular-devkit/build-angular` | `angular` | Angular | 4200 | `ng serve` | +| `astro` | `astro` | Astro | 4321 | `astro dev` | +| `gatsby` | `gatsby` | Gatsby | 8000 | `gatsby develop` | +| `react-scripts` | `create-react-app` | Create React App | 3000 | `react-scripts start` | +| `@tanstack/router-plugin` | `tanstack-router` | Vite | 5173 | `vite` | +| `vite` | `vite` | Vite | 5173 | `vite` | + +Notes: +- "React Router v7 framework mode" in the spec is read as `@react-router/dev`. A plain `react-router` dependency is library mode inside some other framework, usually Vite, and matches that framework instead. +- The `remix` package's major version comes from its range (`^3`, `3.x`, `~3.0.0`, `>=3`). Below 3 it is the old v1 meta package and is ignored. Task 3 checked `remix@3.3.0` (npm `latest`): the starter in `@remix-run/cli` runs `NODE_ENV=development node --watch --import remix/node-tsx server.ts`, and `server.ts` listens on `PORT` or 44100. +- `vite` as a dev command means the word `vite` (also `npx vite`, `vite dev`, `vite serve`) not followed by `build`, `preview` or `optimize`. +- The label and default port feed 2c's chip ("Vite · :5173") and its port suggestion. Task 3 checks each port against the framework's current docs and corrects the table if one is wrong. +- Non-React frameworks (Angular, Nuxt, Remix 3, and Vue or Svelte apps through `vite`) run as live frames. Source mapping and component cards stay React-only (§3 non-goals). + +**R3. Dev script** (A-M1). Look only at `dev`, `start` and `serve`, in that order, and only at string values with safe names. +1. **Prefer** the first whose text contains one of the framework's dev commands (R2). So `"dev": "next dev || next start"` and `"dev": "tsc -w & vite"` are picked. +2. **Otherwise** take the first that isn't skipped. A script is skipped when its text contains: + - a build: `vite build`, `next build` (without `next dev`), `tsc`, `tsup`, `rollup`; + - a production run: `next start`, `vite preview`, `astro preview`, `gatsby serve`, `remix-serve`, `react-router-serve`, `NODE_ENV=production`, `serve -s`; + - Storybook: `storybook`; + - a workspace runner: `turbo`, `nx ` (word, then a space), `lerna`, `pnpm -r`, `pnpm --recursive`, `--filter`, `--workspaces`, `yarn workspaces`; and, from the code review, scripts that hand off to one member: `yarn workspace`, `pnpm -C`, `concurrently`, `npm-run-all`, `run-p`, and `-w`, `--workspace`, `--prefix`, `--dir` (with or without `=`). The four flags count only when the script also names `npm`, `pnpm`, `yarn` or `bun`, because other tools use `-w` for watch (`tsc -w`, `rollup -c -w`). + - **A workspace root** (a root that declares `workspaces` or has `pnpm-workspace.yaml` patterns) is `web` only through step 1. Any other usable script there hands off to a member and counts as a workspace runner (R4 rule 5). +3. **Otherwise** there's no script. + +The check is word-based, so the tokens match only as words: `tsc` doesn't match `tscx`. The scan also records whether a dev/start/serve script existed at all and whether one was skipped as a workspace runner, for R4. The list of safe script names (at most 50) is returned too, for 2b's `choose`. + +**R4. Kind** (§6.2.1, §6.8, decision 9; widened by S21). For each candidate, in order: + +| # | Condition | `kind` | `reason` | +|---|---|---|---| +| 0 | No `package.json`, but a Deno marker (`deno.json`, `deno.jsonc`, `deno.lock`); the folder is still a candidate so its manager reports `unsupported: "deno"` (PR #911 review) | `none` | `no-package-json` | +| 1 | `package.json` unreadable, over the cap, not a regular file, or not a JSON object | `none` | `invalid-package-json` | +| 2 | a desktop shell in deps (`electron`, `@tauri-apps/api`, `@tauri-apps/cli`) and React (`react` or `react-dom`) | `react-nonweb` | `desktop` | +| 3 | a desktop shell, no React | `none` | `desktop` | +| 4 | a framework (R2) and a dev script (R3) | `web` | `ok` | +| 5 | a dev/start/serve script was skipped as a workspace runner, or the folder holds `nx.json`, `turbo.json` or `lerna.json` | `none` | `workspace-runner` | +| 6 | `react-native` or `expo` in deps | `react-nonweb` | `react-native` | +| 7 | a framework, no usable script, no Storybook (`storybook` or any `@storybook/` dependency), and either no dev/start/serve string script at all or only production runs (a Next app whose only script is `start: "next start"`) | `none` | `no-dev-script` | +| 8 | a usable (not skipped) dev/start/serve script, and no framework matched | `none` | `unknown-framework` | +| 9 | React in deps | `react-nonweb` | `no-web-framework` | +| 10 | anything else | `none` | `no-web-framework` | + +Notes: +- `desktop` apps also carry `desktopShell: "electron" | "tauri"`, so 3d's question can name the shell (§6.8). Rule 2 before rule 4 is the spec's "no `electron` dependency", extended to Tauri (A-M3). An Electron + Vite + React app, such as Aiden itself, is `react-nonweb`. +- `no-dev-script` means exactly "this is a framework app with nothing to run", so "add a dev script" is the right advice. A Storybook-only repo, or a library whose `dev` is `vite build --watch`, falls through to rule 9 (React mocks) or rule 10 instead. +- `workspace-runner` covers a turbo or Nx root and an Nx integrated repo whose apps have no `package.json`. Its members, when they have one, are found as their own candidates. 2c and 3d say "this repo runs its apps through a workspace tool", and never offer to scaffold. +- `unknown-framework` is an app with a runnable script that design mode doesn't recognise, such as a custom webpack server. 3d must not scaffold for it (A-M2). 2b can still offer it later through `choose`; that's 2b's call. +- Rule 6 is the spec's "uses React but can't run as a web page by itself". A React Native package that also lists `vite` and a dev command runs on the web and is caught by rule 4. +- A `scripts` value that is missing, an array, or not an object counts as no scripts. A script whose value isn't a string (`42`, `null`) counts as missing. +- `.aiden/canvas.json` can later mark a project `react-nonweb` (§6.2.1). That override is 3b's. + +**R5. Package manager and lockfiles** (A-M5, A-m2, A-m4; S20). Signals, per folder: + +| File | Manager | +|---|---| +| `pnpm-lock.yaml` | pnpm | +| `yarn.lock` | yarn | +| `bun.lock`, `bun.lockb` | bun | +| `package-lock.json`, `npm-shrinkwrap.json` | npm | + +Two files of the same manager (`bun.lock` with `bun.lockb`, `package-lock.json` with `npm-shrinkwrap.json`) are not a conflict. The manager is decided at the candidate's install root (R6). Let L be the set of managers with a lockfile there, and F the manager named by the `packageManager` field (`"pnpm@9.15.0+sha512…"`; only `npm`, `pnpm`, `yarn` or `bun` count). +1. **F set, and L empty or `{F}`:** F, `source: "packageManager"`. +2. **F set, and L holds another manager:** `name: null`, `conflict` = L ∪ {F}, sorted. +3. **No F, one manager in L:** that manager, `source: "lockfile"`. +4. **No F, several managers in L:** `name: null`, `conflict` = L, sorted. +5. **Conflict tie-break:** when `node_modules` at the install root holds markers of exactly one manager in the conflict, pick it with `source: "installed"`, and keep `conflict`. The markers are `.package-lock.json` (npm), `.modules.yaml` (pnpm), `.yarn-integrity` or `.yarn-state.yml` (yarn). A `null` name otherwise; 2b refuses to install or start that app, with a message saying how to fix it. Guessing could rewrite the wrong lockfile. +6. **No F, L empty, `pnpm-workspace.yaml` present:** pnpm, `source: "workspace-file"`. +7. **No F, L empty, `deno.lock`, `deno.json` or `deno.jsonc` present:** `name: null`, `unsupported: "deno"`. +8. **Nothing at the install root:** the enclosing walk (R6). If it finds nothing either, npm with `source: "none"`; install is `npm install`, not `npm ci` (§6.2.3). + +**Yarn flavour.** The field's major version decides when the field names yarn (1 is `classic`, 2 or more `berry`). Otherwise it's `berry` when the folder holding the yarn signal has `.yarnrc.yml` or `.pnp.cjs`, or the first 512 bytes of its `yarn.lock` contain `__metadata:`. Anything else is `classic`, including an empty `yarn.lock`. + +**R6. Install root, workspaces and enclosing repos.** +- **Own signals:** a candidate with its own lockfile (or `pnpm-workspace.yaml`) is its own install root, even inside a declared workspace. This covers a standalone `frontend/` in a Python repo, and pnpm's `shared-workspace-lockfile=false`. +- **Workspace member:** a candidate without its own lockfile that matches a root workspace pattern (R1, step 3) has `installRoot: "."`. Its manager comes from the root's signals and `packageManager` field; the candidate's own field wins when it has one. +- **Fixed-folder candidate:** a candidate found only through the fixed list, with no lockfile and no matching pattern, is its own install root. +- **Workspace inside a bigger repo:** a workspace opened at `apps/web` of a pnpm monorepo has no lockfile of its own. Installing with `npm install` there would write a `package-lock.json` and a second `node_modules` into the person's repo. So `detectWebApp` walks upward when all of these hold: + - the root has no lockfile; + - the root has no `packageManager` field, `pnpm-workspace.yaml` or Deno marker; + - the root has no `.git` (A-m1). + + The walk: + - checks each parent folder for the R5 lockfile names, `pnpm-workspace.yaml`, the yarn-flavour markers and `node_modules`; + - stops at the first folder with a lockfile or `pnpm-workspace.yaml`, and after checking a folder that holds `.git` (file or folder); + - never reads the home folder, `stopAt`, anything above them, or past 5 levels. Both `stopAt` and home are compared after `realpath`; + - a signal found there decides the manager by R5, with `source: "enclosing"` (or `"installed"` after a tie-break) and `lockfileLevelsUp` set to how many folders up it was. `installRoot` stays the candidate's own path, because every manager finds its workspace root from a member folder. + + - **Membership** (code review): the folder's signal counts only when that folder's `package.json` `workspaces` or `pnpm-workspace.yaml` lists the workspace's path (`matchesWorkspacePattern`, excludes applied). Otherwise the walk stops and the workspace gets npm with `source: "none"` and a plain install. This covers `examples/next-app` under a library root with a `package-lock.json`, a pnpm repo whose workspace file lists other folders, and a stray parent lockfile. + + The walk reads names, the 512-byte `yarn.lock` head, and the found folder's `package.json` and `pnpm-workspace.yaml` through `readBounded`. It never returns the enclosing path and never runs Deno checks. Tests pass `stopAt` to keep it inside the temp folder. + +**R7. Install state.** `installed` is true when `node_modules` at the install root `stat`s as a folder, or `.pnp.cjs` exists there (Yarn PnP). For an enclosing signal, `node_modules` at that enclosing folder counts too, since npm and yarn hoist there. `stat` follows symlinks: 3a's E2E fixture symlinks its `node_modules` to the repo root's (§7). A dangling symlink is `installed: false`, not an error. This is a hint only: 2b's install stamp (S8) decides whether to reinstall. + +**R8. What a detection returns.** + +```ts +type AppKind = "web" | "react-nonweb" | "none"; +type AppReason = "ok" | "desktop" | "workspace-runner" | "react-native" | "no-dev-script" + | "unknown-framework" | "no-web-framework" | "invalid-package-json" | "no-package-json"; +type FrameworkId = "next" | "react-router" | "remix" | "remix-3" | "tanstack-start" | "nuxt" | "angular" + | "astro" | "gatsby" | "create-react-app" | "tanstack-router" | "vite"; +type PackageManagerName = "npm" | "pnpm" | "yarn" | "bun"; + +interface PackageManagerInfo { + name: PackageManagerName | null; // null on an unresolved conflict or an unsupported manager + source: "packageManager" | "lockfile" | "installed" | "workspace-file" | "enclosing" | "none"; + lockfile?: string; // the file R5 chose, e.g. "pnpm-lock.yaml" + lockfileLevelsUp: number; // 0 inside the workspace; ≥ 1 for an enclosing signal + conflict?: PackageManagerName[]; // R5 steps 2, 4 (kept after a step-5 tie-break) + field?: PackageManagerName; // the packageManager field's manager, on a step-2 conflict (added in Task 6) + unsupported?: "deno"; // R5 step 7 + yarn?: "classic" | "berry"; +} + +interface DetectedApp { + root: string; // "." or "apps/web" + name?: string; // package name, ≤ 214 chars, control characters stripped + kind: AppKind; + reason: AppReason; + desktopShell?: "electron" | "tauri"; + framework?: FrameworkId; + script?: string; // R3 + scripts: string[]; // safe script names, ≤ 50 + usesReact: boolean; + packageManager: PackageManagerInfo; + installRoot: string; // R6 + installed: boolean; // R7 +} + +interface WebAppDetection { apps: DetectedApp[]; truncated: boolean } +``` + +`designTarget(detection)` sums it up for 2b: + +| Detection | `designTarget` | What 2b does (for reviewers; not built here) | +|---|---|---| +| exactly one `web` app | `{ kind: "single", app }` | Turning design mode on starts it (after S2 consent). | +| two or more `web` apps | `{ kind: "choose", apps }` (only the `web` ones) | Nothing starts. Aiden asks which apps, and the chip shows **Choose apps…** (§6.2.1). | +| no `web`, one or more `react-nonweb` | `{ kind: "react-nonweb", apps }` | Nothing starts. 3d's mock-app question. | +| no `web`, no `react-nonweb` | `{ kind: "none", apps }` (all candidates, so `no-dev-script`, `workspace-runner` and `unknown-framework` stay visible) | Nothing starts. 3d's scaffold question only when no candidate has `workspace-runner` or `unknown-framework`; otherwise a hint from the reason. | +| no `package.json` anywhere | `{ kind: "none", apps: [] }` | As above. | + +A `react-nonweb` package next to a `web` app (for example `packages/ui` beside `apps/web`) doesn't change the target. A web app whose manager is `null` is still `web`. Refusing it is 2b's job, so the person sees why. + +**R9. Missing Node or package manager** (§6.8, §4, A-M4, A-m3). `resolveAppToolchain(app, deps)`: +1. **Node first:** `resolveExecutable("node")` with `isStandaloneNodeExecutable(…, { minMajor: 22 })`, the same floor as devices. None found: `{ ok: false, problem: "node-missing" }`. Node is needed even with pnpm's standalone build or bun, because the frameworks' own CLIs run on Node. +2. **No manager name:** + - `unsupported`: `{ ok: false, problem: "unsupported-manager", manager: "deno" }`; + - a conflict: `{ ok: false, problem: "manager-conflict", conflict }`. +3. **The manager:** + - npm is looked for first at `dirname(node)/npm`, then through `resolveExecutable("npm")`; + - other managers go through `resolveExecutable(name)` with a plain executable check. + + None found: `{ ok: false, problem: "manager-missing", manager }`. There's no fallback to npm for a pnpm, yarn or bun project, because that would write a second lockfile, and no corepack fallback (S19). +4. Otherwise `{ ok: true, node, manager: { name, path } }`. + +`toolchainProblemMessage(problem)` gives one fixed sentence per problem, for 2b's tool answers and 2c's chip: +- `node-missing`: "Node.js 22 or newer wasn't found. Install it from nodejs.org or Homebrew, then try again." +- `manager-missing`: "This app uses pnpm, which wasn't found. Install pnpm, then try again." (the manager's name filled in) +- `manager-conflict`: "This app has lockfiles for npm and yarn. Delete the one you don't use, or set packageManager in package.json." (the names filled in; a field-and-lockfile conflict says "packageManager says pnpm, but the lockfile is npm's.") +- `unsupported-manager`: "This app uses Deno, which design mode can't run yet." + +The design callers pass a shared `ExecutableCache` to `resolveExecutable` (B-M3): +- it keeps only a login-shell answer that is absolute and passed `isExecutable`; +- before using a kept path, `resolveExecutable` checks it again and drops it when the check fails; +- junk output and misses are never kept, so installing Node and pressing Retry works without a restart (§6.8 "offers Retry"). + +**R10. Commands** (§6.2.3, S2, B-M5). Pure argv builders. The caller chooses the cwd. + +| Manager | `installCommand` with a lockfile | without | `runScriptCommand(info, script, extraArgs)` | +|---|---|---|---| +| npm | `npm ci` | `npm install` | `npm run