Skip to content

fix(content): one agent state per rule, the Length conflict first, and the page type before any run - #2391

Merged
gkhngyk merged 6 commits into
ansvisor:mainfrom
cihan-gyk:fix/editor-one-agent-state
Nov 14, 2026
Merged

gkhngyk merged 6 commits into
ansvisor:mainfrom
cihan-gyk:fix/editor-one-agent-state

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Stacked on #2389 (fix/editor-rules-follow-page-type: rules follow the page type, "Not checked on this page", ruleSetType()). Review and merge that first; until it lands, this diff also shows its commit.

The owner allowed this change in the Content Editor folder (dashboard/content/editor/[draftId]/).

Summary

The owner hit a loop in the Content Editor. Fix open rules took the rules from 10 to 11 met. Then "Next · Shorten to your Length" ran a rewrite that dropped the FAQ and fan-out sections, so the count fell to 9 and Fix came back. After that, the steps window marked Fix open rules done, while the Rules tab still said "4 rules are not met" with an active Fix open rules button.

The cause was that each part read a different state. The Rules tab, a Fix run, Next's order and the steps window each counted "what the agent can still fix" their own way, and "tried" only changed a rule's colour.

This PR covers three of the four parts of the fix:

  • One state per rule (F1). A single pure helper, agentFixable(), now feeds every place that offers the agent a rule.
  • Conflict first (B1). When the rules can't fit the Length, the next step is to raise the Length, before Fix or a rewrite.
  • Page type first (A2). With no page type, the first step is Set page type.

Next's order is now: page type → conflict → Fix open rules → the Length's rewrite → Before you publish.

The fourth part, "Rewrite within all rules" (B2), follows in its own PR to keep this one to size. That PR gives the server's cut pass the rules so it never drops a section they ask for. It also adds the "Rewrite left N rules open that were met" line beside Undo and renames the Length step.

Changes

  • agentFixable() (lib/content/tried-rules.ts) returns two lists.
    • fixable: the open rules, less those the agent never fixes, a setting only the person fills (Who it's for, unset), rules held by what the page keeps, rules the agent tried and couldn't close, and rules not checked on this page.
    • yours: the rest of the open rules, which are the person's to decide.
  • Where it's used. The Rules tab's Fix button, fixRules(), the agent card's Run, rulesForNext() (Next's Fix step) and the steps window all read agentFixable(), so a tried rule is no longer offered to the agent anywhere.
  • Rules tab. With nothing the agent can fix and rules still open, the button gives way to "Content Agent did what it could. N rules are yours to decide." Under it is the list of those rules, each with:
    • Change the page: focuses the page, and the rule's spot where it has one (an AI trace's phrase);
    • Change the rule: focuses the rule's value, or its switch;
    • Ask again: for a tried rule only, clears its mark and runs Fix for that rule alone.
  • Steps window. Fix open rules shows as "done by Content Agent, the rest is in Rules" whenever nothing open is the agent's but rules remain, as the Rules tab says.
  • Next step order (lib/content/next-step.ts):
    • New pageType step, with the Set page type action. It opens the header's page type menu.
    • New conflict step, "Raise Length to ~N". N is what the rules need, rounded up to 50. One click sets the Length value. The other action, Ask for fewer, opens Rules on the count rule's value.
    • Fix open rules now comes before the Length's rewrite.
    • A tip no longer repeats the step's other button.
  • Strings are in en.json. Help is updated in "Write to the Content Editor rules" (new "Rules that are yours") and "Check a page's Quality" (new "The order of the steps"), and regenerated.

Known gap

If the agent's own accepted batch opens a rule it was never sent, the steps window can still show Fix as passed while the Rules tab offers Fix for that one rule. That rule becomes "tried" after one more run, so it can't loop.

How to test

  1. Tried rules. Open a draft with a few open rules and run Fix open rules. Reject what it suggests.
    • The rules it tried turn amber.
    • Once none is left that the agent can fix, the Rules tab shows "Content Agent did what it could…" and the list instead of the button.
    • Next step shows Fix open rules as done by Content Agent, with the rest in Rules.
  2. List actions. In that list:
    • Ask again runs Fix on that one rule.
    • Change the rule focuses its value.
    • Change the page focuses the page.
  3. Length conflict. Set Length to 400 on a page whose rules ask for a fan-out section, an FAQ and a summary.
    • Next step reads "Raise Length to ~1,050".
    • Raise Length sets 1050.
    • Ask for fewer opens Rules on the fan-out H2 count.
  4. No page type. On a draft with no page type, Next step starts with Set page type, which opens the header's menu.
  5. Order. On a page far over its Length with open rules, Next offers Fix open rules first (with Rewrite page beside it), then the rewrite.

Checks

  • Web typecheck (tsc --noEmit): passes.
  • ESLint and Prettier on the changed files: pass. The one ESLint warning is an unused _args in an existing test, not part of this change.
  • Tests in src/lib/content, the Content Editor folder, use-server-exports and Help: 131 files, 1,755 tests, all pass.
  • Server content-writer tests: pass (no server change in this PR).
  • New tests cover:
    • the agentFixable helper;
    • Next's order: page type → conflict → Fix → rewrite → Before you publish;
    • Raise Length's value (rounded up to 50) and its one-click save;
    • the Rules tab's button turning into the "N rules are yours" list, with its three actions;
    • the steps window showing Fix open rules as taken by the agent;
    • rulesForNext leaving out tried rules.
  • No migrations, lockfile changes or new dependencies.

Generated by Claude Code

…n't meet are set apart

