fix(hooks): POSIX-normalize worktree path in SessionStart hook#81
Open
thinkyou0714 wants to merge 1 commit into
Open
fix(hooks): POSIX-normalize worktree path in SessionStart hook#81thinkyou0714 wants to merge 1 commit into
thinkyou0714 wants to merge 1 commit into
Conversation
writeSessionStartHook embedded the raw worktree path into the generated session-start.sh, unlike writeStopHook (L66) and writePreToolUseHook (L288) which convert backslashes via .replace(/\/g, "/"). On Windows this corrupted TASK_STATE_FILE (backslashes become bash escapes), so TASK_STATE.md was not re-injected after context compaction. Apply the same wtPosix conversion and add a regression test asserting the generated hook embeds a backslash-free POSIX path (exercised by the windows-latest CI job).
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.
Problem (root cause)
writeSessionStartHookinsrc/core/hooks.tsembedded the raw worktree path (${worktreePath}) into the generatedsession-start.sh, unlike its siblingswriteStopHook(L66) andwritePreToolUseHook(L288), which normalize backslashes via.replace(/\/g, "/").On Windows, a worktree path like
C:\Users\…\sessionbecomesTASK_STATE_FILE="C:\Users\…\session/TASK_STATE.md"inside the bash hook, where\U,\s, … are interpreted as bash escapes. Result: after a context compaction, the SessionStart hook silently fails to re-injectTASK_STATE.md.Fix
const wtPosix = worktreePath.replace(/\/g, "/");and use${wtPosix}forTASK_STATE_FILE— matching the established pattern in the two sibling hook writers. Behavior is unchanged on POSIX; Windows is corrected.Test
tests/hooks-session-start.test.tsinstalls the hooks into a temp dir and asserts the generatedsession-start.shembeds a backslash-free POSIX path. This is exercised by the existingwindows-latestCI matrix job, where the old code would fail.Verification (local)
npm run typecheck✅ ·npm run lint✅ · new test ✅ (1 passed).hooks-circuit-breaker,hooks-blocklist) time out locally on Windows because theyspawnSync("bash", …)(slow on this machine, vitest 5s default). They are pre-existing onmainand pass on GitHub CI; a follow-up PR addsvitest.config.tswith a highertestTimeoutto remove that local flakiness.Scope: exactly 2 files (
src/core/hooks.ts,tests/hooks-session-start.test.ts).