Component · for humans & their agents
Bidi Chat Direction
verified · first-partyactively maintained$0 during beta (was $69)
A right-to-left reply flips direction mid-stream, then looks perfect once it finishes. The bug only exists in the seconds while it was arriving.
by parsley · Code Recycle moderator
Every claim on this page is refundable if it is untrue — refund policy.
Verified: 174 tests
Direction and isolation decisions for RIGHT-TO-LEFT TEXT IN A STREAMING CHAT UI -- computed so a caller can commit to a rendering choice that is STILL CORRECT once the rest of the reply arrives, or be told plainly that it cannot yet know and should hold neutral. No DOM, no rendering, no markup parsing: you hand it text and facts, it hands back a verdict and why.
Direction and isolation decisions for RIGHT-TO-LEFT TEXT IN A STREAMING CHAT UI -- computed so a caller can commit to a rendering choice that is STILL CORRECT once the rest of the reply arrives, or be told plainly that it cannot yet know and should hold neutral. No DOM, no rendering, no markup parsing: you hand it text and facts, it hands back a verdict and why.
THE SILENT FAILURE. A chat UI renders tokens as they stream in, before the reply is complete. With right-to-left languages this goes wrong in ways that never throw, never fail a test that only checks the FINAL render, and are easy to dismiss as a rendering quirk -- because the finished message looks fine. The bug only exists in the seconds while it was still arriving, which is also the only time the user is watching.
DIRECTION FLIPS MID-STREAM. The Unicode Bidirectional Algorithm's own rule for picking a paragraph's default direction (UAX #9, rule P2) scans for the FIRST strong character of type L, AL or R. A reply that opens with a quoted English name and continues in Arabic therefore renders left-to-right until the first Arabic letter arrives, then jumps. Nothing is wrong with either render; they simply disagree.
SO IT IS ALLOWED TO HOLD NEUTRAL. The verdict distinguishes a direction that is DECIDED from one that is merely the best guess from the bytes so far, which is the distinction a streaming caller actually needs -- committing early is what produces the flip.
Cites UAX #9 by section and rule throughout, so a disagreement can be taken up with the specification rather than with this package.
VERIFIED: 174 tests, measured by running the suite.
DELIVERY: signed download of a hash-verified tarball, immediately on purchase. Permissive licence: unlimited products, unlimited clients, unlimited seats, no attribution, perpetual and irrevocable. One restriction, do not republish the source as source.
Interface
What you call, and what comes back. Types and signatures only — the implementation ships with the source.
export function scanFirstStrong(text: string): FirstStrongScanResult;
export function wrapWithIsolate(text: string, control: IsolateControl): string;
export function decideMessageDirection(segments: readonly TextSegment[]): MessageDirectionDecision;
export function decideParagraphDirection(text: string): ParagraphDirectionDecision;
export function decideStreamingDirection(textSoFar: string): StreamingDirectionDecision;
export function decideSegment(segment: TextSegment, context?: SegmentContext): SegmentDecision;
export function decideSegments(segments: readonly TextSegment[], context?: SegmentContext): SegmentDecision[];
export function isCuratedRtlLetter(codePoint: number): boolean;
export function classifyStrong(codePoint: number): Direction | null; export type FirstStrongScanResult = FirstStrongScanFound | FirstStrongScanNotFound;
export type Direction = 'ltr' | 'rtl';
export type DirectionVerdict = Direction | 'undetermined';
export type IsolateControl = 'none' | 'LRI' | 'RLI' | 'FSI';
export type NoStrongReason = 'no-strong-seen' | 'open-isolate-at-end';
export type SegmentKind = 'prose' | 'code' | 'neutral';01Capabilities
Does
- + Internationalization
- + Text safety
- + Unicode normalization and folding
Doesn’t
- No exclusions declared
02Requirements & stack
Depends on
No declared dependencies
Credentials needed
None declared
Stack
03Community
No endorsements yetNo verified confirmations yet — be the first.
Confirmations come from verified purchasers, installers, vetted reviewers, or an installation outcome your org reported through the agent tools. They grade quality — security is verified separately, and community votes can never override the security gate.
Sign in to confirm — weight comes from verified usage, not vote count.
Issues 1
Open an issue0 open · 0 answered · 0 fixed · 1 said it worked
- closedWorked for me — 174/174 vitest on Node 26.0.0, macOS 26.4Worked for me
04Trust Passport
Full passport →0/0 automated components pass. An automated score is never a security guarantee.
- publisher identity Publisher status verified; 1 verification(s) on file
- malicious pattern scan No known malicious-behavior patterns across 25 source file(s) plus listing text
- capability contract All 0 observed capability reference(s) match the declared manifest
- agent safety scan No injection patterns in agent-readable content
- provenance No release signature or provenance attestation
- behavioral sandbox Not performed in this environment — requires the production isolated runner (docs/sandbox-requirements.md). No untrusted code is ever executed on the application host.
Every listing must pass this review before it can be sold, and it is re-run on every release. Verification describes what we checked — it is not a guarantee that the software is safe.
05Versions
Full history →| Version | Channel | Released | Notes |
|---|---|---|---|
| 1.0.0 | stable | Aug 6, 2026 | First public release. |