Skip to content

gretchenfitze/anti-slop / skills/anti-slop-rollout

anti-slop-rollout

Verified

Carry out the next step of an anti-AI-slop rollout plan (anti-slop/todo.md, with the reasoning in anti-slop/plan.md) as one pull request: add a single check in whatever stack the plan records (a strict TypeScript flag, sonarjs, unnecessary-effect, or test lint rules, layer boundaries, a custom lint rule from a past bug, an agent hook, Stryker mutation testing, knip and dead-file scripts, jscpd, react-doctor, a CI gate, a scheduled report, and the final trim of the agent rules file), fix or baseline what it finds, document its commands in the agent rules file, verify it, and open the PR. Use when the user says "next anti-slop step", "do step N of the plan", asks which rules in AGENTS.md or CLAUDE.md the linters now cover, or asks to set up knip, jscpd, react-doctor, Stryker, sonarjs, or boundaries the gradual way (warnings first, CI gate last) in a repo that has an anti-slop plan. Needs the plan from anti-slop-audit; without one, run the audit first.

assets/scripts/jscpd-top.mjs

View on GitHub
// From ts-workbench (https://github.com/mikhin/ts-workbench) by Yuri Mikhin (https://github.com/mikhin), MIT.
import { readFileSync, statSync } from "node:fs";
import path from "node:path";

const ROOT = path.resolve(import.meta.dirname, "..");
const REPORT = path.resolve(ROOT, "reports/jscpd/jscpd-report.json");

const DEFAULT_TOP = 30;
const FRAGMENT_WIDTH = 200;
const PLACES_SHOWN = 6;
const MIN_SIGNAL_WORDS = 3;
const MIN_PLACES = 3;
const MIN_WORD_LENGTH = 3;

const IMPORT_RE = /\bimport\b[\s\S]*?from\s*["'][^"']*["']\s*;?/g;
const REEXPORT_RE = /\}\s*from\s*["'][^"']*["']\s*;?/g;
const WORD_RE = /[A-Za-z_$][A-Za-z0-9_$]*/g;

const NOISE_WORDS = new Set(
  "afterEach as async await beforeEach boolean const default describe expect export false fn from if import it let mock mocked new not null number rejects resolves return string test this toBe toBeNull toBeUndefined toEqual toHaveBeenCalled toHaveBeenCalledTimes toHaveBeenCalledWith toHaveLength toStrictEqual true type undefined vi void".split(
    " ",
  ),
);

const args = process.argv.slice(2);

const flagValue = (name) => {
  const index = args.indexOf(name);

  return index === -1 ? null : args[index + 1];
};

const showAll = args.includes("--all");
const showPairs = args.includes("--pairs");
const showFull = args.includes("--full");
const grep = flagValue("--grep")?.toLowerCase() ?? null;
const top = Number(flagValue("--top") ?? DEFAULT_TOP);

if (statSync(REPORT, { throwIfNoEntry: false }) === undefined) {
  console.log(`No report at ${path.relative(ROOT, REPORT)}. Run the dup:top script first.`);

  process.exit(0);
}

const report = JSON.parse(readFileSync(REPORT, "utf8"));

const normalize = (fragment) => fragment.replaceAll(/\s+/g, " ").trim();

const signalWords = (fragment) => {
  const withoutImports = fragment.replace(IMPORT_RE, " ").replace(REEXPORT_RE, " ");

  return new Set(
    (withoutImports.match(WORD_RE) ?? []).filter(
      (word) => word.length >= MIN_WORD_LENGTH && !NOISE_WORDS.has(word),
    ),
  );
};

const shortPath = (name) =>
  path.isAbsolute(name) ? path.relative(ROOT, name) : name.replace(/^\.\//, "");

const groups = new Map();

for (const duplicate of report.duplicates) {
  const fragment = normalize(duplicate.fragment ?? "");

  if (fragment === "") continue;

  const group = groups.get(fragment) ?? { fragment, lines: duplicate.lines, places: new Set() };

  for (const file of [duplicate.firstFile, duplicate.secondFile]) {
    group.places.add(`${shortPath(file.name)}:${file.start}`);
  }

  groups.set(fragment, group);
}

const scored = [...groups.values()].map((group) => ({
  ...group,
  places: [...group.places].toSorted(),
  signal: signalWords(group.fragment).size,
}));

const noisy = scored.filter((group) => group.signal < MIN_SIGNAL_WORDS);

const matches = (group) =>
  grep === null ||
  group.fragment.toLowerCase().includes(grep) ||
  group.places.some((place) => place.toLowerCase().includes(grep));

const findings = scored
  .filter((group) => group.signal >= MIN_SIGNAL_WORDS)
  .filter((group) => showPairs || group.places.length >= MIN_PLACES)
  .filter(matches)
  .toSorted(
    (a, b) =>
      b.places.length - a.places.length ||
      b.lines - a.lines ||
      a.fragment.localeCompare(b.fragment),
  );

const shown = showAll ? findings : findings.slice(0, top);

const clip = (fragment) =>
  showFull || fragment.length <= FRAGMENT_WIDTH
    ? fragment
    : `${fragment.slice(0, FRAGMENT_WIDTH)}…`;

const twoPlaceCount = scored.filter(
  (group) => group.signal >= MIN_SIGNAL_WORDS && group.places.length < MIN_PLACES,
).length;

const grepNote = grep === null ? "" : ` matching "${grep}"`;
const pairsNote = showPairs ? "" : `, ${twoPlaceCount} seen twice only (--pairs)`;

console.log(
  `${report.duplicates.length} clone pairs → ${findings.length} fragments${grepNote}` +
    `, ${noisy.length} dropped as scaffolding${pairsNote}.\n`,
);

for (const group of shown) {
  console.log(`×${group.places.length}  ${group.lines} lines`);

  console.log(`  ${clip(group.fragment)}`);

  console.log(`  ${group.places.slice(0, PLACES_SHOWN).join(", ")}`);

  if (group.places.length > PLACES_SHOWN) {
    console.log(`  …and ${group.places.length - PLACES_SHOWN} more`);
  }

  console.log("");
}

if (shown.length < findings.length) {
  console.log(`Showing ${shown.length} of ${findings.length}. Use --all.`);
}
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall