Repository navigation
fix(media): keep each index.md row on one line and show control characters as escapes - #8127
Conversation
…cters as escapes The .media/index.md generators (figma's mediaIndex.ts and media-use's index-gen.mjs) turned only CR and LF in a record into a space. Vertical tab, form feed, NEL, U+2028 and U+2029 still ended a row early for readers that treat them as line breaks, and other control characters (NUL, ESC, BEL, C1) reached the file as raw bytes. - Every line-ending character now becomes a space. - Other control characters are written as visible \xNN escapes through the existing terminalText helper; tabs stay as they are. - Both generators and the skill copy change together, so their output stays byte-identical.
Edit accuracy: accurate 271 (base branch 271), smooth 44 of thoseThe gate passes. Quarantined, measured but not gated (0) Unstable (2)
|
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 6b5ad36.
The copies match. The two index-gen.mjs copies (packages/cli/src/media-use/lib and skills/media-use/scripts/lib) have the same blob (2e6cf0a6ad5). The terminal-text.mjs they import is also the same blob in both places (7cd7d9b8). Its isControlCode is character-for-character core's terminalText.ts. mediaIndex.ts uses the same LINE_BREAKS pattern and core's terminalText, and the existing byte-for-byte test keeps the core and media-use outputs identical. The skills-manifest hash bump matches the changed skill file.
Escaping is right.
LINE_BREAKSfolds CR, LF, VT, FF, NEL, U+2028 and U+2029 (plus surrounding whitespace) into one space before escaping, so none of them can start a new line of the index.terminalTextthen escapes every remaining C0 control except tab, plus DEL and the whole C1 range (0x7f–0x9f). So ESC, BEL, NUL and the 8-bit CSI (\x9b) all come out as visible\xNN.- The new tests cover each line-break kind and each of those escapes, including a CSI colour sequence.
Nits, not blocking:
- Bidi controls (U+202A–U+202E, U+2066–U+2069) and zero-width characters pass through unescaped. They aren't line breaks or C0/C1, so they're outside this PR's scope. But a description holding U+202E can still reorder how a row reads in a terminal or editor. If the index is meant to be safe to show as-is, adding those ranges to
isControlCodein all three copies would cover it. - A
|in a value still splits a markdown table cell. That predates this PR, and the index is read as text, so it's cosmetic.
What
.media/index.mdcells now turn every line-ending character into a space, and show other control characters as visible\xNNescapes. Tabs are unchanged.Why
The index generators turned only CR and LF in a record into a space. Vertical tab, form feed, NEL, U+2028 and U+2029 still split a row for readers that treat them as line breaks, and NUL, ESC, BEL and C1 characters reached the file as raw bytes.
Related work
Follows the line-break handling added to both generators in #8111.
How
LINE_BREAKSpattern (\r \n \v \f U+0085 U+2028 U+2029) collapses to a single space, as CR/LF already did.terminalTexthelper (core'sterminalText.ts, and media-use's copyterminal-text.mjs), which writes control characters as\xNNand keeps tabs.mediaIndex.ts, media-use'sindex-gen.mjsand the skill copyskills/media-use/scripts/lib/index-gen.mjschange together, so their output stays byte-identical.skills-manifest.jsonpicks up the skill's new hash.Test plan
mediaIndex.test.ts: rows with U+2028, U+2029, NEL, VT and FF stay one line each; NUL, ESC, BEL, DEL and C1 appear as\xNNand tabs stay. Both fail before this change.index-gen.mjsruns on the new rows and passes.manifestandresolvesuites, andcheck-media-use-copy-paritypass; lint, format, typecheck and both comment checks pass.