Repository navigation
Read an agent message's options apart in its thread's name and Done row - #6198
Conversation
A thread named by its opening message, and On Me's Done row for it, ran a choice's option titles together when the agent's message carried an lf-options group: "Open it nowHold it". prepareAuthoredMessage took the message's words from the inert fragment's textContent, so adjacent blocks met with no space. It now reads them with the passage reader's `says`, as accessible names and page search do, from a copy of the fragment inside a <div> of the template's inert document, where no widget upgrades. Probed on the on-me-thread-choice state in Chromium and Firefox: the Threads row and the Done row read "Open it nowHold it" on main and "Open it now Hold it" here.
leaf-agent
left a comment
There was a problem hiding this comment.
One consumer of the prepared text doesn't read it on one line. openingLine in thread/messages.js takes a message's first line (messageText(message).split("\n").map(labelWords).find(Boolean)), and threadPreview shows that as the detail line for a thread's last message. textContent kept the newlines an agent writes between blocks. So <p>Opened the PR.</p>\n<p>CI is running…</p> used to preview as "Opened the PR.", and with says collapsing whitespace it now previews the whole message, cut at PREVIEWED_LINE.
Markup with no newline between blocks already read as one run before this change, so openingLine's "first line" was never a reliable reading for authored messages. To settle this, either give openingLine a definition that says can answer, such as the first block, or accept that the preview shows the start of the message and say so. Whichever you choose, the description's claim that "every consumer of that text puts it on one line" becomes main's commit message, so it should name this one.
…element's words end, at page protocol 47 (#6216) A thread's name, On Me's Done row and `leaf page state` read an option such as `<lf-option><strong>Leave it</strong>; the send keeps…</lf-option>` as "Leave it ; the send keeps…", and `(<code>beta</code>)` as "( beta )". They now read "Leave it; the send keeps…" and "(beta)". The page protocol moves from 46 to 47. Found in review of #6198. ## Cause Outside a text block, the words a reading shows put a space where two elements' words meet with nothing between them, since a page most often draws them apart: a chip beside its title, or an `lf-option`'s title above its description. The same rule put a space where an inline element's words meet punctuation. The rule lives in `shownApart` (`passages.js`) and in `_write`'s soft space (`passages.py`). #6198 moved thread names and Done rows onto `says`, which reads it. ## Change Both readings now leave that space out before a closing mark and after an opening one. The two lists are new kernel facts, `$passages.closing` (`. , ; : ! ? … ) ] } ' ’ ” »`) and `$passages.opening` (`( [ { " ‘ “ «`), which both runtimes read; `why-closing-and-opening` beside them says why. A straight `'` only closes, as a possessive after code does (`<code>Foo</code>'s`). A straight `"` only opens, so a chip before a title that opens with a quote (`<small class="tag">recommended</small><strong>"Update" …`) still reads apart. Quote matching treats an edge as a place a word may end, with or without a space, so a quote still finds the same passage. A captured anchor also logs the words on either side of its quote as the reading shows them, and those change; see "Protocol". The structural rule the report suggested, no space where an inline element meets its own parent's text, would also have joined the 42 such edges in the corpus below with a letter or digit on both sides. Most are an `lf-option` title written flush against its description (`<strong>Apply</strong>Implement the change described above.`), which the theme sets on its own line; that rule would read "ApplyImplement the change…". ## Protocol Resolution compares an anchor's stored context, the words logged on either side of its quote, exactly. A Leaf on either side of this change misreads a context the other captured wherever it crosses a changed edge, as the bump rule in `layer-registry.md` ("Page protocol") describes. In an independent review, anchors captured with the merge base's browser capture (`anchorForRange`) on four ordinary shapes were resolved on this branch, and three detached in both runtimes. For example, in `<div><strong>Keep</strong>; MARK…</div><div><strong>Drop</strong>; MARK…</div>` the base stores the prefix "Keep ;" and this branch reads "Keep;". So `$events.protocol` moves to 47 (`kernel-registry.json`, with `build/browser/protocol-baseline.json` regenerated), and the `$passages` description names `closing` and `opening` among the lists whose change bumps it. The 418 quote anchors already in the surveyed logs resolve to the same words at base and head (27 resolve on neither), so the misread shows up in fresh captures, not in the logs surveyed here. A possible follow-up would take shown spacing out of the protocol: compare a stored context the way quote matching compares a quote, treating an edge space as optional. ## Evidence The corpus is the shipped examples, every `index.html` with a log beside it under `~/.local/state/leaf/pages` and, recursively, under `~/.tmp` (792 pages), and the agent messages holding HTML in local logs. Each reading ran at base and head: | Reading | Spaces dropped | Documents changed | | --- | --- | --- | | file (`page_passages`) | 460 | 144 of 830 | | runtime (`quoteFrom(pageText().segments)` under happy-dom) | 460 | 144 of 827 | The two runtimes drop the same number of spaces in every document, and no other character changes. The dropped spaces stood before `,` (169), `.` (149), `)` (37), `;` (32), `'` (21, all possessives after code, as `semantic-state.js's`) and `:` (13), and after `(` (35) and `"` (1). Among them, 459 sit where an inline element meets its parent's text, and every one of those is a fix. One is not. It sits between two sibling elements, a label and its value, in a `how-it-works` page: `<span>…with a more specific selector</span><code>:scope.featured { padding: 8px }</code>` now reads "selector:scope.featured". The other 1,994 spaces between sibling elements stand. Six shipped examples change, for instance `rust-sort.html`: "Short slices ( len <= max_insertion ) take" → "Short slices (len <= max_insertion) take". None of the agent messages found locally holds the pattern, so the 5-of-51 count from #6198's review isn't reproduced here. `leaf page state PAGE send-choice`, after the user chooses an option written `<strong>Leave it</strong>; the send keeps its place (<code>held</code>).`, gives the choice's words as "Leave it ; the send keeps its place ( held )." on main and "Leave it; the send keeps its place (held)." here. ## Tests - `tests/quote_cases.json` gets a case where only the new spacing tells two copies of a quote apart by their prefix. On main it resolves to nothing in both runtimes. - `tests/runtime/passage-boundaries.test.mjs` (`says`) and `tests/model/test_interact_anchors.py` (`page_passages`) read the same markup as `Leave it; the send keeps Foo's place (beta). recommended Apply Ship it. recommended "Update" for mixed input`. On main both read "Leave it ; the send keeps Foo 's place ( beta ). …". The chip still reads apart from a plain title and from one that opens with a quote. - `pnpm run test:runtime` (997 pass), `pnpm run check:browser`, `node --test build/registry.test.mjs`, and 1,158 model tests in the modules that read passages or the protocol (`interact_contract/`, `test_claims`, `test_forks`, `test_interact_document`, `test_interact_layer`, `test_interact_anchors`, `test_obligations`, `test_clerk`, `test_delivery`, `test_provenance`, `test_stop_guard`, `test_thread_reading`, `test_workflows`, `test_page_inspection`). Browser tests weren't run. A grep of `tests/browser` and `tests/journeys` finds no expectation of a space before punctuation that follows an element.
A thread named by its opening message, and On Me's Done row for it, ran a choice's option titles together when the agent's message carried an
lf-optionsgroup: "Open the pull request now, or hold it? Open it nowHold it". They now read "… Open it now Hold it".Both surfaces read the authored message's words from
prepareAuthoredMessage(thread/messages.js), which took them from the inert fragment'stextContent, so two adjacent blocks with no whitespace between them met with no space. The words now come from the passage reader'ssays, the reading accessible names (addressableSays) and page search already use, which parts runs of words read in different blocks.saysrefuses text with no element over it, and a message may open with bare text, so it reads a copy of the fragment inside a<div>of the template's inert document, where nothing upgrades.saysreturns the words on one line, which changes nothing the consumers show. Every consumer puts the text on one line (messageText→messageWords/threadName, andqueueTitlefor a reply's row), and none reads its line breaks for structure: admission refuses an agent's message with empty prose (checked_text,src/leaf/validation/admission.py), andstate-application.jsputs that prose before the markup's words, so a reader of the message's opening line, such as a thread preview'sopeningLine, still meets the prose.Trade
saysreads as the page reading does everywhere else, so it also:<style>,<script>and<textarea>in the markup, which no reader sees;<lf-option><strong>Leave it</strong>; …</lf-option>reads "Leave it ; …". In review, 5 of 51 real agent markup messages read with such a space, where main ran words together in 33. The space comes from the shared reader'sshownApart(passages.js, mirrored inpassages.py's_write), which this PR leaves.Evidence
uv run leaf-dev probe --state on-me-thread-choice --journey …(Threads view, then the Done row after picking an option and returning to On Me):… hold it? Open it nowHold it… hold it? Open it nowHold it… hold it? Open it now Hold it… hold it? Open it now Hold itTests
tests/runtime/authored-messages.test.mjs: a new case holds a prepared message's words to"Pick one: Open it now Hold it"; on main it read"Pick one:Open it nowHold it".pnpm run test:runtime(994 pass),pnpm run check:browser.test_on_panel.py,test_threads.py,test_obligation_walk.pyandtest_agent_replies.pyunder-k "choice_asked_in_a_thread or thread_choice or choice_in_a_thread or widget_a_message_carries or drag_across_an_obligation or seated_in_a_widget or agent_message_edit or widget_an_agent_sent or measures_from_chrome or obligation_in_a_reply or reply"(16 passed).A message written as Markdown alone still takes its words from
renderedWords(markdown.js), which readstextContenttoo; markdown-it writes a newline between the blocks it renders, so its blocks already read apart.