- A rule set picked while the page has no type sets the page type (through
  the header's page type path); a set picked for another type holds only
  while the page keeps the type it was picked on (rules.setFor), so setting
  or changing the page type brings back the page type's own set. Every
  reader (editor, Chat's rules read, the agent's request, Quality's type
  rules) goes through ruleSetType.
- Rules the page can't meet (another type's rule, no feed, no sizes, a
  product page with no specs, no fan-outs...) go under "Not checked on this
  page": never counted, and Rewrite and Chat's optimize no longer send them.
- Product, Category, Collection and Sizing-guide sets ask for 2 fan-out
  H2s, 3 FAQ questions and 2 fan-out questions, so no default set has a
  Length conflict (tested for every page type).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
…p what the rules ask for

One state per rule (F1): agentFixable() is the open rules less those the
agent never fixes, a setting only the person fills, rules held by what the
page keeps, rules it tried and couldn't close, and rules not checked on
this page. The Rules tab's Fix button, Fix open rules, the agent card's
Run, rulesForNext, the Next step and its steps window all read it. With
nothing left it can fix, the Rules tab says "Content Agent did what it
could. N rules are yours to decide." in place of the button and lists
them, each with Change the page, Change the rule and, for a tried rule,
Ask again (clears its mark and runs Fix for it alone). The steps window
shows Fix open rules as taken by the agent then, as the Rules tab says.

Conflicts first (B1): when the rules can't fit the Length, the next step
is "Raise Length to ~N" (what the rules need, rounded up to 50), set in
one click, with Ask for fewer beside it, before Fix or a rewrite.

Page type first (A2): with no page type, the first step is Set page type,
which opens the header's page type menu.

Next step order: page type, conflict, Fix open rules, then the Length's
rewrite, then Before you publish.

The rewrite within all rules (B2: the cut pass told the rules, the
rewrite-drop warning, the step's new name) is left for a follow-up, to
keep this change to its scope.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Keeps both PR1's "Not checked on this page" note and main's missing
fan-outs line in the rule row. The Rules tab Help section went over 150
words with both, so the fan-out paragraph is its own section now. Help
is regenerated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Brings in main (with the agent reliability and score changes) through
PR1's branch. No conflicts; Help needed no regeneration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
gkhngyk previously approved these changes Nov 14, 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.

LGTM (its own commits). Waits on #2389.

…set on an unrelated edit

- A set saved before setFor existed (rules.set with no setFor) holds
  whatever the page type, with or without one, as it did before ansvisor#2389:
  ruleSetType returns it, and rulesPageType checks its type rules as its
  own (editor, Chat's rules read, Quality's type rules), so they aren't
  set apart as another type's. Its customised rules stay.
- A set with setFor still holds only while the page keeps that type.
- Only the person's own set pick writes set (and setFor, which a legacy
  pin gains then); a rule's change, a toggle, the Length, Reset or the
  page type changed from the header keep set, setFor and the custom rules
  as stored, so nothing writes set: null behind the person's back.
- Help: the set follows the page type, except a set picked for another
  type (while the page keeps its type) and one picked before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
gkhngyk previously approved these changes Nov 14, 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.

LGTM.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 14, 2026 10:58

The merge-base changed after approval.

@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.

LGTM.

@gkhngyk
gkhngyk merged commit 209d4cb into ansvisor:main Nov 14, 2026
12 checks passed
gkhngyk pushed a commit that referenced this pull request Nov 14, 2026
When a brand has banned phrases in Brand settings › Content rules, the
Content Editor's Rules tab shows "Avoid your brand's banned phrases" in
Style: on by default, turned off per draft like other rules, open while
the page has one (whole words, any case, as Chat's check), listing them,
counted, fixable by Content Agent, and under Before you publish › Fix
before you publish. With an empty list nothing new shows.

- getContentDraft reads the list through the draft (its brand, under the
  member's row policies), in parallel; a failed read leaves the rule out.
- Content Agent: Fix open rules is told the phrases only when there are
  some; a suggestion (Fix or a live page's) that brings one in is dropped
  and counted in the log. The page rewrite gets the after-write pass a
  new page has: those sentences once more, kept only when every kept
  line and heading stays. cutToLength and cutPrompt are unchanged.

Stacked on #2396 (-> #2391 -> #2389).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk pushed a commit that referenced this pull request Nov 14, 2026
…ge with the status, panel toggle in the panel

The Content Editor's header and side panel, as the owner approved them.

- No jump: getContentDraft also says whether the agent card shows as the
  editor opens (the latest batch, unless a restore since closed it with
  none open, the editor's own rule) and the author's name, read with the
  member's client and failing soft. The editor keeps the card's place from
  the first paint with a skeleton of the same box (tile, two lines,
  buttons) until its batch is read; nothing when it doesn't show or the
  read failed. The suggestions card is one line, about 56 px: the tile
  with its count, "6 suggestions", then what they change truncating
  ("..., +5 more · 9 → 12/16 rules"), with a warning, See sources and the
  action's link kept in sight, and Review, Reject all, Accept all.
- Steady chips: Rules and Quality keep a minimum width while they read
  ("Rules ···", "Quality ···"); the author chip shows from the draft's
  read until the menu is read; the Action line is a chip at the row's
  end, "From Action AC-…", its hint and label saying Mark ready completes
  its task.
- Next is the dots and "Next"; the step's name is in its label and title.
- AI usage moves to the status group after Saved, as a 16 px ring with
  "AI 4.7%", amber and red as before; its popover and tooltip stay.
- Hide side panel moves to the right end of the panel's tab row; the
  closed panel's rail gets Show side panel on top.
- Help: the editor's header and side panel, and Next in Quality.

Stacked on #2397 (-> #2396 -> #2391 -> #2389).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
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.

3 participants