Skip to content

fix(content): one count for the rules and for a rewrite's characters, as the editor shows them - #1521

Merged
gkhngyk merged 30 commits into
ansvisor:mainfrom
cihan-gyk:fix/editor-one-count
Oct 26, 2026
Merged

gkhngyk merged 30 commits into
ansvisor:mainfrom
cihan-gyk:fix/editor-one-count

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #1520. The PR's own changes are its commits after the merge of #1520's branch.

In the live editor test (2026-10-25), the counts disagreed:

  • the header's rules chip read 8/12 on first paint, then 11/15;
  • the rewrite's waiting page said "Reading 16 rules" while the chip said 15;
  • the agent card's rewrite read "6,725 → 5,571 characters" while the toolbar counter said 6,617 → 5,468.

One count for the rules.

  • The chip: it says "Rules · reading" until the count stands (rulesSettled). That's once My rules, the fan-outs (the fan-out rules'), the brief (the keywords rule's) and, for a product page, the catalog (the feed rule's) are read. Before that, rules came and went from it.
  • The same wait: the side panel's open-rules badges, the Rules tab's "N of M rules met" and the agent card's gain wait too.
  • "Reading N rules": a Start or a Rewrite page now sends counted, the chip's total. The API's run counts that, falling back to the rules sent (writeDraftInput.counted, optional). So the waiting page says what the chip says. The rules sent still include the ones only AI reads (tone, language).

One count for characters. A rewrite's characters, before and after, are counted the way the toolbar counts the page: the editor's own count over the page parsed with its schema (htmlChars, createDocument). That applies to:

Related issue

Editor test findings 2026-10-25 (group E).

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. Open a draft. The rules chip says "Rules · reading" briefly, then one count that doesn't move while nothing on the page changes.
  2. Run Rewrite page. The waiting page's "Reading N rules" says the chip's total.
  3. With the rewrite shown, the card's "before → after characters" and Compare's labels match what the toolbar counter shows before and after Accept.

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

Server: format, lint, npm test. One audit test timed out once under load; it passes on its own, and this PR doesn't touch it. Web: yarn test and yarn build. A pre-push review ran; its findings are the last commit.

🤖 Generated with Claude Code

cihan-gyk and others added 21 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]>
…wasn't given or drops a name a passage has

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…give claims only to sources the page or its input names, and put a rewrite's as a placeholder (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…editor shows them, and hold the rules chip until its count stands

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aracters as the toolbar counts them, and the run's rule count

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…for the brief and catalog before the rules' count, hold the panel's counts with it, and read the shown rewrite's Length by the editor's count (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 sits on #1520's head. Its merge of #1520's branch (c29a90b) adds nothing beyond its parents. With the stack, it merges cleanly on main.
  • The chip settles, and only once. rulesSettled waits for My rules, the sources, the brief and, on a product page, the catalog. A failed read of each still ends its wait: the sources come back marked failed, the brief's status leaves loading, and the catalog reads null. So the chip can't stay on "Rules · reading". The panel's open-rules badge, the Rules tab's "N of M rules met" and the card's gain wait with it.
  • "Reading N rules". The editor sends counted only once the count stands; otherwise the API counts the rules sent, as before. A page's rule set is its type's rules plus the shared ones, well under the schema's 60, so counted can't fail the request.
  • Before the API deploy. writeBody is a plain z.object, so an older API drops counted, and the waiting page keeps saying the number of rules sent until the API is deployed. Everything else is web and changes on merge: the chip, the panel, and the card's and Compare's counts. Nothing breaks.
  • Characters. htmlChars is the toolbar's own count (characterCount.characters) over the page parsed with the editor's schema. That's how ruleEffects already counts a Fix's page, and Accept puts the same HTML in with setContent. So the card's "before → after", Compare, the Length line and C1's check agree with the counter before and after Accept. Without an editor it falls back to pageTextLength.
  • Tests. The chip holding its count, the card with the editor's count, the run's rule count, and getLastPageRewrite's id.

Low, follow-up:

  1. The same rewrite is read two ways (_draft-editor.tsx:1960-1964).
    • While it's the batch shown, its Length reach uses the editor's count. After a later Fix batch replaces it, lastRewrite is the API's after_chars again.
    • The two counts differ by 1–2% (5,571 vs 5,468 in the PR's example). Near the edge of the Length's band, the Rules tab can call the same rewrite's Length in reach, then out of reach with a new Length suggested.
    • Fix: count it one way in both cases. For example, have the API count after_chars as the editor does, or keep the editor's count by the rewrite's id once it has been read.

cihan-gyk and others added 5 commits October 26, 2026 10:11
…ead "per" only as an attribution, "claims" and "states" only before "that", and "göre" not as a comparison; keep a change that keeps every name worded or cased another way, or as bullets; know a source by its possessive, never its last word alone; let the prompts name Your input as a source (review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e Doe", "Recently Gartner"), keep a sentence's first word out of a placeholder, read "per" on English pages only, read "U.S." as one name, and start a name only at a word's start (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Thanks. #1526 further up the stack does this: the Rules note counts the last rewrite's page with the editor's own htmlChars, read by its id (getLastPageRewrite). That count stays the same while the rewrite is shown and after a later Fix batch replaces it, so its Length reach doesn't flip.

This branch now also has #1520's review fixes merged in.

@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged the PR below it forward (6d3db71), which brings in main now that #1514–#1519 are in. No conflicts; its diff against main is its own files again.

Checks after the merge:

@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.

The new head, 6d3db71, only merges #1520's new head (bf7742b), and through it main (4efa150). Re-merging its parents (14f106f and bf7742b) is clean and gives the commit's tree (7f18990e), so the merge hides nothing. Its own change against #1520 is the same as in round 31, line for line. With its stack, it merges cleanly on main. Round 30's verdict stands.

@gkhngyk
gkhngyk merged commit e8daeaf into ansvisor:main Oct 26, 2026
4 of 5 checks passed
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