Skip to content

feat(design): run the workspace's dev server after a consent card (design mode v2 Phase 2b) - #916

Open
sambitcreate wants to merge 39 commits into
t3/design-mode-v2-dmfrom
t3/design-mode-v2-p2b
Open

sambitcreate wants to merge 39 commits into
t3/design-mode-v2-dmfrom
t3/design-mode-v2-p2b

Conversation

@sambitcreate

@sambitcreate sambitcreate commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

This is stacked on #915 (Phase DM), then #911 (2a), #908 (1b) and #894 (1a). Merge them in order; GitHub retargets each PR when its base merges.

This PR is Phase 2b of design mode v2.

  • Spec: docs/superpowers/specs/2026-11-23-design-mode-live-app-design.md §6.2 and §8.
  • Plan: docs/superpowers/plans/2026-11-24-design-mode-v2-p2b-dev-server.md, including its "As built" notes.
  • Amendments: S25–S32.

Aiden can now run the workspace's own dev server so design mode can show the real app. It does this only after a consent card, and everything is behind AIDEN_EXPERIMENTAL_DESIGN_LIVE. With the flag off, the tool, card, IPC and processes don't exist. 2c adds the status chip and attach; 3a adds the live frames.

Consent card

Light Dark
Consent card, light Consent card, dark

Card with a multi-line predev script:

Consent card with a multi-line script

What the card shows

  • The exact command (npm run dev) and each script it runs, with its pre/post scripts and install-lifecycle scripts when an install will run.
  • Line breaks marked with ↵, runs of blank lines or spaces collapsed into visible [N blank lines] and [N spaces] tokens, and a line count in the header.
  • Bidi and default-ignorable characters escaped, in the scripts, the app root and the package name.

How it behaves

  • The details scroll inside a 50vh area, and Allow and Not now stay visible below it.
  • There is one card per request, so a second card never hides the first.
  • Allowing saves the person's choice to .aiden/canvas.json when they picked an app in a monorepo.

What changes

When a new card is needed

Consent is bound to a fingerprint of everything that decides what runs:

  • the scripts and their pre/post scripts;
  • install-lifecycle scripts at the app root and the install root;
  • packageManager and devEngines;
  • .npmrc, .yarnrc, .yarnrc.yml and its yarnPath target, pnpm-workspace.yaml, .pnpmfile.cjs and bunfig.toml, in every folder from the app up to the lockfile;
  • framework configs;
  • the workspace folder's real path, so a workspace re-pointed at another checkout, or a moved folder, asks again even when its launch files are identical.

A changed fingerprint shows a new "changed" card. An install the card never showed asks again.

Before every spawn, including after consent and after an install, detection, toolchain, fingerprint, folder and permission are read again. An app with no lockfile asks once and installs once: the consent moves to the lockfile the install creates.

Where the server runs

  • It runs on http://127.0.0.1:<port>, on a sticky free port.
  • One shared poller, running one ps and one lsof (or /proc) per tick, reads every socket the job's process group and descendants hold. It ticks every 500 ms while the server starts and every 2 s while it runs.
  • A server listening beyond loopback is stopped as exposed.
  • The reader fails closed. A timeout, a buffer overflow, an unreadable fd folder or /proc/net, or more fds than the cap all count as failures, and three in a row stop the server.
  • A missing /proc/net/tcp6 (kernel booted with ipv6.disable=1) counts as an empty table.
  • Origins served this session stay app origins until the workspace is forgotten, for 3a's filter.

Environment and install

  • Never passed to the server: argv only, never a shell. Aiden's provider keys (pi-ai's list plus AWS_BEARER_TOKEN_BEDROCK), AIDEN_*, npm_*, npm_config_* and INIT_CWD are removed.
  • Set unless the person set them: framework telemetry is off (NEXT_, ASTRO_, NUXT_ and GATSBY_TELEMETRY_DISABLED, NG_CLI_ANALYTICS=false and DO_NOT_TRACK=1).
  • Never installed: nothing from a lockfile outside the workspace (install-outside-workspace), including a forced install.

Lifecycle

  • One server per app: one server per workspace and app root, shared by its chats.
  • Visibility and stopping: a server stops 60 s after no window shows its canvas. "Shows" means the canvas pane is visible and the window isn't minimized or hidden, checked in main.
  • Workspace changes:
    • each attempt goes through workspaceMutationGate.admit;
    • changing the folder stops the server;
    • read-only or no access reports no-access;
    • removing the workspace stops its servers.
  • Quit and crashes:
    • on quit, design jobs stop;
    • starts wait for crash recovery, and the next launch reaps leftovers;
    • processes that left the group with setsid are found by the job marker and stopped.

Tool, approval, IPC and analytics

  • Tool: design_app has start | stop | restart | choose | status actions, up to 4 starts per turn. It refuses Remote and windowless turns (desktop-only) and waits for the card's own timeout plus 5 s.
  • Approval: an approval exception returns via: "reviewed-exception"; a hook or rules-page Block still blocks.
  • IPC: every designApp:* call goes through rendererDocumentOwner, and a subframe sender is refused. The log cursor carries its run's id; a stale cursor reads from the oldest byte with truncated: true.
  • Analytics: a new design_app_started event, with its registry entry, docs row and test. It sends only enums and buckets, and manager is optional.

Review

  • Plan: two adversarial Opus reviews, then a cross-plan re-check with DM. Every finding was applied.
  • Code: two Opus code reviews.
    • The process and security review probed real processes: a poisoned env, a rebind to 0.0.0.0, setsid children, swapped-in links, and a no-lockfile app.
    • The lifecycle, contracts, UI and tests review included a mutation check on the pre-spawn re-read.
  • Fixes: 2 majors and 4 minors from the first review, and 4 majors and 8 minors from the second, each test-first.

Pullfrog review fixes

  • lsof errors (62a4644). Any text lsof prints as an error now counts as a failed check, even when it also printed output and even on exit 0. Exit 1 with nothing on stderr is still a success.
  • Choose (dce8fba, 459ad52).
    • A choose always gets its own choose card.
    • If a start is already waiting, it waits for that start to finish.
    • If the app is running, it stops it and starts it again through the card.
    • A Stop requested after the choose cancels it.
  • Unsaved choice (dce8fba). A choice that isn't saved runs nothing, and the app shows the new problem choice-not-saved.
  • One chat guard (093f4d3). chatRunsDesignApps (no botId, no owner) is the one check for every app start: the designApp:* channels, the Design toggle and Enter on Aiden's design-mode card. The chat store already refuses design mode for a Bot's or a feature-owned chat, so this was not reachable today; the shared guard keeps the paths aligned if that changes.
  • Consent covers the checkout (8b31e81). Stored consent is keyed by workspace id and app root, and the fingerprint only hashed launch files, so re-pointing the workspace at another checkout with identical files ran it without a card. The fingerprint (now v3) also hashes the workspace folder's real path. The same folder reached through a link keeps its consent.

Tests

Suite Result
test:design-mode 1232/1232 after the review fixes; see Notes
test:follow-through 206 passed, 1 skipped
test:analytics 178
test:approval-gate 183
test:ci-policy 123
app-server-process (real processes, macOS host and Linux) 15/15
E2E in the Cua Space (design-app-server and design-canvas) 15/15

npx tsc --noEmit -p ., npm run lint, npm run build and npm run cli:build pass.

Notes

  • Flaky test: design-md/tool.test.ts "export over 64 KiB is refused with its size" timed out once while the Space E2E loaded the machine. It passes 17/17 alone. It's DM's test and 2b doesn't touch it.
  • Flaky test (CLI): packages/cli/tests/server-visuals.test.mjs "an installed browser draws a chart offline into a picture and leaves no profile behind" timed out at 15 s on 459ad52 (run 45404937046). The headless browser didn't finish drawing in time, so the reply said "Not shown". The same test failed the same way on feat(design): DESIGN.md read, lint and draft behind the live flag (design mode v2 Phase DM) #915 (d5083ab), and 2b doesn't touch the CLI's visuals. I'll rerun it once, after the run finishes.
  • iOS on Xcode 27 (non-blocking): the simulator "Clone 2 of iPhone Duo" didn't boot within 60 s, and the app wouldn't launch on it (run 45404937046). Every test that ran passed. This PR changes nothing on iOS. I'll rerun it once with the CLI job.
  • macOS leftover limit: on macOS, ps -E can't read the environment of Apple's own programs, so a leftover /bin/sh or sleep that left the group with setsid isn't found by the marker sweep. The person's own node processes are found.
  • Linux without IPv6: a host booted with ipv6.disable=1 now works. Other /proc/net read errors still fail closed.
  • Onboarding: no change, because the feature sits behind an experimental, off-by-default flag.

🤖 Generated with Claude Code

The renderer's capability record now carries designLive, so 2c's chip can
read it. DM's flag helper and tests already match the binding definition.
Design jobs belong to a workspace's app root, not a chat: they spawn an argv
with no shell, never reach a chat's list, notice or settlement, have their own
cap of 8, and rotate their log at 25 MB instead of stopping. Reads take byte
offsets over the whole output.
designSockets lists every listening socket of each design job's process group
and descendants, from one ps and one lsof (or /proc pass) for all jobs. A
timeout, an overrun, an unreadable table or fd folder, or too many fds fails
the read instead of returning nothing.
renderer/shared/design-app.ts holds the status, problem and consent types 2c
and 3a build on, the fixed problem messages and the card's display escapes.
app-launch-core.ts is pure: the run argv and scrubbed environment per
framework, the ready port, exposed sockets, the install rule and the launch
fingerprint's canonical form.
readLaunchSurface hashes every script, rc, workspace, lockfile, yarnPath and
framework config file that changes what installing or starting does, with
bounded no-follow reads that refuse links and special files. The records file
keeps consents, install stamps and sticky ports and fails closed.
saveCanvasConfigApp merges a monorepo choice through writeConfinedWorkspaceText,
write_file's confined writer, with no link followed on the path.
The sticky port, then the framework default, then an OS port. Free means no
answer on 127.0.0.1 or [::1] within 250 ms and a test listen on 127.0.0.1
succeeds, so a wildcard or IPv6-only server elsewhere counts as in use.
…se a forced install above the workspace

A-m4: AWS_BEARER_TOKEN_BEDROCK is a fixed extra provider key, and the card's
hidden-character class adds Default_Ignorable_Code_Point (U+034F, U+17B4).
A-m2: restart with install on an app whose lockfile is above the workspace
answers install-outside-workspace instead of silently skipping.
…thout IPv6

A-m1: with ipv6.disable=1 every start was not-ready. A missing tcp table,
or any other read failure, still fails closed.
…d and in the tool

B-M1: the attempt's first read, the pre-spawn read, the gate-abort read and
the running check all refuse a workspace without a folder or with none or
read-only access; design_app refuses start, restart and choose on a
read-only or no-access turn without reaching the service.
B-M2: tests cover a folder, access or removal change while the card waits
and after the install; deleting either pre-spawn check fails them.
A-M1: npm install writes a lockfile, which changed the fingerprint and the
lock hash, so a second card and a second install followed. After Aiden's
install the surface is read again; when only the install root's lockfile
and the install argv changed, the consent moves to the new fingerprint with
its installShown kept, and the install stamp takes the new lock hash.
…test run from its start

B-M3: DesignAppLogs carries the run (the dev server's job id) and the end
of its output; logs take a run. A cursor that names another run, or points
past this run's end, reads the latest run from its oldest kept byte with
truncated set. design_app reads its last window from the run it probed.
…red card answers unanswered

B2: the wait while a card is open is the card's time plus a 5 s grace.
B3: a [::1] origin a running server holds later, and forgetting a workspace
whose servers already stopped, now fire onOriginsChanged.
…ns on

B5: each root's card shows at once, so one unanswered card no longer holds
the others back.
…s missing-module hint is covered

B6: the moved-chat test shows the same workspace does start once design mode
is turned on, so its negative isn't vacuous; a crashed start or restart on a
missing module answers the restart-with-install hint; the tool-description
change detector is gone.
…ment visibility

B8: macOS can report an occluded window's document hidden, which stopped
the dev server under a window the person could still see. The renderer
now reports only whether the canvas pane is shown; main counts a canvas
while its window is visible and not minimized, and re-counts on minimize,
restore, hide and show.
…sion's, are ended by marker

A-m3: a setsid child leaves the job's group, and once its parent is gone no
parent-pid walk reaches it. When a design job's leader exits, and when the
next launch reaps the record's design jobs, every live process of this user
carrying the job's AIDEN_BACKGROUND_JOB marker is ended, politely then
forced (/proc/*/environ on Linux, ps -E on macOS, which hides the
environment of Apple's platform binaries).
…ons on screen, and shows every waiting card

A-M2: each script well shows its text in full with every line break marked
(↵), runs of three or more blank lines and eight or more spaces as their
count, and a multi-line script's line count in its label; no well scrolls
on its own.
B1: the card's details scroll in one region capped at half the window, with
a Scroll for more cue, so the question and Allow and Not now stay visible.
B4: waiting cards are kept by request id and every one for the chat shows,
oldest first, so none times out unseen behind another.

@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.

Three correctness/safety issues need changes before merge. Focused state-machine and socket-reader suites pass, but they do not cover the failing branches described inline.

Validation: app-server-main.test.ts 55/55; listening-ports.test.ts 21/21. A combined run including canvas-config.test.ts reached 89/94 because the native confined writer was unavailable in this environment; those environment failures are not an additional finding.

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 | 𝕏

…uns nothing

A choose waits for pending work and restarts a running app through its own
choose card; a save that returns unknown-version or throws ends with
choice-not-saved before any spawn. Addresses Pullfrog review on #916.

@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

  • One stop-ordering regression remains in the deferred choice flow.
  • Focused app-server, socket-monitoring, and shared design-app suites pass.

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 | 𝕏

A deferred choose (behind a pending attempt, or restarting a running app)
no longer reopens its card after a later explicit stop. Addresses Pullfrog
review on #916.

@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
Reviewed the stop-generation fix added since the prior Pullfrog review and rechecked the complete PR in its final state.

  • Preserved choice/stop ordering: stop() now advances a per-entry generation synchronously, and begin() rechecks its captured generation before queued work, after pending consent settles, and after stopping an already running server. Choices invoked before a later stop are dropped; choices invoked after it remain eligible.
  • Added race coverage: Focused tests now exercise the deferred-choice ordering behind both a pending consent attempt and a running app server.

Validation
npx tsx --test main/services/design-canvas/app-server/app-server-main.test.ts passed 60/60.


Review metadata

  • Base commit: 138d6aa
  • Head commit: 459ad52
  • Files reviewed: 74
  • Commits reviewed: 1
  • Reviewed commits:
    • 459ad52 fix(design-canvas): cancel deferred choices after explicit stop
  • Head ref: t3/design-mode-v2-p2b
  • Prior Pullfrog review: #916 (review)

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 | 𝕏

…nApp channels' chat guard

chatRunsDesignApps (no botId, no owner) is now the one check every app
start for a chat goes through: the designApp:* channels, the toggle's
designModeEntered call and Enter on Aiden's design-mode card.
…files

The fingerprint (v3) hashes the workspace folder's real path, so a
workspace re-pointed at another checkout with identical launch files, or
a moved folder, shows the Run app again card. The same folder reached
through a link keeps its consent.

@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 checkout-binding change still permits a workspace-root symlink retarget between fingerprint validation and process spawn, so the consent boundary is not complete yet.

Reviewed changes
Reviewed the two commits added since the prior Pullfrog review and rechecked their behavior in the complete PR context.

  • Unified chat eligibility: Routed the designApp:* IPC handlers, Design toggle, and design-mode consent-card entry through chatRunsDesignApps, consistently excluding Bot and feature-owned chats.
  • Bound fingerprints to checkout paths: Added the workspace folder's canonical realpath to fingerprint v3, making identical files in distinct physical checkouts require separate consent while preserving aliases to the same folder.

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 | 𝕏

…overs

The spawn cwd comes from the fingerprinted surface's real path, not the
configured workspace path, so a workspace link retargeted after the read
can't move a consented launch into another checkout. Addresses Pullfrog
review on #916.

@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 workspace-root retarget is fixed, but nested app and install roots can still redirect a spawn outside the fingerprinted launch surface.

Reviewed changes Reviewed the checkout-binding commit added since the prior Pullfrog review and rechecked it in the complete PR context.

  • Bound jobs to the canonical checkout: Changed install and server cwd values to use the real checkout captured by the current launch surface rather than the mutable configured workspace path.
  • Added focused checkout coverage: Added a state-machine test asserting that both install and server jobs stay in the canonical checkout when the workspace path is an alias.

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 | 𝕏

… read validated

The launch-surface read now reports the real app and install directories it
checked and hashed, and the install and server run in those, so a nested
root swapped for a link after the read can't redirect a spawn. Addresses
Pullfrog review on #916.

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