Skip to content

feat: terminal-to-desktop project-open handoff (t3 .) - #637

Closed
bloxy-studios wants to merge 3 commits into
pingdotgg:mainfrom
bloxy-studios:feat/terminal-desktop-handoff
Closed

bloxy-studios wants to merge 3 commits into
pingdotgg:mainfrom
bloxy-studios:feat/terminal-desktop-handoff

Conversation

@bloxy-studios

@bloxy-studios bloxy-studios commented Mar 9, 2026 •

Copy link
Copy Markdown

Summary

  • Implements the full t3 . / t3 <path> desktop handoff flow: when the desktop app is installed, the CLI spawns it with the project path and exits silently instead of starting the web server
  • Fixes macOS argv contamination where Chromium-injected switches (e.g. --allow-file-access-from-files) were appended to the workspace path, causing "Project directory does not exist" errors
  • Makes the handoff fast and silent by running it before heavy server initialization (SQLite, migrations, orchestration engine)
  • Adds launcher install flow, case-insensitive project matching, no-thread handling, hydration race guards, and single-instance support

Details

Bug fixed

Running t3 . on macOS with the desktop app installed produced a toast error like:

Unable to open project from terminal
Project directory does not exist:
/Users/.../Bloop/--allow-file-access-from-files

Root cause: the --t3-project-path <value> format used two separate argv tokens. On macOS, Electron's second-instance event injects Chromium switches into the commandLine array, which could land between the flag and its value. The parser naively took args[flagIndex + 1], picking up --allow-file-access-from-files instead of the real path.

Fix: switched to atomic --t3-project-path=<value> format (single token, immune to reordering). Added fallback parsing that skips --prefixed tokens, and a guard that rejects switch-like values.

Architecture

  • CLI → server (apps/server/src/main.ts): maybeLaunchDesktopFromCli runs before LayerLive (no SQLite/orchestration init), checks for desktop metadata, resolves workspace root, spawns desktop app
  • Server → desktop (apps/server/src/open.ts): resolveDesktopAppLaunch builds spawn args with --t3-project-path=<path>, clears ELECTRON_RUN_AS_NODE
  • Desktop argv parsing (apps/desktop/src/projectPathParser.ts): extracted to testable module, handles both = and space-separated formats, rejects switch-like values, canonicalizes via fs.realpathSync.native
  • Desktop main (apps/desktop/src/main.ts): requestSingleInstanceLock + second-instance handler, pending project path IPC, launcher metadata publishing
  • Renderer (apps/web/src/routes/__root.tsx): DesktopProjectBootstrap component handles incoming project paths with hydration queue, case-insensitive matching via workspacePathsMatch, creates thread if project exists without one
  • Path comparison (apps/web/src/lib/workspacePaths.ts): case-insensitive on macOS/Windows, case-sensitive on Linux
  • Launcher install (apps/desktop/src/launcherManager.ts, packages/shared/src/launcher.ts): writes launcher script, manages PATH config, compatibility shims for ~/.t3/bin/t3

Test plan

  • bun lint — 0 errors
  • bun typecheck — all 7 packages pass
  • Desktop tests (41/41 pass) — includes 14 new projectPathParser tests covering Chromium contamination, = format, legacy fallback, switch rejection, path canonicalization
  • Server tests — open.test.ts (12/12), workspaceRoot.test.ts (1/1) pass
  • Web tests — workspacePaths.test.ts (4/4) pass
  • Built Intel Mac DMG, installed, verified t3 . opens desktop app silently with no verbose output
  • Verify on Apple Silicon Mac
  • Verify on Windows
  • Verify on Linux (fallback to web server)

🤖 Generated with Claude Code

Note

Add terminal-to-desktop project-open handoff and parse optional project path in CLI, launching the desktop app on t3 . via apps/server/src/main.ts and apps/server/src/open.ts

Introduce early desktop handoff in the server CLI, add project-path parsing, and wire Open.openDesktopApp with sanitized env and --t3-project-path passing; add desktop-side single-instance routing, IPC for launcher state and project-open delivery, and shared launcher utilities; update web bootstrap to process project-open events and normalize workspace path matching.

📍Where to Start

Start with the CLI handoff flow in maybeLaunchDesktopFromCli and makeServerProgram in apps/server/src/main.ts, then review open.resolveDesktopAppLaunch and open.make in apps/server/src/open.ts.

Macroscope summarized a0b9f48.

Adds the full `t3 .` / `t3 <path>` flow that detects an installed desktop
app and hands off the workspace launch instead of starting the web server.

