Skip to content

feat(design): detect a workspace's web app and its package manager (design mode v2, Phase 2a) - #911

Open
sambitcreate wants to merge 14 commits into
t3/design-mode-v2-p1bfrom
t3/design-mode-v2-p2a
Open

sambitcreate wants to merge 14 commits into
t3/design-mode-v2-p1bfrom
t3/design-mode-v2-p2a

Conversation

@sambitcreate

Copy link
Copy Markdown
Owner

Stacked on #908 (Phase 1b), which is stacked on #894 (Phase 1a). Merge in order. GitHub retargets each PR when its base merges.

Phase 2a of design mode v2 (spec docs/superpowers/specs/2026-11-23-design-mode-live-app-design.md §8; plan docs/superpowers/plans/2026-11-24-design-mode-v2-p2a-app-detection.md; amendments S19–S24). It adds pure detection only: no IPC, no tool, no UI and no process. Nothing in the running app calls the new design modules until 2b, so there is no flag yet; AIDEN_EXPERIMENTAL_DESIGN_LIVE starts in 2b.

What changes

Devices: empty PATH entries (fix)

An empty PATH entry means "the current folder" to a shell. These spots could add one:

  • the device helpers (deviceNodeEnvironment, androidSdkEnv, createNpmRunner);
  • the agent-device launcher, which runs from the person's repo;
  • early host commands.

A file named like a tool (adb, say) in the working folder could then run instead of the tool. Empty entries are now dropped everywhere these paths are built.

Shared Node toolchain (refactor)

main/services/node-toolchain.ts is lifted out of device-toolchain.ts. It finds node, npm, pnpm, yarn and bun:

  • on PATH;
  • through the login shell (5 s timeout, bounded output);
  • through Homebrew.

The cache keeps only paths that passed the executable check. The device wrappers keep every export and setting, including Node 22. The existing device tests pass unedited. A reviewer also diffed the old and new modules side by side over PATH, lookup and version-probe cases, with identical results apart from the PATH fix.

Web-app detection (app-server-core.ts, app-detect.ts, app-toolchain.ts)

Frameworks:

  • Next, Vite (React, Vue and Svelte), Remix 2 and 3, React Router 7, Astro, SvelteKit, Nuxt, Angular, CRA, Gatsby and TanStack Start.
  • Electron and Tauri are desktop apps, so a plain browser frame can't run them. Expo and React Native are react-native.
  • Storybook-only repos and turbo/Nx/lerna roots get their own reasons, so the person never sees a misleading "add a dev script".

Choosing the dev script:

  • The script that runs the framework's own dev command wins.
  • These are skipped: production servers (next start, serve -s), builds, workspace runners, and roots that hand off to a member (-w, yarn workspace, concurrently).

Package managers:

  • The packageManager field wins only when no lockfile disagrees. When one does, the result is a conflict, and 2b will refuse with a message saying how to fix it rather than write the wrong lockfile. When node_modules holds exactly one manager's install marker, that manager breaks the tie.
  • pnpm-workspace.yaml alone means pnpm.
  • A Deno project is reported as unsupported.
  • Each manager gets the right install and run commands. Only npm takes -- before extra script arguments; this was checked against npm 10, pnpm 12, Yarn 1 and 4, and bun 1.3.

Monorepos:

  • Workspace members install from the workspace root.
  • A workspace opened inside a bigger repo looks upward by file names only, up to 5 levels, stopping at .git or home. It uses the outer lockfile only when the workspace is a declared member, so npm ci or pnpm install never runs against a lockfile that doesn't cover it.

Reads are bounded:

  • files open with no-follow and non-blocking flags, and must be regular files;
  • reads are size-capped;
  • symlinked container folders and workspace patterns with .. or absolute paths are ignored.

A FIFO named package.json returns at once.

Missing tools: app-toolchain.ts turns a missing Node (Node 22 or newer is required) or a missing package manager into a typed reason with a one-line message. clearAppToolchainCache() is ready for 2c's Retry.

Review

  • Plan: two adversarial Opus reviews, covering detection accuracy and the safety of the lift. Every finding was applied.
  • Build: two Opus reviews. One proved device behaviour unchanged. The other ran detectWebApp against 45 real-shape fixture folders. Ten fixes followed, each starting from a failing test.

Tests

  • npm run test:devices: 660/660. Existing device tests are unedited; 19 cases were added.
  • npm run test:design-mode: 920/920, including the new detection suites.
  • npx tsc --noEmit -p ., npm run lint, npm run test:ci-policy and npm run cli:build pass.
  • Device E2E on macOS (host, since the PATH change touches the darwin paths): environment-devices-{tab,agent,android,features,stream}.spec.ts, 6 passed and 1 skipped (the off-macOS case).

