Commit Graph
449 Commits
Author SHA1 Message Date
haelyra ab10daba18 Merge reviewed PR #3870 2026-11-05 23:10:32 -05:00
haelyra a222e0091b Merge reviewed PR #3849 2026-11-05 23:10:32 -05:00
haelyra 22596737f7 Merge reviewed PR #3829 2026-11-05 23:09:32 -05:00
haelyra 759a3ba299 Merge reviewed PR #3822 2026-11-05 23:09:32 -05:00
haelyra 44de2e5996 Merge reviewed PR #3814 2026-11-05 23:09:32 -05:00
Gaurav DubeyandClaude Opus 5.5 f0eee4b543 fix(hooks): redact JWTs joined to an underscore-prefixed label
The JWT chain scanner only accepted a header at the start of a segment or
after `-`, so `session_<JWT>` reached the audit and cost logs unredacted.
Treat `_` as a prefix boundary too and cover it in the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:30:52 +00:00
Rahul Selvaraj 846a561a7b fix(hooks): drop classifier notices from LLM summary input
The safety-classifier notice filter only covered the mechanical summary.
When generateSessionSummary runs (low context or message interval),
extractConversationText read the raw transcript and passed the notice to
the LLM as a user turn, so it could still reach saved context.

Move the check into one shared isClassifierNotice() in
scripts/lib/llm-summary.js and use it in both userMessageText() and
extractConversationText(). Add LLM-path regression tests, and split the
session-end classifier-notice tests into small functions (<50 lines).

Refs #3867

Assisted-by: Claude <noreply@anthropic.com>
2026-11-05 18:06:51 +08:00
Gaurav DubeyandClaude Opus 5.5 71084e0555 fix(hooks): redact JWTs joined to a hyphenated prefix
The lookbehind added to keep the JWT scan linear also skipped tokens right
after a `-`, so `--cookie "session=jwt-<JWT>"` reached the logs unredacted.
Scan each `[A-Za-z0-9_.-]` run once instead, checking every dot segment for
a header at its start or after a `-`, decoding at most once per segment so
long `ey-ey-...` runs stay linear.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 03:31:50 +00:00
Rahul Selvaraj a08d5da8c9 fix(hooks): skip safety-classifier notices in session summaries
When a response is stopped by the safety classifier, the harness records
a notice ("Your response above was stopped by a safety classifier ...")
as a user entry in the transcript. session-end.js kept it as a user
message, so it was written under "### Tasks" and re-injected by
session-start.js on the next session.

userMessageText() now drops entries that start with that notice, next
to the existing HARNESS_NOISE filter. User messages that only mention
the phrase are kept, since the match is anchored to the start.

Fixes #3867

Assisted-by: Claude <noreply@anthropic.com>
2026-11-04 19:29:32 +08:00
Gaurav DubeyandClaude Opus 5.5 4d3e66e0ab fix(hooks): redact joined-fragment secret values and make JWT scan linear
- Replace the secret=/api_key= value regex with a single-pass, quote-aware
  scanner so the whole Bash word is redacted when quoted and unquoted
  fragments are joined (e.g. --secret='prefix-'suffix), while a value inside
  an enclosing quoted string stops at that string's closing quote.
- Searching for the keyword itself (grep -n "secret =" file,
  rg 'api_key:' dir) no longer redacts the rest of the command.
- Use a lookbehind instead of \b before the JWT header so long dot-free
  ey-ey-... runs are scanned in linear time instead of quadratic.
- Add regression tests for joined fragments, keyword searches, and the
  ey- performance case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 03:41:05 +00:00
Gaurav Dubey 0b57406e57 fix(hooks): redact spaced-header JWTs and escaped or $'...' secret values
Match JWT headers that start with ey or ew (whitespace after the opening
brace) and keep non-eyJ matches only when the header does not decode to
an object with an alg field. Parse secret= / api_key= values with escaped
double quotes, $'...' quoting and backslash escapes, and redact an
unterminated quoted value to the end of the command.

Refs #3846
2026-11-03 04:19:37 +00:00
Gaurav Dubey 08fb3c8a1c fix(hooks): redact bare API keys, JWTs and PEM blocks in bash command logs
sanitizeCommand only redacted keyword- or flag-shaped secrets, so a bare
Anthropic/OpenAI sk- key, a JWT, a PEM private key block, or a secret= /
api_key= / x-api-key: value was written verbatim to bash-commands.log and
cost-tracker.log. Add value-shape patterns for these and keep the key name
and separator for assignments so the log stays readable.

