Skip to content

fix(windows): correct shell flag for Git Bash / POSIX shells (fix #7) - #8

Merged
yvgude merged 1 commit into
yvgude:mainfrom
sinouw:fix/windows-shell-flag-issue-7
Mar 27, 2026
Merged

fix(windows): correct shell flag for Git Bash / POSIX shells (fix #7)#8
yvgude merged 1 commit into
yvgude:mainfrom
sinouw:fix/windows-shell-flag-issue-7

Conversation

@sinouw

@sinouw sinouw commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Closes #7.

Full reproduction and environment details: #7.

Problem

On Windows, lean-ctx -c <command> failed with output like /C: Is a directory and exit code 126 in Git Bash and when SHELL points at a POSIX shell (e.g. bash.exe). Global shell hooks (alias git='lean-ctx -c git', etc.) were unusable in those environments.

Root cause

detect_shell() returns SHELL when set (e.g. Git for Windows sets it to bash.exe). shell_and_flag() treated every non–PowerShell executable on Windows as cmd.exe, passing /C. That switch is only valid for cmd.exe; bash expects -c. Invoking bash with /C leads to the MSYS-style error and 126.

Solution

Shell executable (basename) Flag
powershell / pwsh -Command
cmd.exe / cmd /C
bash, sh, zsh, fish, … (default) -c

Implemented in windows_shell_flag_for_exe_basename() and wired through shell_and_flag() so exec, -c passthrough, and ctx_shell-style spawn paths stay consistent.

Testing

  • Unit tests for windows_shell_flag_for_exe_basename (cmd, PowerShell, bash, etc.) in rust/src/shell.rs
  • cargo test: all tests passed in Docker rust:1.88-bookworm (contributor host lacked MSVC link.exe; CI should confirm)
  • Manual (Windows + Git Bash): lean-ctx -c "git --version" and lean-ctx -c "echo ok" should succeed after build

Checklist

  • Targeted change (shell.rs only); no unrelated refactors
  • Linux/macOS: behavior unchanged (-c only branch)

Git Bash sets SHELL to bash.exe but shell_and_flag() used /C for every
non-PowerShell shell. /C is only valid for cmd.exe; bash expects -c,
which caused /C: Is a directory and exit 126 (fixes yvgude#7).

- cmd.exe / cmd -> /C
- powershell / pwsh -> -Command
- bash, sh, zsh, fish, ... -> -c

Adds windows_shell_flag_for_exe_basename + unit tests.

Made-with: Cursor

@yvgude yvgude left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested root cause analysis: detect_shell() returns SHELL env var (bash.exe on Git for Windows), but shell_and_flag() treated all non-PowerShell Windows shells as cmd.exe and passed /C. Fix is correct — proper detection of POSIX shells (bash/sh/zsh/fish) and assignment of -c flag. Unit tests are solid. Merging.

@yvgude
yvgude merged commit 70b4a52 into yvgude:main Mar 27, 2026
yvgude pushed a commit that referenced this pull request Mar 27, 2026
- fix(#7/#11): Windows shell flag — detect POSIX shells (Git Bash) and
  use -c instead of /C (via PR #8, now merged from GitHub)
- fix(#10): excluded_commands config option now actually enforced in
  shell::exec() — commands matching entries bypass compression entirely
- feat(#13): lean-ctx-on / lean-ctx-off / lean-ctx-status shell
  functions added to init --global hook (bash/zsh/fish); LEAN_CTX_ENABLED
  env var controls default state
- feat(#14): slow query log — commands exceeding slow_command_threshold_ms
  (default 5s) logged to ~/.lean-ctx/slow-commands.log;
  new lean-ctx slow-log [list|clear] command
- feat(#15): lean-ctx update — self-update from GitHub Releases; detects
  platform, downloads archive, safely replaces binary;
  lean-ctx update --check for version check only

Also synced docs PR #9 (README + session metrics mdc example).
yvgude pushed a commit that referenced this pull request Jun 21, 2026
Wire ten neuroscience/physics-motivated mechanisms to real hot-path call
sites, deterministic by default (Rule #498 / prompt-cache intact), and make
them provable via a new `lean-ctx introspect cognition` activity registry.

- Phase 0: introspect registry + CLI + doctor; is_stochastic_enabled() gate
- #2 time-variant Phi (EMA re-read); #1 Ebbinghaus decay + spacing effect
- #3 Hebbian eviction + CLS consolidation (previously dead code, now wired)
- #5 integration-aware Phi (greedy MMR) + content-based dedup fix
- #6 global-workspace ignition; #4 learned field weights (bandit, argmax default)
- #7 idle replay (sharp-wave-ripple); #9 FEP prefetch (active inference)
- #8 immune detector vs context poisoning (coupled to workspace trust)
- #10 QUBO selection spike behind LEAN_CTX_EXPERIMENTAL_QUBO (greedy stays default)

Stochastic exploration gated behind LEAN_CTX_STOCHASTIC. Docs + CHANGELOG added.
GitLab: epic root/lean-ctx#771 + foundation #772 + features #773-#782.

5653 lib tests green, zero clippy warnings.

Co-authored-by: Cursor <cursoragent@cursor.com>
yvgude added a commit that referenced this pull request Jul 1, 2026
… wave 1)

Universal-provider-framework (enterprise#7): new [[proxy.providers]] registry
(id + wire shape + base_url + optional api_key_env) with /providers/{id}/...
routes — a new OpenAI/Anthropic/Gemini-compatible endpoint is pure config.
WireShape is deliberately separate from provider identity; gateway-held keys
replace caller credentials, callers authenticate with the Bearer token only.

Gateway bind (enterprise#8): proxy_bind_host + LEAN_CTX_PROXY_BIND_HOST
(default loopback, typo narrows to loopback); non-loopback bind hard-disables
the provider-key auth fallback and activates the proxy_allowed_hosts
Host-header allowlist (DNS-rebinding guard).

Security hardening M1 (enterprise#37): proxy-wide token-bucket rate limit
(proxy_max_rps; gateway default 50 rps, /health exempt) + negative tests for
host allowlist, bind fallback, credential stripping and burst limiting.

Refs: lean-ctx-enterprise#7 #8 #37 (backlog doc 13, wave 1)
Co-authored-by: Cursor <cursoragent@cursor.com>
yvgude pushed a commit that referenced this pull request Jul 29, 2026
Git Bash sets SHELL to bash.exe but shell_and_flag() used /C for every
non-PowerShell shell. /C is only valid for cmd.exe; bash expects -c,
which caused /C: Is a directory and exit 126 (fixes #7).

- cmd.exe / cmd -> /C
- powershell / pwsh -> -Command
- bash, sh, zsh, fish, ... -> -c

Adds windows_shell_flag_for_exe_basename + unit tests.

Made-with: Cursor
yvgude pushed a commit that referenced this pull request Jul 29, 2026
- fix(#7/#11): Windows shell flag — detect POSIX shells (Git Bash) and
  use -c instead of /C (via PR #8, now merged from GitHub)
- fix(#10): excluded_commands config option now actually enforced in
  shell::exec() — commands matching entries bypass compression entirely
- feat(#13): lean-ctx-on / lean-ctx-off / lean-ctx-status shell
  functions added to init --global hook (bash/zsh/fish); LEAN_CTX_ENABLED
  env var controls default state
- feat(#14): slow query log — commands exceeding slow_command_threshold_ms
  (default 5s) logged to ~/.lean-ctx/slow-commands.log;
  new lean-ctx slow-log [list|clear] command
- feat(#15): lean-ctx update — self-update from GitHub Releases; detects
  platform, downloads archive, safely replaces binary;
  lean-ctx update --check for version check only

Also synced docs PR #9 (README + session metrics mdc example).
yvgude pushed a commit that referenced this pull request Jul 29, 2026
Git Bash sets SHELL to bash.exe but shell_and_flag() used /C for every
non-PowerShell shell. /C is only valid for cmd.exe; bash expects -c,
which caused /C: Is a directory and exit 126 (fixes #7).

- cmd.exe / cmd -> /C
- powershell / pwsh -> -Command
- bash, sh, zsh, fish, ... -> -c

Adds windows_shell_flag_for_exe_basename + unit tests.

Made-with: Cursor
yvgude pushed a commit that referenced this pull request Jul 29, 2026
- fix(#7/#11): Windows shell flag — detect POSIX shells (Git Bash) and
  use -c instead of /C (via PR #8, now merged from GitHub)
- fix(#10): excluded_commands config option now actually enforced in
  shell::exec() — commands matching entries bypass compression entirely
- feat(#13): lean-ctx-on / lean-ctx-off / lean-ctx-status shell
  functions added to init --global hook (bash/zsh/fish); LEAN_CTX_ENABLED
  env var controls default state
- feat(#14): slow query log — commands exceeding slow_command_threshold_ms
  (default 5s) logged to ~/.lean-ctx/slow-commands.log;
  new lean-ctx slow-log [list|clear] command
- feat(#15): lean-ctx update — self-update from GitHub Releases; detects
  platform, downloads archive, safely replaces binary;
  lean-ctx update --check for version check only

Also synced docs PR #9 (README + session metrics mdc example).
yvgude pushed a commit that referenced this pull request Jul 29, 2026
Wire ten neuroscience/physics-motivated mechanisms to real hot-path call
sites, deterministic by default (Rule #498 / prompt-cache intact), and make
them provable via a new `lean-ctx introspect cognition` activity registry.

- Phase 0: introspect registry + CLI + doctor; is_stochastic_enabled() gate
- #2 time-variant Phi (EMA re-read); #1 Ebbinghaus decay + spacing effect
- #3 Hebbian eviction + CLS consolidation (previously dead code, now wired)
- #5 integration-aware Phi (greedy MMR) + content-based dedup fix
- #6 global-workspace ignition; #4 learned field weights (bandit, argmax default)
- #7 idle replay (sharp-wave-ripple); #9 FEP prefetch (active inference)
- #8 immune detector vs context poisoning (coupled to workspace trust)
- #10 QUBO selection spike behind LEAN_CTX_EXPERIMENTAL_QUBO (greedy stays default)

Stochastic exploration gated behind LEAN_CTX_STOCHASTIC. Docs + CHANGELOG added.
GitLab: epic root/lean-ctx#771 + foundation #772 + features #773-#782.

5653 lib tests green, zero clippy warnings.

Co-authored-by: Cursor <cursoragent@cursor.com>
yvgude added a commit that referenced this pull request Jul 29, 2026
… wave 1)

Universal-provider-framework (enterprise#7): new [[proxy.providers]] registry
(id + wire shape + base_url + optional api_key_env) with /providers/{id}/...
routes — a new OpenAI/Anthropic/Gemini-compatible endpoint is pure config.
WireShape is deliberately separate from provider identity; gateway-held keys
replace caller credentials, callers authenticate with the Bearer token only.

Gateway bind (enterprise#8): proxy_bind_host + LEAN_CTX_PROXY_BIND_HOST
(default loopback, typo narrows to loopback); non-loopback bind hard-disables
the provider-key auth fallback and activates the proxy_allowed_hosts
Host-header allowlist (DNS-rebinding guard).

Security hardening M1 (enterprise#37): proxy-wide token-bucket rate limit
(proxy_max_rps; gateway default 50 rps, /health exempt) + negative tests for
host allowlist, bind fallback, credential stripping and burst limiting.

Refs: lean-ctx-enterprise#7 #8 #37 (backlog doc 13, wave 1)
Co-authored-by: Cursor <cursoragent@cursor.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.

Windows: lean-ctx -c git fails with "/C: Is a directory" and exit 126 (Git Bash + PowerShell; profile path with space)

2 participants