// Renders registry entries for `tsus explain`, docs/rules.md and the code// table in AGENTS.md. Everything here reads from rules/registry.js.import { REGISTRY, ruleFor } from "./rules/registry.js";import { V2_REGISTRY, V2_RULES, V1_DISPOSITION } from "./v2/registry.js";const FIX_TEXT = { safe: "`tsus fix` applies it (behavior is kept).", unsafe: "`tsus fix --unsafe` applies it; review the change, it can alter behavior.", none: "No automatic fix: the right change depends on intent.",};const indent = (text, pad = " ") => text .split("\n") .map((l) => (l === "" ? "" : pad + l)) .join("\n");export const renderExplainText = (rule) => [ `${rule.code} ${rule.name}: ${rule.title}`, "", ` ${rule.message}`, "", "Why", indent(rule.why, " "), "", "Bad", indent(rule.bad), "", "Good", indent(rule.good), "", ...(rule.evidence ? ["Evidence", indent(rule.evidence, " "), ""] : []), `Hint: ${rule.hint}`, `Fix: ${FIX_TEXT[rule.fix].replaceAll("`", "")}`, ].join("\n");export const renderList = () => [...REGISTRY, ...V2_REGISTRY].map((r) => `${r.code} ${r.name.padEnd(30)} ${r.title}`).join("\n");export const explain = (code) => ruleFor(code) ?? V2_RULES.get(code.toUpperCase());const mdFence = (code) => "```ts\n" + code + "\n```";export const renderRuleMarkdown = (rule) => [ `## ${rule.code} ${rule.name}`, "", `**${rule.title}.** ${rule.why}`, "", "Rejected:", "", mdFence(rule.bad), "", "Accepted:", "", mdFence(rule.good), "", `Hint: ${rule.hint}`, "", `Fix: ${FIX_TEXT[rule.fix]}`, ].join("\n");export const renderRulesDoc = () => [ "# TSUS diagnostic codes", "", "Generated from `packages/cli/src/rules/registry.js` by `npm run docs`. Do not edit by hand; `tsus explain <CODE>` prints the same text.", "", renderCodeTable(), "", ...REGISTRY.map(renderRuleMarkdown).flatMap((s) => [s, ""]), ].join("\n");export const renderCodeTable = () => [ "| Code | Rule | Fix |", "|---|---|---|", ...REGISTRY.map((r) => `| ${r.code} | ${r.title} | ${r.fix} |`), ].join("\n");// docs/v2/rules.md: every v2 code with the reason it stays, then what happened to each v1 rule.export const renderV2RulesDoc = () => [ "# TSUS v2 diagnostic codes", "", "Generated from `packages/cli/src/v2/registry.js` by `npm run docs`. Do not edit by hand; `tsus explain <CODE>` prints the same text.", "", "v2 checks plain `.ts` (`tsus check --v2`). A rule is here only if there is a bug it catches; each entry says which one, citing the search-query experiment (plain strict TS against TSUS v1, judged on 118 hidden tests and 20,400 fuzz pairs), the on-call pilot (docs/v2/tsus-pilot.md in Rebasely), or the risks reviews of AI-written web code kept finding (SQL injection, permission scoping, secrets, untrusted input).", "", "| Code | Rule |", "|---|---|", ...V2_REGISTRY.map((r) => `| ${r.code} | ${r.title} |`), "", ...V2_REGISTRY.flatMap((rule) => [ `## ${rule.code} ${rule.name}`, "", `**${rule.title}.** ${rule.why}`, "", `**Why it stays:** ${rule.evidence}`, "", "Rejected:", "", mdFence(rule.bad), "", "Accepted:", "", mdFence(rule.good), "", `Hint: ${rule.hint}`, "", ]), "## What happened to v1's rules", "", "| v1 | v2 | Why |", "|---|---|---|", ...V1_DISPOSITION.map(([rule, fate, why]) => `| ${rule} | ${fate} | ${why} |`), "", ].join("\n");