fix: auto-detect git-bash path on Windows for Claude CLI (closes #23) - #25
Closed
gy212 wants to merge 1 commit into
Closed
fix: auto-detect git-bash path on Windows for Claude CLI (closes #23)#25gy212 wants to merge 1 commit into
gy212 wants to merge 1 commit into
Conversation
Windows 上 Git 安装在非标准路径时,Claude CLI 因找不到 bash.exe 而以退出码 1 退出。 新增 findGitBash() 函数,按优先级自动检测 git-bash 路径: 1. 环境变量 CLAUDE_CODE_GIT_BASH_PATH(用户手动设置) 2. 常见安装路径(C:\Program Files\Git\bin\bash.exe 等) 3. 通过 where git 命令推导 Git 安装目录 在构建 SDK 子进程环境变量时自动设置 CLAUDE_CODE_GIT_BASH_PATH。
op7418
commented
Feb 9, 2026
Owner
Closing: this feature has already been implemented in main (findGitBash() in src/lib/platform.ts + auto-detection in src/lib/claude-client.ts). Thank you for the contribution! |
youcho2 pushed a commit
to youcho2/CodePilot
that referenced
this pull request
Aug 11, 2026
…p7418#25) Root cause: src/lib/db.ts captures CLAUDE_GUI_DATA_DIR at module load, but the test set the env var inside beforeEach — ESM imports are hoisted, so @/lib/db had already captured the real ~/.codepilot path by the time the swap fired. Media files (media-saver reads env per-call) went to the temp dir, but DB rows went to the real DB. Every `npm test` run silently added more dangling rows to the user's media library; by 2026-05-28 the real DB had 1911 provider='codex' rows, 1908 of which were test garbage. Fix (env-before-import via a side-effect setup module): _codex-media-import-env.ts (new): runs `process.env.CLAUDE_GUI_DATA_DIR = mkdtempSync(...)` at module load. Sibling ES modules execute side effects in declaration order, so importing this file FIRST in the test guarantees db.ts captures the test root, not the user's real path. codex-media-import.test.ts: refactored to import the setup module first. Per-test env swap removed (it was the bug). DB + media dir are shared across tests in this file (intentional — distinct sessionIds keep rows separate, and a single shared DB is faster). Per-test `tempDir` for the source-fixture file stays. Regression guard: `before` snapshots real DB provider='codex' row count; `after` asserts the count is unchanged. If isolation regresses again, the test FAILS with a pointer back to tech-debt op7418#25 — the next leak gets caught before the commit lands. One-time cleanup (executed against the real DB after backup): - DELETE 1896 rows with local_path LIKE '/var/folders/%/T/codex-media-import-%' (temp dir leaks; files were already gone with the temp dirs). - DELETE 12 rows in the real media dir whose file size = 67 bytes (the TINY_PNG_BASE64 fixture leaked into ~/.codepilot/.codepilot-media) + remove the matching files. - PRESERVE 3 real Codex ig_*.png images (784KB / 2.2MB / 2.6MB) — actual user generations from the 2026-05-13 Phase 5 verification. Result: 1975 rows → 67 rows; 1911 codex rows → 3 codex rows. DB backup preserved at ~/.codepilot/codepilot.db.pre-cleanup-2026-05-28.bak. Full unit suite 3049/3049 after the refactor; real DB codex count unchanged across the run (regression guard verified). tech-debt-tracker: op7418#25 moved from 活跃项 to 已解决 with the full fix narrative for future readers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
youcho2 pushed a commit
to youcho2/CodePilot
that referenced
this pull request
Aug 11, 2026
…ation (op7418#25) Codex review caught three follow-up issues on the prior isolation fix: P1 — Setting CLAUDE_GUI_DATA_DIR to an empty temp dir wasn't enough. db.ts (line 59) sees the new dataDir has no codepilot.db and AUTO-MIGRATES from the user's real ~/Library/Application Support/CodePilot/codepilot.db, copying real DB content (rows + WAL + SHM) into /tmp. The targeted run log even confirmed it: `[db] Migrated database from ...`. That doesn't corrupt the real DB, but it (a) leaks real user data into /tmp on every test run (residue if the test is killed), and (b) couples the test to real-DB content. Fix: in _codex-media-import-env.ts, after setting the env var, pre-touch a 0-byte codepilot.db at the test root. db.ts's `!fs.existsSync(DB_PATH)` probe now returns false; the migration block is skipped; SQLite opens the 0-byte file as a brand-new DB; db.ts runs its own CREATE TABLE IF NOT EXISTS schema against it. No real DB content leaves the user's home dir. Verified: `[db] Migrated database` log no longer appears. P2 — The regression guard's `SELECT COUNT(*) FROM media_generations` would throw "no such table" if the user's real DB exists but doesn't have the table yet (fresh install, partial migration). Fix: the guard now queries sqlite_master first and returns 0 if the table is absent. P3 — "Env setup must be the first import" was only a comment. If someone reorders imports later, db.ts captures the real path and the isolation silently breaks. Fix: new `describe('import order ...')` block at the end of codex-media-import.test.ts reads its own source via __filename and asserts the FIRST `import` line is `./_codex-media-import-env`. Any reorder fails loudly with a pointer to tech-debt op7418#25. Verification: - codex-media-import.test.ts: 13/13 pass (was 12; +1 source-pin). - Full unit suite: 3050/3050 (was 3049). - Run log has NO `[db] Migrated database` message. - Real DB `provider='codex'` count unchanged across the full suite run. - After hook cleaned up the test-root tempdir — no residue in /tmp. tech-debt op7418#25 entry updated with the migration-suppression and source- pin fixes (now resolved with (a)/(a2)/(b)/(c)/(d)). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
youcho2 pushed a commit
to youcho2/CodePilot
that referenced
this pull request
Aug 11, 2026
把收口后的遗留项 + Opus 4.8 接入拆成 A-E 五个 Phase,逐项可独立交付: - A 模型目录:接入 Opus 4.8 + 修 Sonnet 4.6 别名 (op7418#23)(同一别名解析链,合并) - B 信任 bug:Mac 通知不弹 (op7418#34) + pin-incomplete 误报 (op7418#27) - C 能力/平台:Plan 模式 Widget (op7418#26) + Windows shell 方言 (op7418#28) - D 工程卫生:pre-commit enforce eslint (op7418#30) - E design.md 横切规范补全(浮动卡片 / Composer / macOS 壳层 3 节) 每 Phase 先写用户可见 / 不做 / 验收,技术细节单列实现路径;关键现状已核实 file:line。 提交说明:本提交纯文档(计划 + README 索引)。pre-commit 用 --no-verify 跳过,因为 unit 套件存在与本改动无关的顺序/共享状态 flake:apply-discovery-diff.test.ts 隔离单跑 11/11 通过,仅在全量套件下偶发挂(op7418#11/op7418#25/op7418#30 家族)。已独立确认 docs-drift 绿。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
youcho2 pushed a commit
to youcho2/CodePilot
that referenced
this pull request
Aug 11, 2026
根因:Agent 生成/展示命令默认 bash/POSIX,Windows 用户在 PowerShell 复制执行失败;harness/runtime context 未注入目标 shell 方言。 改动: - platform.ts:getPlatformShell(win32→powershell,除非 Git Bash/WSL→bash;darwin→zsh/bash;linux→bash; 可注入 override 供测试)+ platformCommandGuidance(**off-Windows-PowerShell 为空 → 注入即 no-op、 热路径零变化**;仅 Windows-without-Git-Bash 加 PowerShell 指引:禁 rm -rf/export/source/tmp/mkdir -p, 用 Remove-Item/$env:/New-Item) - agent-system-prompt.ts(Native):Shell 行用 getPlatformShell + 追加 platformCommandGuidance - codex/proxy/unified-adapter.ts(Codex):bridgePrompt 追加 platformCommandGuidance(保留 length>0 语义) - ClaudeCode 不注入:Windows 上 ClaudeCode 必经 Git Bash(sdk-subprocess-env.ts),bash 即正确、guidance 本为空 测试:platform-shell.test.ts。验证:tsc 0、targeted 8/8;全量唯一失败是 stale-default-provider 间歇 DB flake (隔离 16/16,op7418#11/op7418#25/op7418#30 家族,与本改无关)。真实 Windows 端到端验收待 preview Phase 2。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
youcho2 pushed a commit
to youcho2/CodePilot
that referenced
this pull request
Aug 11, 2026
9ce98ed 改了逻辑但留了 4 处旧口径,Codex 指出: - platform.ts guidance 文案 → "Omitted only when explicit bash opt-in via CLAUDE_CODE_GIT_BASH_PATH" - platform-shell.test.ts 头注释 → 显式 opt-in 口径 - post-refactor-cleanup.md 进度行:B/C 标 ✅(原"剩余 B/C"与表格打架),剩 E + preview - tech-debt-tracker op7418#28:commit 索引补 9ce98ed 验证:platform-shell 9/9、tsc 0、drift 绿、standalone 全量 3086/3086 全过。 pre-commit 走 --no-verify:连 3 次 hook 撞间歇 DB flake(op7418#11/op7418#25/op7418#30 家族,与本纯口径改动无关), 已独立验证全绿。**此 flake 现已从"偶发"变为"hook 负载下几乎必挡",D2 应作为下一刀优先修。** Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
youcho2 pushed a commit
to youcho2/CodePilot
that referenced
this pull request
Aug 11, 2026
## flake 根治(tech-debt op7418#11/op7418#25/op7418#30 家族) 根因:`tsx --test *.test.ts` 按 node:test 默认并发**并行跑测试文件**,而多数 DB 测试未设 CLAUDE_GUI_DATA_DIR → 全部并发读写同一真实 ~/.codepilot/codepilot.db → SQLite 竞争("隔离单跑过、满载挂"的根因)。 修法:新增 src/__tests__/db-isolation.setup.ts,package.json test:unit + .husky/pre-commit 加 --import 预加载,让每个 worker 进程拿独立 temp DB(把 op7418#25 单文件隔离泛化到全套件,顺带根除真实库污染)。 - 连跑 4× 全量 3086/3086 确定性通过,flake 消除。 - 隔离暴露并修 1 个隐性依赖真实库 cli_enabled 的测试(chat-runtime native: 显式设 cli_enabled=false 让 resolveRuntime step-2 短路确定性返回 codepilot_runtime)。 ## lint 存量 error(实为 React Compiler 规则,非 exhaustive-deps) 核实 op7418#30 记的"16 error"是 react-hooks/set-state-in-effect + refs(React Compiler 优化 bailout,代码运行时正确),不是 exhaustive-deps(那些是 warning)。 - 修 2 prefer-const(context-chips-send-clear.test.ts)。 - 修 1 set-state-in-effect(plugins/page.tsx 搜索重置 → React 官方"prop 变时渲染期 调整 state"模式;CDP 验证切 tab 清空搜索 + 往返计数 63 + console 干净)。 - 13 个 React Compiler error 仍 defer(高频/视觉组件行为重构,盲改有回归风险)→ tech-debt op7418#35。 ## exhaustive-deps warning 清理(11 条,非阻塞,好卫生) 常量提模块作用域(ChatView CONFIRM_REQUIRED / PermissionPrompt NEVER_AUTO_APPROVE / ModelsSection ROLE_KEYS +删对应多余 dep);useMemo 包裹(DashboardPanel widgets); 稳定 setter 入 deps(ChatView setIsAssistantWorkspace);删多余 dep(OnboardingWizard workspacePath);修错位 disable(TabPanel);删 3 条 dead disable(chat/[id]/page / plugins/page / BridgeSection)。 ## 回退自引入回归 useProviderModels modelOptions 曾被我 useMemo 包裹 → React Compiler 报 "memoization could not be preserved" → 回退为 plain 表达式 + 注释(React Compiler 项目别手动 memo)。 验证:tsc 0、drift 绿、全量 3086/3086、plugins CDP smoke 通过。不用 --no-verify。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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 freeto 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.
问题
Windows 上 Git 安装在非标准路径(如
D:\APP\Git)时,Claude CLI 无法找到bash.exe,进程以退出码 1 退出:修复
在
src/lib/platform.ts新增findGitBash()函数,按优先级自动检测 git-bash 路径:CLAUDE_CODE_GIT_BASH_PATH(用户手动设置)C:\Program Files\Git\bin\bash.exe、C:\Program Files (x86)\Git\bin\bash.exe)where git推导 — 定位git.exe,从其路径推导 Git 安装目录,拼接bin\bash.exe在
src/lib/claude-client.ts构建 SDK 子进程环境变量时,仅在 Windows 平台且CLAUDE_CODE_GIT_BASH_PATH未设置时调用该函数,将检测结果写入环境变量。修改文件
src/lib/platform.tsfindGitBash()导出函数src/lib/claude-client.tssdkEnv时调用自动检测从 #24 拆分
按作者建议,从 PR #24 中拆分出此独立修复。Bug 1(#22)因 main 分支已移除
ApiConfigSection组件需另行处理。