Skip to content

feat(content): tell the Content Agent what the live page earns before it changes it (learning B5, part 3) - #1699

Merged
gkhngyk merged 17 commits into
ansvisor:mainfrom
cihan-gyk:feature/content-agent-page-impact
Oct 28, 2026
Merged

gkhngyk merged 17 commits into
ansvisor:mainfrom
cihan-gyk:feature/content-agent-page-impact

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Agentic learning, B5 part 3: the Content Agent is told what the live page earns before it changes it.

Stacked on #1686 (B6). Both change the same places: buildFixPrompt's parameters and template line, fixWithRun, run.steps, agent-runs.ts, _agent-card.tsx, en.json and the same content-editor.mdx paragraph. This PR's own commits are afa15c7 and the review fixes after it.

content-live-page.js reads the Live page tab's figures through content_page_impact (00209, service role), for 30 days and the 30 before:

  • citations now and before;
  • how many prompts cite the page, and how many it lost, with the text of the 3 lost prompts most cited before;
  • AI visits now and before.

It returns null when the page was neither cited nor visited in either window.

content-agent.js reads this summary only for Apply rules with Agent on a draft of a live page. Quality's Hand off is unchanged.

  • The fix prompt gets "How the live page does now …", with this guidance:
    • keep the answers, facts and names that are cited;
    • don't change them unless a rule needs it;
    • where it can, answer a lost prompt's question.
  • run.steps[1] keeps live: { days, citations, before, lost }.
  • If the read fails, a warning is logged and the run goes on as before.

Web. While the agent runs, its card says: "Keeping what the live page earns: cited 12 times in 30 days (20 before), 2 prompts lost."

Pre-push review fixes:

  • 3d18772: the page is read at published_url ?? source_url, the address the Live page tab measures. Before, a draft published and then reverted to Draft read its old source address.
  • f99fa7a: new tests:
    • Hand off reads nothing;
    • the RPC gets the brand id, the page and 30 days;
    • a failed read keeps the run going;
    • readLivePage: null, window, lost-prompt order.
  • 5134a5e: the card's live line sits under careful, with its own comment.
  • 1e36871: {before, number}, so the count reads "1,200" like the other.
  • 3192a1b: a page with AI visits but no citations shows no card line ("cited 0 times" read oddly); the prompt still mentions the visits.
  • 1aa293d: "1 time", "1 AI visit" in the prompt.
  • f592f7a: the guide's "Quality's Hand off isn't affected" now closes the paragraph, covering both B6 and this.

Safety:

  • The route checks brand access, and the draft must belong to the requested brand.
  • The RPC filters every table by p_brand_id and the brand's own domains, so no other brand's data is read.
  • The lost prompts quoted are the brand's own; the output still goes through the number, people and link guards, and asks a person to accept it.

Follow-ups:

  • paused prompts count as "lost", as on the Live page tab;
  • the page path is matched without its domain, as on the tab;
  • no timeout on content_page_impact.

Where people see it: Content › Editor › a draft optimizing a live page › Rules › Apply rules with Agent: the line on the agent card while it runs. New-page drafts show nothing. No new button. Cost: one paragraph more in the same model call, and one RPC per run.

Related issue

Agentic learning report, phase B (B5). No GitHub issue. Learning stays within one brand.

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. cd server && npx vitest run src/lib/content-agent.test.js src/lib/content-live-page.test.js
  2. cd web && npx vitest run "src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-card.test.tsx"

The local demo brand has no draft of a live page with impact data, so this was checked by tests.

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

Full checks at f592f7a:

  • server format, lint and npm test (no SUPABASE_* env, as in CI): 248 files, 3,362 tests passed;
  • web format, lint (0 errors; 7 warnings already on main), typecheck, vitest (443 files, 4,338 tests) and build: all pass.

A pre-push review was run, and its findings are fixed.

🤖 Generated with Claude Code

cihan-gyk and others added 12 commits October 28, 2026 09:20
…nd mostly rejects them for

