Repository navigation
fix: safely launch Windows SSH executors - #4664
Conversation
|
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Signed-off-by: 7Sageer <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b178304d98
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| ); | ||
| } | ||
| if (this.environmentValue.pathClass !== 'posix') { | ||
| if (this.environmentValue.pathClass !== 'posix' && this.environmentValue.pathClass !== 'win32') { |
There was a problem hiding this comment.
Provision ripgrep for newly accepted Windows targets
For a Windows target that does not already have rg on PATH (for example a bare executor plus Git Bash), this newly accepted handshake reaches ensureRgPath; however detectRemoteTarget in src/os/backends/node-local/tools/rgLocator.ts explicitly returns undefined for Windows and shareBinRgPath still names rg rather than rg.exe. Both Glob and Grep therefore return “Unsupported platform/arch” instead of provisioning their fallback, so enable the existing Windows archive/install path before admitting this environment.
AGENTS.md reference: AGENTS.md:L128-L128
Useful? React with 👍 / 👎.
| get path(): Environment['path'] { | ||
| return this.session === undefined ? undefined : POSIX_ENVIRONMENT_PATH; | ||
| if (this.session === undefined) return undefined; | ||
| return this.session.host.pathClass === 'win32' ? WIN32_ENVIRONMENT_PATH : POSIX_ENVIRONMENT_PATH; |
There was a problem hiding this comment.
Resolve Git Bash mount paths on the remote host
When a non-Windows Kimi host drives this Windows environment and remote Git Bash emits a non-drive mount path such as /tmp/out from mktemp, EnvironmentWorkspaceView and path-access call getShellPathBridge with the remote host metadata, but that bridge locates and runs cygpath.exe using the client process's local existsSync/execFileSync. It therefore leaves /tmp/out unresolved and the new win32 path implementation sends \tmp\out (effectively C:\tmp\out) instead of Git Bash's actual mount, so Read/Edit can fail or target the wrong file; the provider needs a bridge backed by the remote FS/process or server-side conversion.
AGENTS.md reference: AGENTS.md:L128-L128
Useful? React with 👍 / 👎.
|
|
||
| private scheduleGroupReap(processId: string, group: ExitedProcessGroup): void { | ||
| if (process.platform === 'win32') { | ||
| this.exitedGroups.delete(processId); |
There was a problem hiding this comment.
Retain exited Windows process trees until cleanup
When a Windows remote process leader exits after daemonizing a child with redirected stdio (for example a Git Bash command ending in &), maybeClose reaches this branch and immediately deletes the only processId ownership record. A later RemoteProcess.kill('SIGTERM') is silently accepted as an unknown pre-start termination and terminateAll() cannot invoke taskkill, leaving the child running after the session or SSH connection closes; retain Windows tree ownership, for example with a Job Object, rather than discarding it here.
AGENTS.md reference: AGENTS.md:L128-L128
Useful? React with 👍 / 👎.
| function sshRemoteCommand(remoteBin: string): string { | ||
| const posix = shQuote(execServerShellCommand(remoteBin)); | ||
| const windows = `"${execServerPowerShellCommand(remoteBin)}"`; | ||
| return `sh -c exit && sh -c ${posix} || powershell -NoLogo -NoProfile -NonInteractive -Command ${windows}`; |
There was a problem hiding this comment.
Avoid POSIX chaining under a PowerShell default shell
When Windows OpenSSH is configured to use built-in Windows PowerShell 5.1 as its DefaultShell, sshd asks that shell to parse this entire remote command before the nested powershell invocation can run. Microsoft's pipeline-chain documentation says && and || are available beginning in PowerShell 7, so 5.1 rejects the line and every connection fails before starting the executor; dispatch with syntax valid for the configured remote shell instead of assuming cmd/POSIX parsing.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| function windowsExecutorPath(remoteBin: string): string { | ||
| const path = remoteBin === DEFAULT_REMOTE_BIN ? '~/.kimi-code/bin/kimi.exe' : remoteBin; |
There was a problem hiding this comment.
Report the Windows executor path in upgrade guidance
When a Windows executor completes the handshake but is below the minimum version, connectWithGuidance obtains the path from launcherRemoteBin() and tells the user to replace ~/.kimi-code/bin/kimi. This line silently changes the executable actually launched to ~/.kimi-code/bin/kimi.exe, so following the upgrade guidance leaves the old .exe in place and reconnecting repeats the same incompatibility; carry the effective Windows path (or both platform paths) into the guidance.
AGENTS.md reference: AGENTS.md:L128-L128
Useful? React with 👍 / 👎.
| function sshRemoteCommand(remoteBin: string): string { | ||
| const posix = shQuote(execServerShellCommand(remoteBin)); | ||
| const windows = `"${execServerPowerShellCommand(remoteBin)}"`; | ||
| return `sh -c exit && sh -c ${posix} || powershell -NoLogo -NoProfile -NonInteractive -Command ${windows}`; |
There was a problem hiding this comment.
Preserve install guidance for PowerShell command misses
When the Windows executor is not installed yet, the nested PowerShell command-not-found leaves $? false and the documented string -Command exit contract returns code 1. classifyHandshakeFailure recognizes only executor exits 126/127 as missing, so the normal first Windows connection is rethrown without the promised install instructions; make the PowerShell branch return a recognized missing-executable status or classify this failure explicitly.
AGENTS.md reference: AGENTS.md:L128-L128
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21f68c0a73
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| throw new HandshakeError(`Could not detect the SSH target platform: ${result.stderr.trim() || result.stdout.trim() || `probe exited with code ${result.code}`}`, { | ||
| kind: 'executor-exit', exitCode: result.code, |
There was a problem hiding this comment.
Avoid labeling platform-probe failures as a missing executor
When a path-based SSH target cannot run the probes—for example, both uname and powershell are blocked or missing—this assigns the final probe's 126/127 status to an executor-exit; classifyHandshakeFailure consequently takes its missing-executor branch and connectWithGuidance tells the user to reinstall Kimi even though the executor was never started. The timeout branch at line 148 similarly reuses the handshake timeout kind and receives install guidance, so preserve a probe-specific failure class (or skip executor guidance) instead.
AGENTS.md reference: AGENTS.md:L112-L112
Useful? React with 👍 / 👎.
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21f68c0a73
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }; | ||
| const remoteBin = spec.remoteBin ?? DEFAULT_REMOTE_BIN; | ||
| return resolveSshCommand(spec.host, | ||
| sshPlatform === 'windows' && !isBareRemoteBin(remoteBin) |
There was a problem hiding this comment.
Add a changeset for the Windows SSH launch fix
This new Windows path-based launch branch changes behavior visible to CLI users, but the commit adds no .changeset entry, so the fix is omitted from the user-facing changelog; add a @moonshot-ai/kimi-code patch changeset.
AGENTS.md reference: AGENTS.md:L89-L90
Useful? React with 👍 / 👎.
| function execServerPowerShellCommand(remoteBin: string): string { | ||
| const path = remoteBin === DEFAULT_REMOTE_BIN ? '~/.kimi-code/bin/kimi.exe' : remoteBin; | ||
| const literal = (value: string) => `'${value.replaceAll("'", "''")}'`; | ||
| const executable = /^~[\\/]/.test(path) |
There was a problem hiding this comment.
Preserve named-user tilde paths in Windows SSH
When a Windows SSH target uses Git Bash and remoteBin is a named-home path such as ~alice/bin/kimi.exe, this predicate falls through to a literal PowerShell path because it only recognizes ~/ or ~\; the previous execServerShellCommand path let Bash expand ~alice, so the executor now fails to launch. Preserve named-user expansion in this branch.
AGENTS.md reference: AGENTS.md:L112-L112
Useful? React with 👍 / 👎.
* fix(tui): read welcome cwd and footer git status from the session environment (#4649) * fix(tui): show remote cwd in welcome panel * fix(tui): read footer git status through the session environment The footer ran git and gh on the local machine, so a remote-bound session hid the git badge. Read branch, working-tree, and pull request state through the SDK instead: a live session's own environment, or the local work dir before the lazy session exists. The local HEAD poll stays as a refresh trigger only. Core git commands now time out after 30s, and the pull request cache is keyed by branch so a branch switch no longer serves the previous branch's pull request. * fix(agent-core-v2): resolve local git and gh outside the working directory GitService spawned bare git and gh with the workspace as cwd. On Windows a bare name is looked up in the cwd before PATH, so a binary planted in the workspace could run, and the TUI footer now reads git status at startup, before the workspace trust gate. Resolve both through PATH for the local environment and refuse any match inside the working directory. * chore: merge changesets for remote cwd and git status * fix(tui): drop the startup Ready. row once startup succeeds The startup progress row turned into a permanent "Ready." line under the welcome panel. Remove it on success; a failed startup still leaves the "Startup failed." row. * fix(agent-core-v2): compare workspace containment case-insensitively on Windows resolveProgramPath compared the PATH candidate against the working directory case-sensitively, so on Windows a PATH entry spelled with different casing (c:\repo\bin vs C:\Repo) let a workspace-local executable through. * fix(tui): keep the footer git badge through a remote disconnect The git cache key included the environment status, so a remote dropping to connecting or disconnected rebuilt the cache and lost the last badge. Key the cache by session and work dir only, and refresh it when the environment turns ready again. * feat: isolate plugin availability by client (#4653) * fix: preserve marketplace descriptions * fix: preserve localized plugin display names * feat: isolate plugin availability by client * fix: preserve cli marketplace loading * fix: harden plugin availability reconciliation * fix: hash plugin marketplace provenance * fix: complete plugin availability reconciliation * fix(transcript): keep realigned turn ids unique when folding cold facts (#4658) * fix(transcript): keep realigned turn ids unique when folding cold facts Realigning base turns to their wire ids only skipped ordinals held by turns without a wire id. When an inherited turn held a forked turn's wire id, that turn kept its base ordinal, and the next turn's wire id could land on the same ordinal, so two turns shared a turn id and the later one replaced the earlier in clients. Claim ordinals in order: turns without a wire id or already at their wire id first, then each realigned turn takes its wire id when free, else keeps its ordinal or moves to the next free one. * chore: add changeset for side chat turn order fix * fix(kap-server): wait for an agent's history before accepting its prompt (#4659) * fix(kap-server): backfill a side chat fork before replying to :btw A fork's inherited history folds into a cold turn at t0, while the live transcript only records it as markers. When the fork's first prompt started before anything read the fork transcript, its live turn took t0; the history backfill then merged the inherited main turn into it by turn id, so the first side chat turn carried the main answer and the real answer landed in a duplicate turn. Finish the fork's history backfill before :btw replies, so the inherited turn holds t0 before the first prompt can start. * fix(kap-server): wait for an agent's history before accepting its prompt Delaying the :btw reply did not order the fork's first prompt after its history backfill: other clients learn the fork from the agent roster as soon as it is created, and checking for a live transcript with forSessionLive created one, so every :btw also waited for the whole main history. Move the wait to prompt submission: a prompt for a non-main agent awaits that agent's history backfill before it is enqueued, which covers every client and leaves :btw unchanged. The backfill is cached per agent, so later prompts do not wait again. * fix: safely launch Windows SSH executors (#4664) * feat: support Windows SSH remote environments * Delete .changeset/windows-remote-environments.md Signed-off-by: 7Sageer <[email protected]> --------- Signed-off-by: 7Sageer <[email protected]> * fix(agent-core-v2): match regional plugin locales (#4666) * fix(plugins): confirm stopping Windows CU processes before install (#4670) * fix(plugins): confirm stopping Windows CU processes before install * test(plugins): cover capability install confirmation contract * fix(plugins): preserve bodyless installs and plugin-only repairs * chore: sync web dist from code-app (#4667) * chore: sync web dist from code-app code-app: 63661fc449e2ec0ce024bc08fe87f2c757d483e8 * chore: sync web dist from code-app code-app: d0e913a6c9607be778c62f0c74ee7310bfb8862a * chore: sync web dist from code-app code-app: b306f4a2f9be8944e5a8064ecb076e3137c968f1 --------- Co-authored-by: kimi-agent-bot <[email protected]> * ci: release packages (#4672) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Signed-off-by: 7Sageer <[email protected]> Co-authored-by: 7Sageer <[email protected]> Co-authored-by: liruifengv <[email protected]> Co-authored-by: qer <[email protected]> Co-authored-by: kimi-agent-bot <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Fifteen rows enter the ledger: the six commits that landed on upstream/main after the last refresh, and the nine commits that reach main only through the release/2026-11-04 sync (MoonshotAI#4674), which is where the 2.5.0 changelog entries come from. Each 2.5.0 row records what it needs from this tree, so the next batch starts from the blocker instead of rediscovering it: - MoonshotAI#4658 and MoonshotAI#4659 are ported (79a4199, 7a531f5) with tests that fail on the pre-change tree. - MoonshotAI#4649 is in_progress: its agent-core-v2 half landed in 2fa7b6b, while the footer and welcome half needs the pull-request API of MoonshotAI#4527 and the session workdir of MoonshotAI#4062. - MoonshotAI#4653, MoonshotAI#4666 and MoonshotAI#4670 build on the MoonshotAI#4525 plugin marketplace, absent here; MoonshotAI#4670 additionally needs isError2. - MoonshotAI#4664 needs the MoonshotAI#4062 remote environments. - MoonshotAI#4667 and MoonshotAI#4672 are generated-bundle and release commits; settling them as not-applicable needs a signature. Rows were appended by a one-off writer because --refresh fetches and that fetch does not complete on this network; the file still parses under the tool's own column contract, and --verify --batch B5 passes both new probes.
Port of upstream MoonshotAI/kimi-code 212127a (MoonshotAI#4664). An SSH target running Windows could only be reached with a bare `remoteBin` name: the launcher always built a POSIX shell command, so a path such as `~/.kimi-code/bin/kimi.exe` was handed to cmd or PowerShell as broken syntax. - `launchers.ts` gains `isBareRemoteBin`, `powerShellCommand` (one `-EncodedCommand` carrying the base64 of the UTF-16LE script), `execServerPowerShellCommand` (`$env:USERPROFILE` for `~/` paths, single-quote doubling for literals, `exit $LASTEXITCODE`), and `resolveSshCommand`; `resolveLauncher` takes an `sshPlatform` and switches only when the `remoteBin` is a path, so a bare name keeps today's command. - A bare `remoteBin` is no longer quoted on the shell path either. - `RemoteSession.connect` probes the target before launching: `uname -s`, and `windows` when it reports MINGW/MSYS/CYGWIN; otherwise a PowerShell probe that prints `KIMI_WINDOWS`. Exit 255 becomes an `authentication` or `executor-exit` HandshakeError and a killed probe a `timeout`, so a wrong password or a missing shell fails with the same shape as the executor handshake. Coverage gap, recorded rather than hidden: the upstream session-level detection cases are POSIX-only (a fake `ssh` on `PATH`) and are not ported, so the probe branch is pinned only through the launcher command shape; this fork's remote suite is POSIX-gated the same way. Verified: agent-core-v2 typecheck clean, remote suite 54 pass / 49 skip with three new launcher cases (the encoded Windows script for the default path, a `~/` path and a path with quotes/metacharacters, plus the bare-name and posix counterparts), sessionManager 31 pass, node-local tools 348 pass; check:no-comments, check:deep-imports and check:boundaries green. Docs updated in both locales: `remoteBin` now documents the Windows default and the probe. Ledger: MoonshotAI#4664 ported; closed 72 -> 73, remaining 27 -> 26.
Requirement or Bug
Windows SSH 用户使用默认安装位置或带空格的 Windows 绝对路径时,执行器需要通过适合目标系统的命令启动。当前发布基线已经包含 #4610 的 Windows 环境、路径桥接和 ripgrep 支持;本 PR 补齐 SSH 启动路径,并守住会话创建前的信任检查时序。
Bug Reproduction Steps
.kimi-code/bin/kimi.exe。type = "ssh"、host = "windows-dev"、defaultCwd = 'C:\work\project',不设置remoteBin;或将remoteBin设为带空格的 Windows 绝对路径。$HOME和引号,无法由 cmd / Windows PowerShell 直接执行。Root Cause
SSH 会把远端命令交给目标账户的默认 Shell,客户端不能在握手前假定它支持 POSIX 语法。把 POSIX 和 PowerShell 执行器串成条件命令,还会把执行器自身的非零退出误当成平台探测失败,并让路径经过外层 Shell 的展开。
修复将平台探测与执行器启动分开。探测只运行固定命令,执行器只启动一次,退出码直接向上传递。会话信任检查继续使用基线的纯路径规范化,不提前建立 SSH 连接。
Code Changes
探测与执行阶段复用 SSH 主机校验、认证参数和 askpass。每次探测与握手各有 10 秒上限,探测输出也有大小上限;认证失败或超时立即终止。Windows 脚本使用
-EncodedCommand,外层命令没有&&/||,适用于 Windows PowerShell 5.1。先看
remote/client/launchers.ts的命令构造,再看remote/client/remoteSession.ts的探测与资源释放。其余改动是回归测试和双语说明。Windows 路径桥接、进程生命周期、握手能力和 ripgrep 安装沿用发布基线。Behavior Changes and Affected Users
~/.kimi-code/bin/kimi.exe启动,支持绝对路径和空格remoteBin = "kimi"或"kimi.exe"remoteBin的用户rg.exe安装/c/...可用;/tmp、/usr等无法确认映射的 MSYS 路径继续明确拒绝覆盖了执行器非零退出、含引号和命令替换字符的完整路径执行、Windows 编码命令、探测超时和失败、真实 askpass 密码重试、信任检查不发起连接,以及 Windows x64/arm64 ripgrep 下载选择。没有修改配置字段、会话存储格式或外部 API 契约。
验证范围与结果
@moonshot-ai/agent-core-v2typecheck 通过。rg.exe,未调用 chmod。lint:imports有一条基线已有失败:human/agent/origin.ts导入agent/prompt/promptMetadataText。该文件和检查脚本均与发布基线一致。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.