Repository navigation
feat: add native Windows support across runtime, CLI/TUI, web UI, ConPTY, desktop app, and CI - #201
Open
Miguel del Amor (forlayo) wants to merge 1 commit into
Open
Miguel del Amor (forlayo) wants to merge 1 commit into
Miguel del Amor (forlayo) wants to merge 1 commit into
Conversation
…web UI, ConPTY, desktop app, and CI
Miguel del Amor (forlayo)
requested a review
from Zezi Zeng (ClarenceStark)
as a code owner
December 6, 2026 11:47
|
Thanks for the pull request! A few friendly reminders based on the files changed:
(This comment updates automatically when you edit the PR description or push new commits.) |
Author
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical defects can clear clipboard contents, hang process timeouts and terminal shutdown, and break Windows release builds.
12 open issues
Restrict macOS signing secrets to macOS jobs · New Normalize SVG line endings before checksum verification · New Fall back to process-tree termination when job assignment fails · New Use a valid clipboard owner before setting clipboard data · New Drain pseudo-console output before closing to avoid hangs · New Quote discovered batch-file paths when spawning with shell · New Do not mark credential permissions safe without checking ACLs · New Configure redirected stdin for UTF-8 on Windows · New Check serialized command length against the CreateProcess limit · New Write UTF-8 BOM for PowerShell fallback scripts · New Preserve literal backslashes in POSIX paths · New Prevent echoed input from satisfying interactive success markers · New
What changed in this PR
Adds native Windows support across Freehand’s runtime, interfaces, desktop packaging, and CI, addressing #180 without requiring WSL.
Changes:
- Introduces PowerShell execution, Windows locking and process management, and ConPTY terminals.
- Adapts clipboard, editor, path, and file handling for Windows.
- Adds Windows installation and desktop releases, with cross-platform test coverage.
| File | Description |
|---|---|
| tests/test_workbench.py | Adapts terminal and editor tests. |
| tests/test_windows_support.py | Adds dedicated Windows coverage. |
| tests/test_web_workbench.py | Uses portable terminal commands. |
| tests/test_web_ui.py | Adapts paths and Unicode fixtures. |
| tests/test_web_panels.py | Sends JavaScript through stdin. |
| tests/test_web_no_project.py | Uses portable file commands. |
| tests/test_web_files.py | Adapts Windows file checks. |
| tests/test_web_e2e.py | Supports Windows browser discovery and logging. |
| tests/test_web_e2e_more.py | Controls fixture line endings. |
| tests/test_ux_matrix.py | Tests native CLI execution. |
| tests/test_usercommands.py | Normalizes path assertions. |
| tests/test_tui_fixes.py | Makes command fixtures portable. |
| tests/test_tui_details.py | Uses portable editor fixtures. |
| tests/test_tui_audit.py | Replaces shell-specific editor fixture. |
| tests/test_trust.py | Escapes project keys correctly. |
| tests/test_terminal.py | Adapts permissions and file commands. |
| tests/test_terminal_theme.py | Guards POSIX-only tests. |
| tests/test_terminal_startup_cleanup.py | Isolates POSIX descriptor checks. |
| tests/test_snapshots.py | Adapts encoding and path assertions. |
| tests/test_snapshot_repositories.py | Normalizes relative paths. |
| tests/test_setup.py | Guards POSIX permission assertions. |
| tests/test_server.py | Adapts interrupts and JavaScript execution. |
| tests/test_runtime.py | Uses portable transcript-editing commands. |
| tests/test_release_workflows.py | Verifies Windows release configuration. |
| tests/test_providers.py | Measures latency from cancellation. |
| tests/test_packaging.py | Adds PowerShell installer tests. |
| tests/test_no_project.py | Uses portable workspace commands. |
| tests/test_interactive.py | Adapts signals and process checks. |
| tests/test_inputs.py | Isolates platform mocks and paths. |
| tests/test_image_recovery.py | Makes transcript edits portable. |
| tests/test_hardening.py | Tests shared locking and atomic writes. |
| tests/test_gitflow.py | Adapts Git input and terminal scripts. |
| tests/test_fullscreen.py | Accommodates ConPTY terminal modes. |
| tests/test_file_index_paths.py | Skips Windows-invalid filenames. |
| tests/test_desktop_workbench.py | Updates packaging assertions. |
| tests/test_desktop_service_ui.py | Reads launcher source as UTF-8. |
| tests/test_daemon.py | Guards POSIX permission assertions. |
| tests/test_connections.py | Guards POSIX credential modes. |
| tests/test_ci.py | Parses test sources as UTF-8. |
| tests/test_chat_images.py | Uses portable transcript edits. |
| tests/test_brand_assets.py | Validates Windows icon packaging. |
| tests/test_auth.py | Guards POSIX credential modes. |
| tests/test_anthropic_images.py | Uses portable image-transcript edits. |
| tests/repl_driver.py | Adds failed-test teardown cleanup. |
| tests/pty_driver.py | Adds ConPTY-backed test sessions. |
| tests/fakes.py | Adds portable command and process helpers. |
| tests/desktop_updates.js | Checks Windows installer selection. |
| tests/desktop_service.js | Uses platform-aware test paths. |
| tests/desktop_release_updates.js | Tests Windows release artifacts. |
| tests/desktop_recovery.js | Guards POSIX permission assertions. |
| tests/desktop_development.js | Tests Windows CLI discovery. |
| tests/conftest.py | Cleans up remaining interactive drivers. |
| src/freehand/workbench.py | Adapts parsing, paths, and native actions. |
| src/freehand/winpty.py | Implements the ConPTY backend. |
| src/freehand/web/workbench.js | Uses cross-platform path helpers. |
| src/freehand/web/panels.js | Allows Ctrl+V terminal paste. |
| src/freehand/web/md.js | Recognizes Windows path separators. |
| src/freehand/web/app.js | Adds path joining and comparison helpers. |
| src/freehand/ui.py | Adapts terminal sessions and editor launching. |
| src/freehand/tui.py | Adds Windows clipboard and editor support. |
| src/freehand/terminals.py | Integrates ConPTY terminals. |
| src/freehand/snapshots.py | Adapts locking, exclusions, and restoration. |
| src/freehand/session.py | Adapts persistence, locks, and environment context. |
| src/freehand/server.py | Adapts native actions and connection handling. |
| src/freehand/runtime/shellenv.py | Handles case-insensitive Windows environments. |
| src/freehand/runtime/providers.py | Adapts socket cancellation and workdirs. |
| src/freehand/runtime/osutil.py | Centralizes cross-platform OS primitives. |
| src/freehand/runtime/copilot.py | Adapts bridge persistence and process cleanup. |
| src/freehand/runtime/calltrace.py | Writes consistent trace line endings. |
| src/freehand/runtime/auth.py | Uses shared locking and private writes. |
| src/freehand/runtime/agent.py | Integrates Windows execution and cancellation. |
| src/freehand/mcp.py | Adapts executable resolution and daemon startup. |
| src/freehand/limits.py | Adapts tool discovery and process cleanup. |
| src/freehand/integrations/harbor.py | Normalizes container script line endings. |
| src/freehand/inputs.py | Adds Windows image paste and shell execution. |
| src/freehand/hooks.py | Runs Windows hooks through PowerShell. |
| src/freehand/daemon.py | Adapts background launch and state writes. |
| src/freehand/copilot_bridge.py | Configures UTF-8 protocol streams. |
| src/freehand/control.py | Adapts locks, cancellation, and image URLs. |
| src/freehand/cli.py | Enables native Windows CLI operation. |
| README.zh-CN.md | Documents Windows installation in Chinese. |
| README.md | Documents native Windows installation. |
| pyproject.toml | Declares Windows platform support. |
| install.ps1 | Adds the PowerShell installer. |
| desktop/updates.js | Selects Windows update installers. |
| desktop/scripts/render-icons.py | Generates multi-size Windows icons. |
| desktop/scripts/release-updates.js | Merges and publishes Windows artifacts. |
| desktop/scripts/bundle-cli.js | Adds cross-platform CLI bundling. |
| desktop/README.md | Documents Windows desktop builds. |
| desktop/package.json | Configures NSIS packaging and portable scripts. |
| desktop/main.js | Adapts Windows discovery and service launch. |
| desktop/build/icons.json | Updates icon checksums. |
| .github/workflows/desktop-release.yml | Adds Windows release packaging. |
| .github/workflows/ci.yml | Adds Windows test and installer jobs. |
| .github/scripts/npm_audit.py | Resolves npm and uses UTF-8. |
| .github/scripts/ci.py | Uses UTF-8 for CI metadata. |
Review effort: Balanced
| fail-fast: false | ||
| matrix: | ||
| os: [macos-15, macos-15-intel, ubuntu-24.04] | ||
| os: [macos-15, macos-15-intel, ubuntu-24.04, windows-latest] |
| { | ||
| "sha256": { | ||
| "src/freehand/web/favicon.svg": "d1dc05d0a29946bf085045cfd2bbff9a8d1a21503de9ae9b83263462e5611077", | ||
| "src/freehand/web/favicon.svg": "0b0c313413caec86c745bebdea3e692e4c74b9daae627f60c499f141825bd2f6", |
Comment on lines
+353
to
+354
| if _kernel32.TerminateJobObject(job, 1): | ||
| return |
| k32.GlobalFree.argtypes = [wintypes.HGLOBAL] | ||
| k32.GlobalFree.restype = wintypes.HGLOBAL | ||
| raw = text.encode("utf-16-le") + b"\x00\x00" | ||
| if not u32.OpenClipboard(None): |
| _k32.CloseHandle(in_write) | ||
| if hpc: | ||
| # ClosePseudoConsole notifies the attached console process to exit and unblocks ReadFile on out_read. | ||
| _k32.ClosePseudoConsole(hpc) |
| if not IS_WINDOWS: | ||
| return | ||
| import sys | ||
| for stream in (sys.stdout, sys.stderr): |
| return [shell, "-lc", cmd], None | ||
| script = _PS_PREFIX + cmd + _PS_SUFFIX | ||
| # Windows CreateProcess caps the command line at 32,767 chars; fall back to a temporary script for long commands. | ||
| if len(script) > 20000: |
| if len(script) > 20000: | ||
| fd, name = tempfile.mkstemp(prefix="freehand-cmd-", suffix=".ps1") | ||
| with os.fdopen(fd, "wb") as f: | ||
| f.write(script.encode("utf-8")) |
Comment on lines
+305
to
+309
| const pathSep = (p) => String(p || "").includes("\\") ? "\\" : "/"; | ||
| const joinPath = (base, ...parts) => { | ||
| const sep = pathSep(base); | ||
| const head = String(base || "").replace(/[\\/]+$/, ""); | ||
| const tail = parts.flatMap((p) => String(p || "").split(/[\\/]/).filter(Boolean)); |
Comment on lines
+173
to
+183
| term.write("Write-Output WIN_CONPTY_HELLO\r") | ||
| end = time.time() + 12 | ||
| while time.time() < end and "WIN_CONPTY_HELLO" not in term.read()["output"]: | ||
| time.sleep(0.05) | ||
| assert "WIN_CONPTY_HELLO" in term.read()["output"] | ||
| term.resize(36, 110) | ||
| term.write("Start-Sleep -Seconds 30\r") | ||
| time.sleep(0.4) | ||
| term.write("\x03") | ||
| time.sleep(0.2) | ||
| term.write("Write-Output WIN_CONPTY_AFTER_CTRLC\r") |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Linked issue
Addresses #180 ("Windows build") — adds full native Windows support for the runtime, CLI/TUI, web UI, integrated terminal, desktop Electron app, installer, CI, and offline test suite (without requiring WSL).
What changed (Before / After)
freehandon native Windows exited immediately with"Freehand does not run natively on Windows yet (it requires POSIX bash)". POSIX-only primitives (fcntl.flock,os.killpg,os.openpty,termios,bash -lc,/path assumptions,0o600permission checks) prevented the runtime, CLI/TUI, snapshots, MCP stdio/daemon servers, integrated terminals, web UI, desktop app, and test suite from working natively on Windows.win32) using native PowerShell (pwshpreferred, falling back topowershell.exe), Win32LockFileEx, Win32 Job Objects, stdlibctypesConPTY integrated terminals, native Windows clipboard/editor/Explorer integrations, a native PowerShell installer (install.ps1), Windows NSIS Electron packaging & auto-updates, andwindows-latestCI/release workflows — with zero new Python or JS dependencies and zero changes to macOS, Linux, or benchmark container behavior.Summary of changes by area
Stdlib-only Python 3.9+ Windows runtime primitives (
src/freehand/runtime/osutil.py,agent.py,providers.py,shellenv.py,auth.py,copilot.py,calltrace.py)find_shell()preferspwshand falls back topowershell.exe(never invoking WSL'sSystem32\bash.exe).prepare_shell_command()sets UTF-8 console encoding, initializes$global:LASTEXITCODE = 0, preserves native command exit codes accurately, and automatically falls back to a temporary.ps1-Filescript when commands exceed 20,000 characters (avoiding the 32 KBCreateProcesscommand-line limit). Output\r\nis normalized to\n.fcntl.flockon POSIX, Win32LockFileEx/UnlockFileExviactypes.windll.kernel32+msvcrt.get_osfhandleon Windows. On Windows, session lock files live under$FREEHAND_HOME/locks/session-<sha256>.locksosession.trash()can hold the exclusive lock acrossshutil.movewithout hittingWinError 32.create_process_job/assign_process_job/kill_process_treereplaceos.killpg/SIGKILLon Windows (JOB_OBJECT_LIMIT_BREAKAWAY_OK, intentionally withoutKILL_ON_JOB_CLOSEso detached background jobs outlive normal exit whileTerminateJobObjectkills the entire tree on timeout/cancel/interrupt).replace_fileretries transient WindowsPermissionError(WinError 5/32), andatomic_write_bytes/atomic_write_textuse unique per-call temp filenames with guaranteed cleanup.sock.shutdown(SHUT_RDWR)alone does not wake a thread blocked inrecv(), andsock.close()defers whilehttp.client'smakefile()holds_io_refs._abort_socket()andAgent.cancel()invoke_real_close()on Windows so stopping a turn during TTFT or mid-stream aborts immediately."bash"on all platforms for full transcript, journal, provider, Copilot bridge, hook, and UI compatibility. Updated_tool_specs(),session.environment(), andsession.own_command()exclusively underwin32to accurately describe PowerShell; macOS, Linux, and Linux benchmark containers are byte-for-byte unchanged.CLI, TUI, Server, Snapshots, Workbench, Hooks, Daemon, MCP & Limits (
src/freehand/cli.py,session.py,control.py,server.py,workbench.py,snapshots.py,inputs.py,tui.py,ui.py,daemon.py,hooks.py,mcp.py,limits.py,copilot_bridge.py,integrations/harbor.py)win32hard block incli.main(), enabled UTF-8 console stdio +ENABLE_VIRTUAL_TERMINAL_PROCESSING, addedSIGBREAKgraceful shutdown tofreehand web, and updatedfreehand doctorfor PowerShell, Windows user ACLs, and native clipboard reporting.CF_UNICODETEXTclipboard copy (tui.py), PowerShellSystem.Windows.Forms.Clipboardimage paste (inputs.py),os.startfile/explorer.exe /select,<path>(handling Explorer's exit code 1) (server.py,workbench.py), and.cmd/.exeresolution viaosutil.resolve_executable(mcp.py,limits.py,server.py,workbench.py,tui.py).prompt_toolkitNoConsoleScreenBufferErrorunder redirected/dummy outputs on Windows by wrappingInteractive.run()increate_app_session(input=..., output=...), and ensuredclear_input()callsload_history_if_not_yet_loaded()so↑immediately restores cleared drafts.ProjectHistoryCRLF handling, Windows backslash-escaped space image paths (\),Controller.shell()[stopped]detection on Job Object termination,workbench.parse_mcpWindows quote/backslash tokenization,ConnectionAbortedError(WinError 10053) handling inserver.py, andsnapshots.pyexcludingFREEHAND_HOME/git_dirwhen working in an ancestor directory.Win32 ConPTY Integrated Terminal (
src/freehand/winpty.py,src/freehand/terminals.py)ctypeswrapper (ConPtyProcess) aroundCreatePseudoConsole,ResizePseudoConsole, andClosePseudoConsole(withSTARTF_USESTDHANDLESisolation so redirected parent pipes do not hijack child stdio, plus Job Object cleanup). Nopywinptyor native binary wheel dependency required.Web UI Windows Path & Paste Support (
src/freehand/web/app.js,workbench.js,md.js,panels.js)pathSep,joinPath,normPath,pathInside), updatedshort,baseName,langOf, skills filtering, folder breadcrumbs, changed-files filtering, and allowedCtrl+Vpaste in the integrated terminal.Desktop Electron App, Installer, Packaging & CI (
install.ps1,pyproject.toml,desktop/main.js,desktop/package.json,desktop/updates.js,desktop/scripts/release-updates.js,desktop/scripts/bundle-cli.js,desktop/scripts/render-icons.py,desktop/build/icon.ico,desktop/build/icons.json,.github/workflows/ci.yml,.github/workflows/desktop-release.yml,.github/scripts/ci.py,.github/scripts/npm_audit.py,README.md,README.zh-CN.md,desktop/README.md)install.ps1mirroringinstall.sh(installsuvif needed, installs Freehand viauv tool install --upgrade --python 3.12, respectsFREEHAND_INSTALL_SPEC).x64NSIS desktop target (Freehand-Setup-${version}.exe), multi-sizedesktop/build/icon.ico, cross-platform PyInstaller bundler (desktop/scripts/bundle-cli.jswith--hidden-import freehand.winpty),freehand.exe/freehand.cmddiscovery +windowsHideindesktop/main.js, andwin32/x64release manifest & updater support.windows-latestto CI (core,browser,install-script) anddesktop-release.yml(package).Cross-platform Test Suite & Dedicated Windows Coverage (
tests/test_windows_support.py,tests/fakes.py,tests/pty_driver.py,tests/repl_driver.py,tests/conftest.py,tests/test_web_e2e.py, and targeted cross-platform test updates)tests/test_windows_support.pycoveringosutillocks, Job Object tree termination, PowerShell exit codes and >20 KB command fallback, ConPTY interactive I/O/resize/Ctrl-C, web JS Windows path helpers, andinstall.ps1verification intests/test_packaging.py.CDPPageChrome deadlock (4 KB anonymousstderrpipe filling under Chrome's verbose logs) by logging Chrome stderr to a file insideuser_dir, pinneden-USlocale inCDPPagefor deterministic number formatting across non-English developer machines, and addedDriver.close()teardown cleanup so failed tests never leaveWin32PipeInputexecutor threads blocking pytest exit.Visual proof (UI / TUI / Web / Desktop / export changes)
Native Windows
freehand doctoroutput (Windows 11, Python 3.12.13, PowerShell 7):Real browser UI, integrated ConPTY terminal, file preview matrix (HTML, Markdown, PNG, PDF, CSV/TSV, code, downloads, right-click menus), and fullscreen TUI were all exercised directly on native Windows via the offline browser and PTY test suites (440/440 browser tests + 4/4 ConPTY fullscreen tests passing).
How you verified it
All checks were run natively on Windows (
win32, Python 3.12.13 viauv, Python 3.9 viauv, Node.js v24.19.0, Google Chrome 158):uv run --no-sync pyflakes src tests .github/scripts→ prints nothing (0 warnings).uv run --no-project --python 3.9 python -I -c "import sys; sys.path.insert(0, 'src/freehand/runtime'); import agent, providers, auth, shellenv, wsclient, calltrace, osutil, copilot"→ passed.node --checkon every.jsfile insrc/freehand/web/,desktop/, anddesktop/scripts/→ passed.--suite=core, 3 parallel shards):test_esc_esc_clears_the_input_and_up_brings_it_backverified 3/3 after addingload_history_if_not_yet_loaded()toclear_input())--suite=browser --require-browser, 3 shards on real Chrome 158):test_web_file_review.py2/2 in 13.52s)desktop/):python ../.github/scripts/npm_audit.py→ clean (no unreviewed advisories)npm run test:build-deps→ passednpm run test:updates→ 22 + 19 tests passed, 0 failednode ../tests/desktop_development.js(POSIX + WindowsfindFreehand),desktop_recovery.js,desktop_service.js→ all passedmicrosoft/FreeHand:main(7660526, v0.1.3): re-ranpyflakes, Python 3.9 stdlib check,test_windows_support.py,test_packaging.py,test_release_workflows.py,test_brand_assets.py,test_tui_details.py(54 passed), and all desktop tests (41+ passed).AI disclosure & checklist
uv run pyflakes src tests .github/scriptsprints nothing and relevant tests pass locally (full cross-OS suite runs in CI)CHANGELOG.mduntouched (maintainers update it at release time)prompt.md, tool descriptions, status line, harness notes are byte-for-byte unchanged on POSIX); on native Windows only (sys.platform == "win32"), the tool description and environment block accurately describe PowerShell while keeping the tool name"bash"src/freehand/runtime/still uses only the standard library and imports on Python 3.9