Repository navigation
feat(content): hand a draft's open Quality checks to the Content Agent in one run (00275, CE-051, part 1) - #1481
Conversation
…t in one run (00275, CE-051, part 1) POST /api/content-drafts/:draftId/handoff (Quality phase 2): the editor sends the page's fixable checks by key, with what each names on the page; the server says what each asks and runs Fix open rules as one run of kind 'handoff', its suggestions left for review. The editor's details are no fact the agent may write, and a placeholder stays the person's. 00275: content_agent_runs.kind 'handoff' and origin (person | auto), an automatic hand-off once a draft; brands.content_quality_handoff (off by default) and content_drafts.quality_handoff, the brand's setting copied when the draft is made. An automatic run on a draft its brand doesn't hand off is 409 not_due, a second one 409 already; one the AI budget stops before it begins is taken back, to run once the budget renews. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rand's approved facts Pre-push review fixes: - the source checks (claims, fresh, weak, primary, broken) read the draft's sources as link targets, so the agent can link one - trust:brandFacts writes the brand's approved facts, read on the server - a placeholder is read in the passage before and after the change: a "before" that cuts into its brackets doesn't fill it - the person's own rules are no fact a hand-off may write either - not_due first; a person's run writes no origin (the column's default), so a database before 00275 takes it; a run not taken back is failed Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tting off Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
One fix before merge, plus two small follow-ups.
I ran 00275 against the current schema in a rolled-back transaction, after 00271–00274. It applies cleanly, and these all behaved as described:
- A new draft copies its brand's setting, and a member can't change it on the draft.
- Only admins and managers can change the brand's setting; another organization's member can't see or change it.
- Members can read runs but can't write them.
- A second automatic hand-off on a draft is refused; a person's hand-offs can repeat.
- The
prompt_improve_usage.featurecheck is untouched (a hand-off chargescontent).
The budget hold, the miss/timeout handling and Stop are the same as Fix open rules'. Unknown or to-do check keys are rejected (400).
-
The placeholder check lets a fill through when a passage has the same placeholder twice.
server/src/lib/content-agent.js:525-530:dropsPlaceholderonly asks whether each placeholder still appears somewhere in the changed passage (changed.includes(placeholder)). The number guard writes its own placeholder in one fixed form ([figure, source]), so a paragraph with two unsourced figures often has the same placeholder twice.- Example: in "Teams save [figure, source] and cut costs by [figure, source].", a replace of "Teams save [figure, source]" with a sourced figure is kept, because the second copy still matches.
trust:claimsSourcedasks for exactly this kind of change. - Fix: count each placeholder before and after the change, and drop the suggestion when any count falls. Ideally, count it in what will actually be kept (the words and blocks after
splitReplace), not in the rawafter. - Add a test with a duplicate placeholder.
- Smaller point: the editor reads only the agent's own placeholder forms in headings (
placeholderIn(heading)inweb/src/lib/content/placeholders.ts). Using the same rule for h1–h6 passages would stop a title like "… [2026 Update]" from blocking a heading change.
- Example: in "Teams save [figure, source] and cut costs by [figure, source].", a replace of "Teams save [figure, source]" with a sourced figure is kept, because the second copy still matches.
-
Low, follow-up: the model isn't told to leave placeholders alone. The guard throws those suggestions away only after the model's call has been paid for.
buildFixPrompt(content-agent.js:533, called at:830) gets no hand-off flag. For a hand-off, add one line along these lines: "Leave every [placeholder] exactly as it is: the person fills it; don't change or remove one." -
Low, follow-up: nothing on the server stops two runs at once on the same draft. Fix and Hand off both check for open suggestions and a Start/Rewrite claim (
content-agent.js:653-666), but not for another Fix or hand-off run that's still going. A person's Hand off (or Fix) during the automatic run, or from a second tab, would make two model calls and charge both. The later batch would then hide the earlier one. This already happens with Fix, but the automatic run makes overlaps more likely.- Fix: before
startRun, refuse with 409 (running) when the draft has afixorhandoffrun that hasn't finished and isn't stale. - At the least, the web part should disable Hand off and Fix while either is running.
- Fix: before
…doff-api # Conflicts: # supabase/schema.sql
…ne fix at a time (CE-051) - dropsPlaceholder counts each placeholder before and after the change, read in what is kept (the new words and the blocks after them): filling one of two "[figure, source]" in a passage is dropped too. In a heading only the agent's own forms count, as the editor reads them. - A hand-off's prompt says to leave every [placeholder] as it is. - Fix open rules and a hand-off are refused with 409 `running` while another fix or hand-off on the draft is under way (fixUnderWay). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Fixed in a1b8c2c. Main was merged forward first in 01aae69; the only conflict was
Server: format, lint and |
… Hand off sends, and say `running` (CE-051) - usePageRead's reading now counts a save not asked about yet (ansvisor#1468), so the hand-off's own `behind` flag goes. Hand off waits for the page's read before its first answer, or after a save while it sends what AI read of the page (Answer first, the disclosure, balance); not after every save. - The API's 409 `running` (another fix or hand-off on the draft, ansvisor#1481) is said, for Fix open rules too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
All items done:
dropsPlaceholdercounts each placeholder before and after the change, in what will be kept. In headings it counts only the agent's own forms, as the editor does.- On a hand-off, the prompt tells the model to leave placeholders as they are. Fix open rules' prompt is unchanged.
- Fix and Hand off answer 409
runningwhile another fix or hand-off on the draft is under way. This is checked before anything is charged. An automatic hand-off refused this way hasn't taken its claim yet, so it can still run later.
The merge of main (01aae69) changes nothing beyond the schema.sql rebuild.
I ran 00275 again after 00273 and 00274 against the current schema, in a rolled-back transaction. I tested it as an analyst, a manager and another organization's admin:
- Only the manager can change the brand's setting. Another organization's admin can't see or change the brand, its drafts or its runs.
- A new draft copies the brand's setting, even when the insert asks otherwise. Neither the analyst nor the manager can change it on the draft.
- Members can read runs but can't insert or update them.
- A second automatic hand-off on a draft is refused (23505). A person's hand-offs can repeat.
- An unknown
kindororiginis refused. - The
prompt_improve_usage.featurecheck is untouched; a hand-off chargescontent, which it allows.
Two small follow-ups:
- Low: the new
keepSuggestionscase passes without the placeholder check. Incontent-agent.test.js:1342-1350, thefilledsuggestion writes "30%" with no source, so the number guard drops it anyway. Fill the placeholder with words instead (for example "Teams save hours"), so that only the placeholder check can drop it. - Low: a stopped run still counts as under way until it ends.
fixUnderWay(content-runs.js:53-63) doesn't skip stopped runs. When another server holds the stopped run, it ends only after its model call returns, which can take up to a minute. Until then, Stop followed by Hand off or Fix answersrunning. A stopped run keeps nothing, so the query can add.is('stopped_at', null), asstopDraftRundoes.
Summary
Quality Phase 2, CE-051 "Hand off to Content Agent", part 1: the server and 00275. This PR is from main.
The spec (§5) says: "One button, Hand off, in the Quality segment. The agent runs every fixable suggestion in one go… Results arrive as normal suggestions. What only the user can give stays on the to-do list. The agent leaves [placeholders]; it never fills them itself." There's also a Settings › Content toggle, "Hand off quality fixes automatically" (off by default), that does it for every new or optimized page, with every run logged and counted toward AI usage.
Quality's checks are computed in the browser, so the editor sends the open, fixable ones. The server says what each asks, and runs the existing Fix open rules pipeline as one run of its own kind. That pipeline already has the budget hold, the step chips, Stop, the number, person and quote guards, and locked passages. The web parts follow as stacked PRs: Settings, the Hand off card, then the automatic run and History.
POST /api/content-drafts/:draftId/handoff(Quality phase 2, else 404off){ brandId, items: [{ key, detail }], textRules, locked, sources?, origin }.keyis one of the 15 fixable checks:HANDOFF_CHECKSholds the instruction for each key in the server's own words. A to-do's key, or any other, is a 400.detailis what the check names on the page (its sentences, links, the disclosure line).{ count, batchId }and its errors as/suggestionsdoes. New:not_due: an automatic hand-off on a draft its brand doesn't hand off. It's checked first.already: the draft had its automatic one.Guards, on top of Fix's
trust:brandFactsreads the brand's approved facts (still on its site) on the server, and those it may write.00275
content_agent_runs:kindgains'handoff';origincolumn (person|auto, defaultperson);brands.content_quality_handoff, off by default; brands' admin/manager update policy covers who may change it.content_drafts.quality_handoff: a trigger copies the brand's setting when the draft is made, and undoes a member's change. Turning it on reaches new drafts only. Turning it off stops the drafts not handed off yet: an automatic run also needs the brand's setting as it is now (3c8eb75).Automatic runs
Deploy order: apply 00275 before this server code. A person's run writes no
origin; the column's default covers it, so older runs still insert. But hand-off runs, and the new kind, need the migration.Pre-push review fixes: link targets for the source checks, brand facts read on the server, the placeholder check on the whole passage, text rules no longer counted as facts,
not_duefirst, nooriginon a person's run, a run not taken back marked failed. All have tests.Left for follow-ups:
Related issue
Quality spec (Drive), Phase 2, CE-051 (part 1).
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
CONTENT_QUALITY_PHASE=2on the server.POST /api/content-drafts/{id}/handoffwith{ brandId, items: [{ key: "readability:longSentences", detail: "…" }] }. It answers{ count, batchId }, and the draft has a new suggestion batch.content_agent_runshas ahandoffrun.origin: "auto"on a brand withcontent_quality_handoffoff: 409not_due. Turn it on, make a new draft, hand it off twice: the second is 409already.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/) — no web changeyarn typecheckpasses (run fromweb/) — no web changeyarn format:checkpasses (run fromweb/) — no web changeServer:
npm run format,npm run lintandnpm test(2,534 passed) pass.supabase/schema.sqlrebuilt.Migration order: 00275 follows 00271–00274 (open PRs). I'll renumber if they merge out of order.
🤖 Generated with Claude Code