Skip to content

feat: configurable terminal shell with Windows pwsh auto-probe - #95

Open
oy-g wants to merge 2 commits into
omdsh-dev:mainfrom
oy-g:feat/terminal-shell-config
Open

feat: configurable terminal shell with Windows pwsh auto-probe#95
oy-g wants to merge 2 commits into
omdsh-dev:mainfrom
oy-g:feat/terminal-shell-config

Conversation

@oy-g

@oy-g oy-g commented Aug 15, 2026

Copy link
Copy Markdown

feat: configurable terminal shell — Windows pwsh 探测 + shell 配置

仓库:omdsh-dev/DSH-better-sidebar | 分支:feat/terminal-shell-config
关联:#46 Windows 终端 shell 硬编码 powershell.exe(5.1),希望可配置 / 自动探测 pwsh

问题

defaultShell() 在 Windows 上硬编码返回 powershell.exe(5.1):装了 PowerShell 7 的用户仍然拿到 5.1,且没有任何配置出口。该函数同时决定两条终端路径:侧边栏 UI 终端 tab 和注入给模型的 terminal_* 工具。

方案

解析优先级:

  1. shell 配置字段(新增)——显式配置最高;
  2. Windows:环境变量 DSH_SIDEBAR_SHELL
  3. Windows:自动探测 pwsh.exe(PATH → ProgramFiles / ProgramW6432 / LOCALAPPDATA 下的已知安装目录,含 7-preview),命中返回完整路径;
  4. Windows:回退 powershell.exe(5.1)——没装 pwsh 的机器行为不变;
  5. POSIX:保持原链($SHELL → login shell → /bin/bash)。

defaultShell() 增加可注入参数(platform / env / exists / explicit),使 Windows 解析链能在 ubuntu CI 上被单测真实执行(CI 不跑 win32 分支)。

改动

文件 内容
src/pty-manager.ts defaultShell 重构 + Windows 探测链
src/config.ts 新增 shell 配置字段(默认空 = 自动)
src/index.ts UI 终端与模型终端共用一次解析结果
tests/unit.spec.ts POSIX 链 + Windows 全链注入式单测
tests/plugin-shape.spec.ts schema 默认值与覆盖值断言

用法

# ~/.dsh/profiles/web/cordis.patch.yml(对既有挂载行做配置覆盖)
- id: better-sidebar
  name: 'dsh-better-sidebar'
  config:
    shell: pwsh.exe            # 或 C:\Program Files\PowerShell\7\pwsh.exe;留空 = 自动

不配置时:装了 pwsh 7 的机器自动用 pwsh;没装的保持 5.1。

验证

  • pnpm typecheck ✅;聚焦测试 114/115(唯一失败为 Windows 本机既有失败,已确认与本次无关);tsc + tsdown 构建 ✅。
  • Windows 11 + DSH 0.1.0-rc.6 经 link: 安装实测:UI 终端与模型 terminal_* 工具均打开 PowerShell 7.6.3
  • check:consumer-types 与真实 DSH 挂载冒烟由 CI 的 ubuntu job 覆盖(依赖 bash 脚本,Windows 本机无法运行)。

讨论

  • shell 目前是 host 配置(cordis.patch.yml,重启生效);是否升级为用户级设置项(设置页可见)可后续讨论。

Windows previously hardcoded powershell.exe (5.1) in defaultShell(), ignoring PowerShell 7 installs. Resolve the shell in priority order: explicit shell config -> DSH_SIDEBAR_SHELL -> PATH/known-dir probe for pwsh.exe -> inbox 5.1 fallback. The same resolved shell feeds both the UI terminal tabs (PtyManager) and the model-facing terminal_* tools (AgentPtyRegistry).

defaultShell() now accepts injectable platform/env/exists options so the Windows chain is unit-testable on the ubuntu CI, which never executes win32 branches. The probe also checks ProgramW6432 for 32-bit Node, and machines without PowerShell 7 keep the 5.1 fallback.

Refs: omdsh-dev#46
Copilot AI lite review requested due to automatic review settings August 15, 2026 09:38

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.

Pull request overview

This PR adds a configurable terminal shell selection mechanism so Windows users can automatically prefer PowerShell 7 (pwsh.exe) (or explicitly configure a shell), while ensuring the UI terminal tabs and model-facing terminal_* tools use the same resolved shell.

Changes:

  • Refactors defaultShell() to accept injectable resolution inputs and adds a Windows probe chain (shell config → DSH_SIDEBAR_SHELL → probe pwsh.exe → fallback powershell.exe).
  • Introduces a new shell field in plugin config (default '' = auto-resolution).
  • Updates wiring and tests so both terminal surfaces share one resolution and the Windows chain is unit-tested via injection.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/pty-manager.ts Adds injectable shell resolution options + Windows pwsh.exe probing and updated resolution order.
src/config.ts Adds shell config field, schema default, and trimming in resolved config.
src/index.ts Computes shell once and passes it to both PtyManager and AgentPtyRegistry to keep behavior consistent.
tests/unit.spec.ts Adds injected-platform tests covering POSIX chain and full Windows chain behavior.
tests/plugin-shape.spec.ts Asserts config schema default and override behavior for the new shell field.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/pty-manager.ts Outdated
Comment on lines 281 to 282
const envShell = env.SHELL
if (envShell !== undefined && envShell.trim() !== '') return envShell

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in e190aa3

Comment thread src/pty-manager.ts Outdated
export interface ShellResolutionOptions {
/** Platform override (defaults to `process.platform`). */
platform?: NodeJS.Platform
/** Environment override; the resolver only reads SHELL, DSH_SIDEBAR_SHELL, PATH, ProgramFiles, LOCALAPPDATA. */
- POSIX SHELL is validated with trim() but was returned untrimmed; trailing whitespace could leak into the spawned executable path. Return the trimmed value like the explicit/config and Windows/env branches.
- ShellResolutionOptions.env comment now lists ProgramW6432, which the Windows probe prefers over ProgramFiles on 32-bit Node.
- Test pins the SHELL trimming behavior.
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.

2 participants