Skip to content

feat: make each bound file a data source under its binding's id - #7306

Merged
max-sixty merged 12 commits into
mainfrom
agent-ab3dfe3a9e25fe26f
Nov 26, 2026
Merged

max-sixty merged 12 commits into
mainfrom
agent-ab3dfe3a9e25fe26f

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A file a page binds with leaf file bind is now a data source under its binding's id. Its value is {key, name, text, revision} under the text-document contract. So <lf-text-document source="notes" preview="markdown"> or <lf-diff before="notes-head" after="notes"> shows every write to the file, whoever makes it, and works with no editor on the page. A comment on either records the source's revision. The revision digests the value, as every source's does. The run digests the path, the label and the file's stat, so every write reaches the tab. leaf data set and leaf data clear refuse a bound id, and page check refuses an input of another contract that binds one (file-contract).

The editor keeps reading and saving through boundFile. It owns the reader's unsaved draft, and the copy the page receives can lag the editor's own save. A preview beside an editor still binds the editor with for, which keeps #7297's double-click to a line. source is for pages with no editor.

To weigh: the hosted site's first-visit state and exports now carry the bound files that published markup binds, with the data version of exactly those. Two rare paths stay open. One is a hand-crafted comment on a file bound after the page's markup was checked. The other is that the file-contract check doesn't reach samples or messages.

Max picked this ("B") on a findings page. Checked agent writes stay in #7292. Codex reviewed it over five rounds. Tests: model tests of the source, the door and first visits; browser tests of the preview, the diff, the editor and the double-click; pnpm run test:runtime.

This was written by Claude Code on behalf of max-sixty

`leaf file bind` granted a file only to the editor's module, through `boundFile`.
A preview of the file had to bind the editor's `text` output with `for`, so it
needed an editor on the page, and a comment on the preview recorded no revision of
the file.

Each binding is now one of the page's data sources (`data.file_sources`): a
`text-document` valued `{key, name, text, revision}`, read again whenever the
file's stamp moves, and sent to the browser as any source is. So
`<lf-text-document source="readme" preview="markdown">` shows each write to the
file, the editor's saves and an agent's alike, with or without an editor on the
page, and a comment on its words carries `source` and `source_revision`. The door
admits such a comment because `read_contracts` now names each binding.
`leaf data set` refuses a bound file's id, since the file is what a write
changes. The `text-document` contract gains an optional `revision`. The editor
keeps reading and saving through `boundFile`; its `text` output stays for a
preview that follows whichever file an editor of several has open.

The file-editor example binds its preview by `source`, and the file editor's
author instructions say to, and add a sentence asking agents to edit a bound file
as it stands rather than write it whole from an earlier copy, which puts back
words the reader saved since. That sentence was not scored: it states a
consequence and its remedy, with no goal it competes with, and agents on Claude
Code use Edit in both arms, so a score would show no difference.

Comments on the editor's own lines are not in this change. CodeMirror rewrites the
attributes of its line and token elements from its own decorations, so the
provenance Leaf stamps on a datum and the `data-lf-marked-words` mark a comment's
words need are removed the next time the caret moves: in a probe on the
file-editor example, 9 of 10 attributes set on lines and token spans were gone
after the caret moved two lines, and writes made inside CodeMirror's observer's
`ignore` still lost the lines the caret passed. Only `.cm-content` keeps an
attribute it didn't set.
Codex's review of the previous commit found four faults in a bound file's
source, and a second copy of one fact:

- A file's value skipped the registry's judgement that a publication's gets, so
  a contract it stopped fitting showed nowhere. `read_data` now judges both
  through `_judged`.
- `leaf page state PAGE THREAD` named `data/<binding>@N.json`, a publication
  file nobody writes, as where to change a widget's input bound to a file. It now
  names the bound file (`construction.input_readings`, `kind: "file"`).
- The source was cached for every binding together and kept an unreadable
  file's error under a stamp that a permission change doesn't move, so a file
  made readable again stayed "Permission denied" in its preview. Each binding is
  now kept on its own, and an unreadable file is read again each time.