Refs #3846
2026-11-03 04:12:32 +00:00
Muhammad Mirza 3e7b4d74b9 fix(continuous-learning): sync Stop hook and fail-closed delivery marker
Address bot review on the Stop delivery path: the stop:evaluate-session
registration no longer carries async (an async Stop registration cannot
block), so delivery is synchronous, and the metadata fingerprint for the
changed entry is regenerated with the repo's own function; the delivery
marker is now claimed atomically with exclusive create and any write
failure fails closed instead of delivering without once-per-session
protection; the skill doc now marks the shell entry as counting-only,
requires the JavaScript evaluator through the plugin hooks for delivery,
and clarifies that Stop fires whenever Claude finishes responding; test
spawn helpers no longer coerce a failed spawn to exit 0.

Test plan:
- tests/hooks/evaluate-session.test.js: 25 passed, 0 failed (2 new:
  marker write failure skips delivery, registration is synchronous);
  pristine comparison: 22 passed, 3 failed (delivery, marker, registration)
- tests/hooks/hooks.test.js: 260 passed
- tests/hooks/stop-hooks-stdout.test.js: 48 passed
- tests/hooks/cursor-hook-dispatchers.test.js: 27 passed
- tests/integration/hooks.test.js: 27 passed
- scripts/ci/check-unicode-safety.js: passed
2026-10-31 23:36:38 +07:00
Muhammad Mirza Kurniawan f82eb1414b fix(continuous-learning): deliver v1 Stop nudge via native Stop contract behind explicit opt-in
The v1 evaluator computed the learning signal but wrote it to stderr, which Claude Code never forwards to the model, so the learned-skills folder was never populated through this path.

Delivery now follows the maintainer-endorsed shape: an explicit stop_nudge_opt_in flag (default off, so existing installs are unchanged), the native Stop block contract (decision block plus reason) instead of plain stdout text, at most one delivery per session via a temp-dir marker, Stop-loop protection via stop_hook_active, and delivery only for sessions with a registered lease from SessionStart.

Tests: 7 new evaluator tests (opt-in off, no lease, one valid block then silence on repeat, stop_hook_active, short session, non-Stop event, missing session id). Evaluator suite 23/23 with the fix, failing on pristine; hooks suite 260/260; Stop stdout contract suite 48/48.

Limits stated plainly: end-to-end delivery in a live Claude Code session is not certified from this host (unit-level spawn plus parse only), and the fix ships inert by default until a user opts in.
2026-10-31 22:40:13 +07:00
Iain f914d617fd fix(hooks): accept the ! breaking-change marker in commit-quality 2026-10-30 22:46:01 +00:00
Quinn O'Donnell 00a8fe96f8 fix(hooks): skip stdin listeners on require and match exact tsc paths in post-edit-typecheck
config-protection.js and post-edit-typecheck.js attached process.stdin
listeners at module scope. tests/hooks/hook-input.test.js requires
config-protection.js, so that test never exits while stdin stays open.
Attach the listeners only when the script runs directly
(require.main === module), as stop-format-typecheck.js and quality-gate.js
already do.

post-edit-typecheck.js picked tsc diagnostics with line.includes(candidate),
so editing a root index.ts reported the errors of src/index.ts, and a
Windows relative path (src\index.ts) never matched tsc's forward-slash
output. Compare the file at the start of each diagnostic instead, the same
check diagnosticMatchesFile() does in stop-format-typecheck.js.

Refs #3821
2026-10-30 12:29:32 -04:00
rabbit-collabandClaude Opus 5.5 21d651cb8e fix: exit hook runners whose parent process is gone
On Windows, Claude Code kills an overrunning hook by killing the bash.exe
wrapper; the node.exe runner underneath survives. If another process still
holds the write end of the runner's stdin (a handle inherited by a process
spawned at the same moment), the runner never sees EOF and waits forever.
Orphaned runners were observed living 3-18 hours.

Add scripts/hooks/hook-watchdog.js and start it from the four hook entry
points (plugin-hook-bootstrap, run-with-flags, posttooluse-dispatcher,
lifecycle-hook-bootstrap). It exits the process when the parent PID is gone
(Windows) or the process was re-parented (POSIX), polled every 2s, or when a
hard deadline passes (330s, above the longest hooks.json timeout, or an
earlier inherited ECC_HOOK_DEADLINE_MS). Timers are unref'd so a finished
hook is never kept alive.

