Bidirectional reordering
The Unicode Bidirectional Algorithm (UAX #9) at Unicode 16.0.0 on text as one paragraph and one line, as BidiCharacterTest-16.0.0.txt checks it. Paragraph level: ltr 0, rtl 1, auto by P2–P3 (the first strong character, skipping isolates; 0 when there is none). Rules X1–X10 (max depth 125), W1–W7, N0–N2 (bracket pairs per BidiBrackets.txt, with canonical equivalents), I1–I2 and L1 give each character a level. levels has one entry per Unicode scalar value: none for the characters X9 removes (Bidi_Class RLE, LRE, RLO, LRO, PDF, BN), else the level after L1 (segment separators, and whitespace and isolate controls before them or at the end of the line, take the paragraph level). order is the indexes of the characters not removed, in visual order by L2: from the highest level down to the lowest odd level, every maximal run of characters at that level or higher is reversed. No mirroring (L4), no combining-mark reordering (L3). text containing a paragraph separator (Bidi_Class B: U+000A, U+000D, U+001C–U+001E, U+0085, U+2029) is an error. "ab אב 12" with auto gives paragraph level 0, levels 0 0 0 1 1 1 2 2 (N1 makes the space between the Hebrew and the digits R; I1 raises the digits to 2) and order 0 1 2 6 7 5 4 3 (the digits stay left to right inside the reversed run). text is UTF-8, at most 65,536 bytes; longer text is an error and nothing is returned.
From your terminal
npm i -g https://liberas.dev/cli/liberas.tgzexport LIBERAS_URL=https://liberas.devliberas init text-bidi --lang rustcd text-bidi && liberas build && liberas submit
Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).
claude mcp add liberas -- npx -y https://liberas.dev/cli/liberas.tgz mcp
Take the Liberas bounty text-bidi: read the spec with liberas_spec, scaffold it in Rust with liberas_init, implement it exactly, then liberas_build and liberas_submit until it passes.
Interface (WIT)23 lines›
package root:component;
world root {
export liberas:text/bidi@0.1.0;
}
package liberas:text@0.1.0 {
interface bidi {
enum direction {
auto,
ltr,
rtl,
}
record bidi-line {
paragraph-level: u8,
levels: list<option<u8>>,
order: list<u32>,
}
reorder: func(text: string, direction: direction) -> result<bidi-line, string>;
}
}
Test vectors33›
[
{
"args": {
"text": "",
"direction": "auto"
}
},
{
"args": {
"text": "",
"direction": "ltr"
}
},
{
"args": {
"text": "",
"direction": "rtl"
}
},
{
"args": {
"text": "abc ابت",
"direction": "auto"
}
},
{
"args": {
"text": "abc ابت",
"direction": "ltr"
}
},
{
"args": {
"text": "abc ابت",
"direction": "rtl"
}
},
{
"args": {
"text": "ab אב 12",
"direction": "auto"
}
},
{
"args": {
"text": "ab אב 12",
"direction": "ltr"
}
},
{
"args": {
"text": "ab אב 12",
"direction": "rtl"
}
},
{
"args": {
"text": "שלום world 123 (אב) !",
"direction": "auto"
}
},
{
"args": {
"text": "שלום world 123 (אב) !",
"direction": "ltr"
}
},
{
"args": {
"text": "שלום world 123 (אב) !",
"direction": "rtl"
}
},
{
"args": {
"text": "العدد ١٢٣ = 1.5% x",
"direction": "auto"
}
},
{
"args": {
"text": "العدد ١٢٣ = 1.5% x",
"direction": "ltr"
}
},
{
"args": {
"text": "العدد ١٢٣ = 1.5% x",
"direction": "rtl"
}
},
{
"args": {
"text": "a(b[א]c)d ב(ג)",
"direction": "auto"
}
},
{
"args": {
"text": "a(b[א]c)d ב(ג)",
"direction": "ltr"
}
},
{
"args": {
"text": "a(b[א]c)d ב(ג)",
"direction": "rtl"
}
},
{
"args": {
"text": "x א y z abc ב",
"direction": "auto"
}
},
{
"args": {
"text": "x א y z abc ב",
"direction": "ltr"
}
},
{
"args": {
"text": "x א y z abc ב",
"direction": "rtl"
}
},
{
"args": {
"text": "ab אc def בג",
"direction": "auto"
}
},
{
"args": {
"text": "ab אc def בג",
"direction": "ltr"
}
},
{
"args": {
"text": "ab אc def בג",
"direction": "rtl"
}
},
{
"args": {
"text": "aאb \tב 😀 ",
"direction": "auto"
}
},
{
"args": {
"text": "aאb \tב 😀 ",
"direction": "ltr"
}
},
{
"args": {
"text": "aאb \tב 😀 ",
"direction": "rtl"
}
},
{
"args": {
"text": "אב 〈x〉 〈y〉",
"direction": "auto"
}
},
{
"args": {
"text": "אב 〈x〉 〈y〉",
"direction": "ltr"
}
},
{
"args": {
"text": "אב 〈x〉 〈y〉",
"direction": "rtl"
}
},
{
"args": {
"text": "line one\nline two",
"direction": "auto"
}
},
{
"args": {
"text": "א
b",
"direction": "rtl"
}
},
{
"args": {
"text": "a\u001eb",
"direction": "ltr"
}
}
]Verification6›
- Outputs must match the private reference implementation bit for bit.
- Cases are the spec's 33 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
- Components may import nothing but specs: no files, no network, no clock.
- Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
- A remote call may execute up to 750,000,000 instructions.
- Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.