- The run was the file's revision, so rewriting the same bytes wasn't news. It
  now digests the file's path and stamp.

That run is the stamp the state answer's `files` map already carried for each
binding, which `boundFile().watch` heard to read the file again. `files` now
holds only labels, so an unreadable file keeps its name, and the watch hears
the source's run.
…s own revision

Codex's second review of the bound-file source found these, numbered as it
numbered them:

- #1: a comment was admitted on a value its widget could never draw. `page check`
  now refuses an input of another contract than `text-document` that binds a
  bound file's id (`file-contract`, `data.bound_file_conflicts`), and the door
  refuses a datum comment naming the value a source holds now where that value
  holds an error or no input of the section reads its contract
  (`datum-undrawn-source`). A comment naming a value since replaced is admitted
  as before.
- #3: the source missed a permission removal and a same-size rewrite that put
  the old modification time back, and its run didn't move. The page's news, the
  source's cache and its run now read one observation of a bound file,
  `file_bindings.observed`: its stamp and its change time. Adding the change time
  to `file_stamp` itself re-parsed revisions in two `test_interact_document`
  tests, since Leaf hard-links a revision's files and a link moves the change
  time, so it stays out of `file_stamp`.
- #9: a clean editor opened before `leaf file bind` stayed at "No file is bound"
  until Retry. A failure now holds a file's reads only while it holds a draft or
  a save whose answer was lost.
- #10: a comment recorded a digest of the source's value, which a new label
  moves. A bound file's source revision is now the first 16 digits of the file's
  own, the one a save names. Its run digests the observation, path and label, and
  the served state's tail now sends a source's value again when its revision or
  its run moves, so a new label reaches the tab. A publication rerun with the same
  value now sends that value again, where it sent only the run; the tail still
  sends nothing of the sources a write leaves alone.
- #11: `leaf data clear` on a bound file's id deleted the publication behind it.
  It now refuses the id, as `set` does (`page_data._published`).

The public site's first-visit state carried every granted file. It now holds the
data the page's markup binds, through the export's filter (`markup_data`).

`text-document`'s `revision` is an opaque non-empty string.
…age data on first visits

Codex's review of the previous commit found faults in it, numbered as its findings
are:

- #1: the door refused a comment a reader genuinely drew. A revision digests a
  value alone, so the same value republished under another contract read as a
  contract the seat never drew. The door now refuses only a current reading that
  holds an error; an input of another contract is left to `page check`.
