Address the second round of review findings:
- Cache: trust an entry only while it is newer than the repository .git/config
as well as while git reports the stored origin, so a core.worktree change
that moves the root is not served stale.
- observe.sh: emit observer.enabled as a literal true or false so a value
containing a newline cannot shift the fields that follow.
- Tests: remove GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_COMMON_DIR and
GIT_PREFIX from the detection test environment; add a config-change test and
an observer.enabled newline test. Refresh the registry digest.
Address the review findings on the observe hook trim:
- Cache entries store the credential-stripped origin detection read, and a hit
compares it with `git remote get-url origin`, so included, global and
GIT_CONFIG_* origins and a config change during detection are all caught.
- Keep the payload cwd byte for byte (a directory name may hold a newline).
- Follow a symlinked python stub outside WindowsApps on Windows-like shells.
- Run housekeeping once a day from its own per-project marker, independent of
the detection cache.
observe.sh runs before and after every tool call and launched about 50
external processes per run. Each costs a few milliseconds on Linux/macOS
but 80-280 ms under Git Bash on Windows, where one run took 5-7 s.
- Read cwd, agent_id and observer.enabled in one Python start, and parse,
scrub and write the observation in one more (was six). The redaction
patterns are unchanged.
- Cache project detection per (CLV2_NO_PROJECT, CLAUDE_PROJECT_DIR, PWD)
for the rest of the day. An entry is rejected when .git/config is not
older than it, when the project dir or root is gone, or when the id is
not a shape detection can produce. Worktrees, submodules and non-git
roots are never cached. CLV2_PROJECT_CACHE=0 disables it; bash < 4.2
skips it.
- Run the stdin-independent guards before the first interpreter start.
- Run the find/du housekeeping only when detection was not cached.
- Replace dirname/readlink/subshell calls on the hot path with builtins.
Measured on Windows 11 / Git Bash, warm cache: 5.2-5.8 s -> 1.1-1.2 s
per run. Output compared against the previous script on 19 payloads
(records, redaction, registry, counters, exit codes): identical.
Behavior changes: projects.json last_seen refreshes at least daily
instead of every call; observations.jsonl may exceed the 10 MB cap by up
to a day of records before archiving; the App Installer stub check only
follows symlinks for paths under WindowsApps.
GateGuard denies by printing a PreToolUse permissionDecision on stdout at
exit 0. runHooks only stopped early on a non-zero exit, and its final
return preferred any advisory additionalContext over the hook stdout, so
in the strict profile the git-push reminder replaced GateGuard's deny and
the command ran. Stop at the first deny and return it unchanged.
Replace the literal /tmp/... cwd values in the context-gate suites with
paths under each test's realpath'd mkdtemp sandbox. CodeQL treats /tmp
string literals as shared temp sources and traced them through the hook
input into readFileTail. The hook only hashes cwd, so assertions are
unchanged.
Wrap #3106's mkdtemp fixture roots in realpathSync, matching the existing
atomic-write tests, so CodeQL no longer traces shared-temp paths from
these fixtures into read handles. Assertions are unchanged.
The hook proposes a correct absolute checkpoint path on Windows, but the
tests located that line with /^\s+[/\\].*\.md$/, which only matches paths
starting with a slash. Windows paths start with a drive letter (C:\...),
so every case that read the proposed path saw undefined and failed.
- Extract the proposed checkpoint as the indented line that ends in .md
and satisfies path.isAbsolute, so POSIX and Windows paths both match.
- Include the hook output in the "both fires should propose" assertion
so a genuine decline is diagnosable from CI logs.
- Write transcript fixtures into private fs.mkdtempSync directories
instead of predictable names directly under os.tmpdir() (CodeQL
js/insecure-temporary-file) in context-gate, context-gate-state and
ecc-context-monitor tests.
Add cross-manager fixtures for the same short flag with different meanings
(npm/pnpm -d, pnpm -w, bun -d, bun -c optional value), options before and
after run, -- boundaries, quoted script names and missing values, through
the real pre-bash-dev-server-block entry point and auto-tmux-dev. The new
tests/lib/dev-command.test.js rows for npm and Yarn match real npm 11.6.0
and Yarn 4.9.2 runs of a scratch project whose dev script writes a marker.
Main kept evolving pre-bash-dev-server-block.js while this branch waited:
tmux pane-launch detection past tmux options and command sequences, bash
double-quote backslash rules, here-document segment scanning and an indexed
segment queue. Resolve by keeping this branch's thin hook and moving main's
current helpers into scripts/lib/dev-command.js, so both dev hooks still
share one classifier without losing main's tmux behavior.
The same resolution makes package-manager option arity manager-specific,
as requested in review: npm -d / pnpm -d are loglevel flags, pnpm -w is
--workspace-root, bun -d is --define <K:V>. A shared value table swallowed
the script after the boolean spellings, so `npm -d run dev` escaped tmux.
Maintainer carry-forward of the four edge cases reproduced on 5a565cf:
- Same-named project roots: bind the proposal to a SHA-256 owner key of
the full real project root plus the raw session ID, and put that key in
both the file name and the ownership marker.
- Sanitized session-ID aliasing: hash the raw session ID before filename
sanitization so IDs such as owner/a and owner?a no longer share a path.
- Linked or special destinations: probe with lstat, open read-only with
O_NOFOLLOW and O_NONBLOCK, require a regular single-link file whose
complete first-line marker matches, and decline linked handoff
directories. A FIFO at the destination previously hung the prompt.
- Literal resume arguments: emit the resume prompt as one single-quoted
POSIX (or PowerShell on Windows) argument.
Also merge the UserPromptSubmit registration into the existing event
array. The main merge left a duplicate UserPromptSubmit key in
hooks.json and hooks.metadata.json, and JSON.parse kept only the last,
which silently dropped prompt:hookify-runtime.
Adds tests/hooks/context-gate-ownership.test.js, which fires the hook
through the registered run-with-flags.js entry: 12/12 pass here, 1/12
pass on 5a565cf.
Main now resolves sudo/doas/env and the timeout/setsid/nice/stdbuf/ionice/
taskset/nohup/time launchers for top-level commands, but find -exec still
read its action argv literally. `find . -exec sudo rm {} \;`,
`find . -exec timeout 5 rm -rf {} +`, `find . -exec sh -c 'rm -rf {}' \;`
and `sudo find . -exec rm {} \;` were allowed although each runs rm.
Resolve the exec argv through unwrapLeadWrappers (external argv, so no shell
builtins), classify find behind a wrapper, and send the -c text of a shell
that find starts through the same bounded quote-aware recursion as a
top-level `sh -c`. Non-executing modes such as `sudo -l` and quoted data
such as `sh -c 'echo rm -rf {}'` stay allowed.
Co-authored-by: Nguyen Thanh Dat <ntdat812.dev@gmail.com>
Carry forward the still-missing part of this PR onto main's scanner:
git commit --trailer and the git push value options (-o, --push-option,
--receive-pack, --exec, --repo) now consume the following token, and an
abbreviation that names exactly one value-taking long option consumes it
too. A flag-looking value such as `git push -o --no-verify` is data that
Git sends verbatim while still running pre-push, so refusing it was a
false positive.
--force-with-lease stays out (optional inline-only value), inline =value
forms consume nothing, and prefixes ambiguous among the value options
resolve to none of them. A real-Git sweep over every prefix of every
commit/push long option followed by --no-verify (866 commands, Git
2.50.1) found no command the hook allows while Git skips a refusing hook.
Co-authored-by: Nguyen Thanh Dat <ntdat812.dev@gmail.com>
Main already carries the first three commits of this PR (merged in
22596737f) plus later maintainer hardening that moved the delivery
marker into the private observer directory (bfb4dbe7b, f5ff589cd).
Conflict resolution keeps main's evaluate-session.js and test file as
the base, then re-applies only the remaining change from f64a9b5d0:
deliverStopNudge returns whether it wrote the Stop JSON, writes it with
process.stdout.write, and exits from the flush callback. The
async-stdout regression test is ported with the marker path pointed at
main's private delivery-markers directory.
Verified: evaluate-session 27/27 (new test fails on main 26/27),
hooks 260/260, stop-hooks-stdout 48/48, integration hooks 27/27.