seo 0.17.7 → 0.17.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __seoCreateRequire } from 'node:module'; const require = __seoCreateRequire(import.meta.url);
2
- import { n as version, t as load } from "./esm-D2vwEHEA.js";
2
+ import { n as version, t as load } from "./esm-R3uezpJ-.js";
3
3
  import { SEO_PROVIDER_API_VERSION } from "./provider-sdk.js";
4
4
  import crypto$1, { createHash, randomUUID, sign } from "node:crypto";
5
5
  import { z } from "zod";
@@ -2572,6 +2572,7 @@ const ID_COLUMNS = [
2572
2572
  "changeDate",
2573
2573
  "query",
2574
2574
  "queryFlags",
2575
+ "shape",
2575
2576
  "keyword",
2576
2577
  "url",
2577
2578
  "page",
@@ -11338,10 +11339,251 @@ async function pageOpportunitiesReport(input, dependencies = defaultDependencies
11338
11339
  recommendations: pageOpportunityRecommendations(analysis)
11339
11340
  };
11340
11341
  }
11342
+ // packages/core/src/analyze/ai-queries.ts
11343
+ const RULES = [
11344
+ ["agent_prompt", "^(search the web for|browse the web|find sources)|do not invent|return the [0-9]+ most relevant|include source urls|context: location|do not include location|question: |reply only with|the model you are using"],
11345
+ ["tracker", "\\. ?my location is |\\?\\. ?my( |$)|^evaluate the .+ on "],
11346
+ ["reply", "^(yes|yeah|yep|ok|okay|sure|yes please|go on|continue|keep going|tell me more|why not|how so|really|exactly|show me|and then|thanks|thank you|got it|what else|anything else)[?!.,]*$"],
11347
+ ["follow_up", "^(what|how) about .{1,40}$|^(and|so|ok so|okay so|but) (what|which|how|why) "],
11348
+ ["operator", "(^|\\s)-?(site|before|after|intitle|inurl|intext|filetype):|\"[^\"]*\" or \""],
11349
+ ["chat", "\\b(please|can you|could you|give me|show me|tell me|i want|i need|i have|i am|should i|do i need|is it worth|help me|walk me through)\\b|^(what|how|why|is|does|can|will|would) (it|that|this|they)\\b"],
11350
+ ["long", "^(\\S+\\s+){9,}\\S+$"]
11351
+ ];
11352
+ const AI_QUERY_KINDS = {
11353
+ agent_prompt: "text from an agent prompt, such as \"search the web for\"",
11354
+ tracker: "a visibility-tool probe, such as \"my location is\"",
11355
+ reply: "a bare reply, such as \"yes\" or \"tell me more\"",
11356
+ follow_up: "a follow-up, such as \"what about …\"",
11357
+ operator: "search operators, such as site:, before: or \"a\" or \"b\"",
11358
+ chat: "chat phrasing, such as \"can you\" or \"should i\"",
11359
+ long: "ten or more words with no other sign"
11360
+ };
11361
+ const MATCHERS = RULES.map(([kind, pattern]) => [kind, new RegExp(pattern)]);
11362
+ const AI_QUERY_PATTERN = RULES.map(([, pattern]) => `(?:${pattern})`).join("|");
11363
+ const NOISE = [
11364
+ ["spaced_letters", /(^|\s)(\S\s){3,}\S(\s|$)/u],
11365
+ ["broken_encoding", /^(яю|ÿþ|þÿ)|&#[0-9]+;?|&[a-z]+;|[âÃÂ][\u0080-\u00bf€™œ“”]|\ufffd/u],
11366
+ ["pasted_text", /^(p [a-z]{3,} |here (are|is) (all )?the |here's the |done[,.!]? (you|here) |current state: )/u]
11367
+ ];
11368
+ function aiQueryNoise(query) {
11369
+ const text = query.trim().toLowerCase();
11370
+ return NOISE.find(([, pattern]) => pattern.test(text))?.[0] ?? null;
11371
+ }
11372
+ const QUESTION = /^(how|what|what's|whats|which|why|when|where|who|is|are|can|could|does|do|should|would|will|i need|i want|i have|i'm looking|we need|we want)\b|\?$/u;
11373
+ const ASKABLE_KINDS = /* @__PURE__ */ new Set(["chat", "long"]);
11374
+ const PROMPT_CHARACTERS = 500;
11375
+ function askable(query, kind) {
11376
+ const text = query.trim().toLowerCase().replace(/^["'“]+/u, "");
11377
+ return Boolean(kind && ASKABLE_KINDS.has(kind)) && text.length <= PROMPT_CHARACTERS && QUESTION.test(text);
11378
+ }
11379
+ function aiQueryKind(query) {
11380
+ const text = query.trim().toLowerCase();
11381
+ return MATCHERS.find(([, pattern]) => pattern.test(text))?.[0] ?? null;
11382
+ }
11383
+ const STOP = new Set("the and for with that this what which who how why when where are is was can does do did you your our from about into than then them they their there have has had will would should could not but its it’s me my i am of to in on at by or an as be if so".split(" "));
11384
+ function words$3(query) {
11385
+ return new Set(query.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter((word) => word.length >= 3 && !STOP.has(word)).map((word) => word.length > 4 && word.endsWith("s") ? word.slice(0, -1) : word));
11386
+ }
11387
+ const SAME_QUESTION = .6;
11388
+ const MAX_ROWS = 25e3;
11389
+ const EXAMPLES = 3;
11390
+ const CANDIDATES = 200;
11391
+ const overlap = (a, b, weight) => {
11392
+ let shared = 0;
11393
+ let union = 0;
11394
+ for (const word of a) {
11395
+ union += weight(word);
11396
+ if (b.has(word)) shared += weight(word);
11397
+ }
11398
+ for (const word of b) if (!a.has(word)) union += weight(word);
11399
+ return union ? shared / union : 0;
11400
+ };
11401
+ const round$2 = (value, places) => Math.round(value * 10 ** places) / 10 ** places;
11402
+ async function aiQueriesReport(input, searchAnalytics) {
11403
+ const range = {
11404
+ startDate: input.startDate,
11405
+ endDate: input.endDate
11406
+ };
11407
+ const [matched, site] = await Promise.all([searchAnalytics(input.site, {
11408
+ ...range,
11409
+ dimensions: ["query", "page"],
11410
+ type: "web",
11411
+ dataState: "final",
11412
+ maxRows: MAX_ROWS,
11413
+ dimensionFilterGroups: [{ filters: [{
11414
+ dimension: "query",
11415
+ operator: "includingRegex",
11416
+ expression: AI_QUERY_PATTERN
11417
+ }] }]
11418
+ }), searchAnalytics(input.site, {
11419
+ ...range,
11420
+ dimensions: [],
11421
+ type: "web",
11422
+ dataState: "final"
11423
+ })]);
11424
+ const rows = [...matched.rows].sort((a, b) => b.impressions - a.impressions || String(a.keys[0]).localeCompare(String(b.keys[0])) || String(a.keys[1]).localeCompare(String(b.keys[1])));
11425
+ const usage = /* @__PURE__ */ new Map();
11426
+ const unique = new Set(rows.map((row) => String(row.keys[0] ?? "")));
11427
+ for (const query of unique) for (const word of words$3(query)) usage.set(word, (usage.get(word) ?? 0) + 1);
11428
+ const weight = (word) => Math.log((unique.size + 1) / (usage.get(word) ?? 1));
11429
+ const groups = [];
11430
+ const byWord = /* @__PURE__ */ new Map();
11431
+ const byText = /* @__PURE__ */ new Map();
11432
+ const kindOf = /* @__PURE__ */ new Map();
11433
+ const noise = /* @__PURE__ */ new Map();
11434
+ for (const row of rows) {
11435
+ const query = String(row.keys[0] ?? "");
11436
+ const page = String(row.keys[1] ?? "");
11437
+ const kind = aiQueryKind(query);
11438
+ if (!kind) continue;
11439
+ const junk = aiQueryNoise(query);
11440
+ if (junk) {
11441
+ const seen = noise.get(junk) ?? /* @__PURE__ */ new Set();
11442
+ seen.add(query.trim().toLowerCase());
11443
+ noise.set(junk, seen);
11444
+ continue;
11445
+ }
11446
+ const text = query.trim().toLowerCase();
11447
+ const own = words$3(query);
11448
+ let group = byText.get(text);
11449
+ if (!group) {
11450
+ let checked = 0;
11451
+ for (const word of own) {
11452
+ for (const candidate of byWord.get(word) ?? []) {
11453
+ if (++checked > CANDIDATES) break;
11454
+ if (overlap(own, candidate.words, weight) >= SAME_QUESTION) {
11455
+ group = candidate;
11456
+ break;
11457
+ }
11458
+ }
11459
+ if (group || checked > CANDIDATES) break;
11460
+ }
11461
+ }
11462
+ if (!group) {
11463
+ group = {
11464
+ words: own,
11465
+ queries: /* @__PURE__ */ new Map(),
11466
+ pages: /* @__PURE__ */ new Map(),
11467
+ kinds: /* @__PURE__ */ new Map(),
11468
+ clicks: 0,
11469
+ impressions: 0,
11470
+ positionWeight: 0
11471
+ };
11472
+ groups.push(group);
11473
+ for (const word of own) {
11474
+ const list = byWord.get(word) ?? [];
11475
+ list.push(group);
11476
+ byWord.set(word, list);
11477
+ }
11478
+ }
11479
+ byText.set(text, group);
11480
+ if (!kindOf.has(text)) {
11481
+ kindOf.set(text, kind);
11482
+ group.kinds.set(kind, (group.kinds.get(kind) ?? 0) + 1);
11483
+ }
11484
+ group.queries.set(query, (group.queries.get(query) ?? 0) + row.impressions);
11485
+ group.pages.set(page, (group.pages.get(page) ?? 0) + row.impressions);
11486
+ group.clicks += row.clicks;
11487
+ group.impressions += row.impressions;
11488
+ group.positionWeight += row.position * row.impressions;
11489
+ }
11490
+ const byKind = /* @__PURE__ */ new Map();
11491
+ for (const kind of kindOf.values()) {
11492
+ const entry = byKind.get(kind) ?? {
11493
+ queries: 0,
11494
+ impressions: 0
11495
+ };
11496
+ entry.queries += 1;
11497
+ byKind.set(kind, entry);
11498
+ }
11499
+ for (const row of rows) {
11500
+ const kind = kindOf.get(String(row.keys[0] ?? "").trim().toLowerCase());
11501
+ const entry = kind && byKind.get(kind);
11502
+ if (entry) entry.impressions += row.impressions;
11503
+ }
11504
+ const queries = kindOf.size;
11505
+ const impressions = groups.reduce((sum, g) => sum + g.impressions, 0);
11506
+ const clicks = groups.reduce((sum, g) => sum + g.clicks, 0);
11507
+ const total = site.rows[0] ?? {
11508
+ clicks: 0,
11509
+ impressions: 0
11510
+ };
11511
+ const items = groups.map((group) => {
11512
+ const most = (map) => [...map].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([name]) => name);
11513
+ const [first, ...rest] = most(group.queries);
11514
+ const kind = [...group.kinds].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0]?.[0];
11515
+ return {
11516
+ query: first ?? "",
11517
+ page: most(group.pages)[0] ?? "",
11518
+ askable: askable(first ?? "", kind),
11519
+ pages: group.pages.size,
11520
+ kind,
11521
+ wordings: group.queries.size,
11522
+ impressions: group.impressions,
11523
+ clicks: group.clicks,
11524
+ ctr: group.impressions ? round$2(group.clicks / group.impressions, 4) : 0,
11525
+ position: group.impressions ? round$2(group.positionWeight / group.impressions, 1) : 0,
11526
+ otherWordings: rest.slice(0, EXAMPLES)
11527
+ };
11528
+ }).sort((a, b) => b.impressions - a.impressions || b.wordings - a.wordings || a.query.localeCompare(b.query) || a.page.localeCompare(b.page));
11529
+ const pct = (part, whole) => whole ? round$2(part / whole * 100, 1) : null;
11530
+ const kinds = [...byKind].sort((a, b) => b[1].impressions - a[1].impressions || a[0].localeCompare(b[0])).map(([kind, entry]) => `${kind} ${entry.queries}`).join(", ");
11531
+ const leftOut = [...noise].sort((a, b) => a[0].localeCompare(b[0])).map(([reason, seen]) => `${reason.replace("_", " ")} ${seen.size}`).join(", ");
11532
+ const asked = items.filter((item) => item.askable).length;
11533
+ const capped = matched.rowsFetched >= MAX_ROWS;
11534
+ return {
11535
+ range,
11536
+ verdict: queries ? `${queries} queries in ${groups.length} questions have the shape of AI conversations or agent searches.` : "No queries with the shape of AI conversations or agent searches.",
11537
+ summary: {
11538
+ queries,
11539
+ questions: groups.length,
11540
+ askable: asked,
11541
+ leftOut: leftOut || "none",
11542
+ impressions,
11543
+ clicks,
11544
+ shareOfImpressionsPct: pct(impressions, total.impressions),
11545
+ byKind: kinds || "none",
11546
+ ctr: impressions ? round$2(clicks / impressions, 4) : 0,
11547
+ siteCtr: total.impressions ? round$2(total.clicks / total.impressions, 4) : 0
11548
+ },
11549
+ kinds: AI_QUERY_KINDS,
11550
+ items,
11551
+ caveats: [
11552
+ "A heuristic: these queries match the patterns of AI conversations and agent searches. Search Console does not mark AI Mode or AI Overviews, and people type some of these too.",
11553
+ "A minimum: Search Console leaves out rare queries, and these are rare by nature.",
11554
+ "Rewordings of one question are grouped by their shared words; page is the page with the most impressions for it.",
11555
+ "Left out and counted, not shown: letters split by spaces, text broken by a wrong encoding, and text pasted from a tool or an agent’s output.",
11556
+ "askable: a chat or long question that opens with a question word or a request such as \"i need\", or ends with a question mark, so an AI engine can be asked it as it is. ai_answers checks the top askable questions only.",
11557
+ "Search Console’s Generative AI report is not in its API, so it is not here.",
11558
+ ...capped ? [`Capped at the first ${MAX_ROWS} matching query and page rows.`] : []
11559
+ ]
11560
+ };
11561
+ }
11562
+ // packages/core/src/analyze/query-shape.ts
11563
+ const COMPARISON = /\b(vs|versus|alternative|alternatives|compare|comparison|best)\b/;
11564
+ function queryShape(query) {
11565
+ const text = query.trim().toLowerCase();
11566
+ if (COMPARISON.test(text)) return "comparison";
11567
+ const kind = aiQueryKind(text);
11568
+ if (kind && kind !== "chat" && kind !== "long") return kind;
11569
+ if (QUESTION.test(text)) return "question";
11570
+ return kind;
11571
+ }
11572
+ function queryShapeLine(queries) {
11573
+ const counts = /* @__PURE__ */ new Map();
11574
+ for (const query of queries) {
11575
+ const shape = queryShape(query);
11576
+ if (shape) counts.set(shape, (counts.get(shape) ?? 0) + 1);
11577
+ }
11578
+ if (!counts.size) return null;
11579
+ const shaped = [...counts.values()].reduce((sum, n) => sum + n, 0);
11580
+ const parts = [...counts].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([shape, n]) => `${shape} ${n}`);
11581
+ return `Query shapes, ${shaped} of ${queries.length} queries: ${parts.join(", ")}.`;
11582
+ }
11341
11583
  // packages/core/src/analyze/content-optimization.ts
11342
11584
  function intentFor(query) {
11343
11585
  const value = query.toLowerCase();
11344
- if (/\b(vs|versus|alternative|alternatives|compare|comparison|best)\b/.test(value)) return "comparison";
11586
+ if (COMPARISON.test(value)) return "comparison";
11345
11587
  if (/\b(price|pricing|cost|buy|deal|coupon|review|reviews)\b/.test(value)) return "commercial";
11346
11588
  if (/\b(how|steps|guide|tutorial|setup|fix|create|make)\b/.test(value)) return "how-to";
11347
11589
  if (/\b(what is|meaning|definition|explained|why)\b/.test(value)) return "definition";
@@ -19259,7 +19501,7 @@ const NAVIGATIONAL_STEM_THRESHOLDS = {
19259
19501
  function compact(value) {
19260
19502
  return normalizeBrandText(value).replace(/\s+/g, "");
19261
19503
  }
19262
- function round$2(value, digits) {
19504
+ function round$1(value, digits) {
19263
19505
  return Number(value.toFixed(digits));
19264
19506
  }
19265
19507
  function stemQueryEvidence(rows, stem) {
@@ -19286,8 +19528,8 @@ function stemQueryEvidence(rows, stem) {
19286
19528
  query,
19287
19529
  clicks,
19288
19530
  impressions,
19289
- ctr: round$2(clicks / impressions, 4),
19290
- position: round$2(weightedPosition / impressions, 2),
19531
+ ctr: round$1(clicks / impressions, 4),
19532
+ position: round$1(weightedPosition / impressions, 2),
19291
19533
  sourceRows
19292
19534
  };
19293
19535
  }
@@ -25077,7 +25319,7 @@ const GENERIC_ANCHORS = /^(click here|here|read more|learn more|more|this|this p
25077
25319
  function normalise$1(value) {
25078
25320
  return value.normalize("NFKD").replace(/\p{Diacritic}/gu, "").normalize("NFC").replace(/([\p{L}\p{N}])[’'`]([\p{L}\p{N}])/gu, "$1$2").toLowerCase().replace(/&/g, " and ").replace(/[^\p{L}\p{N}]+/gu, " ").replace(/\s+/g, " ").trim();
25079
25321
  }
25080
- const words$3 = (value) => normalise$1(value).split(" ").filter(Boolean);
25322
+ const words$2 = (value) => normalise$1(value).split(" ").filter(Boolean);
25081
25323
  const FUNCTION_WORDS = new Set("a an and are as at be but by for from has have how if in into is it its of on or that the their then there these they this to was we were what when where which who why will with you your our can do does not just more most also than too very about after before over under again all any each other some such no nor only own same so up out off one two both every few several many much should would could because while since although though until unless whether however".split(" "));
25082
25324
  const NOT_PLURAL = /* @__PURE__ */ new Set([
25083
25325
  "always",
@@ -25138,7 +25380,7 @@ function stem(word) {
25138
25380
  if (one.length > 6 && one.endsWith("ing")) return one.slice(0, -3);
25139
25381
  return one;
25140
25382
  }
25141
- const terms = (text) => words$3(text).filter((word) => word.length > 1 && !FUNCTION_WORDS.has(word) && !/^\d+$/.test(word)).map(stem);
25383
+ const terms = (text) => words$2(text).filter((word) => word.length > 1 && !FUNCTION_WORDS.has(word) && !/^\d+$/.test(word)).map(stem);
25142
25384
  const slugWords = (url) => {
25143
25385
  try {
25144
25386
  return new URL(url).pathname.split(/[/._-]+/).filter(Boolean).join(" ");
@@ -25472,7 +25714,7 @@ function siteStartUrl(site) {
25472
25714
  if (value.startsWith("sc-domain:")) return `https://${value.slice(10)}/`;
25473
25715
  return `${new URL(/^https?:\/\//i.test(value) ? value : `https://${value}`).origin}/`;
25474
25716
  }
25475
- function round$1(value, places = 3) {
25717
+ function round(value, places = 3) {
25476
25718
  const factor = 10 ** places;
25477
25719
  return Math.round(value * factor) / factor;
25478
25720
  }
@@ -25828,7 +26070,7 @@ async function analyse(input, deps, crawl, context) {
25828
26070
  sentence: decision.sentence?.text ?? null,
25829
26071
  section: decision.sentence?.section || null,
25830
26072
  sentenceMatch: decision.sentence?.match ?? null,
25831
- similarity: round$1(candidate.similarity),
26073
+ similarity: round(candidate.similarity),
25832
26074
  sharedQueries: candidate.sharedQueries,
25833
26075
  targetInboundLinks: inbound[candidate.target] ?? 0,
25834
26076
  sourceType: types[candidate.source] ?? null,
@@ -31208,7 +31450,7 @@ function push(result, text, from, to) {
31208
31450
  text: text.slice(start, end)
31209
31451
  });
31210
31452
  }
31211
- function words$2(text) {
31453
+ function words$1(text) {
31212
31454
  return text.match(/[A-Za-z0-9][A-Za-z0-9'\u2019-]*/g) ?? [];
31213
31455
  }
31214
31456
  const FINITE = new Set(`am is are was were be been being has have had do does did can could will would shall should may might must
@@ -31225,7 +31467,7 @@ const FINITE = new Set(`am is are was were be been being has have had do does di
31225
31467
  happen happens happened leave leaves left bring brings brought live lives lived set sets love loves loved
31226
31468
  like likes liked hate hates`.split(/\s+/));
31227
31469
  function verbless(sentence) {
31228
- for (const raw of words$2(sentence)) {
31470
+ for (const raw of words$1(sentence)) {
31229
31471
  const word = raw.toLowerCase().replace(/\u2019/g, "'");
31230
31472
  if (FINITE.has(word)) return false;
31231
31473
  if (/(?:n't|'s|'re|'ve|'ll|'d|'m)$/.test(word)) return false;
@@ -31317,7 +31559,7 @@ var Context = class {
31317
31559
  let total = 0;
31318
31560
  let prose = 0;
31319
31561
  for (const block of doc.blocks) {
31320
- const count = words$2(block.text).length;
31562
+ const count = words$1(block.text).length;
31321
31563
  total += count;
31322
31564
  if (PROSE.includes(block.kind)) prose += count;
31323
31565
  }
@@ -32292,7 +32534,7 @@ function heroLength(ctx) {
32292
32534
  if (ctx.level(rule) === "off") return;
32293
32535
  for (const block of ctx.blocks(["heading"])) {
32294
32536
  if (block.level !== 1) continue;
32295
- const count = words$2(block.text).length;
32537
+ const count = words$1(block.text).length;
32296
32538
  if (count <= 12 && block.text.length <= 70) continue;
32297
32539
  ctx.hit(rule, block, 0, block.text.length, `The H1 is ${count} words. A headline that long is hard to take in at a glance.`, "Keep the main promise in the H1 and move the rest to the line below it.");
32298
32540
  }
@@ -32317,7 +32559,7 @@ function reviews(ctx) {
32317
32559
  PROOF.lastIndex = 0;
32318
32560
  for (const found of block.norm.matchAll(PROOF)) ctx.review("proof", block, found.index ?? 0, (found.index ?? 0) + found[0].length, `Is there a source for "${found[0]}" on the page? Link it or say where the number comes from.`);
32319
32561
  }
32320
- if (block.kind === "paragraph" && block.endsSection && sentences.length === 1 && words$2(block.text).length <= 10 && words$2(block.text).filter((word) => /[a-z]/i.test(word)).length >= 3 && /[.!?]["')]?$/.test(block.text)) ctx.review("mic-drop", block, 0, block.text.length, "Does this closing line add a fact? If it only restates the paragraph above, cut it.");
32562
+ if (block.kind === "paragraph" && block.endsSection && sentences.length === 1 && words$1(block.text).length <= 10 && words$1(block.text).filter((word) => /[a-z]/i.test(word)).length >= 3 && /[.!?]["')]?$/.test(block.text)) ctx.review("mic-drop", block, 0, block.text.length, "Does this closing line add a fact? If it only restates the paragraph above, cut it.");
32321
32563
  }
32322
32564
  if (ctx.preset === "landing" || ctx.preset === "meta") for (const block of ctx.blocks([
32323
32565
  "title",
@@ -32326,7 +32568,7 @@ function reviews(ctx) {
32326
32568
  ])) {
32327
32569
  if (block.kind === "heading" && block.level !== 1) continue;
32328
32570
  if (!block.text) continue;
32329
- const later = words$2(block.text).slice(1);
32571
+ const later = words$1(block.text).slice(1);
32330
32572
  if (/\d/.test(block.text) || later.some((word) => /^[A-Z]/.test(word))) continue;
32331
32573
  ctx.review("swap-test", block, 0, block.text.length, "Would this line work unchanged on a competitor's page? If so, add the product, number or result only you can claim.");
32332
32574
  }
@@ -32486,7 +32728,7 @@ function negativeParallelism(ctx) {
32486
32728
  const sentence = sentenceAt(sentences, start);
32487
32729
  const subject = block.norm.slice(sentence.start, start).trim();
32488
32730
  const pronoun = /^(?:but |and |so )?(?:it|this|that|they)?$/i.test(subject.replace(/(?:'s|'re)$/, ""));
32489
- const firstWords = words$2(block.norm.slice(sentence.start, end)).length;
32731
+ const firstWords = words$1(block.norm.slice(sentence.start, end)).length;
32490
32732
  let level = "warning";
32491
32733
  if (kind === "reveal" || kind === "about" || kind === "repeated") level = "error";
32492
32734
  else if (FRAMING.test(subject)) level = "error";
@@ -32540,7 +32782,7 @@ function contrastReframe(ctx) {
32540
32782
  for (const block of ctx.blocks([...SENTENCE_KINDS, "heading"])) for (const sentence of ctx.sentences(block)) {
32541
32783
  const text = sentence.text;
32542
32784
  const just = NOT_JUST.exec(text);
32543
- if (just && (just[0].startsWith(",") || words$2(text).length <= 16) && !insideQuotes(block.norm, sentence.start + just.index, sentence.start + just.index + just[0].length)) {
32785
+ if (just && (just[0].startsWith(",") || words$1(text).length <= 16) && !insideQuotes(block.norm, sentence.start + just.index, sentence.start + just.index + just[0].length)) {
32544
32786
  ctx.hit(rule, block, sentence.start, sentence.end, "A \"not just X\" contrast inflates the claim instead of stating it.", "Say what it is or does in one plain clause, and drop the \"not just\" half.");
32545
32787
  continue;
32546
32788
  }
@@ -32553,8 +32795,8 @@ function contrastReframe(ctx) {
32553
32795
  const right = rightAll.split(/[,;:.!?(]/)[0] ?? "";
32554
32796
  if (!rather && SKIP_AFTER_NOT.test(right)) continue;
32555
32797
  if (/\bor$/i.test(left.trim()) || /\bwhether\b/i.test(left)) continue;
32556
- const leftWords = words$2(left);
32557
- const rightWords = words$2(right);
32798
+ const leftWords = words$1(left);
32799
+ const rightWords = words$1(right);
32558
32800
  if (leftWords.length < 3 || !rightWords.length) continue;
32559
32801
  if (leftWords.length + rightWords.length <= 5 && verbless(text)) continue;
32560
32802
  const lastLeft = leftWords[leftWords.length - 1];
@@ -32652,12 +32894,12 @@ const ABSTRACT_TRIAD = /\b[a-z]+(?:tion|sion|ity|ness|ment|ence|ance|ism), (?:an
32652
32894
  const ECHO = new Set("to our your their my his her its every each more less no it they we you".split(" "));
32653
32895
  const COPULA = /\b(?:is|are|was|were|'s|feels?|felt|looks?|stays?|remains?|seems?)\s+$/i;
32654
32896
  function formulaTriad(items, before) {
32655
- const firsts = items.map((item) => words$2(item)[0]?.toLowerCase() ?? "");
32897
+ const firsts = items.map((item) => words$1(item)[0]?.toLowerCase() ?? "");
32656
32898
  const echo = firsts[0] ?? "";
32657
32899
  if (ECHO.has(echo) && firsts.every((first) => first === echo)) return `Each item opens with "${echo}".`;
32658
- if (items.every((item) => /^(?:the|their|our|your|its|it|they|we|you|he|she)\b/i.test(item) && words$2(item).length >= 3 && words$2(item).length <= 7 && !verbless(item))) return "Three parallel clauses in a row.";
32659
- if (items.every((item) => /^[a-z]/.test(item) && words$2(item).length <= 2 && !PREPOSITIONS.has(words$2(item)[0] ?? "")) && COPULA.test(before)) return "A string of adjectives after \"is\".";
32660
- if (items.every((item) => /^\w+ed\b/i.test(item) && words$2(item).length <= 3)) return "A string of past participles.";
32900
+ if (items.every((item) => /^(?:the|their|our|your|its|it|they|we|you|he|she)\b/i.test(item) && words$1(item).length >= 3 && words$1(item).length <= 7 && !verbless(item))) return "Three parallel clauses in a row.";
32901
+ if (items.every((item) => /^[a-z]/.test(item) && words$1(item).length <= 2 && !PREPOSITIONS.has(words$1(item)[0] ?? "")) && COPULA.test(before)) return "A string of adjectives after \"is\".";
32902
+ if (items.every((item) => /^\w+ed\b/i.test(item) && words$1(item).length <= 3)) return "A string of past participles.";
32661
32903
  return null;
32662
32904
  }
32663
32905
  function triads(ctx) {
@@ -32685,13 +32927,13 @@ function triads(ctx) {
32685
32927
  const items = [...raw];
32686
32928
  const head = raw[0] ?? "";
32687
32929
  const lead = /^.*\b(?:is|are|was|were|'s|feels?|looks?|stays?|remains?|seems?|of|for|to|with|by|from|on|in|like|including|as)\s+/i.exec(head);
32688
- if (lead && words$2(head.slice(lead[0].length)).length) {
32930
+ if (lead && words$1(head.slice(lead[0].length)).length) {
32689
32931
  items[0] = head.slice(lead[0].length);
32690
32932
  from += lead[0].length;
32691
32933
  }
32692
32934
  const end = sentence.start + (match.index ?? 0) + match[0].length;
32693
32935
  const before = block.norm.slice(sentence.start, sentence.start + from);
32694
- const echo = words$2(raw[1] ?? "")[0]?.toLowerCase() ?? "";
32936
+ const echo = words$1(raw[1] ?? "")[0]?.toLowerCase() ?? "";
32695
32937
  const inFirst = new RegExp(`\\b${echo}\\b(?!.*\\b${echo}\\b)`, "i").exec(head);
32696
32938
  if (ECHO.has(echo) && inFirst && inFirst.index > 0) {
32697
32939
  items[0] = head.slice(inFirst.index);
@@ -32742,7 +32984,7 @@ function colonDensity(ctx) {
32742
32984
  const after = block.norm.slice(at + match[0].length);
32743
32985
  if (/^["'(]/.test(after)) continue;
32744
32986
  const lead = block.norm.slice(sentenceAt(sentences, at).start, at);
32745
- if (words$2(lead).length <= 4 && verbless(lead)) continue;
32987
+ if (words$1(lead).length <= 4 && verbless(lead)) continue;
32746
32988
  const source = block.map[at] ?? -1;
32747
32989
  if (/^(?:\*\*|__)/.test(ctx.doc.source.slice(source + 1, source + 3)) || /(?:\*\*|__)$/.test(ctx.doc.source.slice(source - 2, source))) continue;
32748
32990
  if (block.links.some((link) => link.start <= at && link.end > at)) continue;
@@ -32808,7 +33050,7 @@ function heresAnnouncement(ctx) {
32808
33050
  ])) for (const sentence of ctx.sentences(block)) {
32809
33051
  const text = sentence.text;
32810
33052
  if (!/^(?:And |So |But )?Here(?:'s| is| are) (?:the|what|why|how|who|where|when|a|an|my|our|some|two|three|four|five)\b/i.test(text) || /^(?:And |So |But )?Here's the (?:thing|deal|kicker|catch|twist|truth|secret|reality)\b/i.test(text)) continue;
32811
- const count = words$2(text).length;
33053
+ const count = words$1(text).length;
32812
33054
  const colon = text.endsWith(":");
32813
33055
  const sentences = ctx.sentences(block);
32814
33056
  if (sentence === sentences[sentences.length - 1]) {
@@ -32836,7 +33078,7 @@ const LEADING_CLAUSE = /^(?:without|with|for|in|on|at|after|before|if|when|once|
32836
33078
  const MONTH = /\b(?:january|february|march|april|may|june|july|august|september|october|november|december|monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b/i;
32837
33079
  const KICKER = /^(?:That's it|That's all|No exceptions|No catch|No strings attached|No surprises|No asterisks|Period|Full stop|Simple as that|It's that simple|That simple|Nothing more|Nothing else)[.!]$/i;
32838
33080
  function slogan(text) {
32839
- const list = words$2(text);
33081
+ const list = words$1(text);
32840
33082
  return /[.!]$/.test(text) && !/^Not\b/.test(text) && list.length >= 1 && list.length <= 4 && !GREETING.test(text) && !MONTH.test(text) && !list.every((word) => /^[A-Z0-9]/.test(word)) && verbless(text);
32841
33083
  }
32842
33084
  function fragmentRuns(ctx, rule) {
@@ -32845,7 +33087,7 @@ function fragmentRuns(ctx, rule) {
32845
33087
  for (let i = 1; i < sentences.length; i++) {
32846
33088
  const before = sentences[i - 1];
32847
33089
  const sentence = sentences[i];
32848
- const kicker = KICKER.test(sentence.text) && words$2(before.text).length <= 8;
33090
+ const kicker = KICKER.test(sentence.text) && words$1(before.text).length <= 8;
32849
33091
  const pair = slogan(before.text) && slogan(sentence.text);
32850
33092
  if (!kicker && !pair) continue;
32851
33093
  ctx.hit(rule, block, before.start, sentence.end, kicker ? `"${sentence.text}" is a kicker added for rhythm after a short line.` : "Two verbless fragments in a row read as a slogan, not a sentence.", "Join them into one plain sentence with a verb, such as \"Books close within 48 hours of month end, every month,\" or cut the kicker.");
@@ -32860,14 +33102,14 @@ function pithyFragment(ctx) {
32860
33102
  for (const block of ctx.blocks(RHYTHM_KINDS)) for (const sentence of ctx.sentences(block)) {
32861
33103
  const text = sentence.text;
32862
33104
  if (!/[.!]$/.test(text)) continue;
32863
- const list = words$2(text);
33105
+ const list = words$1(text);
32864
33106
  if (list.length < 2 || list.length > 6) continue;
32865
33107
  if (GREETING.test(text) || MONTH.test(text)) continue;
32866
33108
  if (list.every((word) => /^[A-Z0-9]/.test(word))) continue;
32867
33109
  if (!verbless(text)) continue;
32868
33110
  const strong = TWO_BEAT.some((re) => re.test(text));
32869
33111
  const [left = "", right = ""] = text.split(",");
32870
- const twoBeat = text.split(",").length === 2 && words$2(left).length <= 3 && words$2(right).length <= 3 && !LEADING_CLAUSE.test(left.trim()) && !LEADING_CLAUSE.test(right.trim());
33112
+ const twoBeat = text.split(",").length === 2 && words$1(left).length <= 3 && words$1(right).length <= 3 && !LEADING_CLAUSE.test(left.trim()) && !LEADING_CLAUSE.test(right.trim());
32871
33113
  if (!strong && !twoBeat) continue;
32872
33114
  ctx.hit(rule, block, sentence.start, sentence.end, "A verbless two-beat fragment reads as a slogan, not a sentence.", "Write a full sentence with a subject and a verb that says what happened, or join it to the sentence before.", strong ? void 0 : "warning");
32873
33115
  }
@@ -32889,7 +33131,7 @@ function stockCloser(ctx) {
32889
33131
  ctx.hit(rule, block, sentence.start, sentence.end, "A stock kicker that tells the reader how to feel about the last point.", "Cut it. If the text already has the number or fact that makes the point, end on that.");
32890
33132
  continue;
32891
33133
  }
32892
- if (/^(?:but |and )?(?:that|this)(?:'s| is) not (?:how|what|why|where|a|an|the)\b/i.test(text) && words$2(text).length <= 10) ctx.hit(reframe, block, sentence.start, sentence.end, "A short \"That's not ...\" line dismisses a view instead of stating one.", "Cut it, or say what is true with a fact the text already gives.");
33134
+ if (/^(?:but |and )?(?:that|this)(?:'s| is) not (?:how|what|why|where|a|an|the)\b/i.test(text) && words$1(text).length <= 10) ctx.hit(reframe, block, sentence.start, sentence.end, "A short \"That's not ...\" line dismisses a view instead of stating one.", "Cut it, or say what is true with a fact the text already gives.");
32893
33135
  }
32894
33136
  }
32895
33137
  const FIGURATIVE_NOUNS = "fights?|battles?|hills?|wars?|bets?|gambles?|races?|risks?|horses?|roads?|bridges?|doors?|games?|ships?|cards?";
@@ -32933,7 +33175,7 @@ function staccato(ctx) {
32933
33175
  }
32934
33176
  run = [];
32935
33177
  };
32936
- for (const sentence of sentences) if (words$2(sentence.text).length <= 4) run.push(sentence);
33178
+ for (const sentence of sentences) if (words$1(sentence.text).length <= 4) run.push(sentence);
32937
33179
  else report();
32938
33180
  report();
32939
33181
  }
@@ -32986,11 +33228,11 @@ function anaphora(ctx) {
32986
33228
  const sentences = ctx.sentences(block);
32987
33229
  let i = 0;
32988
33230
  while (i < sentences.length) {
32989
- const first = words$2(sentences[i].text)[0]?.toLowerCase();
33231
+ const first = words$1(sentences[i].text)[0]?.toLowerCase();
32990
33232
  let j = i + 1;
32991
- while (j < sentences.length && first && words$2(sentences[j].text)[0]?.toLowerCase() === first) j++;
33233
+ while (j < sentences.length && first && words$1(sentences[j].text)[0]?.toLowerCase() === first) j++;
32992
33234
  const run = sentences.slice(i, j);
32993
- if (first === "no" && j - i >= 2 && run.every((sentence) => /^No (?!one\b|matter\b|doubt\b|longer\b|way\b|wonder\b)[a-z$\d]/.test(sentence.text) && words$2(sentence.text).length <= 12)) ctx.hit(rule, block, sentences[i].start, sentences[j - 1].end, `${j - i} sentences in a row start with "No", a drumbeat of things the product is not.`, "Say what it is in one sentence, and keep only the one \"no\" a reader needs, such as \"One flat monthly fee with no tiers.\"");
33235
+ if (first === "no" && j - i >= 2 && run.every((sentence) => /^No (?!one\b|matter\b|doubt\b|longer\b|way\b|wonder\b)[a-z$\d]/.test(sentence.text) && words$1(sentence.text).length <= 12)) ctx.hit(rule, block, sentences[i].start, sentences[j - 1].end, `${j - i} sentences in a row start with "No", a drumbeat of things the product is not.`, "Say what it is in one sentence, and keep only the one \"no\" a reader needs, such as \"One flat monthly fee with no tiers.\"");
32994
33236
  else if (j - i >= 3 && first && ![
32995
33237
  "the",
32996
33238
  "a",
@@ -33002,7 +33244,7 @@ function anaphora(ctx) {
33002
33244
  "it",
33003
33245
  "this"
33004
33246
  ].includes(first)) {
33005
- if (run.every((sentence) => words$2(sentence.text).length <= 7) && /^(?:it's|they|we|you)$/.test(first)) ctx.hit(rule, block, sentences[i].start, sentences[j - 1].end, `${j - i} short sentences in a row start with "${first}".`, "Merge them into one sentence or a short list.");
33247
+ if (run.every((sentence) => words$1(sentence.text).length <= 7) && /^(?:it's|they|we|you)$/.test(first)) ctx.hit(rule, block, sentences[i].start, sentences[j - 1].end, `${j - i} short sentences in a row start with "${first}".`, "Merge them into one sentence or a short list.");
33006
33248
  else ctx.review("anaphora", block, sentences[i].start, sentences[j - 1].end, `${j - i} sentences in a row start with "${first}". Does the repeat help the reader follow a real list, or is it there for rhythm?`);
33007
33249
  }
33008
33250
  i = j;
@@ -33273,226 +33515,6 @@ function lintReportText(files) {
33273
33515
  if (reviews) lines.push("Errors and warnings each come with a fix. Review items are judgement calls: change a line only when it fails the question.");
33274
33516
  return lines.join("\n").trimEnd();
33275
33517
  }
33276
- // packages/core/src/analyze/ai-queries.ts
33277
- const RULES = [
33278
- ["agent_prompt", "^(search the web for|browse the web|find sources)|do not invent|return the [0-9]+ most relevant|include source urls|context: location|do not include location|question: |reply only with|the model you are using"],
33279
- ["tracker", "\\. ?my location is |\\?\\. ?my( |$)|^evaluate the .+ on "],
33280
- ["reply", "^(yes|yeah|yep|ok|okay|sure|yes please|go on|continue|keep going|tell me more|why not|how so|really|exactly|show me|and then|thanks|thank you|got it|what else|anything else)[?!.,]*$"],
33281
- ["follow_up", "^(what|how) about .{1,40}$|^(and|so|ok so|okay so|but) (what|which|how|why) "],
33282
- ["operator", "(^|\\s)-?(site|before|after|intitle|inurl|intext|filetype):|\"[^\"]*\" or \""],
33283
- ["chat", "\\b(please|can you|could you|give me|show me|tell me|i want|i need|i have|i am|should i|do i need|is it worth|help me|walk me through)\\b|^(what|how|why|is|does|can|will|would) (it|that|this|they)\\b"],
33284
- ["long", "^(\\S+\\s+){9,}\\S+$"]
33285
- ];
33286
- const AI_QUERY_KINDS = {
33287
- agent_prompt: "text from an agent prompt, such as \"search the web for\"",
33288
- tracker: "a visibility-tool probe, such as \"my location is\"",
33289
- reply: "a bare reply, such as \"yes\" or \"tell me more\"",
33290
- follow_up: "a follow-up, such as \"what about …\"",
33291
- operator: "search operators, such as site:, before: or \"a\" or \"b\"",
33292
- chat: "chat phrasing, such as \"can you\" or \"should i\"",
33293
- long: "ten or more words with no other sign"
33294
- };
33295
- const MATCHERS = RULES.map(([kind, pattern]) => [kind, new RegExp(pattern)]);
33296
- const AI_QUERY_PATTERN = RULES.map(([, pattern]) => `(?:${pattern})`).join("|");
33297
- const NOISE = [
33298
- ["spaced_letters", /(^|\s)(\S\s){3,}\S(\s|$)/u],
33299
- ["broken_encoding", /^(яю|ÿþ|þÿ)|&#[0-9]+;?|&[a-z]+;|[âÃÂ][\u0080-\u00bf€™œ“”]|\ufffd/u],
33300
- ["pasted_text", /^(p [a-z]{3,} |here (are|is) (all )?the |here's the |done[,.!]? (you|here) |current state: )/u]
33301
- ];
33302
- function aiQueryNoise(query) {
33303
- const text = query.trim().toLowerCase();
33304
- return NOISE.find(([, pattern]) => pattern.test(text))?.[0] ?? null;
33305
- }
33306
- const QUESTION = /^(how|what|what's|whats|which|why|when|where|who|is|are|can|could|does|do|should|would|will|i need|i want|i have|i'm looking|we need|we want)\b|\?$/u;
33307
- const ASKABLE_KINDS = /* @__PURE__ */ new Set(["chat", "long"]);
33308
- const PROMPT_CHARACTERS = 500;
33309
- function askable(query, kind) {
33310
- const text = query.trim().toLowerCase().replace(/^["'“]+/u, "");
33311
- return Boolean(kind && ASKABLE_KINDS.has(kind)) && text.length <= PROMPT_CHARACTERS && QUESTION.test(text);
33312
- }
33313
- function aiQueryKind(query) {
33314
- const text = query.trim().toLowerCase();
33315
- return MATCHERS.find(([, pattern]) => pattern.test(text))?.[0] ?? null;
33316
- }
33317
- const STOP = new Set("the and for with that this what which who how why when where are is was can does do did you your our from about into than then them they their there have has had will would should could not but its it’s me my i am of to in on at by or an as be if so".split(" "));
33318
- function words$1(query) {
33319
- return new Set(query.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter((word) => word.length >= 3 && !STOP.has(word)).map((word) => word.length > 4 && word.endsWith("s") ? word.slice(0, -1) : word));
33320
- }
33321
- const SAME_QUESTION = .6;
33322
- const MAX_ROWS = 25e3;
33323
- const EXAMPLES = 3;
33324
- const CANDIDATES = 200;
33325
- const overlap = (a, b, weight) => {
33326
- let shared = 0;
33327
- let union = 0;
33328
- for (const word of a) {
33329
- union += weight(word);
33330
- if (b.has(word)) shared += weight(word);
33331
- }
33332
- for (const word of b) if (!a.has(word)) union += weight(word);
33333
- return union ? shared / union : 0;
33334
- };
33335
- const round = (value, places) => Math.round(value * 10 ** places) / 10 ** places;
33336
- async function aiQueriesReport(input, searchAnalytics) {
33337
- const range = {
33338
- startDate: input.startDate,
33339
- endDate: input.endDate
33340
- };
33341
- const [matched, site] = await Promise.all([searchAnalytics(input.site, {
33342
- ...range,
33343
- dimensions: ["query", "page"],
33344
- type: "web",
33345
- dataState: "final",
33346
- maxRows: MAX_ROWS,
33347
- dimensionFilterGroups: [{ filters: [{
33348
- dimension: "query",
33349
- operator: "includingRegex",
33350
- expression: AI_QUERY_PATTERN
33351
- }] }]
33352
- }), searchAnalytics(input.site, {
33353
- ...range,
33354
- dimensions: [],
33355
- type: "web",
33356
- dataState: "final"
33357
- })]);
33358
- const rows = [...matched.rows].sort((a, b) => b.impressions - a.impressions || String(a.keys[0]).localeCompare(String(b.keys[0])) || String(a.keys[1]).localeCompare(String(b.keys[1])));
33359
- const usage = /* @__PURE__ */ new Map();
33360
- const unique = new Set(rows.map((row) => String(row.keys[0] ?? "")));
33361
- for (const query of unique) for (const word of words$1(query)) usage.set(word, (usage.get(word) ?? 0) + 1);
33362
- const weight = (word) => Math.log((unique.size + 1) / (usage.get(word) ?? 1));
33363
- const groups = [];
33364
- const byWord = /* @__PURE__ */ new Map();
33365
- const byText = /* @__PURE__ */ new Map();
33366
- const kindOf = /* @__PURE__ */ new Map();
33367
- const noise = /* @__PURE__ */ new Map();
33368
- for (const row of rows) {
33369
- const query = String(row.keys[0] ?? "");
33370
- const page = String(row.keys[1] ?? "");
33371
- const kind = aiQueryKind(query);
33372
- if (!kind) continue;
33373
- const junk = aiQueryNoise(query);
33374
- if (junk) {
33375
- const seen = noise.get(junk) ?? /* @__PURE__ */ new Set();
33376
- seen.add(query.trim().toLowerCase());
33377
- noise.set(junk, seen);
33378
- continue;
33379
- }
33380
- const text = query.trim().toLowerCase();
33381
- const own = words$1(query);
33382
- let group = byText.get(text);
33383
- if (!group) {
33384
- let checked = 0;
33385
- for (const word of own) {
33386
- for (const candidate of byWord.get(word) ?? []) {
33387
- if (++checked > CANDIDATES) break;
33388
- if (overlap(own, candidate.words, weight) >= SAME_QUESTION) {
33389
- group = candidate;
33390
- break;
33391
- }
33392
- }
33393
- if (group || checked > CANDIDATES) break;
33394
- }
33395
- }
33396
- if (!group) {
33397
- group = {
33398
- words: own,
33399
- queries: /* @__PURE__ */ new Map(),
33400
- pages: /* @__PURE__ */ new Map(),
33401
- kinds: /* @__PURE__ */ new Map(),
33402
- clicks: 0,
33403
- impressions: 0,
33404
- positionWeight: 0
33405
- };
33406
- groups.push(group);
33407
- for (const word of own) {
33408
- const list = byWord.get(word) ?? [];
33409
- list.push(group);
33410
- byWord.set(word, list);
33411
- }
33412
- }
33413
- byText.set(text, group);
33414
- if (!kindOf.has(text)) {
33415
- kindOf.set(text, kind);
33416
- group.kinds.set(kind, (group.kinds.get(kind) ?? 0) + 1);
33417
- }
33418
- group.queries.set(query, (group.queries.get(query) ?? 0) + row.impressions);
33419
- group.pages.set(page, (group.pages.get(page) ?? 0) + row.impressions);
33420
- group.clicks += row.clicks;
33421
- group.impressions += row.impressions;
33422
- group.positionWeight += row.position * row.impressions;
33423
- }
33424
- const byKind = /* @__PURE__ */ new Map();
33425
- for (const kind of kindOf.values()) {
33426
- const entry = byKind.get(kind) ?? {
33427
- queries: 0,
33428
- impressions: 0
33429
- };
33430
- entry.queries += 1;
33431
- byKind.set(kind, entry);
33432
- }
33433
- for (const row of rows) {
33434
- const kind = kindOf.get(String(row.keys[0] ?? "").trim().toLowerCase());
33435
- const entry = kind && byKind.get(kind);
33436
- if (entry) entry.impressions += row.impressions;
33437
- }
33438
- const queries = kindOf.size;
33439
- const impressions = groups.reduce((sum, g) => sum + g.impressions, 0);
33440
- const clicks = groups.reduce((sum, g) => sum + g.clicks, 0);
33441
- const total = site.rows[0] ?? {
33442
- clicks: 0,
33443
- impressions: 0
33444
- };
33445
- const items = groups.map((group) => {
33446
- const most = (map) => [...map].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([name]) => name);
33447
- const [first, ...rest] = most(group.queries);
33448
- const kind = [...group.kinds].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0]?.[0];
33449
- return {
33450
- query: first ?? "",
33451
- page: most(group.pages)[0] ?? "",
33452
- askable: askable(first ?? "", kind),
33453
- pages: group.pages.size,
33454
- kind,
33455
- wordings: group.queries.size,
33456
- impressions: group.impressions,
33457
- clicks: group.clicks,
33458
- ctr: group.impressions ? round(group.clicks / group.impressions, 4) : 0,
33459
- position: group.impressions ? round(group.positionWeight / group.impressions, 1) : 0,
33460
- otherWordings: rest.slice(0, EXAMPLES)
33461
- };
33462
- }).sort((a, b) => b.impressions - a.impressions || b.wordings - a.wordings || a.query.localeCompare(b.query) || a.page.localeCompare(b.page));
33463
- const pct = (part, whole) => whole ? round(part / whole * 100, 1) : null;
33464
- const kinds = [...byKind].sort((a, b) => b[1].impressions - a[1].impressions || a[0].localeCompare(b[0])).map(([kind, entry]) => `${kind} ${entry.queries}`).join(", ");
33465
- const leftOut = [...noise].sort((a, b) => a[0].localeCompare(b[0])).map(([reason, seen]) => `${reason.replace("_", " ")} ${seen.size}`).join(", ");
33466
- const asked = items.filter((item) => item.askable).length;
33467
- const capped = matched.rowsFetched >= MAX_ROWS;
33468
- return {
33469
- range,
33470
- verdict: queries ? `${queries} queries in ${groups.length} questions have the shape of AI conversations or agent searches.` : "No queries with the shape of AI conversations or agent searches.",
33471
- summary: {
33472
- queries,
33473
- questions: groups.length,
33474
- askable: asked,
33475
- leftOut: leftOut || "none",
33476
- impressions,
33477
- clicks,
33478
- shareOfImpressionsPct: pct(impressions, total.impressions),
33479
- byKind: kinds || "none",
33480
- ctr: impressions ? round(clicks / impressions, 4) : 0,
33481
- siteCtr: total.impressions ? round(total.clicks / total.impressions, 4) : 0
33482
- },
33483
- kinds: AI_QUERY_KINDS,
33484
- items,
33485
- caveats: [
33486
- "A heuristic: these queries match the patterns of AI conversations and agent searches. Search Console does not mark AI Mode or AI Overviews, and people type some of these too.",
33487
- "A minimum: Search Console leaves out rare queries, and these are rare by nature.",
33488
- "Rewordings of one question are grouped by their shared words; page is the page with the most impressions for it.",
33489
- "Left out and counted, not shown: letters split by spaces, text broken by a wrong encoding, and text pasted from a tool or an agent’s output.",
33490
- "askable: a chat or long question that opens with a question word or a request such as \"i need\", or ends with a question mark, so an AI engine can be asked it as it is. ai_answers checks the top askable questions only.",
33491
- "Search Console’s Generative AI report is not in its API, so it is not here.",
33492
- ...capped ? [`Capped at the first ${MAX_ROWS} matching query and page rows.`] : []
33493
- ]
33494
- };
33495
- }
33496
33518
  // packages/core/src/commands/research-ahrefs.ts
33497
33519
  async function ahrefs(key, input, missed, totals) {
33498
33520
  const where = targetParts(input).ahrefs;
@@ -34284,12 +34306,6 @@ const DIMENSIONS = [
34284
34306
  "searchAppearance"
34285
34307
  ];
34286
34308
  const REGEX_MAX_CHARS = 4096;
34287
- const QUERY_PRESETS = {
34288
- questions: "^(who|what|where|when|why|how|is|are|can|does|do|should)\\b",
34289
- long_tail: "^(\\S+\\s+){7,}\\S+$",
34290
- comparisons: "\\b(vs|versus|alternatives?)\\b"
34291
- };
34292
- const QUERY_PRESET_NAMES = Object.keys(QUERY_PRESETS);
34293
34309
  function rowTextFilters(input) {
34294
34310
  return [
34295
34311
  [
@@ -34312,11 +34328,6 @@ function rowTextFilters(input) {
34312
34328
  "includingRegex",
34313
34329
  input.queryRegex
34314
34330
  ],
34315
- [
34316
- "query",
34317
- "includingRegex",
34318
- input.queryPreset && QUERY_PRESETS[input.queryPreset]
34319
- ],
34320
34331
  [
34321
34332
  "query",
34322
34333
  "excludingRegex",
@@ -34764,6 +34775,7 @@ async function runAiAnswers(input, headers, deps, more) {
34764
34775
  ] : []];
34765
34776
  const shown = rows.map((row) => ({
34766
34777
  question: row.question,
34778
+ shape: queryShape(row.question),
34767
34779
  impressions: row.impressions,
34768
34780
  engine: row.engine,
34769
34781
  result: row.result,
@@ -37920,6 +37932,33 @@ async function bingLead(overview, bing, origin, rowsPerList) {
37920
37932
  return null;
37921
37933
  }
37922
37934
  }
37935
+ const SHAPED = /* @__PURE__ */ new Set([
37936
+ "quick-wins",
37937
+ "low-ctr",
37938
+ "striking-distance",
37939
+ "second-page",
37940
+ "ai-queries"
37941
+ ]);
37942
+ function labelShapes(report, count) {
37943
+ const queries = [];
37944
+ const visit = (value, depth) => {
37945
+ if (depth > 3 || !value || typeof value !== "object") return;
37946
+ if (Array.isArray(value)) {
37947
+ for (const item of value) visit(item, depth + 1);
37948
+ return;
37949
+ }
37950
+ const row = value;
37951
+ if (typeof row.query === "string") {
37952
+ queries.push(row.query);
37953
+ const shape = queryShape(row.query);
37954
+ if (shape) row.shape = shape;
37955
+ }
37956
+ for (const [key, child] of Object.entries(row)) if (Array.isArray(child) && key !== "caveats") visit(child, depth + 1);
37957
+ };
37958
+ visit(report.items, 0);
37959
+ const line = count && queryShapeLine(queries);
37960
+ if (line) report.queryShapes = line;
37961
+ }
37923
37962
  async function build(read, site, section, range, now, bing) {
37924
37963
  const dependencies = {
37925
37964
  searchAnalytics: read,
@@ -37987,7 +38026,9 @@ async function build(read, site, section, range, now, bing) {
37987
38026
  }, read),
37988
38027
  bing: async () => bingSection(await bing(), read, site, range)
37989
38028
  }[section];
37990
- return factsOnly(await run());
38029
+ const report = factsOnly(await run());
38030
+ if (SHAPED.has(section)) labelShapes(report, section !== "ai-queries");
38031
+ return report;
37991
38032
  }
37992
38033
  function brandNote(report) {
37993
38034
  const brand = report.brand;
@@ -38072,6 +38113,7 @@ async function allSections(input, deps) {
38072
38113
  parts.push([
38073
38114
  `## ${id}: ${shown.total} ${shown.total === 1 ? "row" : "rows"}`,
38074
38115
  SECTIONS[id],
38116
+ typeof run.queryShapes === "string" ? run.queryShapes : null,
38075
38117
  shown.text,
38076
38118
  id === "traffic-drop" ? listOfUpdates(run.googleUpdates, run.updateWindow) : null
38077
38119
  ].filter(Boolean).join("\n"));
@@ -38164,6 +38206,7 @@ async function oneSection(input, deps) {
38164
38206
  report.pageChecks = checked;
38165
38207
  }
38166
38208
  const notes = money ? [money] : [];
38209
+ if (typeof report.queryShapes === "string") notes.push(report.queryShapes);
38167
38210
  const brand = brandNote(report);
38168
38211
  if (brand) notes.push(brand);
38169
38212
  const updates = listOfUpdates(report.googleUpdates, report.updateWindow);
@@ -38926,6 +38969,12 @@ async function runPage(input, deps) {
38926
38969
  });
38927
38970
  }
38928
38971
  rows.sort((a, b) => Number(b.clicks) - Number(a.clicks) || Number(b.impressions) - Number(a.impressions));
38972
+ const shaped = rows.map((row) => ({
38973
+ query: row.query,
38974
+ shape: queryShape(String(row.query ?? "")),
38975
+ ...row
38976
+ }));
38977
+ const shapes = queryShapeLine(rows.map((row) => String(row.query ?? "")));
38929
38978
  const sum = (list, key) => list.reduce((total, row) => total + row[key], 0);
38930
38979
  const offset = input.offset ?? 0;
38931
38980
  return {
@@ -38938,12 +38987,13 @@ async function runPage(input, deps) {
38938
38987
  ...reason ? [`Google's reason: ${reason.reason}. Label: ${reason.label}. ${reason.why} (Labels are rules over this evidence, not Google's; ${deps.call("index")} explains them.)`] : [],
38939
38988
  ...indexed && /^URL is unknown to Google$/i.test(indexed.coverage ?? "") ? [unknownNext(input, sitemap.urls.includes(input.url), deps)] : [],
38940
38989
  `Query totals: clicks ${sum(now.rows, "clicks")} (was ${sum(then.rows, "clicks")}), impressions ${sum(now.rows, "impressions")} (was ${sum(then.rows, "impressions")}). Search Console hides rare queries, so these can be lower than the page total.`,
38990
+ ...shapes ? [shapes] : [],
38941
38991
  deps.pageMarkdown ? `Main content as Markdown: ${deps.call("page", {
38942
38992
  url: input.url,
38943
38993
  detail: "full"
38944
38994
  })}.` : `Main content as Markdown: only in the CLI and the local MCP server, with \`npx -y seo page --url ${input.url} --detail full\`.`
38945
38995
  ],
38946
- rows,
38996
+ rows: shaped,
38947
38997
  offset,
38948
38998
  limit: 50,
38949
38999
  detail: input.detail ?? "summary",
@@ -38967,7 +39017,7 @@ async function runPage(input, deps) {
38967
39017
  indexInspectedAt: savedAt,
38968
39018
  reason,
38969
39019
  totalQueries: rows.length,
38970
- queries: rows.slice(offset, offset + 50),
39020
+ queries: shaped.slice(offset, offset + 50),
38971
39021
  ...full ? { markdown } : {}
38972
39022
  }
38973
39023
  };
@@ -39685,14 +39735,13 @@ const SHARED_TOOLS = [
39685
39735
  name: "seo_data",
39686
39736
  command: "data",
39687
39737
  title: "Raw rows",
39688
- description: `Raw rows for questions the report does not answer. search_console (default): rows for any dimensions, each with the previous period and the change; page and query narrow to rows whose URL or query contains that text; query_preset picks questions, long_tail (8+ words) or comparisons; *_regex take RE2 (no lookarounds). google_analytics: landing pages for visits from search, with Google Analytics’ own metric names. bing: Bing Webmaster query or page rows (first dimension) for the same site, by week. clicky: landing-page visits, traffic sources and search engines from a Clicky site the person saved (site is its domain or Clicky site ID; at most 31 days).`,
39738
+ description: `Raw rows for questions the report does not answer. search_console (default): rows for any dimensions, each with the previous period and the change; page and query narrow to rows whose URL or query contains that text; page_regex, query_regex and exclude_query_regex take RE2 regexes for custom cuts. google_analytics: landing pages for visits from search, with Google Analytics’ own metric names. bing: Bing Webmaster query or page rows (first dimension) for the same site, by week. clicky: landing-page visits, traffic sources and search engines from a Clicky site the person saved (site is its domain or Clicky site ID; at most 31 days).`,
39689
39739
  input: z.object({
39690
39740
  source: z.enum(DATA_SOURCES).default("search_console"),
39691
39741
  site: z.string().min(1).describe("search_console and bing: the property or site. google_analytics: numeric property id from seo_sites. clicky: the site or its Clicky site ID."),
39692
39742
  dimensions: z.array(z.enum(DIMENSIONS)).max(4).default(["query"]).describe("search_console; bing uses the first, query or page."),
39693
39743
  page: z.string().min(1).optional().describe("search_console only: URL text, such as /blog/."),
39694
39744
  query: z.string().min(1).optional().describe("search_console only: query text."),
39695
- query_preset: z.enum(QUERY_PRESET_NAMES).optional(),
39696
39745
  page_regex: z.string().min(1).max(REGEX_MAX_CHARS).optional().describe("search_console only: RE2 the page URL must match."),
39697
39746
  query_regex: z.string().min(1).max(REGEX_MAX_CHARS).optional().describe("search_console only: RE2 the query must match."),
39698
39747
  exclude_query_regex: z.string().min(1).max(REGEX_MAX_CHARS).optional().describe("search_console only: RE2 for queries to leave out, such as the brand."),
@@ -39737,7 +39786,6 @@ const SHARED_TOOLS = [
39737
39786
  query: input.query,
39738
39787
  pageRegex: input.page_regex,
39739
39788
  queryRegex: input.query_regex,
39740
- queryPreset: input.query_preset,
39741
39789
  excludeQueryRegex: input.exclude_query_regex
39742
39790
  }),
39743
39791
  startDate: input.start_date,