content-md 1.0.2 → 1.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.3
4
+
5
+ Fixes from auditing a real 13,000-line monorepo with 1.0.2.
6
+
7
+ - audit_copy no longer reads JSX/TS code as copy. Text between tags that contains `&&`, `||`, `?.`, `.length`, a trailing `? (` or `null,`/`undefined,` is skipped.
8
+ - Tag text is read with a lookahead, so prose after an inline tag (`<br />`, `<strong>…</strong>`) is now checked. It used to be lost.
9
+ - Crawlers, scrapers and top-level `tools/`, `infra/`, `ops/`, `deploy/`, `etl/` and `pipelines/` folders are skipped as not product UI. An app route such as `app/tools/` is still read.
10
+ - On admin and internal pages (`(admin)/`, `admin/`, `internal/`, `staff/`, `ops/`, files like `platformAdminX.ts`) a named env variable is a note, not a block: there, naming it is the fix.
11
+ - `narrating-location` no longer fires on "isn't listed here", which says what a page covers. "will be listed here" and "will appear here" still fire.
12
+ - A "No X yet" headline gets one finding (`no-x-yet`), not that plus `absence-headline`.
13
+ - `remove` deletes a repo `.mcp.json` that held only content-md, instead of leaving `{"mcpServers": {}}`.
14
+
3
15
  ## 1.0.2
4
16
 
5
17
  From a trial in a real product repo and a full audit of 1.0.0. (1.0.1 was built but never published; its changes are listed under it below and ship in this release.)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "content-md",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "UX writing tools for coding agents (Codex, Cursor, Claude Code, VS Code, Windsurf): a tone decider, playbooks for 35 UI patterns, 194 pattern rules, 413 style-guide rules and a copy linter, as an MCP server.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/init.js CHANGED