The regression test reproduces the leak with a detached runner whose stdin
write end is held by an unrelated process; it fails without the watchdog
(runner still alive after 8s) and passes with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 03:08:18 -07:00
haelyra 3dca6e2e88 fix(hooks): preserve provider conversation identity under inherited environments
Restore the shipped payload-first contract from #3464/#3495 and the explicit source #3755 scope clarification. Two provider conversations must retain distinct IDs despite an inherited registered ECC parent ID. Normal and ambient producer24 tests, canonical resolver10 and independent differential review pass. Keep native importer guards; explicit provider/native correlation is queued separately.
2026-10-29 18:57:29 -07:00
haelyra 6cd41995f4 fix(hooks): attribute native activity to the registered ECC session
Verify review discussion4419348312 against actual native producer/importer behavior. Prefer the independently sanitized ECC_SESSION_ID for the ECC-owned metrics feed, retain payload then legacy fallback for standalone hooks, and leave sibling hooks unchanged.

Actual Node producer plus read-only cached native binary reproduces zero imported metrics before the fix and exactly one tool/file/log after repeated sessions/status commands. Four producer regression controls and normal/adversarial inherited-env suites pass22/22. Focused coverage96.47percent lines and91.47percent branches; parent independent source review passed.
2026-10-29 17:43:55 -07:00
haelyra fc549b6372 fix: preserve Windows rule examples and conservative summary budgets
Address #3809 review regressions for CRLF code fences and inferred context capacity. Reproduced unit and actual Stop-hook failures; verified llm-summary38, Stop14, Copilot37 and independent code/security review. Keep confirmed model/ECC context authority, native budget scheduling and unknown capacity separate.
2026-10-29 17:27:56 -07:00
haelyra 14ba1e211f maint: integrate reviewed contribution #3777 2026-10-29 11:27:40 -07:00
haelyra 291635f7f9 maint: integrate reviewed contribution #3776 2026-10-29 11:27:01 -07:00
haelyra ff9095f6f7 maint: integrate reviewed contribution #3775 2026-10-29 11:26:59 -07:00
haelyra 65d83f9290 maint: integrate reviewed contribution #3669 2026-10-29 11:25:30 -07:00
haelyra 9aed578c67 fix: integrate symlink-aware GateGuard exemptions from #3726 2026-10-29 11:20:48 -07:00
haelyra 8e00137b04 fix: integrate observer identity and lease repair with canonical root matching 2026-10-29 11:19:43 -07:00
Brian La Plume 4a76f78411 fix(gateguard): expand unique sudo long-option prefixes
getopt_long accepts a unique prefix, so sudo --use root rm -rf build is
--user root and the resolver read root as the command. Expand unique
prefixes from sudo's long option table before the value/non-exec checks.
--help joins the non-executing modes.
2026-10-28 12:28:55 -07:00
Brian La Plume 2a3ed89600 refactor(config-protection): build targetPaths without mutation 2026-10-28 12:14:38 -07:00
Brian La Plume a46e36d488 fix(gateguard): sudo env assignments between options, missing value flags
sudo accepts VAR=value between its options (parse_args.c is_envar), so
sudo FOO=1 -u root rm -rf resolved -u as the command. Keep reading options
past assignments. Add sudo -R/--chroot, -a/--auth-type, -c/--login-class
and doas -a as value flags, and stop a short-cluster scan at any unknown
letter, so sudo -R/live rm -rf no longer reads the l in /live as -l.
doas -C only checks config, so it is non-executing; the existing doas -C dd
case moves to the passive list.
2026-10-28 12:13:25 -07:00
Brian La Plume 7253c8a261 fix(gateguard): treat sudo list/validate/edit modes as non-executing
sudo -l/--list, -v, -K, -V and -e/--edit (and doas -L) do not run the
command operand, so sudo -l rm -rf build was denied as destructive. The
privilege-wrapper resolver now reports no executable command for those
modes. Short clusters stop at the first value flag, so sudo -ul rm -rf
(user l) stays destructive.
2026-10-28 11:54:13 -07:00
Brian La Plume 646b4d1442 fix(gateguard): classify rm/Git behind sudo/doas/env/command wrappers
isDestructiveRm/isDestructiveGit keyed on argv[0], so sudo rm -rf,
command rm -rf and env git reset --hard read as calls to the wrapper and
were allowed once the routine shell gate was satisfied. Run both checks on
the unwrapLeadWrappers argv too, the resolution the dd and sh -c paths
already use. Overlaps #2832, which also reworks sh -c parsing and has
conflicts with main; this is the minimal rm/Git part.
2026-10-27 11:06:20 -07:00
Brian La Plume 1d55d690b9 fix(run-with-flags): fail closed for oversized Bash GateGuard input
Fixes #3762. pre:bash:gateguard-fact-force was missing from
FAIL_CLOSED_ON_TRUNCATION_HOOKS, so a Bash payload over the stdin cap
exited 0 while the Edit and PowerShell GateGuard ids blocked. Share one
GateGuard id set for the fail-closed list and the off-switch branch, and
add runner-level tests for all three ids plus each off switch.
2026-10-27 11:03:36 -07:00
Brian La Plume ed2f02dd06 fix(config-protection): check MultiEdit edits[].file_path targets
Fixes #3761. config-protection only read tool_input.file_path, so a MultiEdit
with the config path inside edits[] edited an existing ruff.toml/.eslintrc
without the block. Check every effective target and block if any is an
existing protected config.
2026-10-27 11:03:02 -07:00
haelyra 0a7a9a718e fix(hooks): use session repository for console warnings 2026-10-25 19:32:16 -04:00
haelyra 605e006137 Integrate L4XB PR #3662 2026-10-25 19:30:50 -04:00
haelyra 9c8a66b696 Integrate L4XB PR #3664 2026-10-25 19:30:50 -04:00
haelyra 0e7588cec5 Integrate L4XB PR #3667 2026-10-25 19:30:50 -04:00
Gaurav Dubey b98bff4a45 fix(observer): keep project context and leases aligned after remote changes
Integrates #3697 on current main. Prefer the observer project ID, retain a sole legacy ID until the new observer folder exists, and release the ending session lease across same-root aliases. Replace the unsafe live merge hint with read-only project inspection, and validate alias IDs before path use. #3711 independently identified the computed-ID selection gap; its early switch without observer data and unchanged SessionEnd path were not adopted.
2026-10-25 17:54:47 -04:00
Gaurav Dubey dcb947a4e1 fix(gateguard): judge exempt globs against real target location
Port #3656 onto current main, preserving both the contributor fix and the unrelated current changelog entry. Includes the follow-up glob normalization from 2c11fd74.
2026-10-25 17:47:30 -04:00
Gaurav DubeyandClaude Opus 5.5 2600c70298 fix(hooks): fail closed on incomplete input in bash-hook-dispatcher
- bash-hook-dispatcher: honor the reader's truncated flag. pre-Bash
  blocks (exit 2) because safety checks need the complete request;
  post-Bash skips its hooks and does not echo a partial payload.
