Repository navigation
Conversation
Centralise the unsafe-dir check in lib-memory-dir.sh (new REMEMBER_DIR_UNSAFE flag) and gate every mkdir -p "$REMEMBER_DIR/..." site that was not already covered by #902's own guard -- bootstrap-dirs.sh, three more sites in post-tool-hook.sh, session-start-hook.sh (x3), session-end-hook.sh and write-handoff.sh. Fix log()'s own write-to-sink path so a FATAL logged while the sink is active (an append to /dev/null that always succeeds) reaches stderr instead of vanishing silently. Teach both guard predicates (_remember_dir_is_unsafe, _remember_log_dir_unsafe) to accept a UNC-rooted value as absolute rather than misclassifying it as unsafe. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…d sync Explore review (against commit c15e4f3) found a real regression: lib-memory-dir.sh's new unsafe-dir echo and log.sh's own pre-existing one both fired on every tool call once REMEMBER_DIR went unsafe, doubling hook-errors.log noise. log.sh now reads the already-exported REMEMBER_DIR_UNSAFE flag instead of recomputing and re-announcing it. Also fixes a self-contradictory comment ("above" vs "further down this file" about the same call site) and a fictional intermediate line-number claim in the scanner allowlist's own history comment. Adds a pin that lib-memory-dir.sh's and post-tool-hook.sh's necessarily-duplicated _remember_dir_is_unsafe copies (the latter exists because post-tool-hook.sh's fast path never sources lib-memory-dir.sh) stay byte-identical, so a future edit to one that forgets the other fails loudly. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…rd block CI's test_compile_hooks_900.py failed on ubuntu-latest/3.9: the #900 compiled- hook build inlines every sourced file's top level into one script, and lib-memory-dir.sh's new _remember_dir_is_unsafe collided under the SAME name with post-tool-hook.sh's own pre-existing (#902) copy once both land in the same compiled text. Renamed lib-memory-dir.sh's copy to _remember_lmd_dir_is_unsafe and updated tests/test_remember_dir_guard_920_sync.py to compare the three predicates' LOGIC (not their names) across lib-memory-dir.sh, post-tool-hook.sh and log.sh. Also compacted the new block's if/else/fi into a single && guard, trimming compiled bytes toward session-start-hook.sh's 120 KiB release budget (further addressed in the next commit). Co-Authored-By: Claude Sonnet 5 <[email protected]>
….sh's byte budget check_release_tree.py failed on the compiled session-start-hook.sh (123352 bytes, over the 120 KiB release budget) -- that hook was already within 37 bytes of the budget before this fix (per #1002's own comment), and lib-memory-dir.sh's new _remember_lmd_dir_is_unsafe block alone added 472 bytes to every hook that sources it (unconditionally, at top level, regardless of whether that hook's own code reads REMEMBER_DIR_UNSAFE -- tree-shaking only drops unused FUNCTIONS, not top-level code that runs to set the flag). Rewrote the predicate to the smallest form that still preserves byte-wise (#695) LC_ALL=C matching: two `[[ ]]` tests with early returns instead of a nested `{ } || [[ ]]` combined with a separate if/else/echo block, and a single bracket class `*[$'\n\r']*` for the embedded-control-character case instead of two separate `$'...'` glob tests. Also widens the UNC acceptance from "two backslashes then one non-backslash character" to "two backslashes then any one character", which incidentally narrows (but does not close) the auditor's below-bar bare-backslash finding. Updated tests/test_remember_dir_guard_920_sync.py to assert BEHAVIOURAL agreement across all three predicates (a table of REMEMBER_DIR values, run through each predicate, compared) rather than textual body equality -- the compact rewrite legitimately reads differently from the other two copies while classifying every case the same way, so a body-text diff is no longer the right invariant. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…eded export Further shrinks the new lib-memory-dir.sh block toward session-start-hook.sh's 120 KiB compiled-hook budget. Merges the separate predicate function and the if/echo block that called it into one function that sets REMEMBER_DIR_UNSAFE directly (default unsafe=1, cleared to 0 only on a recognised absolute/UNC shape, same as before). Drops `export REMEMBER_DIR_UNSAFE`: nothing reads this variable across a process boundary -- every script that checks it has already sourced lib-memory-dir.sh itself and computed its own copy in its own process, so export was pure overhead paid by every hook that sources this file. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Status: blocked on a maintainer decision, not on remaining engineering work. The duplicate top-level function name that broke compiled-hook tree-shaking (CI's What remains red is Three ways to close this, and none of them is mine to pick unilaterally:
Holding this PR open rather than merging or further modifying it until that call is made. @fdaviddpt |
* Fix #1067: shrink session-start-hook.sh's release-tree budget Move previous-session recovery, slug/case-divergence bookkeeping and capture-gap detection out of session-start-hook.sh into a new scripts/capture-gap-check.sh, invoked (not sourced) the same way scripts/consolidation-launch.sh already was for #1006. Compiled session-start-hook.sh had only 50 bytes of headroom under its 120 KiB release-tree budget, blocking #1064 and #1056; it now has over 21 KiB. Behaviour is unchanged: the moved code still runs inline (REMEMBER_DEFER=0) or backgrounded, exactly as session-start-hook.sh ran it before. Updates the several tests that extracted the moved functions' text directly out of session-start-hook.sh to read from the new file instead, adds a test pinning the 4 KiB headroom floor, and updates the hook-script-size-budget jit-context doc's stale figure. Co-Authored-By: Claude Sonnet 5 <[email protected]> * Fix #1067 review (PR #1069): retarget pinned test, fix fork regression, add parity test Three findings from PR #1069's review: 1. tests/test_case_rewrite_equivalence_898.py pinned a line that moved into scripts/capture-gap-check.sh along with capture_was_seen but still named scripts/session-start-hook.sh as its site -- would have failed on every OS once that leg ran, not just Windows. 2. capture-gap-check.sh re-ran resolve-paths.sh -> detect-tools.sh -> bootstrap-dirs.sh in full inside its own freshly forked process, redoing work its own parent (session-start-hook.sh) had already done and exported moments earlier -- landing directly on #1056 (fewer forks under concurrent Windows session starts). Fixed with a fast path that trusts PROJECT_DIR/PIPELINE_DIR/REMEMBER_DIR when already present and exported, falling back to the full chain otherwise (every direct/ standalone test invocation). The fast path also needed its own copies of resolve-paths.sh's _remember_forward_slash[_into] -- functions are never inherited across exec() the way exported variables are, and the first attempt at this fix omitted them, which tests/test_case_divergence_298.py caught (every external store misreported "not-applicable"). This is a bounded fix, not #1056's own scope: log.sh's own smaller config_into/log merge still runs inside capture-gap-check.sh regardless, needed for log()/config_into(). 3. tests/test_entrypoint_sniff_bookkeeping_message_803.py's own _function_body search tries session-start-hook.sh before capture-gap-check.sh, so every existing test exercised only the SESSION-START-HOOK.SH copy of the duplicated _stdin_json_string_into, never the one that actually runs at SessionStart time. Added a direct parity test asserting the two copies stay byte-identical. Also fixes two timing-sensitive tests the review flagged as newly racy: the deferred phase is now a genuinely separate process (capture-gap- check.sh), slower to start than the pre-#1067 in-process function call, so a "must appear" assertion reading an on-disk effect the instant the parent hook returns can race the still-running backgrounded child. Polls or runs inline (REMEMBER_DEFER=0) instead, matching this suite's own established convention for the difference between a "must appear" and a "must not appear" check. Co-Authored-By: Claude Sonnet 5 <[email protected]> * Fix #1067: CI parity test now strips comments before comparing PR #1069's "hook tests (compiled)" leg (ubuntu + windows) was red on the new _stdin_json_string_into parity test added in 23ed821. That leg runs session-start-hook.sh through compile_hooks.py's compile step first, which strips its whole-line comments (one of the four HOOK_SCRIPT_NAMES scripts the release build inlines); capture-gap-check.sh is never compiled and keeps its comments verbatim on every leg. A straight string comparison of the two copies therefore diverges on a comment-only line in compiled mode, while every plain pytest leg (which reads both files as source) stays green. Fixed the test, not the code: strip whole-line comments from both copies before comparing, delegating to compile_hooks.py's own strip_whole_line_comments rather than a second hand-written filter that could drift from what the build actually does. Added a positive control (test_stdin_json_string_into_copies_stripping_still_catches_real_divergence) proving the stripping does not swallow a real functional divergence on a non-comment line. Reproduced directly: ran compile_hooks.py --apply against a scratch copy of the tree and confirmed the raw comparison goes false (red, matching CI) while the comment-stripped comparison stays true (green). Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
|
Maintainer decision on the byte budget: neither raise the limit nor trim inside this PR. #1069 (fix for #1067) has merged and moved rarely used SessionStart code into a separate script; the built hook now has about 21 KiB of headroom. Rebase this branch on current [AI-generated] |
…cal users Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… the byte-pin guard test_the_per_tool_call_path_is_not_touched (#298/#299) byte-pins lib-memory-dir.sh against origin/main; the new _remember_lmd_set_dir_unsafe block is a deliberate addition this guard had no allowance for yet. Red before: 1 failed, 21 passed in tests/test_case_divergence_298.py. Green after: 26 passed (that file plus test_sanctioned_divergence_state_440.py). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… Windows windows-latest's four pytest legs plus the compiled-hook leg failed two tests in TestUncPathIsSafe (test_remember_dir_guard_920.py) and the cross-predicate consistency test (test_remember_dir_guard_920_sync.py): both guard predicates reported a value carrying an embedded newline as SAFE on windows-latest only, never on ubuntu/macos, and only for the two CASES entries containing a raw newline byte -- every newline-free case agreed across all three predicates on every platform. The guard predicates themselves are unchanged, correct POSIX shell. The break is in how the test harness got the probe value into the child bash process: a bare (list2cmdline leaves it unquoted -- no space/tab/quote to force quoting) argv element carrying a raw newline does not reliably survive to the child's own argv on Windows, since a win32 command line is a single string CreateProcess hands the child, which re-tokenizes it itself. An environment variable's value is not re-tokenized the same way, so both helpers now pass the probe value via env instead of argv. Reasoned, not observed: no Windows host available locally to reproduce the original failure or re-run the fix directly. Verified instead that the change does not regress the 22 tests in these two files plus test_remember_dir_guard_902.py on macOS (all still pass), and that the mechanism change is the minimal one that explains an argv-only, platform- only, newline-only failure pattern. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… first pass missed Seven findings from the scheduler's own review of 5345c9e, all addressed with TDD (red before fix, positive control after): 1. HIGH: capture-gap-check.sh's fast path (inherited PROJECT_DIR/ PIPELINE_DIR/REMEMBER_DIR, #1069/#1079) never re-sources lib-memory-dir.sh, so it could only see REMEMBER_DIR_UNSAFE if the parent exported it -- and lib-memory-dir.sh's own REMEMBER_DIR_UNSAFE=1 was a plain assignment, never exported. Now exported, and all three of this file's own mkdir sites (session-slug, case-divergence, REMEMBER_STORE_ROOT/tmp) gate on the inherited flag. Evidence for the main-regression question: origin/main (no #1064 at all) has ZERO occurrences of REMEMBER_DIR_UNSAFE in lib-memory-dir.sh -- gap 1 was never fixed there; #1067/#1086 added capture-gap-check.sh's own new mkdir sites onto that same pre-existing, still-open gap, not a regression of a working #902 guard. 2. HIGH: session-start-hook.sh:457's tmp/session-started.d mkdir (added by #1084/#1086, after this issue's own 806/1200/1630 gating pass) was never covered. Gated; new full-SessionStart-run test added (not just bootstrap-dirs.sh in isolation). 3. MEDIUM: changelog.d/920.fixed.md's "every memory-folder save site is now covered" overclaimed before round 2 landed the above; reworded to "every ... site this issue found", now true. 4. MEDIUM: doctor.sh's REMEMBER_DIR line printed OK unconditionally even when REMEMBER_DIR_UNSAFE=1 -- the refusal's only other trace is a stderr-only FATAL line Claude Code hides for exit-0 hooks, and user-prompt-hook.sh/capture-gap-check.sh both discard. Now FAILs (human report) and reports remember_dir_unsafe:true/false (--json, always present, never an absent key). 5. LOW: log.sh's _remember_log_dir_unsafe is never called at runtime any more -- documented as deliberately retained (not dead code to delete), since test_remember_dir_guard_920_sync.py extracts and runs it as the "log" arm of the three-way consistency check. 6. LOW: lib-memory-dir.sh's UNC regex accepted a third backslash (`[\\][\\]?*`) where post-tool-hook.sh/log.sh's copies refuse it (`[\\][\\][^\\]*`) -- brought in line with the stricter copies; new sync-test case pins it. 7. LOW: session-end-hook.sh's WARNING said "could not create ... /logs/autonomous" for both an unsafe-dir refusal and an ordinary mkdir failure. Split into two distinct messages. Every fix's test was confirmed red against the unfixed code and green against the fix, including the two-item hazard my own first session-start test initially missed vacuously (see that test's own docstring: an absolute-but-newline-bearing REMEMBER_DIR resolves outside cwd, so "nothing leaked under cwd" alone passes even with the gate fully reverted -- caught by re-deriving against "would this test pass if the code did nothing", fixed by asserting against the actual unsafe path instead). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
tests/test_windows_skip_triage_497.py (#497) requires every module with a module-level `pytestmark = pytest.mark.skipif(sys.platform == "win32", ...)` to have a row in docs/windows-skip-triage.md -- the new tests/test_doctor_unsafe_dir_visibility_920.py carries the same bash-subprocess skip reason as its sibling doctor.sh modules and had none. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…p, Windows test, plain-language changelog 1. The session-store pointer reaper swept by "no transcript under THIS project's SESSIONS_DIR", which is correct for the per-project reaper it was modelled on but wrong for a directory shared by every project: a live session started in a DIFFERENT project had no transcript under this one's folder at all, so its pointer was deleted the moment any other project's SessionStart happened to run. Sweeps by age alone now (REMEMBER_SESSION_STORE_POINTER_MAX_AGE_S, default 7 days). 2. A start that does not (re)write the pointer -- REMEMBER_DIR_UNSAFE, or the write itself failing -- used to leave an earlier start's pointer for the same session id in place, so write-handoff.sh still read a store this start never vouched for, bypassing #1064's own unsafe-store refusal. The pointer is now deleted whenever a start does not successfully republish it. Tested (resume onto an unsafe store). 3. The Windows-path shape test lived inside a module whose own module-level skipif(win32) pytest applies to every item regardless of a class's own docstring. Moved to its own file, tests/test_session_store_shape_windows_1083.py, with no skip, and triaged the parent module's remaining blanket skip in docs/windows-skip-triage.md (the CI check that enforces that list caught the omission). 4. The pointer reaper's foreground stat-per-foreign-pointer cost is moved to the same deferred/background phase this file already uses for other cleanup that nothing downstream of the current start reads back. The comment overclaiming "no new forks" is corrected. 5. changelog.d/1083.fixed.md rewritten for a non-technical reader. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… from cwd (#1093) * Fix #1083: pin the resolved store at SessionStart instead of guessing from cwd write-handoff.sh and doctor.sh used an ancestor walk, bounded by the innermost git toplevel, to disambiguate which store a session's note belongs to -- structurally blind to a resumed session's hint at a sibling directory, a nested repo/submodule one level in, and a non-git sibling the walk never even entered for. SessionStart now pins the resolved REMEMBER_DIR at a session-keyed pointer outside every project store ($HOME/.remember/tmp/session-store/<session-id>), written with a plain redirect and an atomic rename, overwritten on every start including --resume. write-handoff.sh and doctor.sh read that pointer first, through one shared resolver library (scripts/lib-session-store.sh) that replaces each script's own pasted copy of the ancestor-walk logic. The ancestor walk survives only as a fallback for a session that predates the pointer, and now refuses outright when more than one candidate store matches, rather than tie-breaking by mtime -- a same-second write defeated that tie-break outright. The existing stale-hint reaper in session-start-hook.sh is extended to sweep these pointers too. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * Scheduler review on #1083: cross-project reaper, stale-pointer-on-skip, Windows test, plain-language changelog 1. The session-store pointer reaper swept by "no transcript under THIS project's SESSIONS_DIR", which is correct for the per-project reaper it was modelled on but wrong for a directory shared by every project: a live session started in a DIFFERENT project had no transcript under this one's folder at all, so its pointer was deleted the moment any other project's SessionStart happened to run. Sweeps by age alone now (REMEMBER_SESSION_STORE_POINTER_MAX_AGE_S, default 7 days). 2. A start that does not (re)write the pointer -- REMEMBER_DIR_UNSAFE, or the write itself failing -- used to leave an earlier start's pointer for the same session id in place, so write-handoff.sh still read a store this start never vouched for, bypassing #1064's own unsafe-store refusal. The pointer is now deleted whenever a start does not successfully republish it. Tested (resume onto an unsafe store). 3. The Windows-path shape test lived inside a module whose own module-level skipif(win32) pytest applies to every item regardless of a class's own docstring. Moved to its own file, tests/test_session_store_shape_windows_1083.py, with no skip, and triaged the parent module's remaining blanket skip in docs/windows-skip-triage.md (the CI check that enforces that list caught the omission). 4. The pointer reaper's foreground stat-per-foreign-pointer cost is moved to the same deferred/background phase this file already uses for other cleanup that nothing downstream of the current start reads back. The comment overclaiming "no new forks" is corrected. 5. changelog.d/1083.fixed.md rewritten for a non-technical reader. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * Fix #1083: use Git Bash resolution for the Windows shape test, not raw "bash" First CI round on windows-latest showed the literal string "bash" there resolving to the WSL launcher, which prints "Windows Subsystem for Linux has no installed distributions" and exits nonzero -- exactly the hazard tests/_bash_runner.py's own module docstring documents, and that several other test files already route around via resolve_bash()/find_git_bash(). Switched to that helper, and moved the value under test onto stdin (octal-escaped via bash_octal/printf '%b') rather than argv -- argv is not trusted on Windows either, since Git Bash rebuilds it from the raw Windows command line itself (run_bash_file's own docstring). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Closes #920.
What this fixes
Issue #920 reported three gaps in #902's safety guard around REMEMBER_DIR:
scripts/bootstrap-dirs.shand five othermkdir -p "$REMEMBER_DIR/..."sites built the directory tree with no check that REMEMBER_DIR was safe (absolute, no embedded newline/CR) -- only two sites were ever gated by post-tool-hook: failed seed of save-HHMMSS.log → WARNING logged under a REMEMBER_DIR built from the log file's CONTENT; thousands ofHH:MM:SS [post-tool] save triggered\ndirs in the project root #902's own fix.scripts/log.sh'slog()function silently lost a FATAL message once the unsafe-dir sink was active: it appended to$MEMORY_LOG_FILE, which becomes/dev/null, and an append to/dev/nullalways succeeds, so the|| echo ... >&2fallback never ran.\\server\share\proj) was misclassified as unsafe by the guard predicates, which only recognized a leading/or a drive letter as absolute.Fix
scripts/lib-memory-dir.sh(new_remember_dir_is_unsafefunction, new exportedREMEMBER_DIR_UNSAFEflag, computed once after REMEMBER_DIR is resolved) and gated every previously-unguarded mkdir site on it.post-tool-hook.sh's fast path keeps its own pre-existing local copy of the same predicate, since it never sources lib-memory-dir.sh.log()'s write-to-sink behaviour: when the sink (/dev/null) is the active target, write straight to stderr instead of attempting an append nobody can read back.tests/test_remember_dir_guard_920.py(one must-fire case and one must-not-fire positive control per gap).tests/test_locale_ranges_695.py's line-number allowlist to track lines shifted by the new guard code.changelog.d/920.fixed.mdadded, verified against.oss/assemble_changelog.py --check.Self-review round
Spawned
Exploreandoss:auditorconcurrently. Tree snapshot clean both before and after.Explore returned 4 findings:
REMEMBER_DIR_UNSAFEflag instead of recomputing and re-announcing it.post-tool-hook.shstill carries its own, separately-defined copy of_remember_dir_is_unsafe(pre-existing since post-tool-hook: failed seed of save-HHMMSS.log → WARNING logged under a REMEMBER_DIR built from the log file's CONTENT; thousands ofHH:MM:SS [post-tool] save triggered\ndirs in the project root #902) because its fast path never sources lib-memory-dir.sh. The two copies silently shadow each other by name, staying harmless only because both bodies are byte-identical. Restructuring the sourcing architecture is out of this issue's scope; addedtests/test_remember_dir_guard_920_sync.pyinstead, which fails loudly the moment the two copies diverge.oss:auditor returned 1 finding, below-bar:
the UNC regex requires a third character after the two leading backslashes, so a bare backslash-backslash with nothing after it is still classified unsafe -- no realistic project directory takes that shape. Rated very low severity by the auditor: no realistic project-directory value takes this shape, nothing is lost or exposed. Not fixed in this pull request; logged to
trap.d/920.unc-bare-backslash-edge-case.mdper the routing table inskills/manager/phases/findings.md.Testing
RED before fix / GREEN after, both commits.
python3 -m pytest tests/test_remember_dir_guard_920.py -q: 5 of 8 failed before any shell fix existed; 8 passed after. After the self-review round:python3 -m pytest tests/test_remember_dir_guard_920.py tests/test_remember_dir_guard_920_sync.py tests/test_remember_dir_guard_902.py tests/test_locale_ranges_695.py -q-- 27 passed. The repository's fullpytest(no path filter) was deliberately not run locally, per this repo's own CLAUDE.md -- CI's matrix (3 OSes x 4 interpreters) is the actual gate.[AI-generated]