Notes

  • Follow-up, not changed here: ssh-device-script.ts:26 exports …:$PATH on the remote, which adds an empty entry only when the remote PATH is empty.
  • npx tsc -p main/tsconfig.json reports the same errors on the base commit (rootDir and import extensions). None are in files this PR touches.
  • No screenshots: this PR changes no UI.

🤖 Generated with Claude Code

sambitcreate and others added 11 commits November 24, 2026 01:50
Co-Authored-By: Claude <noreply@anthropic.com>
deviceNodeEnvironment, androidSdkEnv and createNpmRunner now build PATH
through prependPathEntries, which drops every empty entry, including ones
inherited from the parent PATH. An empty entry means the working folder.

Co-Authored-By: Claude <noreply@anthropic.com>
… lookup

resolveExecutable, the login-shell lookup, the standalone-Node check and
the PATH helpers move to main/services/node-toolchain.ts, generalised to
node, npm, pnpm, yarn and bun, with an optional cache of validated
login-shell answers for design mode. device-toolchain.ts keeps every
export as a thin wrapper with the device's own settings (Node 22, npm
lookup with Node's default buffer, Node lookup at 16 KiB, no cache).

Two guards pin the device lookups' argv and buffer; they passed on the old
code. Deviation: the plan said a one-argument lookup still fits the new
type, which holds for implementations, but callers now pass the command.
The guards therefore call the device lookups with the matching command;
the device wrappers ignore it. No production caller calls the lookup.

Co-Authored-By: Claude <noreply@anthropic.com>
app-server-core.ts holds R2-R4 of the 2a plan: the framework table, the
dev-script choice (the framework's dev command first, then the first
script that isn't a build, a production run, Storybook or a workspace
runner) and the kind and reason of a package.

Remix 3 keeps its row. Checked against remix@3.3.0 (npm latest) and the
starter in @remix-run/cli: its dev script is
"NODE_ENV=development node --watch --import remix/node-tsx server.ts"
and server.ts listens on PORT or 44100, so the dev command is
"node --watch" and the default port 44100. TanStack Start's own starter
(@tanstack/create) runs "vite dev --port 3000", so 3000 stays.

Co-Authored-By: Claude <noreply@anthropic.com>
R5 (decidePackageManager and its helpers), R10 (installCommand,
runScriptCommand) and R1's workspace pattern helpers, all disk-free.

Argument passing checked by running each manager against a script that
prints its argv: npm 10.9.9 needs "--"; pnpm 12.15.0 and Yarn 4.19.0
pass a bare "--" through to the script; Yarn 1.22.22 and bun 1.3.11
forward arguments with or without it. So only npm gets "--", as the plan
says.

Deviation: decidePackageManager takes levelsUp and derives "enclosing"
from levelsUp > 0 instead of taking both, so the two can't disagree.

Co-Authored-By: Claude <noreply@anthropic.com>
app-detect.ts reads the disk with bounded, no-follow reads (readBounded:
O_NOFOLLOW | O_NONBLOCK, regular files only, cap + 1 bytes) and feeds the
pure rules: candidates at the root, in apps/, packages/, web/, frontend/,
site/ and the declared workspace patterns; install roots for members and
own-lockfile folders; the enclosing walk bounded by .git, stopAt, home
and five levels; install state. designTarget sums a detection up for 2b.

Deviations:
- The plan's edge-shape test asks that "scripts as an array" never give
  no-dev-script, but R4 rule 7 (and Task 3's "a vite app with no scripts
  at all is none no-dev-script") make a vite app with array scripts
  exactly that. The edge test therefore uses a React package without a
  framework for the array case and a vite app whose dev is null but whose
  start runs vite for the null case, which keeps R4 as written.
- readBounded takes an optional { head: true } so the 512-byte yarn.lock
  head can be read from a longer file through the same no-follow open.

Co-Authored-By: Claude <noreply@anthropic.com>
app-toolchain.ts implements R9: Node 22 or newer first, then the app's
own manager (npm beside the resolved Node first), with typed problems
node-missing, manager-missing, manager-conflict and unsupported-manager,
and one fixed message for each. The design resolvers share one cache of
validated login-shell answers; misses are never kept.

Deviation: the plan's field-and-lockfile conflict message names the
field's manager ("packageManager says pnpm, but the lockfile is npm's."),
but R8 recorded no field. PackageManagerInfo and the manager-conflict
problem gain an optional `field`, set only when the packageManager field
is part of the conflict.

Co-Authored-By: Claude <noreply@anthropic.com>
Spec: Phase 2a amendments S19-S24 and the status line; §4's toolchain
sentence now names node-toolchain.ts. Plan index row, the design-mode and
devices memory, and this plan (boxes ticked; the Remix 3 row, the
per-manager "--" facts, the `field` on conflicts and readBounded's `head`
option recorded). docs/devices.md still holds: Node 22, PATH, login
shell, Homebrew.

Co-Authored-By: Claude <noreply@anthropic.com>
…d early host commands

Code review fixes for 2a:
- The generated agent-device launcher runs from the person's repo and
  built PATH as dirname(node) + ":" + PATH, leaving an empty entry when
  PATH was unset or empty, or held "::". It now filters empty entries.
  Settles plan Q7.
- run's branch for commands started before Node is resolved (xcrun simctl
  help) drops inherited empty entries; an unset PATH stays unset, so the
  shell's default search still applies.
