Skip to content

fix(hook): make hook-augment work on Windows drive-letter paths#619

Open
catsmonster wants to merge 1 commit into
DeusData:mainfrom
catsmonster:fix/hook-augment-windows-paths
Open

fix(hook): make hook-augment work on Windows drive-letter paths#619
catsmonster wants to merge 1 commit into
DeusData:mainfrom
catsmonster:fix/hook-augment-windows-paths

Conversation

@catsmonster

@catsmonster catsmonster commented Jun 25, 2026

Copy link
Copy Markdown

What

Fixes the hook-augment PreToolUse Grep/Glob augmenter being a structural no-op on Windows.

Closes #618.

Why

src/cli/hook_augment.c had two POSIX-only path guards that a Windows drive-letter cwd (C:\repo / C:/repo) can never satisfy:

  1. cbm_cmd_hook_augment, _WIN32 branchif (!cwd || cwd[0] != '/') returned early on every invocation (a Windows absolute path never starts with /).
  2. ha_resolve_and_query walk-up loopfor (... && dir[0] == '/'; ...) never iterated for a C:/... path, and the parent-climb terminator assumed a /-root.

cbm_project_name_from_path already handles Windows paths (it produced the indexed project name from the C:\... root), so the fix is purely in these path assumptions.

How

  • Add cbm_hook_path_is_abs() — true for POSIX "/..." and Windows "X:/..." roots.
  • Normalize \/ on the Windows cwd before validation.
  • Loop while cbm_hook_path_is_abs(dir); stop the parent-climb at the drive root (X:/) as well as the POSIX root.
  • POSIX path unchanged (the previous cwd[0] != '/'getcwd fallback is preserved via the predicate).

Testing

The predicate is exposed as cbm_hook_path_is_abs (declared in cli.h) so it has direct regression coverage.

  • Regression test tests/test_cli.c::cli_hook_augment_path_is_abs (registered in the cli suite): asserts the predicate accepts /..., C:/Users/me/proj, C:/, C:, d:/... and rejects relative/path, proj, "", NULL. It fails on the old POSIX-only guard and passes after the fix. Being pure string logic, it also runs on the Linux CI.
  • Walk self-test (standalone, run locally): for C:\Users\me\proj the resolver queries C:/Users/me/projC:/Users/meC:/Users (stops one below the drive root), exactly symmetric to POSIX /home/u/proj/home/u/home.
  • clang-format clean on all three changed files; clang -fsyntax-only -I src -I vendored src/cli/hook_augment.c passes.
  • Not yet built through the full toolchain — I don't have make/zlib locally, so I'm relying on Windows CI to confirm the compile/link. Flagging that explicitly.

clang-tidy note: my additions follow the file's existing idiom ([4096] buffers, unchecked snprintf, drive-index access) that the surrounding code already uses, so I kept them consistent rather than adding one-off named-constants/void-casts. (CI runs lint.sh --ci, which skips clang-tidy.)

Notes

The "never block a tool" guarantee is untouched — every path still ends in exit 0 with output written exactly once. This only changes whether context is added on Windows; it can still never deny a tool. Fits under the Windows umbrella tracker #394.

hook-augment's PreToolUse Grep/Glob augmenter required POSIX-style
'/'-prefixed absolute paths in two guards, so a Windows cwd (C:\repo or
C:/repo) always failed: the _WIN32 cwd check returned early, and the
walk-up loop guard (dir[0] == '/') never iterated. The result was a
structural no-op on Windows — zero additionalContext for every Grep/Glob,
even for an exactly-indexed symbol.

Add ha_is_abs(), which accepts POSIX "/..." and Windows "X:/..." roots;
normalize backslashes to forward slashes on the Windows cwd; and stop the
parent-climb at the drive root as well as the POSIX root. POSIX behavior
is unchanged.

Adds a cli_hook_augment_path_is_abs regression test (the predicate is
exposed as cbm_hook_path_is_abs via cli.h) covering POSIX and Windows
drive roots — it fails on the pre-fix POSIX-only guard and passes after.

Verified with that test plus a standalone walk self-test (full path
resolves first, then climbs to one level below the drive root, symmetric
to POSIX); clang-format clean on all three files; clang -fsyntax-only on
the translation unit. Not built through the full toolchain locally (no
make/zlib) — relying on Windows CI to confirm the build.

Fixes DeusData#618

Signed-off-by: catsmonster <shaked.brand@gmail.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@catsmonster catsmonster force-pushed the fix/hook-augment-windows-paths branch from 48a2738 to 26e85d5 Compare June 25, 2026 01:09
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.

hook_augment PreToolUse augmenter is a structural no-op on Windows (POSIX-only path guards)

1 participant