- resolveStdinIdleTimeout: treat whitespace-only values as unset instead
  of Number('  ') === 0 silently disabling the deadline.
- isCompleteJsonObject: do not accept a JSON array as a hook payload.
- tests: wait for the child's close event so stdio is drained before
  asserting; cover both bash-hook-dispatcher modes.
- hooks/README.md: keep the example below the 5 s per-hook timeout.

Refs #3665

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 23:18:47 +00:00
Gaurav DubeyandClaude Opus 5.5 943eb826b5 fix(hooks): clamp the stdin idle deadline to the timer maximum
setTimeout fires after 1 ms for any delay above 2147483647 ms, so a large
ECC_HOOK_INPUT_IDLE_TIMEOUT_MS turned the deadline into ~1 ms and marked
every hook input incomplete. Clamp to the maximum with a diagnostic, and
surface the invalid-value diagnostic when readStdinRaw resolves the env.

Refs #3665

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 22:54:14 +00:00
Gaurav DubeyandClaude Opus 5.5 0ca9eeb3ce fix(hooks): stop hook stdin reads when the caller never sends EOF
readStdinRaw() only settled on end, error or close. If the parent kept
stdin open without writing EOF, every hook that reads through it waited
until the harness killed it (an 8-10 s stall per call).

Add an idle deadline (default 3000 ms, ECC_HOOK_INPUT_IDLE_TIMEOUT_MS,
0 disables). It is reset on each chunk, unref()ed, and on expiry detaches
from and pauses the stream so a held-open pipe cannot keep the hook alive.
Input that already parses as a complete JSON object is accepted; anything
else is marked truncated so fail-closed safety hooks still block.

bash-hook-dispatcher.js now reads through the shared reader instead of its
own end/error-only loop.

