Skip to main content

Module heal

Module heal 

Source
Expand description

LLM Heal: the fairy that mends a reader’s English (work/LLM_HEAL.md, DAT-108).

A person types English straight into the Studio’s editor, typos and loose phrasing and all, and presses Heal. The text goes to the heal worker (services/heal), which asks a model for the same text as clear, idiomatic LOGOS or logic sentences; the fairy flies to the lines the mend touched and a card shows both versions with Keep and Undo. Nothing lands in the editor until Keep is pressed. This module is the pure core: the wire shapes, the line diff, the flight’s state machine, the worker’s address, the pixelation schedule and the dock bar’s words. The workbench draws it.

Structs§

Answer
The worker’s answer: { ok: true, healed, model } or { ok: false, error }.
LineDiff
What a line diff touched on each side: the ranges of before lines the mend replaced or removed, and of after lines it wrote or added, by the longest common subsequence of lines (spaces at a line’s end ignored). The card marks both sides from this.
Request
The body the worker reads: { "mode": "code" | "logic", "text": "...", "fragment": true }, the text as written. fragment says the text is the lines a person just wrote inside a program that is already right, so the model mends those lines only and answers with them alone.

Enums§

Flight
Where the fairy is and what the card shows.
Mode
The two Studio modes that heal, as the worker names them.

Constants§

EMPTY_EDITOR
What the dock bar says when Heal is pressed over an empty editor.
ENDPOINT
Where a heal is sent: LOGOS_HEAL_URL at build time (nas2’s dev build points at a wrangler dev of the worker), else production.
FAIRY
The fairy, served from the site (the L of Z, her quest form).
NOTHING_NEW
What the dock bar says when nothing has changed since the file opened or was last kept.

Functions§

changed_lines
The line ranges of after the mend touched, by a line diff: identical texts give none, a one-word fix gives that line alone, lines added give their run, and lines deleted give an empty range where they were. Spaces at a line’s end do not count as a change.
edited_regions
The regions of current a person wrote since baseline (the text the file opened with, or was last kept at): the runs of lines that differ, by the line diff, neighbours within one line merged into one region, and nothing for lines only removed. Only these go to the worker, so a heal touches what the person typed and never the code that was already there (the user, 2026-11-02).
line_diff
narration
What the dock bar says while a heal is under way; nothing when the fairy is home.
outcome
The healed text from the worker’s status and body, or the sentence the card shows instead.
pixel_steps
The order in which len characters dissolve, deterministic from seed, so the two halves of the animation mirror: the new text forms in the reverse of this order.
reason
The worker’s named error as the sentence the card shows.
region_text
The lines of text in region, as one text to send.
reindent
The mended lines at the indentation the region had: a model that drops a fragment’s leading spaces (the first line of an indented block comes back at the margin) gets them put back, on every mended line shallower than the region’s first line, so the splice keeps the block.
same_text
Whether two texts say the same thing line for line, spaces at a line’s end and blank lines at the end aside: a mend that only moved whitespace is no mend.
send
POST the text to the worker. On the web, the answer as outcome reads it; on the server there is nothing to send to.
splice
text with each region’s lines replaced by the mended lines it got back, last region first so earlier line numbers stay true; the rest of the text is untouched, byte for byte.
word_marks
A line as pieces, each marked whether it differs from the other line: the common prefix and suffix of words stay plain, what lies between is the mend. For the card to show the word that changed, not only the line.