Skip to content

feat(content): rewrite the page from its brief with the Content Agent - #1351

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/rewrite-from-brief
Oct 22, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/rewrite-from-brief

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Content Editor feedback item 12. The Brief tab could build and edit a brief, but nothing wrote the page from it.

  • Web: a button under the brief.
    • It reads Rewrite from brief on a new page and Suggest changes from brief on a live page. It shows when the brief has an outline.
    • It asks first, inline: the agent writes the page again from the brief, the sources kept and the rules, and the current page stays in History. On a live page, the passages AI quotes stay as they are. Either way it uses the month's AI usage.
    • It then starts the agent with the editor's own start, which Try again already used (retryAgent → startAgent). So the brief, sources and rules in effect go with it, and the editor shows the agent at work.
    • It is offered while the page is a draft or in review, and stays disabled while suggestions are open ("Accept or reject the open suggestions first.").
  • Server: the agent writes a draft in review too. A page the agent wrote is in review, and rewriting it was refused with not_draft.
    • content-writer.js now accepts OPEN_STATUSES = ['draft', 'in_review'] for the check, the claim and the run's finish (openOnly, which was draftOnly).
    • A draft marked ready or published is still refused, and one marked ready during the run keeps its page.
    • The create run keeps the page it replaces in History first (agent_before), as before.
  • Follow-ons: the editor's "couldn't finish" banner and the Library's agent badge now show on a draft in review as well.

What the agent writes from (buildWritePrompt): the brand, the page type and length, the brief (the draft's own, else the opportunity's), the tracked prompts, fan-outs, Search Console queries, the pages AI cites (to beat, never copy), the rules and the writer's own rules, and on a live page its passages, with the quoted ones locked.

Related issue

Content Editor feedback round (no issue).

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 with a brief that has an outline (build one in the Brief tab, or set content_drafts.brief on a dev draft).
  2. In the Brief tab, Rewrite from brief (new page) or Suggest changes from brief (live page) asks first. Start the agent opens the waiting screen, and the editor comes back with the page or the suggestions.
  3. Run it again on the same draft, now in review: it starts instead of saying the draft isn't a draft. A draft marked ready offers no button, and the API refuses it.
  4. With suggestions open, the button is disabled with the reason on hover.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • web: yarn test (2634 pass, with new Brief tab and editor tests) and yarn build;
  • server: npm run format, npm run lint and npm test (2029 pass, with a new test for writing a draft in review).

Checked in the browser in light and dark, on a dev draft given a brief (removed after). The agent itself wasn't run.

🤖 Generated with Claude Code

The Brief tab builds and edits a brief, but nothing wrote the page from it.
Under the brief, Rewrite from brief (a new page) or Suggest changes from brief
(a live page) hands the draft to the agent after a confirm. It uses the
editor's own start (as Try again does), so the brief, the sources kept and
the rules in effect go with it, and the editor waits for the agent. It is
offered while the page is a draft or in review, and waits while suggestions
are open.

The API now writes a draft in review too (a page the agent wrote, written
again), never one marked ready or published. The page it replaces is kept in
History first, as before. The failed banner and the Library's agent badge
show on a draft in review as well.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk this is Rewrite from brief from the editor feedback. One server change to check: content-writer.js now lets the agent write a draft that is in review (so the agent can write again a page it wrote), still never one marked ready or published. The rest is web: a button under the brief that reuses the editor's Try again start. No migration. It touches the editor files like #1347–#1350 in other places; I'll merge main into whichever lands later.

@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. Two small follow-ups.

  1. _draft-editor.tsx:729: Rewrite from brief isn't blocked while Fix open rules (Apply rules with Agent after #1346) is running.
    • On a live page, the writer's model call is metered and then dropped: content-writer.js:446 lets go, because the fix's batch came in during the run.
    • On a new page, the rewrite replaces the page that the fix's batch points at, so its suggestions can't be applied.
    • Fix: add fixing ? t('suggestions.fixing') : null to blocked, and disable the rules button while starting.
  2. web/messages/en.json:3506 (and :3358): not_draft now means "marked ready or published". "This draft is no longer a draft" reads wrong next to a draft in review. For example: "This page is marked ready or published, so the agent didn't start."

Checked, and fine:

  • Route. POST /write is unchanged: guid ids, assertBrandAccess(brandId, req.user.id), the draft's brand_id checked against the brand (404), then its status. The claim stays atomic on status in (draft, in_review) and agent_state, and so does the finish (openOnly). A draft marked ready during the run keeps its page.
  • Cost. It goes the same way as Start's Agent: enforceImproveQuota before the claim, recordUsage after the call, and one run per organization (org_writing). The page is kept in History (agent_before) before it's written over.
  • Prompt injection. The brief and the page go to generateObject with a schema and no tools, so there is no tool call to hijack. A new page's text is escaped (renderPage). An inserted block goes through cleanInsertHtml, which keeps allow-listed tags and strips every attribute, so no links. A person reviews both. This PR adds nothing new to the prompt.

Merge notes

  • Merges cleanly on main and with #1346, #1347, #1348, #1349, #1350 and #1353. No migration.
  • With #1349: this PR's new test expects 'Content Agent is writing this page' (page.test.tsx:1449). #1349 renames it to 'Content Agent is working on this page', so whichever lands second updates it.
  • The server change has to be deployed for the button to work on a draft in review. Until then, the API refuses it with not_draft. Deploy the server with, or before, the web.

Tested on top of main together with #1353, #1347, #1348, #1350 and #1351: web and server tests, tsc, lint and Prettier pass.

@gkhngyk
gkhngyk merged commit 4e14ae5 into ansvisor:main Oct 22, 2026
6 checks passed
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 22, 2026
…keep the timer from screen readers

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk pushed a commit that referenced this pull request Oct 22, 2026
…step (#1349)

* feat(content): open the editor on the Content Agent at work, step by step

Start offers the agent first (Agent · Me · Team; Me stays the default, as
the agent's run is metered). Picking the agent opens the editor at once
instead of a toast to click. While the agent writes, the editor shows its
steps as Chat shows its tools: the reading and the rules done, the writing
(or the suggestions on a live page) under way with the time it has taken,
and the review to come. Past two minutes it says the wait is longer than
usual. The draft carries agent_state_at as agentSince for the timer.

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

* fix(content): read the wait's new title in #1351's test, and keep the timer from screen readers

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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