Fixes #3665

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 22:39:06 +00:00
L4XB 10e7c5800f fix(hooks): recognize Prettier's TypeScript and JSON5 config files
Prettier's config searcher also reads .prettierrc.json5, .prettierrc.ts/.mts/.cts and prettier.config.ts/.mts/.cts. resolve-formatter knew none of them, so a project configured only through prettier.config.ts was never formatted by post-edit-format, quality-gate or the Stop batch. config-protection's rc pattern stopped at .yaml/.toml, so an existing .prettierrc.ts or .prettierrc.json5 could be edited freely.
2026-10-22 23:51:32 +02:00
L4XB cd1f5b74e2 fix(hooks): match tsc diagnostics by the file they name
The Stop typecheck reported every tsc line that contained the edited path anywhere. A root index.ts has the relative path `index.ts`, which every `src/index.ts(...)` diagnostic contains, so a clean root file was reported with the errors of src/index.ts. The same happened to src/utils.ts with web/src/utils.ts, and to any file named in another file's message.

Compare the path that starts the diagnostic (`path(line,col): `), keeping the slash normalization for Windows.
2026-10-22 23:42:21 +02:00
L4XB 5311485e94 fix(hooks): keep a backslash in double quotes as bash does in the dev-server block
readToken dropped every backslash inside double quotes, while bash drops it only before $, `, ", \\ or a newline. `"echo ready\;"` therefore reached the tmux check as `echo ready;`, read as a command separator, and `tmux send-keys -t dev "echo ready\;" "npm run dev" Enter` was blocked although it types into a pane.
2026-10-22 22:45:28 +02:00
L4XB adf435d36f fix(hooks): find console.log in modified files from a subdirectory session
check-console-log took the paths from `git diff --name-only HEAD`, which are relative to the repository root, and checked them with fs.existsSync from the hook's working directory. In a session started in a subdirectory, such as a monorepo package, no path existed from there, so the hook never warned. Resolve each path from the repository root. The exclusion patterns and the warning still use the root-relative path.
2026-10-22 22:42:08 +02:00
L4XB eee00776be fix(hooks): end a tmux command at a semicolon that ends an argument
tmux also separates commands at a `;` that ends an argument, so `new-session -d 'npm run dev;' run-shell 'npm run dev'` runs the second dev server without a pane. Split there as well. An escaped `\;` at the end of an argument stays literal, as in tmux.
2026-10-22 22:32:33 +02:00
L4XB 87945aac1f fix(hooks): read tmux option clusters and command sequences in the dev-server block
Two forms got the pane exemption although they run the dev server without a pane.

`tmux -vL new-session run-shell ...`: in a cluster, the last option that takes a value (f, L, S, T) takes the next token, here the socket name `new-session`. A `c` anywhere in a cluster (`-c'npm run dev'`) runs a shell command without a pane.

`tmux new-session -d \; run-shell "npm run dev"`: only the first command of a sequence was checked. The sequence is now split at `;`, and it is exempt only when every command in it that runs the dev server is a pane command. This also closes the same hole for the plain `tmux new-session ... \; run-shell`, which the old regex exempted.
2026-10-22 21:59:23 +02:00
L4XB 99aa85dde9 fix(hooks): let the dev-server block see a tmux launch past tmux options
The block allowed a dev server only when the segment began with `tmux new`, `new-session`, `new-window` or `split-window`. It therefore blocked dev servers that do start in a tmux pane, the way its own message asks: `tmux -L work new-session ...` and `tmux -f conf new-session ...` (tmux options before the command), `/opt/homebrew/bin/tmux new-session ...` and `env TERM=... tmux new-session ...`, the aliases `neww` and `splitw`, and `tmux send-keys -t dev 'npm run dev' Enter` or `respawn-pane` for a session that exists.

Read the tmux command from the parsed segment instead, after the leading command word and tmux's own options, and allow the commands that run their shell command in a pane. `tmux run-shell` and `tmux -c` run it without one and stay blocked.
2026-10-22 21:15:25 +02:00
Affaan Mustafa 26d2010a16 refactor(hooks): split shell-scan into per-token helpers
heredocDelimiter, executionRegion and scanShell each carried one long character loop with every quote, escape, heredoc, case and scope rule inline, which is where the three complexity warnings came from. The delimiter reader now has skipDelimiterBlanks, delimiterEscape and readDelimiterWord; the $(...) walker dispatches to regionQuotedEnd, regionSubstitution, openRegionQuote, regionHeredocOperator, regionHeredocBodies, casePhaseStep and closeRegionParen; and the top-level scanner keeps its position and pending word on a scan object that scanQuotedChar, scanEscape, scanSubstitution, openQuote, scanOperator and scanRedirect advance.

Every budget.spend call keeps its amount and order, so the work quota tests still land in the same window. The module still has no requires and exports createBudget, scanShell and scanExpansions unchanged; a differential run of the old and new scanner over the hook test corpus plus 58k generated inputs produced identical commands, nested regions and spend totals.
2026-10-19 23:39:18 -04:00