Skip to content

Detect the official DeepSeek Harness dsh.cmd launcher on Windows - #17

Merged
Alex793x merged 3 commits into
syncable-dev:devfrom
magalz:fix-dsh-cmd-discovery
Nov 23, 2026
Merged

Alex793x merged 3 commits into
syncable-dev:devfrom
magalz:fix-dsh-cmd-discovery

Conversation

@magalz

@magalz magalz commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this solve?

On Windows, the official DeepSeek Harness CLI installer writes a dsh.cmd batch launcher (resources/runtime/cli/bin/dsh.cmd) and puts that directory at the front of the user's PATH. MemCode's findCommand() only looked for <PATH dir>\dsh.exe, so a correctly installed CLI was reported as "Not installed" in the worker/harness list.

There is a second constraint: the worker session code spawns harness commands with spawn(..., { shell: false }) (runtime/agents/standard-acp.ts). Windows cannot launch a .cmd/.bat file directly through CreateProcess, so simply adding .cmd to the discovery candidates would turn a detection bug into a spawn failure.

This PR teaches discovery to recognise the official launcher and normalise it into the same { command, prefix, env, identity } shape already used by the existing node_modules fallback. No spawn call site changes.

What changed

runtime/commands.ts

  1. New WINDOWS_DSH_SHIM regex. A single anchored expression matches the whole launcher line:

    " %~dp0<relative exe> " --expose-internals " %~dp0<relative entry>.js " %*
    

    Both paths must be quoted, %~dp0 is expanded relative to the shim, an optional \ right after %~dp0 is accepted, and no unexpanded %VAR% is allowed. Lines that merely mention --expose-internals (rem, echo, @rem, etc.) cannot shadow the real line: the code now scans for the first line that fully matches, not the first line containing the flag.

  2. New windowsShimCommand() helper. It resolves the executable and Electron entry from the shim, then applies four guards before accepting it:

    • the executable is named DeepSeek Harness.exe;
    • the entry lives under <install dir>\resources\app.asar\;
    • the executable exists on disk;
    • the app.asar file exists on disk.

    The name + app.asar checks bind the entry to the installation that owns the executable. Without them, a modified shim could point at a different .exe while keeping the same entry path — and because workerApprovalMatches() compares runtimeIdentity when present, a previously saved approval would still match. With them, a different executable or a different installation produces a different identity and requires a fresh approval.

    The file checks prevent a leftover shim from an incomplete uninstall from being displayed as "Installed", and let discovery fall through to the working node_modules fallback in the same directory.

  3. Returned Command object. The helper returns:

    {
      command: <DeepSeek Harness.exe>,
      prefix: ["--expose-internals", <.../dsh-desktop-host/lib/cli.js>],
      identity: <entry path>,
      env: { ELECTRON_RUN_AS_NODE: "1" },
    }

    prefix is prepended before transport arguments by every spawn site and env is applied on top of childEnv(), so the existing argument-array spawning is preserved. An explicit identity is needed because commandIdentity() would otherwise read --expose-internals as prefix[0].

  4. Discovery extensions. On Windows, dsh is tried as .exe and then .cmd; .bat is not used. Other harness names keep the previous .exe-only probing, so there is no extra access() call for them. .exe still wins inside a directory; between directories, normal PATH order wins. That matches cmd.exe resolution and the installer, which prepends its own directory. Invalid shims fall through to the existing node_modules/@deepseek-ai/dsh/lib/bin.js check.

tests/windows-command-discovery.test.ts (new, 11 tests)

  • the real launcher layout — CRLF and the actual four-up/two-up depths — is normalised;
  • a real dsh.exe in the same directory wins over dsh.cmd;
  • an unrelated .cmd is ignored, never handed to shell: false;
  • a rem line containing the flag cannot spoof the launcher;
  • an echo line mentioning the flag cannot shadow the real line;
  • an executable with a different name is rejected;
  • an entry outside resources\app.asar is rejected;
  • a shim whose app.asar is missing is ignored;
  • a shim whose executable is missing is ignored;
  • an npm-style cmd shim cannot displace the node_modules fallback;
  • between two PATH directories, the first entry wins in both orders.