- The login-shell lookup takes an injectable execFile, so the test proves
  the 5 s default timeout and that maxBuffer reaches execFile only when
  given, without waiting.
- The version-floor test now proves the Node probe clears
  ELECTRON_RUN_AS_NODE.

Deviation: there is no agent-device-shim.test.ts; the shim's tests live
in device-tools.test.ts, so the launcher cases went there. The
ssh-device-script.ts remote ":$PATH" is noted in the plan's Risks as a
follow-up.

Co-Authored-By: Claude <noreply@anthropic.com>
- The enclosing walk counts a parent repo's lockfile only when that
  folder's workspaces or pnpm-workspace.yaml lists the workspace (bounded
  reads, matchesWorkspacePattern). An example app under a library, an
  unlisted folder in a pnpm repo, and a stray parent lockfile now get npm
  with a plain install.
- Root scripts that hand off to one member are runners: yarn workspace,
  pnpm -C, concurrently, npm-run-all, run-p, and -w, --workspace,
  --prefix, --dir. A root that declares workspaces is web only when its
  script runs the framework's own dev command.
- A framework app whose only scripts are production runs is
  no-dev-script, not React mocks.
- clearAppToolchainCache() for 2c's Retry.
- Conflict messages say how to fix, with plural wording for 3+ managers.
- S20 and Risks accept a gitignored leftover lockfile as a refusal.

Deviation: -w, --workspace, --prefix and --dir count as hand-offs only
when the script also names npm, pnpm, yarn or bun. Bare -w would make a
React library with "dev": "tsc -w" (or rollup -c -w) workspace-runner
instead of React mocks; a test pins that.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Two detection contracts need correction before Phase 2b consumes these results: Deno-only workspaces disappear entirely, and malformed package-manager declarations can select the wrong installer.

Reviewed changes I reviewed the complete Phase 2a diff, including app and monorepo detection, package-manager decisions, shared toolchain extraction, device PATH hardening, tests, and project records.

  • App discovery and classification — Adds bounded workspace scanning, framework/script classification, monorepo membership handling, and design-target selection.
  • Package managers and toolchains — Adds lockfile/conflict rules, install/run argv builders, Node 22 and manager resolution, and a validated login-shell cache.
  • Device PATH hardening — Preserves the device toolchain wrappers while removing empty PATH entries from helper, launcher, Android SDK, and early host-command environments.
  • Tests and project records — Adds behavioral coverage for the new modules and updates the Phase 2a plan, specification amendments, memory, test registry, and plan index.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

…geManager values

- A folder with a Deno marker but no package.json is now a candidate,
  with reason no-package-json and Deno reported as its unsupported
  manager, instead of disappearing from detection.
- parsePackageManagerField matches the whole value: a bare manager or
  manager@version with an optional prerelease and +hash. Values such as
  pnpm@junk, pnpm@ and yarn! are ignored, so they can no longer pick an
  install command.

Co-Authored-By: Claude <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The parser hardening still accepts malformed prerelease declarations, so a typo can select the wrong installer.

Reviewed changes I reviewed the app-detection corrections added since the prior Pullfrog review.

  • Admitted Deno-only folders — Added Deno markers to candidate discovery and returns an explicit unsupported-manager result when package.json is absent.

  • Hardened package-manager declarations — Anchored packageManager parsing and added recognized-prefix malformed cases while preserving the repository's hashed declaration form.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The stricter package-manager parser drops valid Corepack hash-pinned declarations, including this repository's own value.

Reviewed changes I reviewed the exact-SemVer hardening added since the prior Pullfrog review.

  • Tightened version parsing — Replaced permissive prerelease and build matching with explicit exact-version identifiers and expanded malformed-value tests.
  • Preserved malformed fallback behavior — Added a package-manager decision assertion proving malformed declarations use the no-signal npm fallback.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes I reviewed the Corepack hash-pin compatibility fix added since the prior Pullfrog review.

  • Accepted SRI-style Corepack pins — Extended packageManager parsing to preserve exact SemVer validation while accepting Corepack hash payloads containing /, +, and terminal = padding.
  • Added real-pin regression coverage — Covered both representative npm, pnpm, and Yarn hash forms and the repository's checked-in packageManager declaration while retaining malformed-padding rejection.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using GPT Sol | 𝕏

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant