Skip to content

fix(content): check the agent's changes and a page rewrite against the rules before they're accepted - #1519

Merged
gkhngyk merged 16 commits into
ansvisor:mainfrom
cihan-gyk:fix/agent-rules-guard
Oct 26, 2026
Merged

gkhngyk merged 16 commits into
ansvisor:mainfrom
cihan-gyk:fix/agent-rules-guard

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #1518. The PR's own changes are its last two commits.

In the live editor test (2026-10-25), fixing one rule broke another:

  • a page rewrite turned 4 open rules into 5 (an FAQ question or an internal link was dropped);
  • an 8-change Fix batch, once accepted, turned 11 of 15 rules met into 10.

The card's "Rules 9 → 10 of 14" was only an estimate, from the rules each change said it fixed.

The agent's open result is checked against the rules before it's accepted (_draft-editor.tsx, ruleEffects).

  • What's checked: each open change, all of them as Accept all takes them (redoDecision, one after another, so two changes on one passage both go in), or a whole page rewritten. Each goes into a copy of the page and is checked as the page is (checkHtml, new on useDraftRules: the same rules and context, another page).
  • Compared with: the page as it is now, read in the same pass, not the rules' deferred read, so a change just accepted isn't blamed on the rest.
  • On each change in the page: "Would break Max sentence length", when it would break a rule met now.
  • On the card:
    • "Rules 9 → 10 of 14", now from the copy; amber when the count goes down;
    • "· would break Internal links".
    • For a page rewrite, the same beside its characters. Its Length is counted as its own "Length missed" line reads it (pageTextLength), and isn't named again as broken.

Nothing is dropped automatically: the person sees what a change would do and decides.

Related issue

Editor test findings 2026-10-25 (group C, part 1).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Run Fix open rules on a page that meets some rules, such as Internal links or Max sentence length.
  2. A change that would break one says "Would break …" on its card in the page.
  3. The agent card's "Rules a → b" counts what Accept all would leave. It's amber, with "would break …", when that's fewer than now.
  4. Run Rewrite page. The card says how many rules it meets and which it would break, for example a dropped FAQ.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors; the 6 warnings are in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Web: yarn test and yarn build. A pre-push review ran; its findings are the last commit. The browser check is in the next batched local test session.

🤖 Generated with Claude Code

cihan-gyk and others added 15 commits October 25, 2026 21:35
…adings' answers and what the last rewrite came to, and offer a Length it can reach

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… for, keep its numbers on the row (00285), and read the floor's sections closer (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and count the last rewrite only within its Length's band and the same kept text (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er to rewrite the cited passages too when they hold the Length out of reach

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e back, release an unused hold, keep a cited-too miss as evidence, and offer it only when cited passages hold the Length (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he agent and Next step move on, and count open rules as the Rules tab does

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es read the page, keep the Length's own words, and wait for the passages before dropping skips (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion, not the next step, and say how many placeholders it leaves to fill

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aphs, and read a rewrite's once, not on every key (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y why a run left nothing, and show a failed last run on the card

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… id and kind, not by clocks, and clear a failed last run once another starts (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e rules before they're accepted, and say which rule met now one would break

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…age as it is now, and count a rewrite's Length as its own line reads it (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 25, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

What I checked:

  • Stack. The PR's own change is its two commits on #1518 (945f984, b17fb3f), with no merge commit. With the stack, it merges cleanly on main.
  • Web only. There is no API change and no migration, so it works as soon as it's merged, whatever API prod runs.
  • The same check as the Rules tab.
    • checkHtml runs the draft's own rules with the same context (rules, ctx in useDraftRules) on another page. Only the page it reads differs.
    • "Now" is checked in the same pass, from the editor's doc: getHTMLFromFragment is what getHTML serializes, with the editor's character count.
    • So both sides are read alike, and a change just accepted counts as part of the page.
  • As Accept takes them.
    • Each change goes into a copy through acceptInto, which Accept itself uses.
    • The whole batch goes through redoDecision, which accepts the changes in order on one transaction and updates each status as it goes, as decide does. So two changes on one passage both go in.
    • Stale changes, locked ones and ones that grow a heading too long are left out of both, as Accept leaves them out.
  • A rewrite.
    • Its Length is read as its "Length missed" line reads it (pageTextLength, pageCharacters), and Length isn't named a second time.
    • The API has already cleaned its HTML to the editor's blocks (cleanPageHtml). readPage reads a list item with or without its paragraph alike. So the raw HTML reads as the page it becomes.
  • Nothing is dropped or held back.
    • It only adds words to the agent card and the cards in the page; Accept and Accept all work as before.
    • Only rules that are on and met now can be named, never an off rule or one the page can't say.
    • With no open change it returns at once, so a page without a batch pays nothing.
  • Cards in the page. The label shows on open cards only, and the card is drawn again when it changes, since the label is part of its key.

Low, follow-up:

  1. _draft-editor.tsx:1709-1758: with a batch open, each recompute reads the page up to ten times (now, each of up to eight changes, then all of them).
    • Each read is a full HTML serialization, a DOMParser read and every rule, and it runs inside the render.
    • It runs again after each pause in typing (pageHtml) and after each decision. On a long page, a person typing beside open suggestions can feel it.
    • useDraftRules keeps its own check a beat behind typing with useDeferredValue. Do the same here: pass useDeferredValue(pageHtml) into the memo's deps, so this runs in an interruptible render and never holds up the keyboard.

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