fix(extract): normalize whitespace before truncating rationale labels (#2206) - #2246
Open
Yyunozor wants to merge 1 commit into
Open
fix(extract): normalize whitespace before truncating rationale labels (#2206)#2246Yyunozor wants to merge 1 commit into
Yyunozor wants to merge 1 commit into
Conversation
…Graphify-Labs#2206) _extract_python_rationale / _extract_js_rationale sliced the raw docstring/comment text to 80 characters before collapsing whitespace, so the cut could land mid-word, leave a run of literal spaces where a newline + indentation used to be, and, when the cut landed on a ".", produce an Obsidian export filename ending in "..md". Both _add_rationale sites now share _shorten_rationale_label, which normalizes whitespace first via textwrap.shorten (word-boundary safe, adds a placeholder only when it actually truncates) and falls back to a plain character truncation when shorten collapses to a bare placeholder -- which it does when the first word alone is already >= 80 chars (e.g. a comment opening with one long URL), a case that would otherwise regress to a content-free label.
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.
Summary
_extract_python_rationale/_extract_js_rationalebuild rationale node labels by slicing the raw docstring/comment text to 80 characters before normalizing whitespace. This can cut a word in half, leave literal spaces where a newline + indentation used to be, and — when the cut lands on a.— produce an Obsidian filename ending in..md. Not export-only: it's thelabelingraph.json, so the artifacts show up inGRAPH_REPORT.md,graphify query, andexplaintoo.Reproduction
Before: label ends
"...because upstream feed"(80 chars, "feeds" sliced mid-word). A docstring whose 80th char lands on a sentence-ending.exports as...and caches..md.Root cause
Both
_add_rationaleclosures ingraphify/extract.pydo:The slice runs before whitespace normalization, so it can land inside a word or a newline's collapsed space run, and
.strip()only trims surrounding whitespace, never a trailing period.Fix
Both sites now call a shared
_shorten_rationale_label:textwrap.shortencollapses whitespace, then drops whole words from the end (never mid-word), adding the placeholder only when it truncates — a short label is unchanged. The fallback guards ashortenquirk: a first word alone >= 80 chars (e.g. one long URL opening a comment) collapses to a bare"…", worse than the parent's raw slice. The fallback restores content.Known limitation
shortenleaves an untruncated label's own trailing punctuation alone, so a short rationale legitimately ending in.still hits a separate, pre-existing gap:export.py's twosafe_name()(~L500, ~L801) strip.md/.mdx/.qmd/.markdownbut not a bare.. Different file, out of scope here — a follow-up would strip a trailing.insafe_name, as it already strips a leading one (#2205).Validation
Nine new tests in
tests/test_rationale.py, split across Python and JS/TS: word-boundary truncation, whitespace-run collapse, no-trailing-period, long-token fallback, short-docstring non-regression. All fail on parent with the reported symptom, pass after the fix.Delta is exactly these 9 tests; skip set identical both sides. Cross-checked on Python 3.10.
ruff checkand all fivetools.skillgenguards clean;graphify updatesmoke run OK.