@@ -153,7 +153,12 @@ export function remove(argv, cwd = process.cwd()) {
153
153
  if (global) jsonFiles.push([join(homedir(), ".codeium", "windsurf", "mcp_config.json"), "mcpServers"]);
154
154
  for (const [p, key] of jsonFiles) {
155
155
  if (!existsSync(p)) continue;
156
- try { const j = JSON.parse(readFileSync(p, "utf8")); if (j[key]?.["content-md"]) { delete j[key]["content-md"]; save(p, JSON.stringify(j, null, 2) + "\n"); } } catch { /* leave invalid JSON alone */ }
156
+ try { const j = JSON.parse(readFileSync(p, "utf8")); if (j[key]?.["content-md"]) {
157
+ delete j[key]["content-md"];
158
+ // a repo file that held only our server is removed, not left behind as {"mcpServers": {}}
159
+ const empty = !Object.keys(j[key]).length && Object.keys(j).length === 1 && p.startsWith(cwd);
160
+ if (empty) { if (!dry) rmSync(p, { force: true }); done.push(show(p)); } else save(p, JSON.stringify(j, null, 2) + "\n");
161
+ } } catch { /* leave invalid JSON alone */ }
157
162
  }
158
163
  for (const p of [join(cwd, ".cursor", "rules", "content-md.mdc"), join(cwd, ".claude", "skills", "content-md")]) {
159
164
  if (existsSync(p)) { if (!dry) rmSync(p, { recursive: true, force: true }); done.push(show(p)); }
package/src/product.js CHANGED
@@ -49,6 +49,10 @@ const CODE_EXT = new Set([".tsx", ".jsx", ".vue", ".svelte", ".html", ".swift",
49
49
  // vendored, generated and demo code: not the product's own copy
50
50
  const VENDOR_PATH = /\/(vendor(ed)?|third[-_]?party|external|demos?|playground|sandbox|generated|__generated__|registry|shadcn[\w-]*|[\w-]*-studio)\//i;
51
51
  const VENDOR_HEAD = /@generated|@vendored|DO NOT EDIT|auto-?generated/i;
52
+ // backend tools, crawlers and infrastructure at the repo's top level: their messages never reach the product's users
53
+ const NON_PRODUCT_PATH = /^\/(tools|infra|infrastructure|ops|deploy|terraform|crawlers?|scrapers?|etl|pipelines?)\/|\/[\w-]*(crawler|scraper)s?\//i;
54
+ // admin and internal pages: the reader is the team, so naming an env variable is the fix, not a leak
55
+ export const ADMIN_PATH = /(^|\/|\()(admin|internal|staff|backoffice|back-office|ops|debug)(\)|\/)|(^|\/)[\w-]*[a-z](Admin|Internal)[A-Z]\w*\.|(^|\/)(admin|internal)[A-Z-]/;
52
56
  const TEST_FILE = /(\.|_|-|\/)(test|spec|stories|story|storybookData|mock|fixture)s?\.|\/(__tests__|tests?|e2e|fixtures|mocks|stories)\//i;
53
57
 
54
58
  // Breadth-first, so a large monorepo is covered level by level instead of one deep branch first.
@@ -92,6 +96,8 @@ const looksLikeCopy = (t) => {
92
96
  if (/^[a-z0-9_.-]+$/.test(s) && !/\s/.test(s)) return false; // keys, ids, class names
93
97
  if (/^(https?:|\/|#|\.|@|\$\{|[A-Z_]{3,}$)/.test(s)) return false; // urls, paths, constants
94
98
  if (/[{};=<>]|=>|\(\)|\bfunction\b|\bimport\b|\bconst\b/.test(s)) return false;
99
+ // JSX/TS code that leaks between tags: ternaries, logical operators, optional chains, object-literal keys
100
+ if (/&&|&amp;&amp;|\|\||\?\.|\.length\b|\?\s*\($|^[)\]:,?]|\b(null|undefined)\s*[,:)]/.test(s)) return false;
95
101
  if (/^[a-z]+(-[a-z]+)+$/.test(s)) return false; // css-ish tokens
96
102
  if (/^[A-Za-z]+[A-Z][\w]*(\[\])?$/.test(s) || /\[\]|\s\|\s|\w:\s*[A-Z]\w+[,|)]/.test(s)) return false; // type names, type unions
97
103
  if ((s.match(/%[A-Za-z-]/g) || []).length >= 2 || /:$/.test(s)) return false; // date formats, yaml parents
@@ -110,7 +116,7 @@ function extractFromCode(src, file) {
110
116
  const out = [];
111
117
  const push = (text, idx, hint) => { const t = text.replace(/\s+/g, " ").trim(); if (looksLikeCopy(t)) out.push({ text: t, file, line: lineOf(src, idx), element: guessElement(t, hint) }); };
112
118
  // JSX/HTML text between tags; element from the tag name
113
- const tagText = /<([A-Za-z][\w.]*)[^<>]*>([^<>{}]{2,400})</g;
119
+ const tagText = /<([A-Za-z][\w.]*)[^<>]*>([^<>{}]{2,400})(?=<)/g; // lookahead, so "<p>A<br />B</p>" yields both A and B
114
120
  let m;
115
121
  while ((m = tagText.exec(src))) {
116
122
  const tag = m[1].toLowerCase();
@@ -183,7 +189,7 @@ export function collectStrings(root, sub) {
183
189
  const ignore = readConfig(root).ignore.map((g) => g.replace(/^\.\//, ""));
184
190
  for (const f of files) {
185
191
  const rel = relative(root, f);
186
- if (TEST_FILE.test("/" + rel) || VENDOR_PATH.test("/" + rel) || ignore.some((g) => rel.startsWith(g))) continue;
192
+ if (TEST_FILE.test("/" + rel) || VENDOR_PATH.test("/" + rel) || NON_PRODUCT_PATH.test("/" + rel) || ignore.some((g) => rel.startsWith(g))) continue;
187
193
  if (LOCALE_FILE.test(rel)) { if (isEnglishLocale(rel)) strings.push(...extractFromLocale(readSafe(f), rel)); continue; }
188
194
  if (CODE_EXT.has(extname(f))) { const src = readSafe(f); if (!VENDOR_HEAD.test(src.slice(0, 400))) strings.push(...extractFromCode(src, rel)); }
189
195
  else if (SERVER_EXT.has(extname(f)) && (isClientScript(rel) || !/(^|\/)(config|db|migrations?|spec|test|api)\//.test(rel))) strings.push(...extractFromServer(readSafe(f), rel));
@@ -293,8 +299,10 @@ export function auditCopy({ root = process.cwd(), strings, limit = 25, path_filt
293
299
  }
294
300
  if (path_filter) list = list.filter((s) => (s.file || "").includes(path_filter.replace(/\/$/, "")));
295
301
  const scored = list.map((s) => {
302
+ const admin = s.file && ADMIN_PATH.test(s.file);
296
303
  const findings = lintCopy({ units: [{ element: s.element, text: s.text }], allow: [...cfg.allow, ...(allow || [])] })
297
- .filter((f) => !["variable", "long", "punctuation"].includes(f.rule));
304
+ .filter((f) => !["variable", "long", "punctuation"].includes(f.rule))
305
+ .map((f) => (admin && f.rule === "raw-code" ? { ...f, severity: "note", detail: f.detail.replace(/;.*$/, "; fine on an admin page if naming it is the fix") } : f));
298
306
  const base = findings.reduce((a, f) => a + SEV[f.severity], 0);
299
307
  const stakes = STAKES.test(s.text);
300
308
  const reach = Math.min(3, Math.log2(1 + (s.uses || 1)));
package/src/tools.js CHANGED
@@ -257,8 +257,11 @@ export function lintCopy({ units, pattern, state, stakes, expected_pieces, origi
257
257
  // structural tics measured against shipped copy: "No X yet" empty states, narrating where things will appear, two even sentences
258
258
  units.forEach((u, i) => {
259
259
  const x = (u.text || "").trim();
260
- if (u.element === "headline" && /^no\b[^.!?]*\byet\b/i.test(x)) add(i, "warn", "no-x-yet", `'${x}' is the most common model empty-state headline (49% of model lines, 5.5% of shipped); lead with what the person gets or can do ("Add your first contact")`);
261
- if (/\b(will|'ll)\s+(show up|appear|be listed|be shown|be displayed)\s+here\b|\blisted here\b|\byou('ll| will) see (it|them|\w+) here\b/i.test(x)) add(i, "warn", "narrating-location", "says where content will appear instead of what the person gets; say what it is and what to do");
260
+ if (u.element === "headline" && /^no\b[^.!?]*\byet\b/i.test(x)) {
261
+ for (let k = out.length - 1; k >= 0; k--) if (out[k].unit === i && out[k].rule === "absence-headline") out.splice(k, 1); // one finding per problem
262
+ add(i, "warn", "no-x-yet", `'${x}' is the most common model empty-state headline (49% of model lines, 5.5% of shipped); lead with what the person gets or can do ("Add your first contact")`);
263
+ }
264
+ if (/\b(will|'ll)\s+(show up|appear|be listed|be shown|be displayed)\s+here\b|\byou('ll| will) see (it|them|\w+) here\b/i.test(x)) add(i, "warn", "narrating-location", "says where content will appear instead of what the person gets; say what it is and what to do");
262
265
  if (u.element === "body") {
263
266
  const sents = x.split(/(?<=[.!?])\s+/).filter((t) => t.split(/\s+/).length > 1);
264
267
  const wc = sents.map((z) => z.split(/\s+/).length);