SLOPSHOPPER

rx-attribution

Drops the Claude trailer and footer from commits and pull requests, then checks each opened or edited PR body and the new commit's author.

guardtoastprocess
A shopper browsing a rack in a slop shop
README

<img src="https://cdn.jsdelivr.net/npm/@rxova/brand@1/assets/rxova-logo-256.png" width="128" alt="rxova logo" />

<h1 align="center">rxova/shared</h1>

<a href="https://github.com/rxova/shared/actions/workflows/ci.yml"><img src="https://github.com/rxova/shared/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI status" /></a> <img src="https://img.shields.io/badge/Node.js-%E2%89%A522.13-5fa04e?logo=nodedotjs&logoColor=white" alt="Node.js 22.13 or newer" /> <img src="https://img.shields.io/badge/pnpm%20%2B%20Turborepo-%E2%9C%93-f69220" alt="Made for pnpm and Turborepo" /> <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license" /></a>

<a href="#packages">Packages</a> · <a href="#ci-building-blocks">CI building blocks</a> · <a href="#using-it-in-an-rxova-repo">Using it</a> · <a href="#developing-this-repo">Developing</a> · <a href="#docs">Docs</a>

Every repository ends up with the same helpers, the same verify gate, the same CI jobs and the same Renovate rules. Copied, they drift. Here they live once: repositories depend on the packages and call the actions and workflows by path, so a fix lands everywhere on the next install or run.

Packages

PackagenpmWhat it is
@rxova/ts-utilsnpmSmall, dependency-free runtime helpers, inlined at build time, plus a /react entry.
@rxova/repo-confignpmThe rxova-repo-config bin (verify gate, changesets, scope, tarball and docs checks) and presets for ESLint, Prettier, tsconfig, Vitest and more.
@rxova/agent-kitnpm10 hooks, 51 skills and 25 agents for Claude Code and OpenCode, installed in profiles by rxova-agent-kit.
@rxova/docs-kitnpmMarkdown twins, llms.txt and the check-md-routes build check for an Astro Starlight docs site.

Each package README lists every export, command and option.

CI building blocks

Composite actions

- uses: rxova/shared/actions/setup-pnpm@main
ActionWhat it does
setup-pnpmpnpm at the packageManager version and Node, with the store cached.
turbo-cacheRestores and saves the local Turbo cache across runs.
turbo-remote-cachePoints Turbo at a remote cache backed by the Actions cache.
setup-playwrightResolves, caches and installs Playwright browsers.
pin-reactPins one React at the root and in the given packages, and proves only that one resolves.
require-jobsFails unless every job in needs passed or was skipped: the one check to require.
notify-websiteTells the rxova.dev website to publish this run's docs build.

Inputs and examples: actions/README.md.

Reusable workflows

jobs:
  commitlint:
    uses: rxova/shared/.github/workflows/commit-messages.yml@main
WorkflowWhat it does
commit-messages.ymlThe root CI job: lints commits and outputs code-changed, docs-only and docs-changed.
docs-checks.ymlThe light job a documentation-only range runs instead of the build and test matrix.
lint-pr-title.ymlLints the PR title, which becomes the squash subject.
changeset-gate.ymlRequires a changeset when a pull request changes a published package.
react-minimum-version.ymlBuilds, tests and typechecks against the oldest React a peer range allows.
node-floor-smoke.ymlInstalls each packed package on exactly the oldest Node its engines promises.
changesets-release.ymlThe version pull request, then publishing with npm trusted publishing and provenance.
snapshot-release.ymlPublishes a prerelease under a dist-tag other than latest, to try a change in another repo.

Inputs, outputs and a full CI graph: .github/workflows/README.md.

Renovate preset

{ extends: ["github>rxova/shared//renovate/default.json5"] }

The org rules live in renovate/default.json5; a repository keeps only its own.

Using it in an rxova repo

Tooling packages go in the root package.json only, never in a workspace package:

pnpm add -D -w @rxova/repo-config @rxova/ts-utils

Point each tool at its preset:

// eslint.config.js
import { rxova } from "@rxova/repo-config/eslint";

export default rxova({ tsconfigRootDir: import.meta.dirname, node: true, tests: true });
// .prettierrc
"@rxova/repo-config/prettier"
// tsconfig.json
{ "extends": "@rxova/repo-config/tsconfig.react.json", "include": ["src"] }

And CI at the shared workflows, pinned to @main:

jobs:
  commitlint:
    uses: rxova/shared/.github/workflows/commit-messages.yml@main
  changeset:
    needs: [commitlint]
    uses: rxova/shared/.github/workflows/changeset-gate.yml@main

The @rxova/repo-config quick start covers the rest: the verify script, the pre-push hook, lint-staged, commitlint, tsdown and Vitest.

Developing this repo

Node 22.13 or newer, and pnpm through Corepack:

corepack enable
pnpm install        # dependencies and git hooks
pnpm test           # unit tests, coverage enforced per file
pnpm docs           # the docs site (apps/docs) on a local dev server
pnpm run verify     # everything CI runs, in CI's order (also the pre-push hook)
pnpm changeset      # record a change to a published package
  • Releases. A change to a published package needs a changeset (see .changeset/README.md). Once CI is green on main, Changesets opens a chore: version packages pull request; merging it publishes to npm with trusted publishing and provenance.
  • Docs-only pull requests. When a range changes only Markdown (and changesets), CI skips the build, test and package jobs and runs the light docs checks job instead; the docs site still builds when apps/docs changed.
  • Releasing a README-only change. A package README change needs no changeset, but npm shows the README of the published version. To ship it, add a patch changeset; the range stays docs-only:
  pnpm exec rxova-repo-config add-changeset ts-utils patch "Rewrite the readme"

See CONTRIBUTING.md for hooks and commit rules, SECURITY.md to report a vulnerability, and SUPPORT.md for help.

Docs

Every README in the repository:

The documentation site's sources are in apps/docs; pnpm docs serves it locally.

License

MIT

