Skip to content

refactor(s): one grammar reads every terminal escape - #1590

Open
rudolphpienaar wants to merge 5 commits into
mainfrom
sec/s-e1
Open

rudolphpienaar wants to merge 5 commits into
mainfrom
sec/s-e1

Conversation

@rudolphpienaar

@rudolphpienaar rudolphpienaar commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Stage S, item S4 (duplicated sources of truth), part 1: one grammar reads every terminal escape.

  • The grammar: one ECMA-48 state machine in menu (packages/menu/src/ansi/grammar.ts).
    • Recognises CSI and its C1 form, OSC to BEL or either ST, DCS/SOS/PM/APC, charset and two-byte sequences.
    • String payloads and CSI parameters are bounded, so a flood cannot grow memory.
    • Two faces over it: whole strings (ansi_tokenize, ansi_strip, ansi_width, ansi_present, ansi_renderHtml) and streams (AnsiTokenizer, AnsiPlainStream, taking strings or UTF-8 bytes).
  • Every site uses it, about 35 hand-written patterns across argus, porter, brasa, calypso, chell, stratus and chili.
    • This includes the streaming ones: the joblet log, pipe and tee sinks, chell's row counter, calypso's face log, stratus's plugin rows.
    • fond no longer reads an escape at all (ListingLook.name_width is supplied by its callers).
  • The invariant: for any input and any way of cutting it, at UTF-16 units or at bytes, the streamed tokens and text equal the whole-string ones.
    • Stripped text holds no control, and stripping is idempotent.
    • Each streaming consumer has a chunking test; a differential test runs the six old patterns.
  • chell's row counter now follows a real autowrapping terminal.
  • porter reads a container's last words as raw frames in order and redacts the token there.
  • Guard: eslint.escapes.config.mjs (inside lint:seam, no inline disables) forbids an escape regex anywhere but the grammar. test:ratchets plants three and checks each fails.

One site waits for the scene-disposal PR (features/dag/refusal.ts), named in the guard with its reason. brasa and argus no longer export their own ansi_strip.

@rudolphpienaar rudolphpienaar changed the title sec/s e1 refactor(s): one grammar reads every terminal escape Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant