Skip to content

fix(hub): run .cmd/.bat shims in PTY sessions on Windows - #465

Merged
antfu merged 3 commits into
devframes:mainfrom
huang-julien:fix/windows-pty-cmd-shims
Oct 30, 2026
Merged

antfu merged 3 commits into
devframes:mainfrom
huang-julien:fix/windows-pty-cmd-shims

Conversation

@huang-julien

Copy link
Copy Markdown
Contributor

fix #463

descirption

On Windows, PTY sessions could not start commands like pnpm, npx or yarn that are .cmd scripts and the Windows terminal API only launches real .exe programs.

The change detects that case and runs the command through cmd.exe instead, the way startChildProcess() already does.

@vercel

vercel Bot commented Oct 27, 2026

Copy link
Copy Markdown

@huang-julien is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

👁️‍🗨️ Review this pull request with grouped, summarized diffs at:
👉 https://pulls.review/gh/devframes/devframe/465?from=github-actions[bot]

raw result

💭 analyzed by vercel-ai-gateway/anthropic/claude-sonnet-5
🕰️ 2026-10-30 22:10 UTC
🔗 head 6ed7cfe
🤖 automated by pulls.review

{
  "headSha": "6ed7cfe7bf871b343077b6ca02702d21d9c23d7c",
  "result": {
    "overallSummary": "Fixes a Windows bug where PTY sessions failed to launch `.cmd`/`.bat` shims (pnpm, npx, yarn, etc.) because the native terminal API only spawns real `.exe` programs. The fix adds a `resolvePtyCommand()` helper that detects shim commands and routes them through `cmd.exe`, matching the existing non-PTY `startChildProcess()` path, with careful argument escaping and accompanying tests.",
    "groups": [
      {
        "key": "pty-cmd-shim-fix",
        "label": "PTY .cmd/.bat shim support",
        "summary": "Adds `resolvePtyCommand()` to detect when a PTY command resolves to a `.cmd`/`.bat` shim (e.g. pnpm, npx, yarn) that ConPTY can't spawn directly, and routes it through `cmd.exe` instead, mirroring the existing `startChildProcess()` behavior. Also handles argument escaping so metacharacters survive `cmd.exe`'s double parsing for batch shims.",
        "category": "core",
        "filePaths": [
          "packages/hub/src/node/pty-command.ts",
          "packages/hub/src/node/host-terminals.ts"
        ],
        "fileNotes": [
          {
            "path": "packages/hub/src/node/pty-command.ts",
            "text": "Core logic: resolves the executable via PATH/PATHEXT, decides whether to wrap with `cmd.exe /d /c`, and escapes arguments for cmd metacharacters (with double-escaping for `.bat`/`.cmd` shims). Subtle quoting/escaping rules are documented inline but worth double-checking given known limits noted in comments.",
            "critical": true
          }
        ]
      },
      {
        "key": "tests",
        "label": "Tests for PTY shim resolution",
        "summary": "Adds unit tests for `resolvePtyCommand()` covering shim detection, escaping and platform fallbacks, plus a Windows-only PTY integration test spawning a real `.cmd` shim.",
        "category": "tests",
        "filePaths": [
          "packages/hub/src/node/__tests__/host-terminals.test.ts",
          "packages/hub/src/node/__tests__/pty-command.test.ts"
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-10-30T22:10:52.851Z",
    "model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
    "locale": "en"
  }
}

antfu and others added 2 commits October 31, 2026 06:00
- Skip `^` escaping for args with a backslash or tab too, since zigpty
  quotes those and `cmd.exe` keeps quoted text as-is.
- Lower-case PATHEXT so the lookup works on case-sensitive filesystems
  (the unit tests failed on Linux).
- Note the known limit for shims passed by path with quoted args.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@antfu
antfu merged commit 2a4bbba into devframes:main Oct 30, 2026
2 of 3 checks passed
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.

startPtySession fails on Windows for .cmd shims

3 participants