Key changes:

- **Desktop handoff via CLI**: when the desktop app is installed, `t3 .`
  spawns it with `--t3-project-path=<path>` and exits immediately.
  Explicit server flags (--mode, --port, etc.) bypass handoff and start
  the web server as before.

- **Robust macOS argv parsing**: uses atomic `--t3-project-path=<value>`
  format so Chromium/Electron-injected switches (e.g.
  `--allow-file-access-from-files`) can never contaminate the workspace
  path. Legacy space-separated format is supported as a fallback with
  switch-skipping.

- **Silent handoff**: desktop handoff runs before heavy server
  initialization (SQLite, migrations, orchestration), keeping `t3 .`
  fast and producing no terminal output.

- **Launcher install flow**: desktop app publishes launcher metadata on
  startup and prompts users to install the `t3` command with optional
  PATH configuration for their shell.

- **Case-insensitive project matching**: `workspacePathsMatch` compares
  paths case-insensitively on macOS/Windows so existing projects are
  found regardless of terminal casing vs stored casing.

- **Project-exists-but-no-thread handling**: when a project is found
  via terminal open but has no thread, a new thread is created and
  focused instead of silently doing nothing.

- **Hydration race guard**: incoming terminal-open requests are queued
  until projects/threads are hydrated, then replayed.

- **Single-instance support**: desktop app uses Electron's
  `requestSingleInstanceLock` so repeated `t3 .` invocations focus the
  existing window and deliver the project path via IPC.

- **Workspace root canonicalization**: `resolveWorkspaceRoot` uses
  `fs.realPath` to resolve symlinks and normalize casing.
  `normalizePendingProjectPath` uses `fs.realpathSync.native` as an
  additional safety net in the desktop main process.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@coderabbitai

coderabbitai Bot commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a62c93c5-d6fb-44c6-a8fb-c7c488f95e05

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the vouch:unvouched Author is not yet trusted in the VOUCHED list. label Mar 9, 2026
Comment thread apps/desktop/src/main.ts Resolved
Comment thread apps/web/src/lib/workspacePaths.ts Resolved
Comment thread packages/shared/src/launcher.ts Resolved
Comment thread packages/shared/src/launcher.ts Resolved
Comment thread packages/shared/src/launcher.ts Resolved
Comment thread apps/server/src/main.ts Resolved
kaiandabdul and others added 2 commits March 9, 2026 12:15
- Remove duplicate IPC delivery in `deliverPendingProjectPath`: the
  one-time `did-finish-load` listener fired alongside the permanent
  handler in `createWindow`, sending PROJECT_OPEN_CHANNEL twice.
  Now only sends when the window is already loaded; the permanent
  handler covers the loading case.

- Fix Windows drive root normalization in `trimTrailingSeparators`:
  regex guard `/^[a-z]:\/$/i` only matched a single trailing slash,
  so `C:\\` normalized to `C:` instead of `c:/`. Changed to
  `/^[a-z]:\/+$/i` and `.slice(0, 3)` to always produce `X:/`.

- Fix `isDirectoryOnPath` using host `Path.resolve` and case-sensitive
  comparison: now uses `pathModuleForPlatform(platform)` and
  case-insensitive comparison on win32/darwin.

- Fix `applyPosixPathUpdate` substring false positive: `includes(installDir)`
  could match paths like `/usr/local/binary` for `/usr/local/bin`.
  Now checks for the quoted form used in managed snippets.

- Fix `resolveShellProfilePath` unconditionally returning `.zprofile`
  for zsh: Linux zsh uses `.zshrc` (non-login interactive shells),
  only macOS should use `.zprofile` (login shells).

- Guard `buildPathExportSnippet` against win32: returns empty string
  instead of generating invalid Unix shell syntax.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
`hasExplicitBooleanFlag` used `Option.filter(flag, Boolean)` which
discarded `Some(false)`, so flags like `--no-auto-bootstrap-project-from-cwd`
were not detected as explicit overrides. This caused
`shouldAttemptDesktopHandoff` to incorrectly hand off to the desktop
app instead of respecting the user's server configuration.

Replaced per-flag `hasExplicitBooleanFlag` with `Option.isSome` which
correctly detects any explicitly provided value regardless of its
boolean content.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@bloxy-studios

Copy link
Copy Markdown
Author

@macroscope-app review

@maria-rcks

Copy link
Copy Markdown
Collaborator

@juliusmarminge we might want to do something similar, but closing now as it seems too big / and projects are really easy to add as-is

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

Labels

vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants