Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/references/seo-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ New pages are checked whole. For an existing page the change touches, the frontm

## Fixing a description

`node scripts/seo/describe.mjs --file <path>` writes a description from the page body, checks it against these rules, has a second model call confirm every claim appears on the page, and changes only the `description` line. Use `--dry-run` to preview.
`node scripts/seo/describe.mjs --file <path>` writes a description from the page body, checks it against these rules, requires every number, acronym, identifier, and name in it to be on the page, has a second model call quote the exact text that states each claim (code checks each quote is really there), and changes only the `description` line. A page that cannot pass keeps its description. Use `--dry-run` to preview.

## Keeping this guide current

Expand Down
16 changes: 10 additions & 6 deletions scripts/seo/backfill.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* backfill.mjs - write real descriptions for the pages of one product that repeat their title or have none.
*
* node scripts/seo/backfill.mjs --product <id> [--version <v>] [--limit <n>] [--dry-run]
* node scripts/seo/backfill.mjs --product <id> [--version <v>] [--limit <n>] [--dry-run] [--include-length]
* [--concurrency 3] [--report out.json]
*
* Meant to run on a branch, one product per PR. It uses describe.mjs, so only each page's
Expand All @@ -18,7 +18,7 @@ import { fileURLToPath } from 'url';
import { PRODUCTS } from '../../src/config/products.js';
import { hasApiKey } from '../quality/lib/llm.mjs';
import { mapPool } from '../quality/lib/pool.mjs';
import { describePage, needsDescription } from './describe.mjs';
import { describePage, needsDescription, BACKFILL_RULES, usage } from './describe.mjs';

/** Every non-partial .md/.mdx page under `dir`, skipping KB copies. */
export function listPages(dir) {
Expand All @@ -38,7 +38,7 @@ async function main() {
const val = n => (args.includes(n) ? args[args.indexOf(n) + 1] : undefined);
const product = PRODUCTS.find(p => p.id === val('--product'));
if (!product) {
console.error(`Usage: node scripts/seo/backfill.mjs --product <id> [--version <v>] [--limit <n>] [--dry-run]\nProducts: ${PRODUCTS.map(p => p.id).join(', ')}`);
console.error(`Usage: node scripts/seo/backfill.mjs --product <id> [--version <v>] [--limit <n>] [--dry-run] [--include-length]\nProducts: ${PRODUCTS.map(p => p.id).join(', ')}`);
process.exit(2);
}
if (!hasApiKey()) {
Expand All @@ -52,14 +52,17 @@ async function main() {
}
const dryRun = args.includes('--dry-run');
const limit = Number(val('--limit')) || Infinity;
const todo = listPages(root).filter(f => needsDescription(f, fs.readFileSync(f, 'utf8'))).slice(0, limit);
// By default only pages with no description, or one that repeats the title. A description someone wrote that is only a
// little too long or short is left alone; --include-length rewrites those too.
const rules = args.includes('--include-length') ? null : BACKFILL_RULES;
const todo = listPages(root).filter(f => needsDescription(f, fs.readFileSync(f, 'utf8'), rules)).slice(0, limit);
console.error(`${product.id}: ${todo.length} page(s) need a description${dryRun ? ' (dry run)' : ''}.`);

let done = 0;
const results = await mapPool(todo, Number(val('--concurrency')) || 3, async f => {
let r;
try {
r = await describePage(f, { dryRun });
r = await describePage(f, { dryRun, rules });
} catch (e) {
r = { path: f, status: 'failed', reason: e.message };
}
Expand All @@ -73,7 +76,8 @@ async function main() {
fs.mkdirSync(path.dirname(report), { recursive: true });
fs.writeFileSync(report, JSON.stringify(results, null, 2));
const count = s => results.filter(r => r.status === s).length;
console.log(`fixed ${count('fixed')}, dry-run ${count('dry-run')}, failed ${count('failed')}. Report: ${report}`);
console.log(`fixed ${count('fixed')}, dry-run ${count('dry-run')}, skipped ${count('skipped')} (no frontmatter), failed ${count('failed')}. Report: ${report}`);
if (usage.calls) console.log(`model usage: ${usage.calls} calls, ${usage.input} input tokens, ${usage.output} output tokens (${(usage.input / Math.max(1, todo.length)).toFixed(0)} in / ${(usage.output / Math.max(1, todo.length)).toFixed(0)} out per page)`);
process.exit(count('failed') ? 1 : 0);
}

Expand Down
Loading
Loading