Skip to content

feat(desktop,computer,agent): bundle PortableGit and enable dual bash+powershell on Windows Pi - #1182

Open
LeoXing1996 wants to merge 1 commit into
mainfrom
leo/win-git-bash-dual-shell
Open

LeoXing1996 wants to merge 1 commit into
mainfrom
leo/win-git-bash-dual-shell

Conversation

@LeoXing1996

@LeoXing1996 LeoXing1996 commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Bundles PortableGit 2.56.0.4 into Windows Desktop releases and enables negotiated dual bash + powershell tools for Windows Pi, backed by full 31-task Windows ablation results (11/31 pass, 8.04 avg score vs 6/31 pass, 6.05 avg score on PowerShell-only, 0 run_aborted, 0 exam_broke).

Key Changes

  • Windows Desktop PortableGit bundling & smoke checks:
    • apps/desktop/packaging/win/package.py: downloads, SHA-256-verifies, unpacks, and trims PortableGit 2.56.0.4 into resources/runtime/git-bash/bin/bash.exe alongside PowerShell 7.6.10, deduplicating cached-download and zip-entry verification helpers.
    • apps/desktop/scripts/teamhub.sh: dispatches MINGW/Git Bash invocations directly to teamhub.exe.
    • scripts/ci/windows-pi-smoke.mjs & scripts/ci/desktop-smoke-helpers.mjs: probe bundled bash.exe and pass LINGER_PI_GIT_BASH_PATH with dual-shell --tools.
  • Non-WSL Git Bash resolution & env hardening:
    • apps/computer/local-daemon/internal/linger/localtools/installation.go: resolves non-WSL Git Bash (bundled PortableGit -> Program Files\Git\bin\bash.exe -> non-WSL bash.exe on PATH), rejecting System32\bash.exe, SysWOW64\bash.exe, and WindowsApps\bash.exe.
    • apps/computer/local-daemon/cmd/linger-computer-daemon/main.go & apps/computer/tools/pi-mcp.mjs: passes resolved Git Bash explicitly via LINGER_PI_GIT_BASH_PATH (consumed and deleted on load) to registerWindowsBashTool as shellPath, and enforces MSYS_NO_PATHCONV=1, MSYS2_ARG_CONV_EXCL=*, LANG=C.UTF-8, and LC_ALL=C.UTF-8 case-insensitively with precedence over inherited env vars.
  • Backward-compatible Runner Gateway negotiation & fallback:
    • contracts/runner-gateway/envelope.schema.json (plus regenerated Go/TS contracts): keeps runner.hello.capabilities restricted to the closed legacy enum ["browser_connection", "computer_permissions"], adds windows_git_bash to runner.welcome.service_features, and adds optional windows_git_bash to post-welcome runner.runtime_diagnostics.
    • Daemon enables dual bash + powershell tools, dual-shell guides, and reports windows_git_bash: true on post-welcome runner.runtime_diagnostics only when both a non-WSL Git Bash binary is present and runner.welcome.service_features advertises windows_git_bash; bash-less hosts and connections to older Agent Services stay on PowerShell-only without 1002 protocol errors.
    • Agent Service serves "posix" dialect for Windows Pi (both preflight and /static-prefixes/v1) only after the Computer reports windows_git_bash: true, keeping "windows-pi" for bash-less hosts and older Daemons.
  • Shell guard & permission hardening:
    • apps/computer/local-daemon/internal/permission/shell_text_powershell.go: blocks corrupted numeric/escaped $ across double quotes, here-strings, bare words, and multi-line PowerShell pipes (| / |& + newline).
    • apps/computer/local-daemon/internal/permission/shell.go: normalizes MSYS /c/... drive paths inside shellPaths.cd() so workspace symlink/junction escape checks remain accurate on Windows.

Boundary

  • Runner Gateway wire contract: Added windows_git_bash to ServiceFeature and optional windows_git_bash boolean to RunnerRuntimeDiagnostics in contracts/runner-gateway/envelope.schema.json, regenerated via pnpm contracts:generate && pnpm contracts:verify, and documented in contracts/README.md. No OpenAPI contract changes.
  • Documentation: Updated docs/desktop-release.md, apps/computer/local-daemon/README.md, apps/desktop/AGENTS.md, contracts/README.md, and scripts/env-inventory.json.
  • User message -> provider_ready critical path: No additional network round trips or file walks; Git Bash path resolution runs once at Daemon startup.

Verification

  • pnpm contracts:generate && pnpm contracts:verify
  • GOOS=windows GOARCH=amd64 go build ./..., go vet ./..., gofmt, and Go unit tests across permission, localtools, context, daemon, cmd/linger-computer-daemon, and provider/native
  • pnpm --filter @linger/node-services run typecheck and 241/241 Vitest tests (context-instructions, static-prefixes, local-backend, runner-connections-public, context-view-content)
  • pnpm --filter @linger/computer run typecheck and Windows bash shellPath / LINGER_PI_GIT_BASH_PATH / applyWindowsBashEnv tests
  • python3 -m unittest discover -s apps/desktop/packaging -p 'win_*_test.py' (7/7) and scripts/ci/windows-pi-smoke.test.ts (9/9)
  • pnpm env:inventory:check, ESLint, Prettier, and lint-staged

@linger-review linger-review Bot 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.

Request changes (3 P1, 4 P2) · merge base 5985e03 · 3 commits, 26 files

Findings

P1

  1. apps/computer/tools/pi-mcp.mjs:2687 (and apps/computer/local-daemon/cmd/linger-computer-daemon/main.go:1254-1294) — WSL System32\bash.exe hijacks Pi's bash tool ahead of bundled PortableGit
    withBundledGitBashPath appends resources\runtime\git-bash\bin to the end of Windows PATH (after C:\Windows\System32), while managedExtension calls registerWindowsBashTool(pi) without passing shellPath. In @earendil-works/pi-coding-agent (dist/utils/shell.js:76-110), getShellConfig(undefined) on win32 checks %ProgramFiles%\Git\bin\bash.exe / %ProgramFiles(x86)%\Git\bin\bash.exe and then takes the first line of where bash.exe. On any Windows machine without Git for Windows in Program Files where WSL is enabled (so C:\Windows\System32\bash.exe exists, which Pi's own isLegacyWslBashPath handles), where bash.exe picks C:\Windows\System32\bash.exe before the bundled PortableGit. If WSL has no distro installed, every bash call fails immediately; if a WSL distro is installed, bash runs in Linux WSL where WINDOWS_BASH_PREFIX hijacks teamhub to teamhub.exe (bypassing teamhub.sh's wslpath -w conversion), WINDOWS_BASH_ENV is not forwarded via WSLENV, and C:/Users/... paths from piWindowsDualShellGuide fail. Pass the resolved GitBashPath from the Daemon into pi-mcp.mjs (via a consumed-on-load env var like LINGER_PI_SHELL_TEXT_HOOK) and pass it as shellPath in registerWindowsBashTool whenever a native Git for Windows binary is absent (or unconditionally prefer the bundled PortableGit).

  2. apps/computer/local-daemon/internal/provider/native/pi_runtime.go:18 (and apps/computer/local-daemon/internal/linger/context/resolver.go:129,155, apps/node-services/src/agent/prompt/environment-knowledge.ts:25) — Unconditional Windows bash enablement and "posix" dialect break bash-less hosts and older Daemons

    • Daemon side: On goos == "windows", piBaseToolsFor unconditionally enables read,bash,powershell,... and resolver.go unconditionally injects windowsBashHostEnvironmentGuide and piWindowsDualShellGuide ("Default to bash for teamhub..."), even when toolInstallation.GitBashPath == "". This breaks Windows Desktop installations receiving a V2 backend update on an older Shell without resources/runtime/git-bash/ (apps/desktop/src/main/index.ts:701-739, minShellVersion: "0.2.0" in apps/desktop/scripts/build-app-bundles.mjs:486) and standalone Windows CLI Computers (scripts/prepare-local-computer-release.mjs), which do not bundle PortableGit: on hosts without Git for Windows, every bash call throws No bash shell found (dist/utils/shell.js:105-109).
    • Agent Service side: shellDialectFromPlatform("win32"|"windows", "pi") unconditionally returns "posix" in both local-backend.ts:242 and runner-gateway.ts:260 with no Daemon version or capability gate. When a newer Agent Service talks to an older Windows Daemon (whose Pi only exposes powershell and appends piWindowsPowerShellGuide / WindowsHostEnvironmentGuide), the static prefix tells the model to use <<'EOF' and find -L, contradicting the Daemon's guides and tripping shell-text-hook. Meanwhile the "windows-pi" dialect is now unreachable from production code.
    • Fix: On the Daemon, enable bash and dual-shell guides on Windows only when a usable Git Bash is present (bundled GitBashPath, %ProgramFiles%\Git\bin\bash.exe, or non-WSL bash.exe on PATH), falling back to PowerShell-only otherwise. On Agent Service, gate "posix" for Windows Pi on a Computer version/capability check and keep "windows-pi" for older Daemons.
  3. apps/computer/local-daemon/internal/permission/shell.go:401-414 — shellPaths.cd() skips normalizeMSYSDrivePath, allowing workspace symlink/junction escape on Windows
    shellPaths.inside() normalizes /c/... to C:\... before checking filepath.IsAbs and withinWorkspace, so p.inside(words[1]) at shell.go:403 returns true for cd /c/Users/alice/work/sub. However, shell.go:407-411 then passes the raw words[1] to filepath.IsAbs(words[1]) (which is false on Windows for /c/...), appending C:\Users\alice\work\c\Users\alice\work\sub instead of C:\Users\alice\work\sub to p.places. If C:\Users\alice\work\sub\link is a symlink or directory junction pointing outside the workspace, cd /c/Users/alice/work/sub && cat <<'EOF' > link/evil.txt && teamhub message list evaluates withinWorkspace only against nonexistent ...\link\evil.txt and ...\c\Users\alice\work\sub\link\evil.txt without ever inspecting sub\link on disk, returning ShellAllow and writing outside the workspace without review. Normalize target := normalizeMSYSDrivePath(words[1], p.workspace) inside cd() and use target in lines 407-411, with a regression test in shell_test.go.

