From 83da216624217300929a8d3f63b6193006f64626 Mon Sep 17 00:00:00 2001 From: Sorawit Kongnurat Date: Sat, 21 Nov 2026 16:02:10 +0700 Subject: [PATCH] Enforce short READMEs in app monorepos --- README.md | 6 ++++++ package.json | 2 +- src/plugin/agent-docs.mjs | 23 ++++++++++++++++++----- test/agent-docs.test.mjs | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d026de2..a6dd315 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,12 @@ Keep HTTP work in the API or a Server Action. Next permits `src/app/health/route API tests, test utilities and fixtures may use `fetch` when the same file starts a local server with `.listen()`, including `.listen(0)`. MSW's `.listen({ ... })` still requires `onUnhandledRequest: "error"` (or `onUnhandledFrame: "error"` in MSW 3). Use `testClient()` for `/api` paths; direct `app.request(...)` or `createApp().request(...)` is allowed for literal paths outside `/api`, including static template literals. +## Monorepo READMEs + +A repository with app workspaces under `apps/` can use up to 60 prose lines in its root README and 40 in each app README. Each file has one `#` title. Use headings that fit the project. Blank lines, fenced examples, and generated blocks are excluded from the count. + +Use the root README for the project's purpose, local setup, checks, and how to navigate or operate the repo. Use app READMEs for app-specific instructions and lasting operating decisions. + ## AGENTS.md An `AGENTS.md` holds only what the code, the config and lint messages can't tell an agent. `pnpm lint` checks its shape: diff --git a/package.json b/package.json index d877149..0682974 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mapringg/standard", - "version": "1.2.8", + "version": "1.3.0", "description": "One oxlint config and plugin for every repository.", "license": "MIT", "repository": "github:mapringg/standard", diff --git a/src/plugin/agent-docs.mjs b/src/plugin/agent-docs.mjs index 68e2e9c..98e0fb0 100644 --- a/src/plugin/agent-docs.mjs +++ b/src/plugin/agent-docs.mjs @@ -5,6 +5,8 @@ import { anchorFor, listFiles, locate } from "./paths.mjs"; const SECTIONS = ["Rules", "Words", "Copy", "Decisions", "Traps", "Operations", "Sources"]; const MAX_LINES = 50; +const ROOT_README_LINES = 60; +const APP_README_LINES = 40; const CODE = /\.[cm]?[jt]sx?$/; const BEGIN = /^\s*$/; const FENCE_OPEN = /^ {0,3}(?:(`{3,})[^`]*|(~{3,}).*)$/; @@ -149,6 +151,16 @@ function shapeProblems(prose) { return found; } +function readmeProblems(prose, maxLines) { + const found = []; + const lines = prose.map(({ line }) => line).filter((line) => line.trim()); + const titles = lines.map(headingOf).filter((heading) => heading?.level === 1 && heading.title); + if (titles.length !== 1) found.push("Use one # title naming the project."); + if (lines.length > maxLines) + found.push(`Cut it to ${maxLines} prose lines; keep setup, checks, and operational decisions.`); + return found; +} + function contentProblems(prose) { const found = []; const spans = [...joined(prose).matchAll(SPAN)].flatMap((match) => match[2].split(/\s+/)); @@ -197,6 +209,7 @@ function sharedSkillProblems(root, documentOf) { function scan(root) { const files = listFiles(root); const lintable = files.filter((rel) => CODE.test(rel)); + const monorepo = files.some((rel) => /^apps\/[^/]+\/package\.json$/.test(rel)); const documents = new Map(); const documentOf = (rel) => { if (!documents.has(rel)) { @@ -211,10 +224,10 @@ function scan(root) { for (const rel of files.filter((file) => file.endsWith(".md"))) { const { prose } = documentOf(rel); const name = rel.slice(rel.lastIndexOf("/") + 1); - const problems = [ - ...(name === "AGENTS.md" ? [...shapeProblems(prose), ...contentProblems(prose)] : []), - ...linkProblems(root, rel, prose, documentOf), - ]; + const problems = linkProblems(root, rel, prose, documentOf); + if (name === "AGENTS.md") problems.push(...shapeProblems(prose), ...contentProblems(prose)); + if (monorepo && rel === "README.md") problems.push(...readmeProblems(prose, ROOT_README_LINES)); + if (/^apps\/[^/]+\/README\.md$/.test(rel)) problems.push(...readmeProblems(prose, APP_README_LINES)); const anchor = anchorFor(rel.includes("/") ? rel.slice(0, rel.lastIndexOf("/")) : "", lintable); if (!anchor || problems.length === 0) continue; findings.set(anchor, [...(findings.get(anchor) ?? []), ...problems.map((message) => `${rel}: ${message}`)]); @@ -235,7 +248,7 @@ export default { type: "problem", docs: { description: - "AGENTS.md files share one shape and hold only what the code cannot show; Markdown links resolve. Findings report on the nearest linted file.", + "AGENTS.md and monorepo READMEs stay short; Markdown links resolve. Findings report on the nearest linted file.", }, }, create(context) { diff --git a/test/agent-docs.test.mjs b/test/agent-docs.test.mjs index 42b54af..076e2c3 100644 --- a/test/agent-docs.test.mjs +++ b/test/agent-docs.test.mjs @@ -221,3 +221,35 @@ test("adopters link the installed skills without local copies", (t) => { ], ); }); + +test("monorepo READMEs accept 60 root and 40 app prose lines with flexible headings", (t) => { + const example = "```sh\n" + "pnpm test\n".repeat(70) + "```\n"; + deepEqual( + findings(t, { + "README.md": `# Repo\n\n## Getting started\n\n${"Run the app.\n\n".repeat(58)}${example}`, + "apps/web/README.md": `# Web\n\n### Run locally\n\n${"Open the app.\n".repeat(38)}${example}`, + }), + [], + ); +}); + +test("monorepo READMEs report prose over budget and missing or duplicate titles", (t) => { + deepEqual( + findings(t, { + "README.md": `## Read this\n${"Run the app.\n".repeat(60)}`, + "apps/web/README.md": `# Web\n# Another title\n${"Open the app.\n".repeat(39)}`, + }), + [ + "README.md: Cut it to 60 prose lines; keep setup, checks, and operational decisions.", + "README.md: Use one # title naming the project.", + "apps/web/README.md: Cut it to 40 prose lines; keep setup, checks, and operational decisions.", + "apps/web/README.md: Use one # title naming the project.", + ], + ); +}); + +test("standalone package and skill READMEs have no monorepo prose budget", (t) => { + const long = "Extended reference.\n".repeat(80); + deepEqual(only(lint(t, { "src/index.ts": code, "README.md": long }), "agent-docs"), []); + deepEqual(findings(t, { ".claude/skills/verify/README.md": long, "packages/tokens/README.md": long }), []); +});