Repository navigation
feat(onboard): add WSL Windows-host Ollama install/start/restart flow #2800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7972ecd
feat(onboard): add WSL Windows-host Ollama install/start flow
zyang-dev d1632ab
fix(onboard): address review feedback for Windows-host Ollama
zyang-dev 034ecdc
fix(onboard): surface launch failures and hint at Windows-host altern…
zyang-dev 8aca72a
fix(onboard): guard stdio listeners against spawn failure on non-Windows
zyang-dev 4d2d93c
test(onboard): adapt install-ollama menu test to WSL menu numbering
zyang-dev 0895f1f
fix(onboard): fail-loud when recorded WSL ollama-local would silently…
zyang-dev 951a217
Merge branch 'main' into feat/wsl-ollama-windows-host-ux
zyang-dev 7d81553
Merge branch 'main' into feat/wsl-ollama-windows-host-ux
zyang-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| // @ts-nocheck | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| // Windows-host Ollama actions invoked from WSL via PowerShell interop. | ||
| // Detection lives in onboard.ts; this module owns the action side. | ||
|
|
||
| const { spawn, spawnSync } = require("child_process"); | ||
| const { run, runCapture } = require("./runner"); | ||
| const { OLLAMA_HOST_DOCKER_INTERNAL, setResolvedOllamaHost } = require("./local-inference"); | ||
| const { OLLAMA_PORT } = require("./ports"); | ||
|
|
||
| function sleep(seconds: number): void { | ||
| spawnSync("sleep", [String(seconds)]); | ||
| } | ||
|
|
||
| // Pre-set OLLAMA_HOST in both User scope (persists across logins) and the | ||
| // current PowerShell session (inherited by the installer's auto-spawned | ||
| // ollama_app + daemon) so the new daemon binds 0.0.0.0 from the start. | ||
| // Don't use stdio:inherit here. When powershell.exe is spawned through | ||
| // WSL interop, its stdout looks like a pipe (not a console), so PowerShell | ||
| // holds output in an internal buffer and the user sees long silent gaps. | ||
| // Reading the pipe from Node and re-writing to our own TTY shows progress | ||
| // as soon as PowerShell flushes a chunk. | ||
| async function installOllamaOnWindowsHost(): Promise<{ ok: boolean; path: string }> { | ||
| console.log(" Installing Ollama on Windows host..."); | ||
| console.log(" This can take several minutes. Output may pause silently"); | ||
| await new Promise<void>((resolve) => { | ||
| const child = spawn( | ||
| "powershell.exe", | ||
| [ | ||
| "-Command", | ||
| "[Environment]::SetEnvironmentVariable('OLLAMA_HOST','0.0.0.0:11434','User'); $env:OLLAMA_HOST='0.0.0.0:11434'; irm https://ollama.com/install.ps1 | iex", | ||
| ], | ||
| { stdio: ["ignore", "pipe", "pipe"] }, | ||
| ); | ||
| child.stdout.on("data", (chunk: Buffer) => process.stdout.write(chunk)); | ||
| child.stderr.on("data", (chunk: Buffer) => process.stderr.write(chunk)); | ||
| child.on("close", () => resolve()); | ||
| child.on("error", () => resolve()); | ||
| }); | ||
| const installedPath = runCapture( | ||
| [ | ||
| "powershell.exe", | ||
| "-Command", | ||
| "$env:PATH = [Environment]::GetEnvironmentVariable('PATH','Machine') + ';' + [Environment]::GetEnvironmentVariable('PATH','User'); Get-Command ollama.exe -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source", | ||
| ], | ||
| { ignoreError: true }, | ||
| ).trim(); | ||
| if (!installedPath) { | ||
| return { ok: false, path: "" }; | ||
| } | ||
| console.log(` ✓ Installed: ${installedPath}`); | ||
| return { ok: true, path: installedPath }; | ||
| } | ||
|
|
||
| // Capture the watcher path so we can relaunch from the same exe after kill, | ||
| // preserving the tray icon and the watcher's auto-restart behavior. | ||
| function captureWindowsOllamaWatcherPath(): string { | ||
| return runCapture( | ||
| [ | ||
| "powershell.exe", | ||
| "-Command", | ||
| "Get-Process 'ollama app' -EA SilentlyContinue | Select-Object -First 1 -ExpandProperty Path", | ||
| ], | ||
| { ignoreError: true }, | ||
| ).trim(); | ||
| } | ||
|
|
||
| // User-scope so the next login-time tray launch keeps the 0.0.0.0 binding | ||
| // without NemoClaw being involved. | ||
| function persistOllamaHostEnvVar(): void { | ||
| runCapture( | ||
| [ | ||
| "powershell.exe", | ||
| "-Command", | ||
| "[Environment]::SetEnvironmentVariable('OLLAMA_HOST','0.0.0.0:11434','User')", | ||
| ], | ||
| { ignoreError: true }, | ||
| ); | ||
| } | ||
|
|
||
| // Order matters: kill 'ollama app' (the tray watcher) before 'ollama' | ||
| // (the daemon). The watcher auto-respawns the daemon as soon as it dies. | ||
| // If the daemon goes first, the watcher can launch a fresh daemon with | ||
| // default env (127.0.0.1) before we get to kill it. That respawned daemon | ||
| // then holds port 11434 and blocks our 0.0.0.0 relaunch. | ||
| function killWindowsOllamaProcesses(): void { | ||
| runCapture( | ||
| [ | ||
| "powershell.exe", | ||
| "-Command", | ||
| "Get-Process 'ollama app' -EA SilentlyContinue | Stop-Process -Force", | ||
| ], | ||
| { ignoreError: true }, | ||
| ); | ||
| runCapture( | ||
| [ | ||
| "powershell.exe", | ||
| "-Command", | ||
| "Get-Process ollama -EA SilentlyContinue | Stop-Process -Force", | ||
| ], | ||
| { ignoreError: true }, | ||
| ); | ||
| } | ||
|
|
||
| function awaitWindowsOllamaReady(): boolean { | ||
| console.log(" Waiting for Ollama to respond on host.docker.internal..."); | ||
| for (let attempt = 0; attempt < 15; attempt++) { | ||
| sleep(2); | ||
| const probe = runCapture( | ||
| [ | ||
| "curl", | ||
| "-sf", | ||
| "--connect-timeout", | ||
| "2", | ||
| "--max-time", | ||
| "5", | ||
| `http://host.docker.internal:${OLLAMA_PORT}/api/tags`, | ||
| ], | ||
| { ignoreError: true }, | ||
| ); | ||
| if (probe) { | ||
| setResolvedOllamaHost(OLLAMA_HOST_DOCKER_INTERNAL); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| // Relaunch via the watcher path when available so the tray icon and the | ||
| // watcher's auto-restart survive; otherwise launch the daemon directly. | ||
| function launchAndAwaitWindowsOllama(watcherPath?: string): boolean { | ||
| console.log(" Starting Ollama on Windows host via WSL interop..."); | ||
| const launchScript = watcherPath | ||
| ? `$env:OLLAMA_HOST='0.0.0.0:11434'; Start-Process -FilePath '${watcherPath.replace(/'/g, "''")}' -WindowStyle Hidden` | ||
| : "$env:OLLAMA_HOST='0.0.0.0:11434'; Start-Process -FilePath ollama.exe -ArgumentList serve -WindowStyle Hidden"; | ||
| runCapture(["powershell.exe", "-Command", launchScript], { ignoreError: true }); | ||
| return awaitWindowsOllamaReady(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| // Used by start and restart paths to force a 0.0.0.0 binding on an already | ||
| // installed Ollama. Install path skips this: the installer's pre-set env | ||
| // already lands on the auto-spawned daemon. | ||
| function setupWindowsOllamaWith0000Binding(opts: { announceStop?: boolean } = {}): boolean { | ||
| const watcherPath = captureWindowsOllamaWatcherPath(); | ||
| persistOllamaHostEnvVar(); | ||
| if (opts.announceStop) { | ||
| console.log(" Stopping existing Ollama on Windows host..."); | ||
| } | ||
| killWindowsOllamaProcesses(); | ||
| sleep(1); | ||
| return launchAndAwaitWindowsOllama(watcherPath || undefined); | ||
| } | ||
|
|
||
| function switchToWindowsOllamaHost(): void { | ||
| setResolvedOllamaHost(OLLAMA_HOST_DOCKER_INTERNAL); | ||
| console.log(` ✓ Using Ollama on host.docker.internal:${OLLAMA_PORT}`); | ||
| } | ||
|
|
||
| module.exports = { | ||
| installOllamaOnWindowsHost, | ||
| awaitWindowsOllamaReady, | ||
| setupWindowsOllamaWith0000Binding, | ||
| switchToWindowsOllamaHost, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.