process.env.PATH is restored with t.after() and node --test runs each file in its own process.

Verification

Run locally on Windows, at commit cd86870:

node --import tsx --test tests/windows-command-discovery.test.ts   # 11/11 pass
npm run typecheck                                                  # pass
npm run build                                                      # pass
npm test                                                           # 1180 tests, 1173 pass, 7 fail
npm run test:smoke                                                  # pass, gracefulShutdown: passed

The 7 failing tests are pre-existing environment/timing failures also present on the base commit (context-preparation slow-helper timeouts, fleet timing, and two terminals cases that hit EACCES on WindowsApps\pwsh.exe). A clean worktree at the same base commit failed 7 tests too; no new failure was introduced. Tests that varied between runs passed when executed in isolation twice.

Real launcher check. With PATH pointing only at ...\DeepSeek Harness\resources\runtime\cli\bin, findCommand("dsh") resolved:

command : ...\DeepSeek Harness\DeepSeek Harness.exe
prefix  : ["--expose-internals", "...\resources\app.asar\dsh\node_modules\@deepseek-ai\dsh-desktop-host\lib\cli.js"]
identity: the same cli.js path
env     : ELECTRON_RUN_AS_NODE=1

Argument-array spawn proof. The exact shape MemCode uses was exercised manually:

spawnSync(command.command, [...command.prefix, "--version"], {
  shell: false,
  env: { ...process.env, ...command.env },
})

Result: status: 0, stdout 0.2.2-rc.5. This is the check the Tauri smoke cannot isolate, because this machine also has a local dsh.exe shim earlier in PATH.

The Tauri smoke passed and listed DeepSeek Harness as available, but it detected the CLI through that local dsh.exe, so it is not used as evidence for the .cmd path.

Review history

Two adversarial review rounds were run against the patch. Round 1 found one high issue (approval inheritance through an arbitrary exe), plus missing file checks, an over-permissive parser, a precedence ambiguity, .bat surface and weak tests — all addressed here. Round 2 returned APPROVE with three low findings; those are also addressed (dedicated regression tests for the three guards, first-full-match parsing, and removal of a tautological assertion).

Notes for reviewers / release notes

  • Users who had a previously approved dsh.exe in a later PATH directory will need to approve again once the official installer puts its dsh.cmd directory first, because the provider identity changes. This is the intended consequence of following PATH order; the alternate behaviour (prefer any .exe in the whole PATH) was considered and rejected.
  • The parser is deliberately tied to the official launcher format. A future change to that format will fail closed and fall back to node_modules, not break spawning.
  • No CI was dispatched and no mandatory check was added. No generated engines, credentials or private project data are included.

Run Proof on this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

The CLI installer writes dsh.cmd, but discovery only looked for dsh.exe. Normalize the official batch shim into the executable, argument prefix and environment the launcher declares, keeping the argument-array spawn sites unchanged. The parser accepts only the official layout, binds the Electron entry to the owning installation, checks both files on disk, and leaves other shims to the node_modules fallback.
@blocksorg

blocksorg Bot commented Nov 21, 2026

Copy link
Copy Markdown

Mention Blocks like a regular teammate with your question or request:

@blocks review this pull request
@blocks make the following changes ...
@blocks create an issue from what was mentioned in the following comment ...
@blocks explain the following code ...
@blocks are there any security or performance concerns?

Run @blocks /help for more information.

Workspace settings | Disable this message

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical issue in runtime/commands.ts routes extensionless Linux PATH executables into the Windows batch-shim branch, skipping installed harnesses and potentially resolving tools such as gh to null.

1 open issue
What changed in this PR

This PR adds detection of the official Windows DeepSeek Harness launcher, converting it into an executable command compatible with MemCode’s existing shell-free worker spawning.

