Repository navigation
feat(content): cut a page rewrite to its Length with one more pass, and say when one came out longer - #1515
Conversation
…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]>
… one more pass 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]>
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good, with follow-ups.
What I checked:
-
When the cut runs. All three must hold:
- the Length rule was sent;
- the first answer is a page;
- its text (its own words plus the kept blocks) is past the band's top by more than 15% of the Length. For 4,000, that's past 5,400.
With Length off, or under that line, there's no second call and no hold. The tests cover both.
-
The AI budget.
- The hold. The cut takes its own hold, with the same feature, model and draft as Start's. It takes it after the first call is charged. On a nearly spent budget the hold is refused, so the cut is skipped and the first rewrite stands.
- An answer is charged at its tokens, and the
finallyrelease does nothing after that. - A stop during the call.
runCallkeeps the hold as the call's cost, and the stop ends the run as before. - A stop before the call goes out.
runCallthrows before sending, and thefinallyreleases the hold. - A failure. A schema miss that reports usage is charged. Any other failure releases the hold. The first rewrite stands either way.
- No double charge. The cut's errors never reach
runDraftWriting's catch, which charges Start's hold.
-
When the cut is taken.
- It must be shorter than the first rewrite.
restoreKeptmust find every kept line on a line of its own in the cut.- The people, link and number guards, the restore and
after_charsall run on the page that's kept. - The first pass's reason and sources stay.
-
Time. Two calls of up to three minutes each fit inside the ten-minute stale window for both the claim and the run.
-
Rewrite, cited passages too.
- It sends
locked: []. The API already takes that, since the editor could always unlock passages. - It's disabled in the same cases as Run Agent: AI usage spent, suggestions still open, cited passages still loading, or the agent busy.
- The hint says the passages may stop being quoted, and that the person compares before anything changes.
lastRewriteSaysnow keeps a miss by a rewrite that kept less than the page keeps now. It doesn't take that rewrite reaching the band as proof the Length is in reach. Both cases have tests.
- It sends
-
"longer than the page before". It shows only when all of these hold:
- the page was over the band's top;
- the rewrite still is;
- the rewrite is longer than the page.
-
Merges. Merge commit 854d28a changes nothing beyond merging its parents. The PR contains #1514, and it merges cleanly on main and with #1525.
-
Before the API is deployed.
- The card's "longer than the page before" works.
- The cited-passages button works on the old API, which takes an empty locked list. It's one call, with no cut.
- Nothing that works today breaks.
- Once the API goes out, a page rewrite far past its Length can make a second, charged call.
Follow-ups:
-
_rules-tab.tsx:264-269: a cited-passages rewrite that misses gets offered again.- After it misses, the note says "The last rewrite came to N, so another won't get there". It still offers Rewrite, cited passages too, the same rewrite that just missed.
- Each click is charged, and costs two calls once the API is deployed. That brings back the loop #1514 closes, through this button.
- Two texts are also wrong for that rewrite, since it kept none of the quoted passages:
- the note's "or unlock passages you're fine to have reworded" (
en.json:5248); - the card's "(N characters are passages AI answers quote…)" (
_agent-card.tsx:383-386), which shows when the floor is past the band.
- the note's "or unlock passages you're fine to have reworded" (
The row already tells such a rewrite apart: its
keptis below the page's by more than the slack, the same test asinReach(rules.ts:885). In that case, after a miss:- hide the button;
- drop the unlock clause;
- skip
lengthKept.
Add a test with
last: { chars: 5_200, target: 4_000, kept: 0 }. -
content-writer.js:639-642: a first answer that leaves a kept line out entirely still gets a cut.- The run fails at
restoreKeptanyway, and the cut can't bring the line back, because it never sees it. - Yet the cut runs first and is charged, and the person waits up to three more minutes before seeing "failed".
- Fix: return
answerbefore reserving when one ofpage.kept's numbers isn't anywhere inanswer.htmlas[[${page.word} n]]. - Leave a line written into a paragraph to the cut. It may put the line back on its own, which saves the run.
- The run fails at
Summary
Stacked on #1514. The PR's own changes are the two commits after the merge of #1514's branch.
In the live editor test (2026-10-25), page rewrites for a Length of 4,000 came to 5,468, 6,843 and 7,335 characters. The third made the page longer, and nothing said so. #1514 stops recommending a rewrite for a Length it can't reach. This PR makes a rewrite reach a Length it can, and says when it didn't.
Server: one more pass that only cuts (
content-writer.js,cutToLength).[[KEEP n]]line as it is, the links, the facts and the placeholders, and adds nothing new.restoreKeptcan put every kept line back. A line written into a paragraph would otherwise fail the whole run. If the cut isn't taken, or the call fails, the first rewrite stands (logged).after_charsall run on the page that's kept. The first pass's reason and data stay; the cut pass gets the page only, so it has no data to name.Web.
rewritePage({ citedToo })).lastRewriteSays):Related issue
Editor test findings 2026-10-25 (group B, part 2).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Server tests cover:
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors; the 6 warnings are in files this PR doesn't touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Server: format, lint,
npm test. Web:yarn testandyarn build. A pre-push review ran; its findings are the last commit.🤖 Generated with Claude Code