html-revisor

A human and an agent trade turns on an HTML page. The human leaves directives and edits prose in the browser; everything lands in the file.

What it's for

🤖 agent writes, then reads the diff OVERVIEW.html the only record 👩🏽‍🦱 human in the browser agent generates grep directives · git diff html-revisor formats, serves directives + prose edits The tool owns the file's shape: it may reformat, restrict, and rewrite it in place.

What it does

Every scope edits as markdown

A paragraph with bold and a link.

p · A paragraph with bold and a link.
Content
Directive
⌘↵ or esc to close
Delete
Done
  1. Click any block. Crop marks show what you picked.
  2. Content holds its words as markdown. Edit them.
  3. Directive asks the agent for something.
  4. Both save into the HTML file as you type. The agent reads the diff and the directives.

Where it's headed

Fidelity every scope edits as markdown, nothing lost Ergonomics the box helps you Performance save keeps up on a big page When one mark in a sentence can't be markdown, only that mark is HTML, not every mark beside it. Inline fallback Tables edit as GFM (GitHub Flavored Markdown) tables whenever they can. Tables as GFM Pick the enclosing scope from the box, for a scope its children cover. Up the scope Content edited on disk swaps into the open tab, with no reload. Disk edits, live Fetch a scope's markdown when its box opens, and drop markdowns from GET and PUT. Telemetry shows what each costs now. Markdown on open A save on a big nested page shows within about 100 ms of the pause, and Done confirms it before the box closes. Fast big saves SVG text edits from the box, tspan included, and the drawing redraws after a save. SVG text edits A stray click outside the directive box leaves it open, instead of closing it mid-sentence. Box stays open The agent answers a directive in the page: each element carries its own thread. REPLY-DESIGN.html holds the design. Built as a prototype, behind the server's --replies flag, until a rewrite handles the agent and the browser changing one page at once. Replies in the page SCOPES-DESIGN.html: what's decided about editing as markdown and element identity, beside examples. DESIGN.html: how everything the tool adds to a page looks, and the design decisions so far. A few example yaks on each trail; hover one for more. The house holds the scope decisions, and the shrine holds the design. In yx, a yak on a trail carries @mountain:fidelity, ergonomics, or performance.

Architecture

⌘-click a box for its step below. (A plain click opens a directive box.)

GET page.html file on disk parse, normalize rewrites disk if changed assign IDs in the file, never reused lift directives comments → JSON inject client + bases, markdown, hash browser PUT page.html {one change: id, base, directive or markdown} sent 0.4 s after you stop typing browser conflict check one element, by base set prose reconciled HTML place directive the one, by ID serialize IDs stay in file on disk POST page.html, Done {id, what the box opened with} when the box closes, after its last save browser file on disk compare opened with vs. now Announcement one JSON line stdout an agent watching, if any Modules I · orchestration top level II · domain domain/, pure functions III · interface interface/, vendor/ server.mjs routing, the GET, PUT, Done flows CLIs, for agents formatter · cleanup reply scopes.mjs CLI, annotates SCOPES-DESIGN domain/ canonical · identity · format · annotation scopes · directives · bases · markdown-edits revision · served-page announcements · cleanup to/from-markdown scope ↔ markdown property-tested interface/ files · http · stdout linkedom HTML parser markdown-it markdown → HTML telemetry.mjs spans → Honeycomb OpenTelemetry API and SDK browser client.js box, docket, PUT, Done, spans client.css every style the tool adds server.mjs inlines both into each page on GET Dependencies point down, with no cycles; test/architecture.test.mjs checks. Yellow: vendored libraries.

How it reaches you

html-revisor main: code, tests, yaks iterate-on-docs html-revisor/ the copy you run GitHub version tag installed plugins ./deploy plain copy, tests, commit ./release bump, tag, --push Contract README table, incl. words iterate-on-docs skills + README out of band we edit, own commit deploy carries the code; a Contract change travels beside it. If they disagree, the Contract wins.

./deploy runs from main only and refuses on a dirty tree. If the tests fail in the copy, it puts the copy back and commits nothing. Details: README, Deploy and Contract with iterate-on-docs.

What makes this hard: prose editing

Round trip is identity IDs survive a save Property-tested Every scope under 4 KB edits as markdown, but the page is HTML that markdown can't fully say. Every case and decision: SCOPES-DESIGN.html.
on disk
<section data-hrv="2">
  <h2 data-hrv="3">Plan</h2>
  <p data-hrv="4">
    <!-- @AI: say why --> ③
    Press <kbd>⌘S</kbd>, ship.
  </p>
  <svg data-hrv="5">…</svg>
</section>
in the box, edited
## Plan

Press <kbd>⌘S</kbd>, ship **today**. ①

Celebrate.

⟦svg⟧ ②
saved
<section data-hrv="2">
  <h2 data-hrv="3">Plan</h2>
  <p data-hrv="4"> ④
    <!-- @AI: say why --> ③
    Press <kbd>⌘S</kbd>, ship <strong>today</strong>.
  </p>
  <p data-hrv="7">Celebrate.</p> ④
  <svg data-hrv="5">…</svg> ②
</section>

Step by step

The pipelines above, stood on end.

GET page.html
file on disk
parse, normalize
add html · head · body
b → strong, i → em
one block per line
collapse whitespace
indent by two
Idempotent! Writes disk only if changed Also a CLI: node formatter.mjs page.html. The agent runs it before each commit.
on disk, before
<h1>Plan</h1>
<p>Ship   the <b>formatter</b>
first.</p><ul><li>one</li><li>two</li></ul>
<img src="map.png">
on disk, after
<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <h1>Plan</h1>
    <p>Ship the <strong>formatter</strong> first.</p>
    <ul>
      <li>one</li>
      <li>two</li>
    </ul>
    <img src="map.png">
  </body>
</html>
assign IDs
scopes · hr · SVG
next ID on <html>
Never changes Never reused Copies of one ID retire it; each copy gets a fresh one.
on disk
<html data-hrv-next="8">
…
<p data-hrv="4">Ship the <strong>formatter</strong> first.</p>
<ul data-hrv="5">
  <li data-hrv="6">one</li>
  <li data-hrv="7">two</li>
</ul>
lift directives
remove comments
write JSON
Inert The browser never runs a type="application/json" script; the client reads it with JSON.parse.
on disk
<p>
  <!-- @AI: say why first -->
  Ship the <strong>formatter</strong> first.
</p>
served
<p data-hrv="4">Ship the …</p>
…
<script type="application/json"
        id="hrv-directives">
  {"4":"say why first"}
</script>
in the browser

Ship the formatter first.

say why first

The real marker and its tip, from client.css.

inject client
client.css
client.js
three JSON scripts
Served copy only The client's own elements have no ID, so they can't take a directive.
served
<html>
  <head>
    … the page's head …
    <style> client.css </style>
  </head>
  <body>
    … the page, with its IDs …
    <script type="application/json" id="hrv-directives"
            data-version="3f9a0c1b2d4e"> {…} </script>
    <script type="application/json" id="hrv-bases"> {"4":"a1c4…"} </script>
    <script type="application/json" id="hrv-markdown"> {"4":"Ship the **formatter** first."} </script>
    <script> client.js: hover · box · docket · PUT </script>
  </body>
</html>
browser
PUT page.html {id, base, directive} or {id, base, markdown}
browser
One change at a time Sent 0.4 s after you stop typing, with the base it started from.
conflict check
strip directives, IDs
hash the element
compare with base
Only that change can conflict No file-wide version. If an agent changed the file elsewhere, the save goes through and the tab says reload.
{id: "6", base: "a1c4", directive: "say more"}
  base matches li 6        →  applied; answer has new bases
  base differs, or no li 6 →  412, nothing written: error, reload suggested
set prose
markdown → HTML
reconcile with prior
new IDs for new
Save unchanged: byte-identical Kept elements keep IDs Any scope. Refused: blank markdown, body, hr, SVG shapes.
{id: "4", base, markdown: "Ship the **formatter** last."}
  →  <p data-hrv="4">Ship the <strong>formatter</strong> last.</p>
place directive
first child
or before img, hr
A finished directive stays gone Empty text removes it.
on disk
<p>
  <!-- @AI: say why first -->
  Ship the <strong>formatter</strong> first.
</p>
<!-- @AI: needs alt text -->
<img src="map.png">
serialize
IDs are part of the file A page's first format is one noisy diff; after that, diffs show only new IDs.
file on disk
POST page.html, Done {id, directive, markdown} as the box opened
browser
Done closes the box Done, esc, ⌘↵, a click away, or opening another box. It queues behind the box's saves, so the file holds what the box left.
compare
directive
content
Nothing changed: nothing printed Changed content is a revision. A directive is no revision until the agent acts on it.
{"page":"/OVERVIEW.html","id":"12","element":"p","heading":"Architecture",
 "directive":{"before":"","after":"say what the tiers are"},
 "revision":{"before":"Three tiers.","after":"Three **tiers**."}}
stdout
One line per Announcement, for an agent watching the output to start work while you work.

Invariants

Terms

directive
A request from the human to the agent, stored as an HTML comment starting @AI:. Avoid: note, comment, annotation.
Done
Closing the directive box, by its button or any other way. Done triggers an Announcement.
Announcement
What one box session changed, printed by the server as a line of JSON. See compare.
revision
Changed content. A directive becomes a revision when the agent acts on it.
normalize
Rewrite the file into canonical shape. See parse, normalize.
element ID
How the browser and server name an element: data-hrv, written into the file by assign IDs.
scope
The unit of editing and directives: any block you pick, plus links, images, and spans, edited as markdown as a whole. Scopes nest.
Contract
What iterate-on-docs relies on, words included: the table in README. See how it reaches you.
deploy, release
Deploy copies main into iterate-on-docs. Release, run there, versions and publishes it. A deploy is not a release.
phrasing content
HTML-spec term: text plus inline markup (b, a, code…). See MDN: content categories.

Current work

Tracker

Work lives in yx. Run yx list.