Source 9 files
hooks/register.ts 117 lines
1import type { EngineInterface, Register } from "claude-code";
2
3import { attributionLines } from "./attribution-lines";
4import { commits } from "./commits";
5import { gitDir } from "./git-dir";
6import { newCommit } from "./new-commit";
7import { opensOrEditsPr } from "./opens-or-edits-pr";
8import { prUrl } from "./pr-url";
9import { withoutAttribution } from "./without-attribution";
10
11/**
12 * Reads a pull request's body and, when it credits Claude, removes those lines with gh pr edit
13 * (or only reports them when `isFixing` is off). Answers the note for the model, if any.
14 */
15const checkPr = async (
16  $: EngineInterface,
17  url: string,
18  isFixing: boolean,
19): Promise<string | undefined> => {
20  const view = await $.process.run(["gh", "pr", "view", url, "--json", "body", "-q", ".body"]);
21  if (view.exitCode !== 0) {
22    return `rx-attribution: could not read ${url} to check its body (${view.stderr.trim()}).`;
23  }
24
25  const found = attributionLines(view.stdout);
26  if (found.length === 0) {
27    return undefined;
28  }
29
30  if (!isFixing) {
31    return `rx-attribution: ${url} carries attribution: ${found.join(" | ")}. Remove it with gh pr edit.`;
32  }
33
34  const edit = await $.process.run(["gh", "pr", "edit", url, "--body-file", "-"], {
35    stdin: withoutAttribution(view.stdout),
36  });
37  if (edit.exitCode !== 0) {
38    return `rx-attribution: ${url} carries attribution (${found.join(" | ")}) and gh pr edit failed: ${edit.stderr.trim()}`;
39  }
40
41  $.ui.toast(`rx-attribution: removed ${found.length} attribution line(s) from ${url}`);
42
43  return `rx-attribution: removed attribution from ${url}'s body: ${found.join(" | ")}.`;
44};
45
46/**
47 * Reads `commit` (a hash, or HEAD) in `cwd` and answers a note for the model when its author or
48 * committer is not `email` (an empty `email` skips that) or its message credits Claude. Nothing
49 * when git can't find it there: a wrong guess at the directory reads nothing, not another commit.
50 */
51const checkCommit = async (
52  $: EngineInterface,
53  cwd: string | undefined,
54  commit: string,
55  email: string,
56): Promise<string | undefined> => {
57  const log = await $.process.run(
58    ["git", "log", "-1", "--pretty=%an <%ae>%n%cn <%ce>%n%B", commit, "--"],
59    cwd === undefined ? undefined : { cwd },
60  );
61  if (log.exitCode !== 0) {
62    return undefined;
63  }
64
65  const [author = "", committer = "", ...message] = log.stdout.split("\n");
66  const problems: string[] = [];
67  if (email !== "" && !author.endsWith(`<${email}>`)) {
68    problems.push(`author is ${author}`);
69  }
70  if (email !== "" && !committer.endsWith(`<${email}>`)) {
71    problems.push(`committer is ${committer}`);
72  }
73  const found = attributionLines(message.join("\n"));
74  if (found.length > 0) {
75    problems.push(`message carries ${found.join(" | ")}`);
76  }
77
78  return problems.length === 0
79    ? undefined
80    : `rx-attribution: the new commit is wrong: ${problems.join("; ")}. Amend it before pushing.`;
81};
82
83export const register: Register = (on, options) => {
84  const email = typeof options.authorEmail === "string" ? options.authorEmail.trim() : "";
85  const isFixing = options.fixPrBody !== false;
86
87  on("attribution.text", { kind: "commit" }, () => ({ text: "" }));
88  on("attribution.text", { kind: "pr" }, () => ({ text: "" }));
89
90  on("tool.call", { tool: "Bash" }, async ($, e, next) => {
91    const ran = await next(e);
92    if (ran.deny !== undefined || ran.isError === true) {
93      return ran;
94    }
95
96    const notes: string[] = [];
97    if (opensOrEditsPr(e.command)) {
98      const url = prUrl(ran.text ?? "");
99      const note = url === undefined ? undefined : await checkPr($, url, isFixing);
100      if (note !== undefined) notes.push(note);
101    }
102    // Judges only the commit this command made: the hash git commit printed, looked up where the
103    // command ran. Reading some other HEAD (a rebase merge on main, say) would ask to amend a
104    // correct commit. Without a hash (`-q`), HEAD only when the command never left the session's
105    // own directory.
106    const dir = commits(e.command) ? gitDir(e.command) : null;
107    const hash = newCommit(ran.text ?? "");
108    const commit = hash ?? (dir === undefined ? "HEAD" : undefined);
109    if (dir !== null && commit !== undefined) {
110      const note = await checkCommit($, dir, commit, email);
111      if (note !== undefined) notes.push(note);
112    }
113
114    return notes.length === 0 ? ran : { ...ran, context: [...(ran.context ?? []), ...notes] };
115  }).catch(($, e, next) => next(e));
116};
117
hooks/attribution-lines.ts 6 lines
1import { carriesAttribution } from "./carries-attribution";
2
3/** The lines of a text that credit Claude. */
4export const attributionLines = (text: string): string[] =>
5  text.split("\n").filter(carriesAttribution);
6
hooks/commits.ts 4 lines
1/** Whether a shell command runs git commit. */
2export const commits = (command: string): boolean =>
3  /\bgit\s+(?:-[cC]\s+\S+\s+)*commit\b/.test(command);
4
hooks/git-dir.ts 39 lines
1// Each word is quoted or has no quote at all, so no word can be read two ways: a word that could
2// (`\S+` also matching `"a"`) backtracks exponentially over a repeated `-C <dir>`.
3const COMMIT = /\bgit\s+((?:-[cC]\s+(?:"[^"]+"|'[^']+'|[^\s"']+)\s+)*)commit\b/;
4const CD = /(?:^|[;&|(\n])\s*cd\s+("[^"]+"|'[^']+'|[^\s;&|)"']+)/g;
5const GIT_C = /-C\s+("[^"]+"|'[^']+'|[^\s"']+)/g;
6
7const unquote = (word: string): string => word.replace(/^["']|["']$/g, "");
8
9/** A directory a shell can't be read for without running it: a variable, `~`, `cd -`. */
10const isOpaque = (dir: string): boolean => /[$`]/.test(dir) || dir.startsWith("~") || dir === "-";
11
12/**
13 * The directory a shell command runs git commit in: every `cd <dir>` before the commit, in turn
14 * (a relative one goes onto the one before it), then the commit's own `git -C <dir>`. Undefined
15 * when there is neither (the session's own directory); null when a step can't be read without
16 * running the shell (`cd "$W"`, `cd ~/x`, `cd -`), so the caller doesn't read some other HEAD.
17 */
18export const gitDir = (command: string): string | null | undefined => {
19  const commit = COMMIT.exec(command);
20  if (commit === null) {
21    return undefined;
22  }
23
24  const steps = [
25    ...[...command.slice(0, commit.index).matchAll(CD)].map((match) => match[1] ?? ""),
26    ...[...(commit[1] ?? "").matchAll(GIT_C)].map((match) => match[1] ?? ""),
27  ].map(unquote);
28
29  let dir: string | undefined;
30  for (const step of steps) {
31    if (isOpaque(step)) {
32      return null;
33    }
34    dir = step.startsWith("/") || dir === undefined ? step : `${dir.replace(/\/+$/, "")}/${step}`;
35  }
36
37  return dir;
38};
39
hooks/new-commit.ts 8 lines
1// `[main abc1234] feat: x`, `[main (root-commit) abc1234] …`, `[detached HEAD abc1234] …`: the
2// hash is the last word inside the brackets. Bounded by the line, so it stays linear.
3const SUMMARY = /^\[[^\]\n]*\s([0-9a-f]{4,40})\]/gm;
4
5/** The hash of the last commit `git commit` reports in its output, or undefined (`-q` prints none). */
6export const newCommit = (output: string): string | undefined =>
7  [...output.matchAll(SUMMARY)].at(-1)?.[1];
8
hooks/opens-or-edits-pr.ts 4 lines
1/** Whether a shell command runs gh pr create or gh pr edit. */
2export const opensOrEditsPr = (command: string): boolean =>
3  /\bgh\s+pr\s+(create|edit)\b/.test(command);
4
hooks/pr-url.ts 5 lines
1const PR_URL = /https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+/;
2
3/** The first GitHub pull request URL in a text, as gh pr create and gh pr edit print it. */
4export const prUrl = (text: string): string | undefined => PR_URL.exec(text)?.[0];
5
hooks/without-attribution.ts 11 lines
1import { carriesAttribution } from "./carries-attribution";
2
3/** The text with every line that credits Claude removed, and the blank runs that leaves collapsed. */
4export const withoutAttribution = (text: string): string =>
5  text
6    .split("\n")
7    .filter((line) => !carriesAttribution(line))
8    .join("\n")
9    .replace(/\n{3,}/g, "\n\n")
10    .trimEnd();
11
hooks/carries-attribution.ts 13 lines
1const ATTRIBUTION = [
2  /^\s*co-authored-by:.*\b(claude|anthropic)\b/i,
3  /^\s*claude-session:/i,
4  /generated with \[?claude/i,
5  /🤖/u,
6  /claude\.ai\/code/i,
7  /\bsession_[A-Za-z0-9]{6,}/,
8];
9
10/** Whether a line credits Claude: a co-author trailer, a session link or the generated-with footer. */
11export const carriesAttribution = (line: string): boolean =>
12  ATTRIBUTION.some((pattern) => pattern.test(line));
13