Changes:

  • Parse and validate dsh.cmd, returning the executable, arguments, environment, and approval identity.
  • Add Windows .cmd discovery while preserving same-directory .exe precedence and PATH ordering.
  • Add 11 Windows tests covering launcher parsing, validation, fallback behavior, and precedence.
File Description
tests/​windows-command-discovery.test.ts Adds Windows launcher discovery and validation tests.
runtime/​commands.ts Normalizes official DSH shims and extends command discovery.

Review effort: Balanced

Comment thread runtime/commands.ts Resolved
Shim normalization ran for every extension other than .exe. On Linux the extension list is [""], so each PATH executable entered that branch and was skipped unless a node_modules fallback existed; git, gh and shell lookups could return null. Normalize only .cmd files so native executables reach the direct return.
@magalz

magalz commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up on the extension-normalization comment: fixed in 98fa754.

runtime/commands.ts now normalizes only .cmd shims. The previous extension !== ".exe" condition treated Linux's [""] as a Windows shim extension, so extensionless PATH executables fell into that branch and were skipped by continue. That made findCommand("git"), findCommand("gh"), findCommand("dsh") and shell lookups return null unless a node_modules fallback happened to exist. Windows behavior is unchanged: dsh.exe is still returned directly and the official dsh.cmd launcher is still normalized.

Added tests/linux-command-discovery.test.ts, which stubs process.platform = "linux" and asserts discovery of git, gh and dsh from a temporary PATH. It fails on cd86870 with actual: null and passes with the fix; the 11 Windows shim tests remain green.

Verification on 98fa754: npm run typecheck and npm run build pass, and the full suite is 1181/1181 green. The suite had to be serialized (--test-concurrency=1) with the broken Microsoft\WindowsApps PATH alias excluded to avoid environment-only timeouts and EACCES; no source or test behavior was changed for that run.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Saved harness entries inside app.asar fail the configured-path existence check when a later GUI launch lacks the installer directory in PATH, making an approved, still-installed harness unavailable.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread runtime/commands.ts Resolved
A GUI launch without the installer's launcher directory on PATH could not reuse an approved dsh runtime: its saved identity points inside app.asar, which ordinary filesystem access cannot read. Reconstruct the Electron command from the owning executable and archive before the configured-path existence check, sharing the validation used for the .cmd shim. Reject non-canonical paths so an identity cannot traverse into another installation.
@magalz

magalz commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up to the saved-runtime comment: fixed in 3b78207.

findCommand() now rebuilds a dsh command from a saved app.asar identity before the configured-path existence check. fs.access() cannot read an entry inside an archive, so a GUI launch without the installer's launcher directory in PATH previously made an approved, still-installed harness unavailable in both worker status and review. The reconstruction reuses the installation validation from the .cmd shim (owning DeepSeek Harness.exe, its resources/app.asar, and the script inside it), keeps the saved identity for approval matching, and rejects non-canonical paths so a saved identity cannot traverse into another installation.

Added regressions for rediscovery without the launcher directory, missing executable/archive, another harness, a normal configured executable, and .. traversal. Verified on 3b78207: typecheck and build pass, the 16 discovery tests pass, and the full suite is 1185/1185 green (serialized with --test-concurrency=1 and the broken WindowsApps PATH alias excluded to avoid environment-only failures). Independent review approved.

Alex793x added a commit to magalz/memcode that referenced this pull request Nov 23, 2026
…setup branch

The Desktop CLI helper installs the official dsh.cmd launcher on Windows;
without syncable-dev#17's shim normalization the installed CLI stays undiscoverable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Alex793x
Alex793x merged commit 014b046 into syncable-dev:dev Nov 23, 2026
1 check passed
Alex793x added a commit that referenced this pull request Nov 23, 2026
Promotes MemCode 0.4.0-beta.21 from dev: shared projects, private worker
conversations on shared projects, deleting a project from the project
switcher, the WebKit Browser tab on Mac, and DeepSeek Harness setup fixes.
Integrates PRs #17 to #22.

The tree is dev at b5c2158 plus the Windows test fixes in PR #22.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants