Skip to content

feat(content): keep the Content Agent's changes small for rules a brand mostly rejects them for (learning B6) - #1686

Merged
gkhngyk merged 6 commits into
ansvisor:mainfrom
cihan-gyk:feature/suggestion-decision-stats
Oct 28, 2026
Merged

gkhngyk merged 6 commits into
ansvisor:mainfrom
cihan-gyk:feature/suggestion-decision-stats

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Agentic learning, B6: the Content Agent keeps its changes small for rules a brand mostly rejects.

Each suggestion the agent leaves on a draft names the rules it fixes, and keeps whether a person accepted or rejected it. Until now, nothing was learned from those decisions.

Migration 00367: content_suggestion_decisions(p_brand_id, p_since). It returns one brand's accepted and rejected suggestions since a given day, by rule key, plus the number of drafts the suggestions were decided on.

  • Only small changes count: kind in ('replace', 'insert'). A whole page rewritten to the rules (kind 'page') names every rule it was asked for, so one rejected rewrite would count against all of them.
  • Service role only. A drop function if exists comes first, because the review changed its return shape on dev. Ends with notify pgrst.

carefulRules (content-suggestion-stats.js). A rule is "careful" when, over the last 90 days, all of these hold:

  • it has at least 5 decisions;
  • at least 7 in 10 of them were rejected;
  • its suggestions were decided on at least 2 drafts, so one Reject all on one draft isn't read as a habit.

The run's own rules are filtered first, then sorted and capped at 5. Only the brand's own decisions are used; nothing crosses brands. That's the user's decision.

content-agent.js.

  • For this run's careful rules, the fix prompt gets a line: "People at this brand reject most of the changes suggested for these rules: faq (7 of 8 rejected). … keep it as small as the rule allows".
  • The run's read_rules step records careful.
  • If the read fails, the run goes on as before.
  • Quality's Hand off is out of scope: no stats are read there.

Web. While the agent runs, its card says: "Keeping its changes small for rules people here mostly reject: Price, GTIN and stock match the feed and FAQ block." Rule names are joined with Intl list formatting, because some names contain commas.

Docs: content-editor.mdx.

Deliberately not done: feeding these decisions into the brief eval. The eval runs on the maintainer's fixed samples, and putting customers' decisions there would use one brand's data for others.

Known noise (follow-up): suggestions auto-rejected when a version is restored from History, and suggestions left by an MCP outside agent, both count as decisions. No column tells them apart yet.

Where people see it: Content Editor › Rules › Apply rules with Agent, on the agent card while it runs. The line only appears once a brand has enough rejections. The local demo brand has no decisions, so it was checked by tests.

Merge note: independent of the learning Phase A stack. Merged with it, only supabase/schema.sql conflicts; re-run bash supabase/build-schema.sh to resolve it.

Related issue

Agentic learning report, Phase B (B6). No GitHub 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. Apply 00367. Then run select * from content_suggestion_decisions('<brand>', now() - interval '90 days'); to get rule keys with accepted, rejected and drafts.
  2. cd server && npx vitest run src/lib/content-suggestion-stats.test.js src/lib/content-agent.test.js
    • Covers the thresholds, the two-draft rule, the run's rules being filtered before the cap of 5, Hand off left out, and the migration's kind filter.
  3. cd web && npx vitest run "src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-card.test.tsx"

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 9661462:

  • server format, lint and npm test (no SUPABASE_* env, as in CI): 3,345 tests passed. content-agent.test.js and content-people.test.js timed out under load; each passed alone (102/102, 32/32).
  • web format, lint (0 errors; 7 warnings already on main), typecheck, vitest (443 files, 4,337 tests) and build: all pass.

A pre-push review was run, and its findings are fixed (0bc6ec1, 8f430e1, 9661462). The first commit's message still quotes the card's old wording ("Kept its changes small…"); it is "Keeping…" now. 00367 is applied on the dev database.

🤖 Generated with Claude Code

cihan-gyk and others added 4 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]>
@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 f05c41c.

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

@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 5961372: drafts counts only the drafts a rule's suggestions were rejected on, so one Reject all can't make a rule careful. 00367 is applied to production. The follow-ups (a version restore counting as rejections, an index on decided_at) stay open.

@gkhngyk
gkhngyk merged commit e7270da into ansvisor:main Oct 28, 2026
6 checks passed
gkhngyk added a commit that referenced this pull request Oct 28, 2026
… it changes it (learning B5, part 3) (#1699)

* feat(content): keep the Content Agent's changes small for rules a brand 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]>

* fix(content): weigh only a brand's small changes decided on two drafts 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]>

* fix(content): say on the agent card it is keeping its changes small, 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]>

* docs(content): say the Content Agent learns from this brand's decisions, 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]>

* feat(content): tell the Content Agent what the live page earns before 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, #1686): same prompt slot,
run step and card line pattern.

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

* fix(content): read the live page at its published address, as the Live 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]>

* test(content): cover the live page's read, its hand-off and a failed 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]>

* refactor(content): give the agent card's live page line its own comment

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]>

* fix(content): write the live page's earlier citations with thousands 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]>

* fix(content): name the live page on the agent card only when AI answers 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]>

* fix(content): tell the Content Agent "1 time" and "1 AI visit", not "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]>

* docs(content): say Quality's Hand off is affected by neither of Apply 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]>

* fix(content-agent): count only the drafts a rule's suggestions were rejected on

* fix(content-agent): quote each lost prompt on one line, cut to 300 characters

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants