Skip to content

Fix Windows support: platform-abstract process lifecycle, binary update, and install script#41

Open
danbao wants to merge 2 commits intofastclaw-ai:mainfrom
danbao:fix/windows-support
Open

Fix Windows support: platform-abstract process lifecycle, binary update, and install script#41
danbao wants to merge 2 commits intofastclaw-ai:mainfrom
danbao:fix/windows-support

Conversation

@danbao
Copy link
Copy Markdown
Contributor

@danbao danbao commented Mar 31, 2026

Problem

WeClaw builds for Windows (windows/amd64, windows/arm64) in CI, but several core functions fail at runtime or compile-time on Windows:

Issue Location Impact
syscall.SIGINT, syscall.SIGTERM in signal.NotifyContext start.go SIGTERM does not exist on Windows — compilation fails or behavior is undefined
Signal(0) for process detection start.go processExists() On Windows Signal(0) always returns nilprocess detection never works
syscall.SIGTERM for process termination start.go stopAllWeclaw(), restart.go Windows has no SIGTERM — process termination silently fails
pkill -f for cleanup start.go stopAllWeclaw() Windows has no pkillorphan cleanup never works
replaceBinary() rename update.go Running .exe is file-locked on Windows — weclaw update always fails
getLatestVersion() uses GitHub API update.go Anonymous rate limit (60/hr) — fails in CI or with frequent checks
No Windows install script Users must manually download and configure PATH

Solution

1. Platform abstraction via build tags (proc_unix.go / proc_windows.go)

Move all platform-specific logic into build-tagged files. The existing files only had setSysProcAttr — now they also provide:

Function Unix Windows
notifyContext() SIGINT + SIGTERM os.Interrupt
processExists() Signal(0) tasklist /FI "PID eq X"
signalTerminate() SIGTERM Kill() (hard kill)
killByName() pkill -f taskkill /F /IM

2. Remove syscall from shared code

start.go and restart.go no longer import syscall. All platform calls go through the abstracted functions above.

3. replaceBinary() — Windows file-lock handling

On Windows, a running .exe cannot be overwritten. The new logic:

  1. Rename current binary to .old
  2. Place new binary at original path
  3. If step 2 fails, restore .old back

4. getLatestVersion() — avoid GitHub API rate limits

Replace api.github.com/repos/.../releases/latest (JSON, 60 req/hr anonymous limit) with HTTP redirect from github.com/.../releases/latest (no rate limit, no JSON parsing).

5. install.ps1 — Windows installer

New PowerShell install script that:

  • Detects architecture (amd64/arm64)
  • Downloads latest release via redirect
  • Installs to $env:LOCALAPPDATA\weclaw
  • Adds to user PATH if not present

Files Changed

  • cmd/proc_unix.go — Added notifyContext, processExists, signalTerminate, killByName
  • cmd/proc_windows.go — Added Windows-specific implementations for all 5 platform functions
  • cmd/start.go — Removed syscall import; use notifyContext, signalTerminate, killByName
  • cmd/restart.go — Removed syscall import; use signalTerminate
  • cmd/update.gogetLatestVersion via redirect; replaceBinary with Windows file-lock handling
  • install.ps1 — New Windows installer script

Testing

  • go build ./... passes (darwin)
  • GOOS=windows GOARCH=amd64 go build ./... passes (cross-compile)
  • go test -race ./... all pass

danbao and others added 2 commits March 31, 2026 20:41
…te, and install script

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.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.

1 participant