Repository navigation
fix(slug): one session-directory slug, and make it truncate - #187
Merged
Merged
Conversation
Three implementations, three different answers, one consequence each time: the plugin computes a ~/.claude/projects/<slug>/ that Claude Code never created, finds no transcript, and saves nothing without saying so. #157 — nothing truncated. Past 200 characters Claude Code keeps the first 200 and appends a hash of the ORIGINAL path (charCodeAt, wrapped to signed 32-bit each round, base36). A project path deep enough to cross that — ordinary monorepo nesting under a long home directory — therefore never saved at all. #158 — lib-memory-dir.sh carried its own naive inline copy: the pre-#144 implementation, with every bug #156 fixed. Not dead code. user-prompt-hook.sh reaches that file without sourcing detect-tools.sh, so in external-storage mode ({slug} in data_dir) that one hook resolved a DIFFERENT REMEMBER_DIR than every other one. Split-brain memory, which hides better than a clean failure. #174 — pipeline/extract.py still used a codepoint regex. Claude Code's has no /u flag and walks UTF-16 code units, so an astral character (emoji, Extension-B kanji) costs two dashes there and one here. Live in 0.8.7, in the one copy nobody re-pointed at the fixed oracle. The algorithm now lives in pipeline/slug.py and scripts/lib-slug.sh, the latter sourced by both detect-tools.sh and lib-memory-dir.sh. Sourcing detect-tools.sh from lib-memory-dir.sh is not an option — it runs Python detection at source time and exits 1 when it finds none, taking its caller with it, which is presumably why the duplicate existed. The shell side calls the Python one for the over-long hash only: bash does not do signed-32-bit wraparound and base36 well, and only long paths pay the subprocess. With no Python reachable it falls back to the untruncated slug — wrong exactly as before rather than crashing, and #156's warning now reports it. A hash that is not base36 is refused the same way: it can only come from a stale or wrong-version plugin copy resolved through PIPELINE_DIR, and appending it verbatim would invent a NEW wrong directory instead of falling back to the old wrong one. tests/test_slug_parity.py checks bash and Python against an independent transcription of the shipped CLI's function rather than against each other, over ASCII, accents, CJK, emoji, astral kanji, newlines, and lengths either side of 200 — and drives the three real entry points, not just the helpers. Six of its test IDs go red against the pre-fix code, covering the three defects (three of them are one parametrized test for #174). The byte table's own comment overstated its guarantee: it diverges from the decoder for any lead byte missing its continuations, not only at end of string, and Linux does not enforce well-formed UTF-8 in filenames the way the comment assumed macOS and Windows do. Narrowed to the truth and tracked in #186. Co-Authored-By: Max <noreply>
This was referenced Jul 26, 2026
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.
Closes #157, #158, #174.
Three implementations of the same rule, three different answers, and one consequence each time: the plugin computes a
~/.claude/projects/<slug>/that Claude Code never created, finds no transcript, and saves nothing without saying so. That is the fourth-and-fifth-and-sixth report of a shape this repo already knows (#144, #166).What was wrong
#157 — nothing truncated. Past 200 characters Claude Code keeps the first 200 and appends a hash of the original path (
charCodeAt, wrapped to signed 32-bit each round, base36). A project path deep enough to cross that — ordinary monorepo nesting under a long home directory — never saved anything at all.#158 —
lib-memory-dir.shcarried its own naive copy, the pre-#144 implementation with every bug #156 fixed. Not dead code:user-prompt-hook.shreaches that file without sourcingdetect-tools.sh, so in external-storage mode ({slug}indata_dir) that one hook resolved a differentREMEMBER_DIRthan every other. Split-brain memory hides better than a clean failure.#174 —
pipeline/extract.pyused a codepoint regex. Claude Code's has no/uflag and walks UTF-16 code units, so an astral character (emoji, Extension-B kanji) costs two dashes there and one here. Live in 0.8.7, in the one copy nobody re-pointed at the fixed oracle.The shape of the fix
pipeline/slug.py(Python) andscripts/lib-slug.sh(shell, sourced by bothdetect-tools.shandlib-memory-dir.sh).Sourcing
detect-tools.shfromlib-memory-dir.shinstead is not available: it runs Python detection at source time andexit 1s when it finds none, taking its caller down with it. That is presumably why the duplicate existed in the first place.The shell side calls the Python one for the over-long hash only — bash does not do signed-32-bit wraparound and base36 well, and only long paths pay a subprocess. Two ways that can go wrong, both handled:
PIPELINE_DIR, and appending it verbatim would invent a new wrong directory instead of falling back to the old wrong one.Tests
tests/test_slug_parity.pychecks bash and Python against an independent transcription of the shipped CLI's function — not against each other — over ASCII, accents, CJK, emoji, astral kanji, embedded newlines, and lengths either side of 200. It drives the three real entry points (extract._session_dir,detect-tools.sh, and the actual{slug}resolution), not just the helpers: my first draft tested only the new modules and passed against the pre-fix code, which proved nothing.Six test IDs go red against pre-fix code, covering the three defects (three of them are one parametrized test for #174). Full suite: 784 passed, 41 skipped.
Review
An adversarial pass fuzzed both implementations against a
nodeoracle running the real function — 46 hand-picked plus 3000 randomized paths, lengths 0–500 — with zero mismatches, and independently verified the revert-proof claim.It also found that the byte table's own comment overstated its guarantee: it diverges from the decoder for any lead byte missing its continuations, not only at end of string, and Linux does not enforce well-formed UTF-8 in filenames the way that comment assumed macOS and Windows do. The comment now says what is true, and the gap is tracked in #186 rather than papered over.