P2

  1. apps/computer/local-daemon/internal/permission/shell_text_powershell.go:374-386 — Multi-line PowerShell pipe (|\n) splits pipelineID and misses corrupted $
    In PowerShell, | followed by a newline continues the same pipeline (e.g., @"\nARR is $6.4M\n"@ |\nteamhub message send --file -). At line 383 | calls flushSegment(false) keeping pipelineID == 0, but the immediately following \n hits line 374 (flushSegment(true)) and increments pipelineID to 1, so teamHubPipelines[0] is false and PowerShellTextProblem allows the corrupted $6.4M through. Track an afterPipe flag across whitespace after | / |&, call flushSegment(!afterPipe) on \n, and add a test case in shell_text_powershell_test.go.

  2. apps/computer/tools/pi-mcp.mjs:119-122 (and apps/computer/local-daemon/cmd/linger-computer-daemon/main.go:1259-1264) — Inherited host env vars override WINDOWS_BASH_ENV
    spawnHook spreads ...WINDOWS_BASH_ENV before ...context.env (populated from process.env in dist/core/tools/bash.js:160), so inherited values such as MSYS_NO_PATHCONV=0, MSYS2_ARG_CONV_EXCL="", LC_ALL=C, or a non-UTF-8 LANG override the guard (contradicting the PR description's claim that pi-mcp.mjs enforces them, and leaving computer-tools.test.ts:340 dependent on host process.env.LANG containing UTF-8). In main.go:1259-1264, checking updated["MSYS_NO_PATHCONV"] is also case-sensitive on Windows, unlike withBundledWindowsRuntimeDir. Strip case-insensitive duplicates and spread ...WINDOWS_BASH_ENV after ...context.env in pi-mcp.mjs, and use case-insensitive lookup/set in withBundledGitBashPath.

  3. apps/desktop/packaging/win/package.py:100-109, 172-197 — Duplicated archive download and zip-entry verification helpers
    verify_git_bash_archive (lines 100-109) and git_bash_archive (lines 172-197) are verbatim copies of verify_pwsh_archive (lines 88-97) and pwsh_zip (lines 134-159). Extract shared _verify_archive_entry(archive, entry) and _cached_verified_archive(...) helpers and call them from both pwsh and git-bash paths.

  4. scripts/ci/desktop-smoke-helpers.mjs:147-154 (and scripts/ci/windows-pi-smoke.mjs:112-137, docs/desktop-release.md:525-530, apps/computer/benchmarks/real-app-eval/lib/product_chain.mjs:258) — Smoke checks, release docs, and eval dialect left on PowerShell-only Windows Pi
    piToolsForPlatform (explicitly commented as matching piWindowsBaseTools) still returns "read,powershell,edit,write,grep,find,ls,mcp__*" on win32, windows-pi-smoke.mjs verifies pwsh.exe without checking resources/runtime/git-bash/bin/bash.exe, docs/desktop-release.md documents pwsh/PWSH_MIRROR without PortableGit/GIT_BASH_MIRROR, and product_chain.mjs still hardcodes "windows-pi". Update all four to stay aligned with dual-shell Windows Pi.

Checked: Pi tool review routing (apps/computer/local-daemon/internal/provider/native/pi_review.go:153) · Pi command activity classification (apps/computer/local-daemon/internal/provider/activity_status.go:42) · Desktop teamhub.sh/exe staging (apps/desktop/scripts/build-steps.mjs:282)

Unverified: live Windows execution of PortableGit packaging, teamhub.sh MINGW dispatch, and dual-shell Pi runs

Process: needs rebase onto main (1 commit behind)

CI: 9 checks passed; CI does not run computer TS or node-services tests


Automated review of f817332 by Antigravity.

@LeoXing1996
LeoXing1996 force-pushed the leo/win-git-bash-dual-shell branch from f817332 to 5d58da3 Compare December 5, 2026 07:46

@linger-review linger-review Bot 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.

Request changes (1 P0, 2 P2) · follow-up on f817332 · merge base 4c095c0 · 4 commits, 52 files

Resolved: WSL bash hijacking (installation.go:244, pi-mcp.mjs:19) · bash-less & older-Daemon fallback (pi_runtime.go:27, environment-knowledge.ts:22) · MSYS cd symlink escape (shell.go:406) · multi-line PowerShell pipe (shell_text_powershell.go:377) · WINDOWS_BASH_ENV precedence (pi-mcp.mjs:92, main.go:1264) · package.py helper duplication (package.py:88,132) · Windows smoke/docs/eval sync (windows-pi-smoke.mjs:98, docs/desktop-release.md:526)

Findings

P0

  1. apps/computer/local-daemon/internal/daemon/connection.go:650 (and contracts/runner-gateway/envelope.schema.json:266) — Adding windows_git_bash to runner.hello.capabilities breaks older Agent Services with a 1002 protocol disconnect
    buildHello() (connection.go:125) sends d.capabilities() in runner.hello before runner.welcome reveals service_features, and capabilities() (connection.go:649-651) now unconditionally appends "windows_git_bash" on every Windows Computer with bundled PortableGit or installed Git for Windows. However, every already-deployed Agent Service validates runner.hello strictly through parseDaemonToAgentEnvelope (apps/node-services/src/agent/runner-gateway/runner-gateway-websocket.ts:854) against the closed Ajv enum RunnerCapability: ["browser_connection", "computer_permissions"] (envelope.schema.json:264-267,5362-5368). During rolling deploys, self-hosted mixed-version runs, or whenever a Windows Desktop upgrade replaces the Daemon ahead of local installed services (the scenario apps/computer/AGENTS.md:286-289 and connection.go:109-112 explicitly guard against), the older Agent Service rejects runner.hello with InvalidRunnerFrameError and closes the WebSocket with 1002 (Runner protocol violation, runner-gateway-websocket.ts:422,689-695), trapping the Windows Computer in an offline reconnect loop. Keep runner.hello.capabilities restricted to ["browser_connection", "computer_permissions"], negotiate support via a new runner.welcome service_features entry (e.g. windows_git_bash, ignored by older Daemons per runner-connections.ts:550-551), report the host's Git Bash availability post-welcome only when advertised (mirroring dynamic_reasoning_efforts in connection.go:780-819), and keep Daemon dual-shell tools and guides on PowerShell-only when connected to an older Agent Service that does not advertise it.

P2

  1. apps/computer/tests/computer-tools.test.ts:329-340 — Windows bash test short-circuits shellPath and never tests LINGER_PI_GIT_BASH_PATH consumption
    Passing custom operations to registerWindowsBashTool causes createShellToolDefinition (@earendil-works/pi-coding-agent/dist/core/tools/bash.js:183) to skip createLocalBashOperations({ shellPath: options?.shellPath }), so dropping shellPath would still pass. Likewise, module-load consumption and deletion of process.env.LINGER_PI_GIT_BASH_PATH (apps/computer/tools/pi-mcp.mjs:19-20,123) has no test coverage. Add assertions using a stub createToolDefinition to verify shellPath forwarding, plus a child-process import with LINGER_PI_GIT_BASH_PATH set verifying both default shellPath wiring and process.env.LINGER_PI_GIT_BASH_PATH === undefined after load.

  2. apps/computer/local-daemon/README.md:722-725 (and contracts/README.md, PR description) — Stale Windows Pi docs and outdated PR summary
    apps/computer/local-daemon/README.md:722-725 (immediately above the edited lines) still states that Windows Pi uses powershell instead of bash and skips pipefail, which is now inaccurate whenever Git Bash is available; contracts/README.md does not document the new Runner Gateway wire gate; and the PR description still claims "No cross-process OpenAPI contract changes" and describes unconditional dual-shell enablement from commits 1-3 without commit 4's capability gating and fallback. Update the README paragraph, document the negotiated wire gate in contracts/README.md, and refresh the PR body.

Checked: Pi bash shellPath precedence (@earendil-works/pi-coding-agent/dist/utils/shell.js:78) · Gateway passthrough to preflight (apps/node-services/src/agent/executor/application.ts:631) · Permission review bash/PowerShell routing (apps/computer/local-daemon/internal/permission/reviewer.go:178)

Unverified: live Windows execution of PortableGit packaging, teamhub.sh MINGW dispatch, and dual-shell Pi runs

Process: squash review-fixup commit 5d58da3 into the earlier commits it patches before rebase-merge

CI: 17 checks passed; CI skips computer TS and node-services tests


Automated review of 5d58da3 by Antigravity.

…+PowerShell on Windows Pi

- Bundle SHA-256-verified PortableGit 2.56.0.4 into Windows Desktop packages (resources/runtime/git-bash/bin/bash.exe), prune GUI/docs, and add Git Bash smoke probes and release documentation.
- Resolve non-WSL Git Bash in the Windows Local Computer Daemon (bundled PortableGit -> Program Files Git -> non-WSL PATH), pass LINGER_PI_GIT_BASH_PATH (consumed at load) into pi-mcp.mjs as shellPath, enforce MSYS_NO_PATHCONV=1 / MSYS2_ARG_CONV_EXCL=* / UTF-8 locale case-insensitively, and route teamhub to teamhub.exe in MINGW/Git Bash.
- Negotiate dual-shell Windows Pi support via runner.welcome service_features (windows_git_bash) and post-welcome runner.runtime_diagnostics.windows_git_bash, keeping runner.hello.capabilities backward-compatible with older Agent Services and falling back to PowerShell-only on bash-less hosts or older Agent Services.
- Harden PowerShell shell-text-hook against numeric/escaped dollar expansion across double quotes, here-strings, bare words, and multi-line pipes, and normalize MSYS drive paths in shellPaths.cd to preserve workspace symlink/junction checks.
@LeoXing1996
LeoXing1996 force-pushed the leo/win-git-bash-dual-shell branch from 5d58da3 to 446d0b3 Compare December 5, 2026 15:20

@linger-review linger-review Bot 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.

Request changes (1 P0, 1 P1) · follow-up on 5d58da3 · merge base 9ef0028 · 1 commit, 59 files

Resolved: runner.hello capability disconnect (apps/computer/local-daemon/internal/daemon/connection.go:425,652) · Windows bash shellPath test (apps/computer/tests/computer-tools.test.ts:342-398) · stale docs and PR body (apps/computer/local-daemon/README.md:733, contracts/README.md:126)

Findings

P0

  1. apps/computer/local-daemon/internal/linger/transport/gateway_test.go:411 — TestGatewayStreamEncodesRuntimeDiagnosticsRevision deadlocks on the second frame, failing CI
    The httptest.NewServer WebSocket handler (gateway_test.go:372-375) calls socket.ReadJSON(&envelope) only once and then returns, closing the server socket. The newly added second stream.Send(...) with WindowsGitBash: true (gateway_test.go:404-410) is therefore never read, and withBash := <-received (gateway_test.go:411) blocks permanently until Go's 10-minute test timeout panics (CI/check (computer-go) failed deterministically at line 411). Read frames in a loop inside the test server handler until socket.ReadJSON returns an error (with received buffered to 2) so both diagnostic envelopes are received.

P1

  1. apps/node-services/src/agent/runner-gateway/runner-connections.ts:350,454,691 (and apps/computer/local-daemon/internal/daemon/connection.go:392,435,441, apps/computer/local-daemon/internal/daemon/prefix_warmup.go:88,111) — Post-welcome windows_git_bash reporting races with Context activation and PolyStrata prefix warm-up
    • Context activation / reconnect race: #replaceConnection (runner-connections.ts:454) resets connection.windowsGitBash = false. On steady-state reconnects or Agent Service restarts where hello.agent_runners already match placements, agentRunnerReconciliation.start (agent-runner-reconciliation.ts:53-54) synchronously invokes completeOperationReconciliation (runner-operations.ts:541-542), firing notifyLocalComputerReady inside #acceptConnectionInternal before the Daemon receives runner.welcome or sends post-welcome runner.runtime_diagnostics. Woken restart-restore (restart-restore.ts:110) and awaitLocalComputerReconnect (local-backend.ts:228) callers immediately run preflight() with localComputerHasWindowsGitBash() === false, rendering "windows-pi" (PowerShell-only) developer instructions while the Daemon already has WindowsGitBashActive() == true and appends piWindowsDualShellGuide + --tools read,bash,powershell,.... Because ActivatedContextRuntime.prepareNextRun() (activation.ts:933-948) only checks instructionTier and never shellDialect, the Context stays stuck with conflicting prompts until recycled.
    • PolyStrata prefix warm-up race: acceptRunnerWelcome publishes d.contentURL (connection.go:392) before storing d.windowsGitBashFeature (connection.go:425) and before activateStreamAndReplay sends runner.runtime_diagnostics (connection.go:435), then immediately starts bootstrapLocalCapabilities (connection.go:441). PrefixWarmupRunner.Warmup() (prefix_warmup.go:88) fetches /static-prefixes/v1 over a separate HTTP connection that races WebSocket delivery and async #checkCredential() (runner-gateway-websocket.ts:486). If HTTP wins, Agent Service returns "windows-pi" while prefix_warmup.go:111-115 stitches on piWindowsDualShellGuide and dual-shell tools, pinning a mismatched prefix in PolyStrata RAM and recording prefixWarmed (localmodels/prefix_warmup.go:139) so it never re-warms until model reload.
    • Fix: Store d.contentURL only after storing service_features and sending post-welcome diagnostics in connection.go, and have PrefixWarmupRunner pass the negotiated flag (for example ?windows_git_bash=1) on /static-prefixes/v1 (falling back to connection state when absent) so warm-up never races the WebSocket. In ActivatedContextRuntime.prepareNextRun() (activation.ts:933-948), re-check shellDialect alongside instructionTier so any Context activated during handshake recycles on the next Run, and preserve previous?.windowsGitBash across reconnects (or gate win32 readiness on post-welcome diagnostics behind a bumped daemon_version) so the first post-restart Run also receives the matching dialect.

Checked: Pi --tools filtering (@earendil-works/pi-coding-agent/dist/core/agent-session.js:2979) · Pi resident shape args (apps/computer/local-daemon/internal/provider/native/pi_resident.go:109) · Go service_features decoding (contracts/generated/go/runnergateway/wire.gen.go:2821)

Unverified: live Windows PortableGit packaging, teamhub.sh MINGW dispatch, and Go -race daemon tests

CI: check (computer-go) failed (transport timeout); 16 passed; CI skips computer TS and node-services


Automated review of 446d0b3 by Antigravity.

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