Skip to content

feat(content): read the Length rule as a target within 20%, not a minimum - #1357

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/rules-length-band
Oct 22, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/rules-length-band

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Content Editor feedback item 9. A Rules entry asked for 3,000 characters on a page the editor counts at 15,921. The Length rule was checked as a minimum, so the page met it and Apply rules with Agent never asked for it to be shortened.

The user chose option (a): the rule becomes a target band.

  • A target within 20% (lib/content/rules.ts): lengthBand(target) gives { min: target × 0.8, max: target × 1.2 }.
    • A page inside the band meets the rule (2,400–3,600 for 3,000). Shorter or longer is open, with the new codes short / long (count, min, max).
    • The editor's counter, the agent's write length and the brief still use the target itself.
  • On the Rules tab, the narrow badge reads "15,921 · over" or "86 · under". The full text shows on hover: "15,921 characters, over 2,400–3,600" (ruleStatusDetail). The Length rule also gets a hover hint: "A target, not a minimum…".
  • To the agent, Apply rules with Agent sends the same full text as the rule's "now". The agent sees how far off the page is and which way, e.g. aim: 3000 characters · now: 15,921 characters, over 2,400–3,600.
  • Limit: the agent still leaves at most 8 suggestions a run (content-agent.js), so a page far over its target shortens a few passages at a time. A whole-page "Shorten" mode (option b) and applying My rules (option c) are not in this PR.

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 whose page is well over its type's length target. In Rules, Length is open and reads "N · over"; hover shows the band.
  2. Apply rules with Agent: the request includes Length with "over 2,400–3,600" (or the type's band), and the suggestions shorten passages.
  3. A page within 20% of the target shows ✓; a page well under it reads "N · under".
  4. yarn test: rules.test.ts (the band, both ways), _rules-tab.test.tsx (15,921 over a 3,000 target) and page.test.tsx (the agent's detail).

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: yarn test (2721 tests pass) and yarn build.

🤖 Generated with Claude Code

…imum

A rule asking for 3,000 characters passed a 15,921-character page, since
length was checked as a floor, so Apply rules with Agent never asked for it
to be shortened. The rule now reads as a target: within 20% meets it
(2,400–3,600 for 3,000); shorter or longer is open, said on the badge
("15,921 · over") and in full on hover and to the agent ("15,921
characters, over 2,400–3,600"). The rule explains itself on hover. The
agent still leaves a few suggestions a run, so a long page shortens step by
step.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk this is item 9 from the editor feedback: the Length rule now reads as a target within ±20%, not a minimum, so a 15,921-character page under a 3,000 rule is open, and Apply rules with Agent asks for it to be shortened. It's web only; the agent's 8-suggestion cap is unchanged, so a long page shortens a few passages per run.

@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: the band check, both statuses, the hover text and what the agent is told all work, and the tests cover them. Two things:

  1. The editor's counter disagrees with the rule. _toolbar.tsx:223 still turns the count amber as soon as characters > target. Now:

    • a 3,300-character page on a 3,000 target is amber, but Length shows ✓;
    • a 2,000-character page is grey, but Length reads "under".

    Colour it by lengthBand(target), amber below min or above max, so the counter and the Rules tab say the same thing. Add a test for it, in _toolbar.test.ts or page.test.tsx.

  2. Follow-up, not blocking. The agent can only shorten by rewriting words in place:

    • keepSuggestions drops a replace with an empty after (server/src/lib/content-agent.js:180);
    • the system prompt asks for "small changes… as little as each rule needs" (:93);
    • other open rules in the same run (FAQ, fan-out H2s) still produce inserts that lengthen the page.

    One line in SYSTEM_PROMPT would help: for a Length rule that reads "over", replace wordy sentences with much shorter ones and don't insert. That fits with option (b) later.

Tested on top of main together with #1354: web and server tests, tsc, lint and Prettier pass.

@gkhngyk
gkhngyk merged commit 3870646 into ansvisor:main Oct 22, 2026
6 checks passed
gkhngyk pushed a commit that referenced this pull request Oct 22, 2026
… own result (#1366)

Follow-up to #1357's review. The counter turned amber past the target
while the Length rule passes within 20%. It now turns amber exactly when
the Length rule is on and reads short or long (lengthWarns), so it can't
disagree with the Rules tab: not with the rule turned off, and not with a
rule value the counter's target clamps.

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