Learning phase B, B6 (the report's gap 6). Each suggestion the agent
leaves names the rules it fixes and keeps whether a person accepted or
rejected it (00217), but nothing read the decisions back: the agent kept
suggesting the kind of change people there turn down.

- 00367 content_suggestion_decisions(brand, since): a brand's accepted and
  rejected suggestions by rule key (service role only; applied on the dev
  DB; schema.sql rebuilt).
- content-suggestion-stats.js: carefulRules reads the last 90 days and
  names the rules with at least 5 decided and 7 in 10 rejected, the most
  rejected first, 5 at most. One brand's own decisions only, never
  another's.
- content-agent.js: for the rules in this run among them, the fix prompt
  says "People at this brand reject most of the changes suggested for
  these rules: faq (7 of 8 rejected). For them, suggest a change only
  where the rule can't be met without it, and keep it as small as the rule
  allows…", and the run's rules step keeps `careful`. A read that fails
  leaves the run as it was.
- The editor's agent card shows, under the run's steps: "Kept its changes
  small for rules people here mostly reject: Price, GTIN and stock match
  the feed."
- The guide says so.

Not done: the report also wanted these stats as an input to the brief
eval. That eval runs the maintainer's fixtures, and feeding it customers'
decisions would use one brand's data beyond it; left out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s or more, among the run's own rules, and leave Quality's hand-off out

Review fixes for B6.

- 00367 counts small changes only (kind 'replace' or 'insert'): a page
  rewrite names every rule it was asked for, and one rejected counted
  against each. It also returns the drafts a rule's suggestions were
  decided on, drops an earlier shape of itself first (create or replace
  can't change its rows), and ends with notify pgrst. schema.sql rebuilt.
- carefulRules needs two drafts or more (CAREFUL_MIN_DRAFTS), so one
  Reject all alone isn't read as a habit, and takes the run's rule keys:
  it looks only at them before naming five, so other keys (an outside
  agent's suggestions can name any) never take their places.
- Quality's hand-off runs as it was: its card doesn't show the note, so
  only Apply rules with Agent reads the decisions.
- The stats test reads the migration, and states its expected line plainly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the rules named as a list

The note shows only while the agent works, so it reads "Keeping its
changes small for rules people here mostly reject: …", not "Kept…". The
rules are joined with format.list (as the editor's ruleNames does), since
a rule's name can have a comma of its own: "Price, GTIN and stock match
the feed and FAQ block".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ns, small changes only, in Apply rules with Agent

The decisions are read per brand, not per workspace; a rule needs them on
two pages or more; a rejected page rewrite doesn't count; the card names
the rules while the agent works; and Quality's Hand off isn't affected.

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

Learning B5, part 3. The agent fixed a live page's rules without knowing
what the page earns as it reads, so a change could take out the very
answer AI engines cite, and it never knew which prompts the page lost.

- content-live-page.js: the Live page tab's numbers (content_page_impact,
  00209, service role) over 30 days against the 30 before: citations, the
  prompts citing it and the ones it lost (three named, most cited before
  first), AI visits. Nothing when the page was neither cited nor visited.
- Apply rules with Agent on a draft with a source page: the fix prompt
  says how the page does now, asks to keep the answers, facts and names AI
  engines may cite and to answer a lost prompt's question where a rule's
  change can. Quality's hand-off runs as it was; a failed read too.
- The run's gather_sources step keeps { days, citations, before, lost };
  the agent card says "Keeping what the live page earns: cited 12 times in
  30 days (20 before), 2 prompts lost."
- The guide says so.

Stacked on feature/suggestion-decision-stats (B6, ansvisor#1686): same prompt slot,
run step and card line pattern.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e page tab does

The agent read the live page at the draft's source address only, while the
Live page tab reads the address the draft was published at first. On a
draft published elsewhere and taken back to Draft, the agent was told about
another page than the one the tab shows.

- fixDraftRules reads published_url too and asks content_page_impact for
  published_url ?? source_url.
- The test supabase records what each function was sent; the B5 test checks
  the brand, the page and the 30 days.

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

- Quality's hand-off neither reads the live page nor is told about it, while
  Apply rules with Agent on the same page is (B6's hand-off test's twin).
- A live page read that fails leaves the run as it was: no line in the
  prompt, nothing on its sources step, its suggestions kept, a warning
  logged.
- readLivePage: what it sends content_page_impact (the brand, the page, 30
  days or the window given), the three lost prompts it names (most cited
  before first, the count past them), nothing without a page or with
  nothing to tell, and the error it throws.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
B6's comment on the careful rules sat above the live page's line; the live
page now comes after them, with a comment of its own.

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

The agent card wrote the citations of the last 30 days through plural's #,
"1,500", and the 30 before as they came, "1200". {before, number} writes
both alike.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rs cited it

A page with AI visits but no citations in either window put "cited 0 times
in 30 days (0 before)" on the agent card. Its sources step keeps the live
page only when it was cited now or before; the agent is still told of its
visits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…1 times"

The live page line counted citations and AI visits in the plural whatever
their number; one is now said as one, as the prompts already were.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… rules with Agent's lessons

The sentence came between what the agent learns from the brand's decisions
and what it is told of the live page; at the paragraph's end it covers both.

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

mintlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 911d4fb.

Approve preview

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 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 with 457168b: each lost prompt is quoted on one line and cut to 300 characters before it reaches the model. Merged on top of #1686. The follow-ups (a timeout on the impact read, naming lost prompts past the first 100) stay open.

@gkhngyk
gkhngyk merged commit 5732d49 into ansvisor:main Oct 28, 2026
5 of 6 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