- #3: on Linux two writes can share a change time, so the separate change-time
  stat still missed a same-size rewrite with the old modification time (35 of
  100 cache trials, 86 of 100 news trials), and the hosted publisher's
  fingerprint (`record_reading`) ignored it. `file_stamp` takes `changed`, which
  adds the change time from the same stat and settles on the later of the two
  times, and every reader of a bound file (news, the hosted fingerprint, the
  source's cache and run) stamps it that way.
- #10: comments keep the file's own revision, but the previous commit made the
  served state's tail resend a publication's unchanged value on every rerun (one
  256 KiB rerun grew the answer from 362 bytes to 262 KB), and a validation
  cached by the file's revision went stale when the label moved. A bound file's
  whole value now has its own digest, kept with its reading, which the tail
  compares (`data.value_key`) and validation keys on; the tail's rerun test is
  back as it was.
- #12: the first-visit state dropped a publication only a thread's widget binds,
  and advertised the version of all data while sending part of it, so a tab
  naming that version never got the rest. It now holds every source a document
  or message of the page binds, and the version of exactly those
  (`page_data.bound_data`), in place of the export's filter, which leaves
  messages out.
- #13 (part): a widget's construction in `leaf page state` said an input of
  another contract had its value available. It now says it has none, with why.
  `page check` still finds a file bound under another contract only in the
  page's own markup, not in a sample's or a message's.
- #14: a read failure whose cause the file's stamp doesn't name, such as a
  symlink in its path, stayed cached after its cause cleared. A source holding
  an error is now read again each time.
- #15: looking up one source for the door read every bound file. It now reads
  the one it names.
… and leave drafts off first visits

Codex's review of the previous commit confirmed #3 fixed on Linux and macOS and
found these still open:

- #10: two overlapping state requests could lose a relabel, since a reading the
  file cache no longer held fell back to the file's revision, which leaves the
  label out. `data.value_key` now takes the digest kept with that exact reading,
  and digests any other reading of a bound file afresh; a publication still
  stands in by its revision, so a rerun sends no value.
- #12: first visits held every binding `working_data_bindings` knows, the
  unpublished source's among them, so a binding only `index.html` holds put its
  file in the public state. `bound_data` now reads the published revisions and
  the messages, and not the draft.
- #14: a symlink put in a bound file's path and taken out again moved neither the
  news nor the run, and a file holding bad bytes was read again on every state
  read. A bound file's observation (`file_bindings.observed`), which the news,
  the hosted fingerprint and the source's cache all read, now also says whether
  its path names it without a symlink, so every reading, an error's included, is
  kept under it.
- #15: admission read every publication to learn whether a source was supplied.
  It now asks for the one source first, and reads the others only where that
  source holds nothing.

Still open, and reported: #1's comment on a file an input of another contract
binds after its page was checked, and a contract that pins the file's name,
which a new label then breaks; #13's file-contract check, which reaches the
page's own markup and not a sample's or a message's; and the copy of a file
source into a live sample, which takes a publication's revision.
# Conflicts:
#	examples/developer/file-editor.html
The merge of main moved the file-editor example's Changes tab from
`for="research-file"` to `after="research-notes"`, so the diff follows the file on
disk now that a bound file is a source, and the diff package's author
instructions say to bind a file that way. That left no example writing
`lf-diff`'s `for`, which `test_every_declared_attribute_and_enum_stands_in_an_example`
requires. `for` still has its own use, a widget's `text-document` output, so the
feature gallery's widget-document section now holds a diff comparing that
widget's output with its first note.

The diff instructions' change names which binding a file takes; it corrects a
fact and moves no goal, so it was not scored.
…ery source's is

A bound file's source revision was the first 16 digits of the file's own revision,
so a comment named the version a save names and a new label left it as it was.
That split a source's revision from its value, and each reader that takes a
revision to name a value needed something of its own: a digest of the whole value
kept beside the reading, which validation keyed on and the served state's tail
compared (`data.value_key`), and a copy into a live sample that took a different
revision from the same value. The parent session's review chose to end the split,
following Max's "If it's hard or fighting with leaf then I'm less keen": a file's
revision is the digest of its whole value, so a new label is a new revision and a
comment made before it reads as made on an earlier value, which it was. This
deletes the file-specific revision, the digest kept beside it and `value_key`, and
puts the tail back as main has it. The run still digests the file's observation,
path and label, so every write and every new label reaches a tab.

A live sample's copy of a file source now reads as the same revision as the
parent's (`test_a_bound_file_is_the_page_s_source_under_its_binding`).

Two of Codex's findings stay open on rare paths, by the parent session's review,
with no mechanism added for them: the door admits a hand-crafted comment on a file
that an input of another contract binds, where the file was bound after the page's
markup was checked; and `page check`'s file-contract check reads the page's own
markup, not a sample's or a message's.
…d stamp at once

Codex's review of the branch against main, after the file source's revision became
its value's digest:

- A hosted page's first-visit state and its container's live state read the same
  page-local file under different revisions, since a file's revision digested its
  absolute path, so a comment pinned to the first one read as outdated once the
  container answered. A revision now digests the path the grant records, the
  page-relative one for a file in the page, and the bytes (`_snapshot`), so the
  editor's save token and the source's value agree on every copy of the page.
- One source reading could pair one write's bytes with another's stamp. The bytes,
  the run and `updated` now come from one descriptor (`_read_stat`).
- A failed access, such as an I/O error, stayed cached until the file's stamp
  moved. A `FileAccessError` is read again next time; a refusal of the bytes
  themselves stays kept under their observation.
- On Python 3.12 a symlink loop in a bound path raised `RuntimeError` out of every
  freshness read. `observed` treats it as an indirect path, which the source reports.
- Reading a thread read the page's grants once per input widget. Thread
  construction now takes them once (`files`).
- An unbound editor heard each publication under its id as a write to its file.
  `boundFile().watch` hears a source's run only while the page grants the binding.
- An export kept the version of all the page's data beside the sources it chose.
  Export and first visit now take the sources they choose and the version of
  exactly those from one operation (`data.data_of`).

Left on a rare path, by the parent session's review: a live sample's fixture that
names an error revision of a file, which sample admission doesn't read.
…ith `source`

#7297 lets a double-click on a word of a Markdown preview bound with `for` to the
file editor put the caret at that word's line; a preview bound with `source` names
no editor, so it keeps the browser's double-click. The parent session's review chose
that, beside an editor, the preview keeps `for` the editor: it shows each save, follows
the open file of an editor of several, and takes the double-click, with no new name.
A widget on a page with no editor binds the file with `source`.

So the file-editor example's preview is back on `for="research-file"`, its Changes
tab keeps `after="research-notes"` and follows the file on disk, the agent's writes
included, and the file editor's author instructions and `lf-text-document`'s say
which binding goes when. These correct which binding each case takes and move no
goal, so they were not scored.
leaf-agent
leaf-agent previously approved these changes Nov 26, 2026
The gallery's eyebrows index every element a section shows, and the diff
this branch added beside the produced document was missing from its list.
@max-sixty
max-sixty merged commit 428b7a0 into main Nov 26, 2026
6 checks passed
@max-sixty
max-sixty deleted the agent-ab3dfe3a9e25fe26f branch November 26, 2026 21:12
max-sixty added a commit that referenced this pull request Nov 26, 2026
…ures and files beside it (#7310)

The maintainer picked rendering the HTML GitHub allows in a file's preview, and on
loading the pictures a file names beside it wrote: "why limit to these files? why
not just allow anything the server can reach? I'm not sure we're really designed to
have a proper sandbox at this point, we shouldn't add complication unless we're
actually tight here". Of the 197 most-starred Markdown READMEs, 81% hold raw HTML,
which the preview printed as tags, 46% name pictures by a path beside the file,
which it couldn't load, and 80% link to another file by a path, which took the page
itself to a missing address.

- markdown.js gains `markdownFileFragment`, a file's reading with HTML, kept to
  GitHub's allowlist by DOMPurify 3.5.0 (31 KB, 12 KB compressed), which loads for
  the first file holding HTML. Beyond GitHub's list it drops `accesskey` and
  `tabindex`, which would rebind the page's keys and tab order, `data-` attributes,
  which Leaf's own marks use, and every class but a code block's language and a task
  list's, `rel`, which could keep an opener for a page a link opens, and the
  attributes that name another element by id, as `for` and `aria-labelledby` do,
  which could name one of the page's; an `id` or `name` takes GitHub's
  `user-content-` prefix, a style stands only as a table cell's alignment, which the
  reading writes so, and an `<input>` only as a disabled checkbox. The host's links and pictures apply after the
  sanitizer, to the file's HTML links as to its Markdown ones. Drafts and messages
  keep showing tags as text, since Python draws a draft's body too and has no
  sanitizer.
- `boundFile(binding).beside(path)` gives the address
  `/api/files/<binding>/beside?path=<path>`, where a live page's server answers the
  file at that path from the bound file's folder, `../` included, or null where the
  page can't reach its server's files, as in an export. It answers any file
  it can read, but only to a request carrying the page's key, so a sample's
  capability and the website's container answer none, and never from Leaf's own
  state home, which holds each page's connection credentials that a page's scripts
  never receive. Text answers as text/plain, so a linked file shows rather than
  downloads, and every answer is sandboxed by `Content-Security-Policy: sandbox`, so
  an SVG a README names, opened on its own, runs no script as the page. A preview of
  a file the page binds, named by its value's `key` as a bound file's source (#7306)
  and its editor both name it, resolves a picture's `src` and `srcset` and a link to
  another file through it, opening a linked file in a new tab. Asking by the binding
  keeps the file's host path out of the browser, as the file editor always has; an
  earlier version handed the browser an address spelling the path.
- A link to an anchor the file names, as `<a name="top">`, lands on it as a link to a
  heading does: the preview carries the file's ids and names as places of its own
  (`data-lf-place`) rather than page ids. A fold the reader opened stays open as they
  type inside it: a redrawn fold takes the state of the drawn one with its summary,
  within the same file. A table cell an HTML table aligns with `align`, as 27 of the
  READMEs do, keeps that alignment, which the reading face's `text-align: start`
  overrode on every page.
- The preview's pictures stand bare, without the frame the reading face draws round a
  picture, as on GitHub.
- An image sized by its `height` alone keeps that height on every page, drawn whole
  within it where its container is narrower: base.css forced `height: auto` on every
  image, which drew 167 logos in 35 of the READMEs at their files' size. No page in
  the corpus has such an image.

On sparkjoy's README all 20 pictures load and no tag shows as text, in Chromium and
Firefox.

Left as they are, each rare: a double-click on a file's HTML text can put the
editor's caret on the wrong line, since #7297's source mapping parses without HTML,
which the editor session that built it is changing next; two previews whose
files group folds under one `<details name>` share that group; an `<a>` with both
`id` and `name` answers only its id; a `.svgz` picture doesn't draw; a live preview
whose value's `key` names no binding asks the server for its pictures and gets none;
after a rebind to another file, a picture at the same path can show from the browser's
cache until a reload; a reference keeps no `#fragment`, and one whose `..` passes
through a missing folder, or whose name mixes a bare `%` with escapes, finds no file.

Tests: the preview's browser test plants a fold it then types inside, a centred
picture beside the file, a link to another file and to a named anchor, an aligned
table, a script, a handler, a `javascript:` link, an opener, a styled div with
Leaf's class, data attribute and a page id, a text field and a task list; a runtime
test holds a host's moved picture in place; a model test reads a picture above the
bound file's folder beside its binding and checks the sandbox, the key and Leaf's
state home. A written
passage's test escapes its `<missing>` placeholder, which GitHub's reading drops as
an unknown tag. Reviewed in five Codex passes.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 26, 2026
… store holds it (#7314)

On leaf.page, a reader's save in the file editor was answered as saved
and lost when the container slept, as Codex found reviewing #7306. The
page's record held only the files Leaf writes, so a file the page binds
from its own directory (`files/`) was never in it, and the save ran
outside a page transaction, so nothing published it before the receipt.

The record is now the whole page directory, less the serving process's
files, the drafts store, staged writes and symlinks, and restore
replaces the release's page directory with it. The file routes commit a
page transaction before answering when a commit provider is set. A save
that fails after its write, as when the store refuses the commit, now
reads to the editor as a save that may have reached the file, and Retry
settles it by reading before it sends again.

Reproducer:
`test_a_save_to_a_file_the_page_binds_is_answered_once_the_page_store_holds_it`
in `tests/process/website_server/test_saved_records.py`.

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent added a commit that referenced this pull request Nov 27, 2026
)

#7306 made each file a page binds with `leaf file bind` a data source
under its binding's id. It said so in its description: "the hosted
site's first-visit state and exports now carry the bound files that
published markup binds". After that change, `data.read_contracts`
returns those bindings, with the `text-document` contract, alongside the
sources the example's data sets.
`test_every_published_page_keeps_its_canonical_page_record` still
expected only the data-set sources, so it failed on the published
example that binds `alerts`, `values`, `runbook`, `values-production`,
`values-staging` and `deploy-workflow`. Journeys run only in the
scheduled suite, which is why #7306's own CI never ran this test.

The code is doing what #7306 intended, so the test changes to match: it
now expects the page's bindings (`file_bindings.bound_paths`) as well.
No behavior #7306 intended is given up. The stored-value check for
data-set sources is unchanged.

Run by node id on Linux, the test fails on `main` with the error from
the issue (`{'alerts', …} == set()`) and passes with this change.

Closes #7406 — automated triage

Co-authored-by: leaf-agent <[email protected]>
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.

2 participants