content-md 1.0.2 → 1.0.8
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 +49 -0
- package/README.md +3 -2
- package/data/tone/decider.json +10 -14
- package/guide/SKILL.md +5 -2
- package/guide/rules.md +3 -3
- package/package.json +1 -1
- package/src/claims.js +122 -0
- package/src/init.js +11 -2
- package/src/position.js +141 -0
- package/src/product.js +15 -5
- package/src/server.js +38 -10
- package/src/tools.js +14 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.8
|
|
4
|
+
|
|
5
|
+
- **The product's own style.** `read_product` now reports the product's own style habits (contractions, "you", full stops, case, length, per moment) from its strings, and `lint_copy` flags departures from them in a repo. New clause-join warning (a colon or semicolon stitching two clauses in short UI copy) and a trailing-"yet" note.
|
|
6
|
+
- **No hedged deletes.** `lint_copy` warns on "you can't restore it yourself" and similar: it tells the person someone else can. Say it can't be undone, or say who can restore it.
|
|
7
|
+
- **Tone rules 1.2:** calmer and less warm in worried moments and on success screens, checked against released apps.
|
|
8
|
+
|
|
9
|
+
## 1.0.7
|
|
10
|
+
|
|
11
|
+
- **Copy is not evidence for copy.** A claim backed only by cited lines where its words sit inside a message string (a toast, a `t`...`` call, the old copy being replaced) is now rejected as bad evidence: cite the code that sets the state. In a held-out test, "Refund of {amount} processed" passed on 1.0.6 because the agent cited the old "Refund processed successfully" toast while the refund could still be pending. Status literals in code (`status = 'refunded'`) still count.
|
|
12
|
+
|
|
13
|
+
## 1.0.6
|
|
14
|
+
|
|
15
|
+
From a held-out test on 11 new cases from five products.
|
|
16
|
+
|
|
17
|
+
- **"Processed", "issued", "completed" and "went through"** now get the started-is-not-finished warning on money claims, alongside "refunded", "charged" and "paid".
|
|
18
|
+
- **Keys stay put.** The instructions, `rules.md` and the skill say to keep string keys, ids and element names as given and change only the text. Agents had renamed `primary_cta` to `button`.
|
|
19
|
+
- **Soft deletes with no restore.** "Can't be undone" on a delete line whose file also soft-deletes is now a warning, not a failure: if the person can restore it, don't say it; if they can't, say it plainly. The skill says the same. 1.0.5 pushed agents into hedges like "you can't restore it yourself".
|
|
20
|
+
|
|
21
|
+
## 1.0.5
|
|
22
|
+
|
|
23
|
+
From the 1.0.4 rerun on the same 30 cases. Under Claude Code's default tool search every run loaded content-md, but only 7 of 30 called `read_product`, the tool that cuts missing facts. Three traps still got through.
|
|
24
|
+
|
|
25
|
+
- **`read_product` comes first.** The `init` pointer and the skill name it first. In a repo, `get_guide` opens with a reminder to call it until it has run.
|
|
26
|
+
- **Conditional sends.** "We've emailed you" backed by a send behind an `if`, a `catch` or a `&&` still passes, with a `conditional-claim` warning: say when it happens, or don't promise it.
|
|
27
|
+
- **Started is not finished.** "Refunded", "charged" or "paid" backed by code that mentions pending, request, processing, a queue or a webhook gets the same warning: say it has started unless the code shows it done.
|
|
28
|
+
- **Soft deletes elsewhere in the file.** "Can't be undone" no longer passes on a delete line when the same file has a trash, soft delete, `deletedAt`, `paranoid` or restore.
|
|
29
|
+
|
|
30
|
+
## 1.0.4
|
|
31
|
+
|
|
32
|
+
From a workflow eval: 30 cases across 10 open-source products, 270 runs. The product reader halved missing facts (18.6% to 9.6%). The old claim check flagged nothing in 83 calls. When a request contradicted the code, the agent found the code and still sided with the request about half the time.
|
|
33
|
+
|
|
34
|
+
- **The claim check reads the code.** `lint_copy` pulls every claim out of the copy: sent, emailed or notified; refunded or charged; deleted, in the trash, or can't be undone; restorable; timelines ("within 30 days", "5–10 business days", "instantly"); saved or published; who can see it. In a repo each claim needs `evidence: [{claim, where: "file:line"}]`. The cited lines are read: they must exist, sit inside the repo, and mention the claim's own words. A hard-delete function can't back "goes to Trash", and a line without "30" can't back "for 30 days". A claim with no evidence is blocked when it is about money, deletion, restore, timing or sending, and is a warning otherwise. Evidence of `"request"` is accepted but flagged: check the code, and if it disagrees, write from the code. Outside a repo, claims are listed as notes. Buttons and labels are not read as claims.
|
|
35
|
+
- **Already-good copy.** With `original`, a claim the rewrite adds that the original didn't make is flagged (`added-claim`). The instructions now say "no change" is a valid answer, and that a rewrite never adds a claim, promise or reassurance.
|
|
36
|
+
- **The request is a brief, not the truth.** The server instructions, `rules.md`, the Claude skill and the `init` pointer say: where the request and the code disagree, write from the code and tell the person what the request got wrong; where the code doesn't settle it, leave the claim out and ask. `read_product`'s `next` asks the agent to list the request's claims about the product and open the code for each.
|
|
37
|
+
- **Claude Code's default setup loads the tools.** `init --claude` adds a pointer to `CLAUDE.md` that names the tools and gives the tool-search query that loads them. The skill says the same. The README documents `ENABLE_TOOL_SEARCH=false`.
|
|
38
|
+
- The product reader (`read_product`) is unchanged apart from that one line.
|
|
39
|
+
|
|
40
|
+
## 1.0.3
|
|
41
|
+
|
|
42
|
+
Fixes from auditing a real 13,000-line monorepo with 1.0.2.
|
|
43
|
+
|
|
44
|
+
- audit_copy no longer reads JSX/TS code as copy. Text between tags that contains `&&`, `||`, `?.`, `.length`, a trailing `? (` or `null,`/`undefined,` is skipped.
|
|
45
|
+
- Tag text is read with a lookahead, so prose after an inline tag (`<br />`, `<strong>…</strong>`) is now checked. It used to be lost.
|
|
46
|
+
- 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.
|
|
47
|
+
- 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.
|
|
48
|
+
- `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.
|
|
49
|
+
- A "No X yet" headline gets one finding (`no-x-yet`), not that plus `absence-headline`.
|
|
50
|
+
- `remove` deletes a repo `.mcp.json` that held only content-md, instead of leaving `{"mcpServers": {}}`.
|
|
51
|
+
|
|
3
52
|
## 1.0.2
|
|
4
53
|
|
|
5
54
|
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/README.md
CHANGED
|
@@ -12,7 +12,7 @@ When your agent writes a button, an error, an empty state, a dialog or a notific
|
|
|
12
12
|
2. **Look up the pattern.** `get_guide` has playbooks for 35 interface patterns (error, empty state, paywall, confirmation dialog, push notification and so on) and an index of 194 pattern rules, with a 1 to 3 self-scoring rubric.
|
|
13
13
|
3. **Check the copy against what the product actually knows.** The writing rules include a state check. Before drafting, the agent lists what the system knows, what it does not know and who acts next. Copy must not claim more than that.
|
|
14
14
|
4. **Audit promises, only when needed.** If a draft claims something beyond the state (a cause, an outcome, a timeline), the agent removes or softens that claim. If nothing goes beyond the state, the audit is skipped, because always-on auditing made good lines worse.
|
|
15
|
-
5. **Lint the draft.** `lint_copy` is deterministic. It catches template leaks, raw error codes, filler, generic buttons, blame words, "Are you sure", a body that repeats its headline, casing and length. It also has checks for habits that models fall into: "No X yet" headlines, copy that narrates where things appear on screen, invented causes, two sentences of the same length, and rewrites that change a short label for no reason.
|
|
15
|
+
5. **Lint the draft, and back every claim.** `lint_copy` pulls every claim out of the copy: that something was sent, refunded or deleted, can be restored, takes N days, is saved, or is visible to someone. In a repo, each one needs a `file:line` in `evidence`. The tool reads those lines, and a claim they don't support is blocked. A claim backed only by the request is flagged, because a request can be wrong about the product. Pass `original` when rewriting, and any claim the original didn't make is flagged too. Beyond claims, `lint_copy` is deterministic. It catches template leaks, raw error codes, filler, generic buttons, blame words, "Are you sure", a body that repeats its headline, casing and length. It also has checks for habits that models fall into: "No X yet" headlines, copy that narrates where things appear on screen, invented causes, two sentences of the same length, and rewrites that change a short label for no reason.
|
|
16
16
|
6. **Look at shipped copy, as optional evidence.** `find_reference` and `find_examples` return lines shipped products used for the same situation. They help the agent settle a doubt. They are not the default way to write (see results below).
|
|
17
17
|
7. **Look up style-guide rules.** `find_rules` searches 413 rules from 16 public style guides, with do and don't examples.
|
|
18
18
|
|
|
@@ -59,12 +59,13 @@ What it does, and what it leaves alone:
|
|
|
59
59
|
- **Your repo's copy rules come first.** `init` looks for them (copy, voice, tone or glossary sections in `AGENTS.md` or `CLAUDE.md`, and files like `docs/glossary.md` or `content-style.md`) and names them in what it writes, so the agent reads them and follows them wherever content-md differs.
|
|
60
60
|
- **It only sets up tools the repo already uses.** With no flags it looks for `.cursor`, `.claude`, `CLAUDE.md`, `AGENTS.md`, `.vscode` and `.windsurfrules` in the repo. If it finds none, it writes nothing and tells you which flag to pass.
|
|
61
61
|
- **The product brief gets its own file.** `save_product_brief` writes `.content-md/product.md`, not your agent instructions.
|
|
62
|
+
- **Claude Code defers MCP tools by default.** It keeps them behind tool search, and an agent that doesn't know they exist never loads them. So `init --claude` also adds a pointer to `CLAUDE.md` that names the tools and how to load them. To load every MCP tool up front instead, start Claude Code with `ENABLE_TOOL_SEARCH=false`.
|
|
62
63
|
- **`npx content-md remove`** takes out everything `init` added. Add `--global` to clean the home-folder entries too.
|
|
63
64
|
|
|
64
65
|
| tool | MCP server registered in | rule installed in |
|
|
65
66
|
|---|---|---|
|
|
66
67
|
| Cursor | `.cursor/mcp.json` | `.cursor/rules/content-md.mdc` |
|
|
67
|
-
| Claude Code | `.mcp.json` | `.claude/skills/content-md/SKILL.md` |
|
|
68
|
+
| Claude Code | `.mcp.json` | `.claude/skills/content-md/SKILL.md`, and a pointer in `CLAUDE.md` |
|
|
68
69
|
| Codex | `~/.codex/config.toml` (with `--global`) | `AGENTS.md` (marked block) |
|
|
69
70
|
| VS Code (Copilot) | `.vscode/mcp.json` | `.github/copilot-instructions.md` (marked block) |
|
|
70
71
|
| Windsurf | `~/.codeium/windsurf/mcp_config.json` (with `--global`) | `.windsurfrules` (marked block) |
|
package/data/tone/decider.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "tone-decider-1.
|
|
2
|
+
"version": "tone-decider-1.2",
|
|
3
3
|
"method": "tone = clip(neutral + per-axis push / sqrt(features pushing it) + flex(stakes) * (voice - neutral), bands). Bands intersect across features; the tightest wins. Tone words are the pair from the label set, eligible in this context, whose blended vector sits closest to the result; wrong tones are label words that break a band; tempting tones are the nearest misfires.",
|
|
4
4
|
"axes": [
|
|
5
5
|
"formality",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"delta": {
|
|
48
48
|
"warmth": 0.5,
|
|
49
49
|
"seriousness": -0.5,
|
|
50
|
-
"energy": 0.
|
|
50
|
+
"energy": 0.25
|
|
51
51
|
},
|
|
52
52
|
"band": {},
|
|
53
|
-
"why": "something worked;
|
|
53
|
+
"why": "something worked; confirm it calmly, then move on"
|
|
54
54
|
},
|
|
55
55
|
"error": {
|
|
56
56
|
"delta": {
|
|
@@ -245,7 +245,6 @@
|
|
|
245
245
|
},
|
|
246
246
|
"user": {
|
|
247
247
|
"delta": {
|
|
248
|
-
"warmth": 0.5,
|
|
249
248
|
"agency": 0.5
|
|
250
249
|
},
|
|
251
250
|
"band": {
|
|
@@ -324,7 +323,7 @@
|
|
|
324
323
|
"exploring": {
|
|
325
324
|
"delta": {
|
|
326
325
|
"warmth": 0.5,
|
|
327
|
-
"energy": 0.
|
|
326
|
+
"energy": 0.25,
|
|
328
327
|
"agency": 0.5
|
|
329
328
|
},
|
|
330
329
|
"band": {}
|
|
@@ -353,7 +352,7 @@
|
|
|
353
352
|
},
|
|
354
353
|
"hesitant": {
|
|
355
354
|
"delta": {
|
|
356
|
-
"warmth": 0.
|
|
355
|
+
"warmth": 0.25,
|
|
357
356
|
"agency": 1,
|
|
358
357
|
"energy": -0.5
|
|
359
358
|
},
|
|
@@ -367,7 +366,6 @@
|
|
|
367
366
|
},
|
|
368
367
|
"worried": {
|
|
369
368
|
"delta": {
|
|
370
|
-
"warmth": 0.5,
|
|
371
369
|
"confidence": 0.5,
|
|
372
370
|
"seriousness": 0.5,
|
|
373
371
|
"energy": -1
|
|
@@ -382,7 +380,7 @@
|
|
|
382
380
|
0
|
|
383
381
|
]
|
|
384
382
|
},
|
|
385
|
-
"why": "calm and specific lowers worry; jokes
|
|
383
|
+
"why": "calm and specific lowers worry; warmth words and jokes read as padding"
|
|
386
384
|
},
|
|
387
385
|
"frustrated": {
|
|
388
386
|
"delta": {
|
|
@@ -408,8 +406,7 @@
|
|
|
408
406
|
},
|
|
409
407
|
"stuck": {
|
|
410
408
|
"delta": {
|
|
411
|
-
"directness": 1
|
|
412
|
-
"warmth": 0.5
|
|
409
|
+
"directness": 1
|
|
413
410
|
},
|
|
414
411
|
"band": {
|
|
415
412
|
"seriousness": [
|
|
@@ -422,7 +419,7 @@
|
|
|
422
419
|
"accomplished": {
|
|
423
420
|
"delta": {
|
|
424
421
|
"warmth": 0.5,
|
|
425
|
-
"energy":
|
|
422
|
+
"energy": 0.75,
|
|
426
423
|
"seriousness": -0.5
|
|
427
424
|
},
|
|
428
425
|
"band": {}
|
|
@@ -481,7 +478,6 @@
|
|
|
481
478
|
},
|
|
482
479
|
"anxious": {
|
|
483
480
|
"delta": {
|
|
484
|
-
"warmth": 0.5,
|
|
485
481
|
"confidence": 0.25,
|
|
486
482
|
"energy": -0.5
|
|
487
483
|
},
|
|
@@ -546,7 +542,7 @@
|
|
|
546
542
|
"journey_stage": {
|
|
547
543
|
"discover": {
|
|
548
544
|
"delta": {
|
|
549
|
-
"energy": 0.
|
|
545
|
+
"energy": 0.25,
|
|
550
546
|
"formality": -0.5
|
|
551
547
|
},
|
|
552
548
|
"band": {}
|
|
@@ -690,7 +686,7 @@
|
|
|
690
686
|
},
|
|
691
687
|
"milestone": {
|
|
692
688
|
"delta": {
|
|
693
|
-
"energy":
|
|
689
|
+
"energy": 0.75,
|
|
694
690
|
"warmth": 0.5,
|
|
695
691
|
"seriousness": -0.5
|
|
696
692
|
},
|
package/guide/SKILL.md
CHANGED
|
@@ -7,6 +7,8 @@ description: Write, review or rewrite product microcopy (buttons, errors, empty
|
|
|
7
7
|
|
|
8
8
|
These rules come from a labeled set of shipped interface copy. Each piece was labeled for pattern, element, intent, tone and a 1 to 3 quality score. Every rule below is backed by examples that scored 3, and every "not this" by examples that scored 1. They were then checked against 16 public style guides (Apple HIG, Atlassian, Baymard, Carbon, GOV.UK Design System, GOV.UK Service Manual, Microsoft HAX, Intuit, Mailchimp, Material, Microsoft Writing Style Guide, Microsoft Windows guidelines, NN/g, Google PAIR, Polaris, Salesforce). Where a guide adds something screenshots can't show, it's cited in [brackets].
|
|
9
9
|
|
|
10
|
+
If the `content-md` MCP tools aren't loaded (Claude Code defers MCP tools behind tool search), load them first with tool search: `select:mcp__content-md__read_product,mcp__content-md__get_guide,mcp__content-md__decide_tone,mcp__content-md__lint_copy,mcp__content-md__audit_copy`. In a codebase, call `read_product` before anything else.
|
|
11
|
+
|
|
10
12
|
**The repo's own copy rules, glossary and voice guide come first.** Look for them in AGENTS.md, CLAUDE.md and the docs before you write, and follow them wherever they differ from anything below. Reuse the product's own words for its own things, even where a rule here would pick another.
|
|
11
13
|
|
|
12
14
|
## How to work
|
|
@@ -16,7 +18,8 @@ These rules come from a labeled set of shipped interface copy. Each piece was la
|
|
|
16
18
|
3. **Write the button first.** It is the decision. The headline and body exist to make the button obvious.
|
|
17
19
|
4. **Check against the universal rules, then the pattern's playbook.**
|
|
18
20
|
**Use only the facts you were given.** Never invent prices, plans, discounts, counts, features, timings or behavior. If a line would help but needs a fact you don't have, leave it out of the copy and suggest it after, as a note ("If the link is public, add..."). Placeholders like [X]% inside the copy count as inventing.
|
|
19
|
-
**Keep what already works.** When rewriting, change only what breaks a rule. Don't rewrite a clear line for style.
|
|
21
|
+
**Keep what already works.** When rewriting, change only what breaks a rule. Don't rewrite a clear line for style. "No change" is a valid answer, and a rewrite never adds a claim the original didn't make. Keep string keys and element names as given; change only the text.
|
|
22
|
+
**The code beats the request.** If the request says something about the product that the code contradicts, write from the code and say what the request got wrong. Back every claim (sent, refunded, deleted, restorable, takes N days) with a file and line; pass them to `lint_copy` as `evidence`.
|
|
20
23
|
5. **When reviewing,** quote the original, name the rule it breaks, and give the rewrite. When writing from scratch, give 2 or 3 options with a one-line reason each, and recommend one.
|
|
21
24
|
6. If the project's shared folder has example copy, use it as evidence for the case at hand, and cite the product when you quote one.
|
|
22
25
|
|
|
@@ -101,7 +104,7 @@ Headline is the action as a question ("Delete event?"). Body says what is lost o
|
|
|
101
104
|
Offer the alternative first if one exists, then list what's lost in concrete nouns, then add friction that matches the stakes.
|
|
102
105
|
- Do: "Downgrade to free instead" (Dovetail). "Any Railcards you've bought" + "We can't get them back." (Trainline). Flag billing traps: "your subscription will stay active". For workspaces: typed confirmation ("Type DELETE WORKSPACE to confirm."), a first-person checkbox, and a button that names the workspace.
|
|
103
106
|
- Pause instead of delete: name the alternative ("How about a pause instead?", Hinge), say what is hidden and what still works ("You can still chat with your current matches."), and head off surprises: time limits, billing ("Your subscription won't be paused automatically..."), and the timeline to permanent deletion.
|
|
104
|
-
- Word choice: "Delete" destroys, "Remove" takes something out of a context, "Move to trash" when it's recoverable [Carbon]. Say "permanently" when it can't be undone [Microsoft, GOV.UK].
|
|
107
|
+
- Word choice: "Delete" destroys, "Remove" takes something out of a context, "Move to trash" when it's recoverable [Carbon]. Say "permanently" when it can't be undone [Microsoft, GOV.UK]. A soft delete the person has no way to restore is gone for them: say plainly that it can't be undone, not "you can't restore it yourself". Say it can be restored only if there is a restore the person can reach.
|
|
105
108
|
- Give a restore deadline when one exists ("This project can be restored until 2024-09-24", GitLab). When leaving a team, say what happens to the user's work ("Everything you have created will remain accessible to the rest of the team.", Todoist).
|
|
106
109
|
- Not this: a vague "All your data will be deleted" with no list. Jokes ("Danger, Will Robinson!").
|
|
107
110
|
|
package/guide/rules.md
CHANGED
|
@@ -12,10 +12,10 @@ Write from the rules, the tone decision and the matching pattern rules. They car
|
|
|
12
12
|
3. Write every piece the screen needs. Do not drop the headline or a button.
|
|
13
13
|
4. Optional: when you want evidence for a decision, or when copy describes progress or an outcome, call `find_reference` with its `role` (or `element`), the situation in a short clause that says what the line does for the person, and the `brief` of the moment. Pass the old line as `draft` when rewriting, and pass `state` (what the product's tool or API reports about the item) whenever copy describes progress or an outcome: it returns a correction example when the copy could claim more than that state supports. It returns up to 3 pairs (the brief a screen was built for, and the line it got), one weak counter-example and the tones to avoid, ready to read in its `xml` field. It often returns nothing: when no pair clears its quality floor, write from the rules and `decide_tone`, and do not hunt for a weaker one.
|
|
14
14
|
5. If you used references, write a short `<pattern_notes>` before the copy: what the pairs share (structure, word count, what each part carries) and what the counter-example gets wrong. Then write from the pattern and the rules. References come from other products, so don't lift their wording or a claim you can't back; the product's own words and glossary are a different matter, and you should reuse them. List what you BORROWED (structure, order, length) and what you CHANGED (facts, words, tone). Use `compare_to_reference` only if you chose to follow a reference's shape.
|
|
15
|
-
6. State-check before you write: name the screen state (empty, loading, error, success, blocked, partial, first time, returning) and the one thing the person must be able to do next. Copy for the wrong state is wrong however well it reads.
|
|
15
|
+
6. State-check before you write: name the screen state (empty, loading, error, success, blocked, partial, first time, returning) and the one thing the person must be able to do next. Copy for the wrong state is wrong however well it reads. Take the state from the code, not from the request. The request is a brief, not the truth: when it says something about the product that the code contradicts (a trash that doesn't exist, a refund timeline, an email that isn't sent), the code wins. Write from the code and tell the person what the request got wrong. When the code doesn't settle it, leave the claim out and ask.
|
|
16
16
|
7. Promise audit, only when the copy describes progress, money, time or an outcome AND a claim in the draft goes beyond what the tool state says (if every claim is already stated, skip this step and leave the copy untouched): list every claim and promise in the draft and tag each as STATED (the tool state says it), IMPLIED (follows directly from it) or INVENTED (a time, step, reassurance or consequence the state does not give). Remove or hedge what is invented; leave every line that passes exactly as it is. Keep a reassurance the state supports ("your money is safe" when the state shows funds held), don't drop a specific the person needs (amounts, times, counts), and prefer a hedge to a deletion when part of a line is supported. Don't make the copy vaguer than the state allows. Also cut these tics: a reason or cause the facts do not give, a line that describes the screen ('shown when...') instead of the situation, a hint at an outcome nobody knows yet, and a hedge that adds no information.
|
|
17
17
|
7b. In a codebase, for explanatory, help, policy or onboarding copy, back every promise or factual claim about how the product works (a time, a rule, a feature, what happens to someone's data or report) with a file and line in the repo or its data. Drop or soften any claim you can't back, and list what you dropped. A page that describes a feature the data doesn't have is worse than a shorter page.
|
|
18
|
-
8. Run `lint_copy` on the draft; fix every `block` and `warn` or say why you kept it. Score each string 1 to 3 (see `get_guide`) and return nothing below 2.
|
|
18
|
+
8. Run `lint_copy` on the draft, with `original` when rewriting; fix every `block` and `warn` or say why you kept it. It lists every claim the copy makes (sent, refunded, deleted, restorable, takes N days, saved, visible to). In a codebase, pass `evidence` with the file:line that backs each one: the tool reads those lines. Cut any claim you can't back. Score each string 1 to 3 (see `get_guide`) and return nothing below 2.
|
|
19
19
|
|
|
20
20
|
Defaults, which also apply when the tools aren't available. They are defaults, not laws: break one when the moment calls for it and say why.
|
|
21
21
|
- Buttons are verb + object and match the headline's noun ("Delete event", not "OK"). Both buttons in a pair name their outcome.
|
|
@@ -30,4 +30,4 @@ Defaults, which also apply when the tools aren't available. They are defaults, n
|
|
|
30
30
|
- Sentence case. "You" for the person, "we" when the product takes responsibility.
|
|
31
31
|
- Avoid confirmshaming, hidden prices and fake urgency. Money copy states the amount, when it's charged, whether it recurs, and how to cancel.
|
|
32
32
|
- Never invent a source, person, outlet, date, case number or figure to use as an example. Use a real one from the repo's own data, or an obvious placeholder like "[Outlet] reported on [date]". A made-up citation with a real outlet's name reads as fact once it is screenshotted.
|
|
33
|
-
- When rewriting, keep the labels, buttons and titles that already work, word for word. Change a line only for a reason you can state (it is wrong for the state, unclear, or misses a fact).
|
|
33
|
+
- When rewriting, keep the labels, buttons and titles that already work, word for word. Change a line only for a reason you can state (it is wrong for the state, unclear, or misses a fact). When asked to tighten or review copy that already works, "no change" is a valid answer. Never add a claim, promise or reassurance the original didn't make. Keep string keys, ids and element names exactly as given (primary_cta stays primary_cta); change only the text.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "content-md",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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/claims.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Claim check, rebuilt for 1.0.4. The old check compared copy with a state the agent wrote itself, so a false
|
|
2
|
+
// brief passed straight through. This one pulls every claim out of the draft and asks for the file and line in the
|
|
3
|
+
// code that backs it. A cited line is read: it must exist and mention what the claim is about.
|
|
4
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
5
|
+
import { join, isAbsolute, resolve, sep } from "node:path";
|
|
6
|
+
|
|
7
|
+
// What a line of interface copy can promise. Each kind names the words that make the promise and the words a
|
|
8
|
+
// backing line in the code is likely to contain.
|
|
9
|
+
const KINDS = [
|
|
10
|
+
["sent", /\b(sent|emailed|texted|notified|messaged|forwarded|we('ve| have) (sent|emailed|let)|(we'll|we will|you'll|you will) (send|email|text|notify|let you know|get|receive|hear)|(check|look in) your (inbox|email))\b/gi, /send|mail|notif|sms|message|deliver|queue|job|webhook/i],
|
|
11
|
+
["money", /\b(refund(ed|ing|s)?|charged?|charging|billed|billing|paid|payment (went through|failed|is processing)|deducted|credited|reimburs\w+|free trial|cancel(led)? (your|the) (plan|subscription))\b/gi, /refund|charge|bill|pay|invoice|stripe|amount|price|credit|subscription|trial/i],
|
|
12
|
+
["deletion", /\b(deleted|removed|erased|wiped|purged|permanently|forever|can('t|not)( be)? (be )?undo(ne)?|cannot be undone|can't be reversed|for good|(goes|go|moved?) to (the )?(trash|bin|archive)|in (the )?(trash|bin))\b/gi, /delete|destroy|remove|purge|trash|bin|archive|soft|restore|undo|paranoid|deleted_at|discard/i],
|
|
13
|
+
["restore", /\b(restore[ds]?|recover(ed|able)?|undo|bring (it|them) back|get (it|them) back|retriev\w+)\b/gi, /restore|recover|undo|trash|deleted_at|soft|revert|retriev/i],
|
|
14
|
+
["timing", /\b(within|in|after|for|up to|takes?|about|around)\s+(\d+|a|an|one|two|three|five|seven|ten|thirty|24|48|72)([-–]\d+)?\s+(seconds?|minutes?|mins?|hours?|hrs?|days?|business days|working days|weeks?|months?)\b|\b(instantly|immediately|right away|by tomorrow|tonight|today|overnight|in real time|real-time)\b/gi, /\d|time|delay|ttl|expire|interval|cron|schedule|duration|days?|hours?|minutes?|seconds?|ms\b|timeout/i],
|
|
15
|
+
["status", /\b(approved|accepted|rejected|declined|delivered|published|is live|went live|verified|confirmed|booked|reserved|synced|backed up|saved|uploaded|imported|exported|completed?|finished|ready|processing|pending|in progress|queued|scheduled|cancel(l)?ed|expired|joined|shared)\b/gi, /status|state|approve|accept|reject|deliver|publish|verif|confirm|book|reserv|sync|backup|save|upload|import|export|complete|ready|process|pend|queue|schedul|cancel|expir|join|share/i],
|
|
16
|
+
["access", /\b(only you|anyone with the link|visible to|can see|can('t| not) see|private|public|encrypted|end-to-end|secure)\b/gi, /visib|private|public|permission|role|access|share|encrypt|auth|policy|scope/i],
|
|
17
|
+
["absolute", /\b(always|never|guarantee[ds]?|every time|all of your|nothing is lost|no data is lost)\b/gi, /./],
|
|
18
|
+
];
|
|
19
|
+
// Buttons and labels name actions; they do not promise outcomes.
|
|
20
|
+
const ACTION_ELEMENTS = new Set(["primary-cta", "secondary-cta", "tertiary-link", "label", "badge", "title-bar", "placeholder", "tab"]);
|
|
21
|
+
const STOP = new Set("this that with your from will have been they them their there what when were would could should about into after before only also just more most other some than then these those very which while where here".split(" "));
|
|
22
|
+
|
|
23
|
+
export function extractClaims(units = []) {
|
|
24
|
+
const out = [];
|
|
25
|
+
units.forEach((u, i) => {
|
|
26
|
+
if (ACTION_ELEMENTS.has(u.element)) return;
|
|
27
|
+
const t = u.text || "";
|
|
28
|
+
for (const [kind, re] of KINDS) {
|
|
29
|
+
const g = new RegExp(re.source, "gi"); let m;
|
|
30
|
+
while ((m = g.exec(t))) {
|
|
31
|
+
// the claim is the sentence around the matched words, so evidence can be matched on either
|
|
32
|
+
const start = Math.max(0, t.lastIndexOf(".", m.index) + 1), endDot = t.indexOf(".", m.index + m[0].length);
|
|
33
|
+
const sentence = t.slice(start, endDot < 0 ? t.length : endDot + 1).trim();
|
|
34
|
+
if (!out.some((c) => c.unit === i && c.kind === kind && c.words.toLowerCase() === m[0].toLowerCase())) out.push({ unit: i, kind, words: m[0], sentence });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const keywords = (s) => [...new Set((s.toLowerCase().match(/[a-z]{4,}|\d+/g) || []).filter((w) => !STOP.has(w)))];
|
|
42
|
+
const stem = (w) => (/^\d+$/.test(w) ? w : w.slice(0, Math.min(5, w.length)));
|
|
43
|
+
|
|
44
|
+
// "src/billing/refund.ts:42" or "src/billing/refund.ts:40-48"
|
|
45
|
+
function readCited(root, where) {
|
|
46
|
+
const m = String(where).trim().match(/^(.+?):(\d+)(?:-(\d+))?$/);
|
|
47
|
+
if (!m) return { error: "not a file:line reference" };
|
|
48
|
+
const abs = isAbsolute(m[1]) ? m[1] : resolve(root, m[1]);
|
|
49
|
+
if (!(abs === root || abs.startsWith(root + sep))) return { error: "outside this repo" };
|
|
50
|
+
if (!existsSync(abs)) return { error: "no such file" };
|
|
51
|
+
try { if (statSync(abs).size > 2_000_000) return { lines: null }; } catch { return { error: "unreadable" }; }
|
|
52
|
+
const lines = readFileSync(abs, "utf8").split("\n");
|
|
53
|
+
const a = +m[2], b = +(m[3] || m[2]);
|
|
54
|
+
if (a < 1 || a > lines.length) return { error: `line ${a} is past the end of the file (${lines.length} lines)` };
|
|
55
|
+
return { text: lines.slice(Math.max(0, a - 6), Math.min(lines.length, b + 5)).join("\n").toLowerCase(), file: lines.join("\n").toLowerCase(), exact: lines.slice(a - 1, b).join("\n").toLowerCase() };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Every claim needs evidence: [{ claim, where }]. `where` is file:line in the repo; "request" marks a claim taken
|
|
59
|
+
// from the request alone, which is allowed but flagged, because a request can be wrong about the product.
|
|
60
|
+
export function checkClaims({ units, evidence, stakes, original, root = process.cwd() }) {
|
|
61
|
+
const claims = extractClaims(units);
|
|
62
|
+
const findings = [];
|
|
63
|
+
const add = (unit, severity, rule, detail) => findings.push({ unit, severity, rule, detail });
|
|
64
|
+
const ev = (evidence || []).map((e) => ({ claim: String(e.claim || "").toLowerCase().trim(), where: String(e.where || "").trim() }));
|
|
65
|
+
const matches = (c, e) => e.claim && (c.sentence.toLowerCase().includes(e.claim) || e.claim.includes(c.words.toLowerCase()) || e.claim.includes(c.sentence.toLowerCase().replace(/[.!?]$/, "")));
|
|
66
|
+
const serious = (k) => ["money", "deletion", "restore", "timing", "sent"].includes(k);
|
|
67
|
+
const status = claims.map((c) => {
|
|
68
|
+
const hits = ev.filter((e) => matches(c, e));
|
|
69
|
+
if (!hits.length) {
|
|
70
|
+
add(c.unit, stakes === "high" || serious(c.kind) ? "block" : "warn", "unbacked-claim",
|
|
71
|
+
`'${c.words}' (${c.kind}) has no evidence. Find the code that does this and pass it in evidence as {claim, where: "file:line"}; if the code doesn't do it, cut the claim. A request saying so is not evidence.`);
|
|
72
|
+
return { ...c, backed: false };
|
|
73
|
+
}
|
|
74
|
+
const results = hits.map((e) => {
|
|
75
|
+
if (/^(request|brief|ticket|user|person)$/i.test(e.where)) return { where: e.where, ok: "request" };
|
|
76
|
+
const r = readCited(root, e.where);
|
|
77
|
+
if (r.error) return { where: e.where, ok: false, why: r.error };
|
|
78
|
+
if (r.text === undefined || r.text === null) return { where: e.where, ok: true };
|
|
79
|
+
const pattern = KINDS.find(([k]) => k === c.kind)[2];
|
|
80
|
+
// match on the claim's own words ("go to Trash", "for 30 days"), not the whole sentence, so a hard-delete
|
|
81
|
+
// function can't back a promise of a trash, and a line without the number can't back a timeline
|
|
82
|
+
let kw = keywords(c.words).map(stem);
|
|
83
|
+
if (!kw.length) kw = keywords(c.sentence).map(stem);
|
|
84
|
+
const permanence = /undo|undone|permanent|forever|for good|revers/i.test(c.words);
|
|
85
|
+
const SOFT = /trash|soft[-_ ]?delete|deleted_?at|paranoid|restore|recycle|bin\b/;
|
|
86
|
+
const says = (t) => permanence
|
|
87
|
+
? /delete|destroy|purge|drop|truncate|unlink|remove/.test(t) && !SOFT.test(t)
|
|
88
|
+
: pattern.test(t) && (c.kind === "absolute" || kw.some((w) => t.includes(w)));
|
|
89
|
+
if (!says(r.text)) return { where: e.where, ok: false, why: "the cited lines don't mention what the claim is about" };
|
|
90
|
+
// copy citing copy: if the claim's words only appear inside prose strings (a toast, a t`...` call, the old
|
|
91
|
+
// message), the lines show what the screen says, not what the product does
|
|
92
|
+
const prose = /(["'`])((?:\\.|(?!\1).)*\s(?:\\.|(?!\1).)*)\1/g;
|
|
93
|
+
const exact = r.exact || "";
|
|
94
|
+
if (exact.match(prose)?.some((q) => says(q)) && !says(exact.replace(prose, '""'))) return { where: e.where, ok: false, why: "the cited lines are interface copy (a message string), not the code that does it. The old copy is not evidence: cite the code that sets the state" };
|
|
95
|
+
// the code does it, but maybe not every time: a send behind an if, a refund that is only requested
|
|
96
|
+
let caveat;
|
|
97
|
+
if (permanence && SOFT.test(r.file || "")) caveat = `the same file also has '${(r.file.match(SOFT) || [])[0]}'. If the person can restore it, don't say it can't be undone. If they have no restore, keep the claim and say it plainly, without hedging`;
|
|
98
|
+
if (c.kind === "sent" && /\bif\s*\(|\bcatch\b|\bunless\b|&&|\?\s*[\w(]/.test(r.text)) caveat = "the cited send sits behind a condition or can fail. Say when it happens (\"if you gave an email\") or don't promise it";
|
|
99
|
+
if (c.kind === "money" && /(refunded|charged|paid|credited|processed|issued|completed|went through)/i.test(c.sentence) && /pending|request|requires_action|processing|async|queue|webhook|status/.test(r.text)) caveat = "the cited code may only start this, not finish it. Say it has started (\"refund requested\") unless the code shows it done";
|
|
100
|
+
return { where: e.where, ok: true, caveat };
|
|
101
|
+
});
|
|
102
|
+
const good = results.find((r) => r.ok === true && !r.caveat) || results.find((r) => r.ok === true);
|
|
103
|
+
if (good) {
|
|
104
|
+
if (good.caveat) add(c.unit, "warn", "conditional-claim", `'${c.words}': ${good.caveat} (${good.where}).`);
|
|
105
|
+
return { ...c, backed: true, where: good.where };
|
|
106
|
+
}
|
|
107
|
+
if (results.some((r) => r.ok === "request")) {
|
|
108
|
+
add(c.unit, serious(c.kind) ? "warn" : "note", "request-only-claim",
|
|
109
|
+
`'${c.words}' is backed only by the request. Check the code: if it disagrees, write from the code and tell the person what the request got wrong.`);
|
|
110
|
+
return { ...c, backed: "request" };
|
|
111
|
+
}
|
|
112
|
+
add(c.unit, "block", "bad-evidence", `evidence for '${c.words}' doesn't hold: ${results.map((r) => `${r.where} (${r.why})`).join("; ")}`);
|
|
113
|
+
return { ...c, backed: false };
|
|
114
|
+
});
|
|
115
|
+
// already-good copy: a rewrite must not promise more than the original did
|
|
116
|
+
if (Array.isArray(original) && original.length) {
|
|
117
|
+
const before = extractClaims(original);
|
|
118
|
+
const had = (c) => before.some((b) => b.kind === c.kind && (b.words.toLowerCase() === c.words.toLowerCase() || keywords(b.sentence).some((w) => keywords(c.sentence).includes(w) && w.length > 4)));
|
|
119
|
+
for (const c of claims) if (!had(c)) add(c.unit, "warn", "added-claim", `'${c.words}' is a new ${c.kind} claim the original didn't make. Drop it unless the code backs it; "no change" is a valid answer for copy that already works.`);
|
|
120
|
+
}
|
|
121
|
+
return { claims: status.map(({ unit, kind, words, backed, where }) => ({ unit, kind, words, backed, ...(where ? { where } : {}) })), findings };
|
|
122
|
+
}
|
package/src/init.js
CHANGED
|
@@ -37,7 +37,9 @@ export function pointer(repoRules = []) {
|
|
|
37
37
|
: "If this repo gains its own copy rules, glossary or voice guide, they come first. Where content-md disagrees with them, follow the repo.";
|
|
38
38
|
return `## Interface copy (content-md)
|
|
39
39
|
|
|
40
|
-
When you write or review user-facing copy (buttons, errors, empty states, dialogs, onboarding, notifications), use the \`content-md\` MCP tools
|
|
40
|
+
When you write or review user-facing copy (buttons, errors, empty states, dialogs, onboarding, notifications), use the \`content-md\` MCP tools. Start with \`read_product\` (once per session, before anything else: it is what keeps facts in the copy, and its \`position\` gives this product's own habits for contractions, full stops, case and length; follow them), then \`get_guide\` for the pattern, \`decide_tone\` when the moment has stakes, and \`lint_copy\` on every draft. Reuse the product's own words.
|
|
41
|
+
When the request says something about the product that the code contradicts, write from the code and say so. Back every claim (sent, refunded, deleted, restorable, takes N days) with a file and line, and pass it to \`lint_copy\` as evidence. "No change" is a valid answer for copy that already works.
|
|
42
|
+
If the content-md tools aren't loaded (Claude Code defers MCP tools behind tool search), load them first: search for \`select:mcp__content-md__read_product,mcp__content-md__get_guide,mcp__content-md__decide_tone,mcp__content-md__lint_copy,mcp__content-md__audit_copy\`.
|
|
41
43
|
${theirs} Lint findings are prompts to look, not verdicts.`;
|
|
42
44
|
}
|
|
43
45
|
|
|
@@ -102,6 +104,8 @@ export function init(argv, cwd = process.cwd()) {
|
|
|
102
104
|
: "6. Use the `content-md` MCP tools: `get_guide` for the pattern's playbook, `find_rules` for style-guide rules, and `lint_copy` on every draft.");
|
|
103
105
|
if (repoRules.length) skill = skill.replace(/^(---[\s\S]*?---\n)/, `$1\nThis repo's own copy rules come first (${repoRules.map((r) => "`" + r.file + "`").join(", ")}). Follow them wherever they differ from this skill.\n`);
|
|
104
106
|
write(join(cwd, ".claude", "skills", "content-md", "SKILL.md"), skill);
|
|
107
|
+
// Claude Code defers MCP tools by default, so the agent needs a standing note that they exist and how to load them
|
|
108
|
+
upsertBlock(join(cwd, "CLAUDE.md"), shared);
|
|
105
109
|
}
|
|
106
110
|
if (t === "codex") {
|
|
107
111
|
const cfg = join(process.env.CODEX_HOME || join(homedir(), ".codex"), "config.toml");
|
|
@@ -153,7 +157,12 @@ export function remove(argv, cwd = process.cwd()) {
|
|
|
153
157
|
if (global) jsonFiles.push([join(homedir(), ".codeium", "windsurf", "mcp_config.json"), "mcpServers"]);
|
|
154
158
|
for (const [p, key] of jsonFiles) {
|
|
155
159
|
if (!existsSync(p)) continue;
|
|
156
|
-
try { const j = JSON.parse(readFileSync(p, "utf8")); if (j[key]?.["content-md"]) {
|
|
160
|
+
try { const j = JSON.parse(readFileSync(p, "utf8")); if (j[key]?.["content-md"]) {
|
|
161
|
+
delete j[key]["content-md"];
|
|
162
|
+
// a repo file that held only our server is removed, not left behind as {"mcpServers": {}}
|
|
163
|
+
const empty = !Object.keys(j[key]).length && Object.keys(j).length === 1 && p.startsWith(cwd);
|
|
164
|
+
if (empty) { if (!dry) rmSync(p, { force: true }); done.push(show(p)); } else save(p, JSON.stringify(j, null, 2) + "\n");
|
|
165
|
+
} } catch { /* leave invalid JSON alone */ }
|
|
157
166
|
}
|
|
158
167
|
for (const p of [join(cwd, ".cursor", "rules", "content-md.mdc"), join(cwd, ".claude", "skills", "content-md")]) {
|
|
159
168
|
if (existsSync(p)) { if (!dry) rmSync(p, { recursive: true, force: true }); done.push(show(p)); }
|
package/src/position.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Product position: the product's own style habits, read from its shipped strings and returned as verdicts.
|
|
2
|
+
// Measured 2026-11-25 on six held-out repos: following these habits raised style agreement with the real strings,
|
|
3
|
+
// mostly by fixing contractions ("can't" in a product that writes "cannot"). The agent sees verdicts, never rates.
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { collectStrings } from "./product.js";
|
|
6
|
+
|
|
7
|
+
const EMOJI = /[\u{1F300}-\u{1FAFF}\u{2600}-\u{27BF}]/u;
|
|
8
|
+
const ap = (t) => String(t || "").replace(/[‘’]/g, "'");
|
|
9
|
+
export const FEATURES = {
|
|
10
|
+
contraction: { label: "contractions (can't, you're)", test: (t) => /\b\w+(n't|'re|'ll|'ve|'m|'d)\b|\b(it|that|there|let|what|here)'s\b/i.test(ap(t)), lint: "warn" },
|
|
11
|
+
full_stop: { label: "a final full stop", test: (t) => /\.\s*$/.test(t.trim()) && !/\.\.\.\s*$/.test(t.trim()), lint: "warn" },
|
|
12
|
+
you: { label: "\"you\"/\"your\"", test: (t) => /\b(you|your|you're|you'll|you've|yours)\b/i.test(ap(t)), lint: "note" },
|
|
13
|
+
we: { label: "\"we\"/\"our\"", test: (t) => /\b(we|we're|we've|we'll|our|us)\b/i.test(ap(t)), lint: "note" },
|
|
14
|
+
exclaim: { label: "an exclamation mark", test: (t) => /[A-Za-z0-9)]!+(\s|$|["'”])/.test(t), lint: "note" },
|
|
15
|
+
please: { label: "\"please\"", test: (t) => /\bplease\b/i.test(t), lint: "note" },
|
|
16
|
+
emoji: { label: "an emoji", test: (t) => EMOJI.test(t), lint: "note" },
|
|
17
|
+
};
|
|
18
|
+
const SHORT = new Set(["headline", "primary-cta", "secondary-cta", "tertiary-link", "label", "badge", "title-bar"]);
|
|
19
|
+
const words = (t) => t.trim().split(/\s+/).filter(Boolean).length;
|
|
20
|
+
export const groupOf = (element, text) => (element && element !== "label" && element !== "body" ? (SHORT.has(element) ? "short" : "sentence")
|
|
21
|
+
: words(text) <= 6 && !/\.$/.test(text.trim()) ? "short" : "sentence");
|
|
22
|
+
const titleWords = (t) => t.replace(/[^A-Za-z' ]/g, " ").split(/\s+/).filter(Boolean).slice(1).filter((w) => w.length > 3 && !/'/.test(w));
|
|
23
|
+
export const isTitleCase = (t) => { const w = titleWords(t); return w.length ? w.every((x) => /^[A-Z]/.test(x)) : null; };
|
|
24
|
+
const pct = (a, q) => { const s = [...a].sort((x, y) => x - y); return s[Math.min(s.length - 1, Math.floor(q * s.length))]; };
|
|
25
|
+
|
|
26
|
+
function habit(pool, test, label, what) {
|
|
27
|
+
const hits = pool.filter((s) => test(s.text));
|
|
28
|
+
const n = pool.length, k = hits.length;
|
|
29
|
+
const ex = (h) => h.slice(0, 2).map((s) => (s.file ? `${s.file}:${s.line} ` : "") + `"${s.text.slice(0, 70)}"`);
|
|
30
|
+
if (k >= 3 && k / n >= 0.25) return { call: "use", why: `This product uses ${label} in ${k} of its ${n} ${what}. Follow it.`, examples: ex(hits) };
|
|
31
|
+
if (n >= 8 && k === 0) return { call: "avoid", why: `This product never uses ${label} in its ${n} ${what}. Follow it.` };
|
|
32
|
+
if (n >= 20 && k / n < 0.05) return { call: "avoid", why: `This product rarely uses ${label} (${k} of its ${n} ${what}). Follow it.`, examples: ex(hits) };
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// strings: the product's own [{text, element, file, line}]. Returns only the habits it can see.
|
|
37
|
+
export function productPosition(strings) {
|
|
38
|
+
const all = (strings || []).filter((s) => s.text && s.text.length < 400);
|
|
39
|
+
const out = {};
|
|
40
|
+
for (const group of ["short", "sentence"]) {
|
|
41
|
+
const pool = all.filter((s) => groupOf(s.element, s.text) === group);
|
|
42
|
+
const what = group === "short" ? "short strings (buttons, headlines, labels)" : "sentences (bodies, errors, toasts, helper text)";
|
|
43
|
+
const v = {};
|
|
44
|
+
for (const [name, f] of Object.entries(FEATURES)) {
|
|
45
|
+
if (group === "short" && (name === "contraction" || name === "please")) continue; // too few words to show a habit
|
|
46
|
+
const sentencePool = group === "sentence" && name === "contraction" ? pool.filter((s) => words(s.text) >= 5) : pool;
|
|
47
|
+
const h = habit(sentencePool, f.test, f.label, what);
|
|
48
|
+
if (h) v[name] = h;
|
|
49
|
+
}
|
|
50
|
+
const cased = pool.map((s) => isTitleCase(s.text)).filter((x) => x !== null);
|
|
51
|
+
const tc = cased.filter(Boolean).length;
|
|
52
|
+
if (cased.length >= 10 && tc / cased.length >= 0.6) v.case = { call: "Title Case", why: `This product writes its ${what} in Title Case (${tc} of ${cased.length}).` };
|
|
53
|
+
else if (cased.length >= 10 && tc / cased.length <= 0.15) v.case = { call: "Sentence case", why: `This product writes its ${what} in sentence case (${cased.length - tc} of ${cased.length}).` };
|
|
54
|
+
if (pool.length >= 8) { const L = pool.map((s) => words(s.text)); v.length = { call: `${pct(L, 0.25)}-${pct(L, 0.75)} words`, why: `The middle half of this product's ${pool.length} ${what}.` }; }
|
|
55
|
+
if (Object.keys(v).length) out[group] = v;
|
|
56
|
+
}
|
|
57
|
+
return Object.keys(out).length ? out : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// --- moments: errors, empty states, confirmations and successes often keep their own habits ---------------
|
|
61
|
+
const PATTERN_CLASS = { success: "success", error: "error", offline: "error", "empty-state": "empty", "search-no-results": "empty",
|
|
62
|
+
"confirmation-dialog": "confirm", "settings-destructive": "confirm" };
|
|
63
|
+
const CLASS_RX = {
|
|
64
|
+
confirm: /\bare you sure\b|\breally (want|delete|remove)\b|\b(can't|cannot|can not) be undone\b|\bpermanently\b|^(delete|remove|discard|leave|reset|revoke|deactivate)\b[^.!]*\?\s*$/i,
|
|
65
|
+
error: /\b(error|fail(ed|ure|s)?|couldn't|could not|can't|cannot|unable|went wrong|invalid|problem|oops|denied|expired|not found|timed out|try again)\b/i,
|
|
66
|
+
empty: /\bno \w+( \w+)? (yet|found|available|here)\b|\bnothing (here|to|yet|found)\b|\bno results\b|\b(is|are) empty\b|^empty\b/i,
|
|
67
|
+
success: /\b(success(ful(ly)?)?|saved|done|complete(d)?|congrat\w*|all set|well done|great( job| work)?|nice( work| job)?|updated|created|added|sent|unlocked|achievement|you did it|you're in|welcome)\b/i,
|
|
68
|
+
};
|
|
69
|
+
const KEY_RX = { confirm: /confirm|areyousure|are_you_sure|really/i, error: /error|fail|invalid/i, empty: /empty|no_?results|nothing/i, success: /success|saved|complete|congrat/i };
|
|
70
|
+
export function classOf(text, key = "") {
|
|
71
|
+
const t = ap(text);
|
|
72
|
+
for (const c of ["confirm", "error", "empty", "success"]) if (CLASS_RX[c].test(t) || KEY_RX[c].test(key)) return c;
|
|
73
|
+
return "other";
|
|
74
|
+
}
|
|
75
|
+
export const momentOf = (pattern) => PATTERN_CLASS[pattern] || null;
|
|
76
|
+
// Verdicts for one moment where they differ from the product-wide ones (only where the moment has 8+ strings of that size).
|
|
77
|
+
export function momentPositions(strings, base) {
|
|
78
|
+
const out = {};
|
|
79
|
+
for (const cls of ["error", "empty", "confirm", "success"]) {
|
|
80
|
+
const p = productPosition((strings || []).filter((s) => s.text && classOf(s.text, s.key || "") === cls));
|
|
81
|
+
if (!p) continue;
|
|
82
|
+
const diff = {};
|
|
83
|
+
for (const g of Object.keys(p)) for (const [k, v] of Object.entries(p[g])) {
|
|
84
|
+
if (k === "length") continue;
|
|
85
|
+
if (base?.[g]?.[k]?.call !== v.call) (diff[g] ||= {})[k] = { call: v.call, why: v.why.replace("This product", `In ${cls === "empty" ? "empty states" : cls === "confirm" ? "confirmations" : cls === "error" ? "errors" : "success messages"}, this product`) };
|
|
86
|
+
}
|
|
87
|
+
if (Object.keys(diff).length) out[cls] = diff;
|
|
88
|
+
}
|
|
89
|
+
return Object.keys(out).length ? out : null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const POSITION_NOTE = "These are this product's own habits, read from its strings. Follow them in new copy: they decide contractions, the final full stop, case, 'you' and 'we', and length. `by_moment` lists where errors, empty states, confirmations or success messages keep a different habit; in those moments it wins. They cover style only; the facts, the state and the outcome the person needs still decide what the copy says. Where the repo's rules say otherwise, the rules win.";
|
|
93
|
+
|
|
94
|
+
const CACHE = new Map();
|
|
95
|
+
// The product's position, with a moment's own habits laid over it when the pattern names one.
|
|
96
|
+
export function positionFor(root, pattern) {
|
|
97
|
+
if (!root || !existsSync(root)) return null;
|
|
98
|
+
if (!CACHE.has(root)) {
|
|
99
|
+
try { const strings = collectStrings(root).strings; const base = productPosition(strings); CACHE.set(root, { base, moments: momentPositions(strings, base) }); }
|
|
100
|
+
catch { CACHE.set(root, { base: null, moments: null }); }
|
|
101
|
+
}
|
|
102
|
+
const { base, moments } = CACHE.get(root);
|
|
103
|
+
const m = momentOf(pattern) && moments?.[momentOf(pattern)];
|
|
104
|
+
if (!m) return base;
|
|
105
|
+
const merged = JSON.parse(JSON.stringify(base || {}));
|
|
106
|
+
for (const g of Object.keys(m)) merged[g] = { ...(merged[g] || {}), ...m[g] };
|
|
107
|
+
return merged;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Departures from the product's habits, as lint findings.
|
|
111
|
+
export function checkPosition(units, position) {
|
|
112
|
+
const out = [];
|
|
113
|
+
if (!position) return out;
|
|
114
|
+
units.forEach((u, i) => {
|
|
115
|
+
const t = u.text || "";
|
|
116
|
+
if (!t.trim()) return;
|
|
117
|
+
const group = groupOf(u.element, t);
|
|
118
|
+
const v = position[group];
|
|
119
|
+
if (!v) return;
|
|
120
|
+
for (const [name, f] of Object.entries(FEATURES)) {
|
|
121
|
+
const h = v[name];
|
|
122
|
+
if (!h) continue;
|
|
123
|
+
if (name === "contraction" && words(t) < 5) continue;
|
|
124
|
+
if (name === "full_stop" && group === "sentence" && /[?!]\s*$/.test(t.trim())) continue;
|
|
125
|
+
const has = f.test(t);
|
|
126
|
+
// only the absence of a habit the copy could have used is checked for 'use'; 'avoid' is checked whenever the feature appears
|
|
127
|
+
if (h.call === "avoid" && has) out.push({ unit: i, severity: f.lint, rule: "product-position", detail: `${h.why.replace(/ Follow it\.$/, "")}; this line uses it` });
|
|
128
|
+
if (h.call === "use" && !has && (name === "full_stop" || name === "contraction" && /\b(can not|cannot|do not|does not|did not|is not|are not|was not|were not|will not|would not|could not|should not|have not|has not|had not|you are|we are|it is|that is|there is|let us|you will|we will)\b/i.test(t)))
|
|
129
|
+
out.push({ unit: i, severity: f.lint, rule: "product-position", detail: `${h.why.replace(/ Follow it\.$/, "")}; this line doesn't` });
|
|
130
|
+
}
|
|
131
|
+
if (v.case && (group === "short")) {
|
|
132
|
+
const tc = isTitleCase(t);
|
|
133
|
+
if (tc !== null && (tc ? "Title Case" : "Sentence case") !== v.case.call) out.push({ unit: i, severity: "warn", rule: "product-position", detail: `${v.case.why} Write this one in ${v.case.call}.` });
|
|
134
|
+
}
|
|
135
|
+
if (v.length && /^\d+-\d+ words$/.test(v.length.call)) {
|
|
136
|
+
const [lo, hi] = v.length.call.match(/\d+/g).map(Number), w = words(t);
|
|
137
|
+
if (w > hi * 2 && w > hi + 4) out.push({ unit: i, severity: "note", rule: "product-position", detail: `${w} words; ${v.length.why.replace(/\.$/, "")} run ${v.length.call}` });
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return out;
|
|
141
|
+
}
|
package/src/product.js
CHANGED
|
@@ -6,6 +6,7 @@ import { findRepoRules, readConfig } from "./repo.js";
|
|
|
6
6
|
import { readdirSync, readFileSync, statSync, existsSync } from "node:fs";
|
|
7
7
|
import { join, relative, extname, basename } from "node:path";
|
|
8
8
|
import { lintCopy } from "./tools.js";
|
|
9
|
+
import { productPosition, momentPositions, POSITION_NOTE } from "./position.js";
|
|
9
10
|
import { inferIndustry, industryProfile, readSavedBrief, contextSlots, ASK_POLICY } from "./context.js";
|
|
10
11
|
|
|
11
12
|
const SKIP_DIRS = new Set(["docs", "dev-docs", "documentation", "examples", "example", "scripts", "node_modules", ".git", "dist", "build", ".next", "out", "coverage", "vendor", "Pods", ".turbo",
|
|
@@ -49,6 +50,10 @@ const CODE_EXT = new Set([".tsx", ".jsx", ".vue", ".svelte", ".html", ".swift",
|
|
|
49
50
|
// vendored, generated and demo code: not the product's own copy
|
|
50
51
|
const VENDOR_PATH = /\/(vendor(ed)?|third[-_]?party|external|demos?|playground|sandbox|generated|__generated__|registry|shadcn[\w-]*|[\w-]*-studio)\//i;
|
|
51
52
|
const VENDOR_HEAD = /@generated|@vendored|DO NOT EDIT|auto-?generated/i;
|
|
53
|
+
// backend tools, crawlers and infrastructure at the repo's top level: their messages never reach the product's users
|
|
54
|
+
const NON_PRODUCT_PATH = /^\/(tools|infra|infrastructure|ops|deploy|terraform|crawlers?|scrapers?|etl|pipelines?)\/|\/[\w-]*(crawler|scraper)s?\//i;
|
|
55
|
+
// admin and internal pages: the reader is the team, so naming an env variable is the fix, not a leak
|
|
56
|
+
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
57
|
const TEST_FILE = /(\.|_|-|\/)(test|spec|stories|story|storybookData|mock|fixture)s?\.|\/(__tests__|tests?|e2e|fixtures|mocks|stories)\//i;
|
|
53
58
|
|
|
54
59
|
// Breadth-first, so a large monorepo is covered level by level instead of one deep branch first.
|
|
@@ -92,6 +97,8 @@ const looksLikeCopy = (t) => {
|
|
|
92
97
|
if (/^[a-z0-9_.-]+$/.test(s) && !/\s/.test(s)) return false; // keys, ids, class names
|
|
93
98
|
if (/^(https?:|\/|#|\.|@|\$\{|[A-Z_]{3,}$)/.test(s)) return false; // urls, paths, constants
|
|
94
99
|
if (/[{};=<>]|=>|\(\)|\bfunction\b|\bimport\b|\bconst\b/.test(s)) return false;
|
|
100
|
+
// JSX/TS code that leaks between tags: ternaries, logical operators, optional chains, object-literal keys
|
|
101
|
+
if (/&&|&&|\|\||\?\.|\.length\b|\?\s*\($|^[)\]:,?]|\b(null|undefined)\s*[,:)]/.test(s)) return false;
|
|
95
102
|
if (/^[a-z]+(-[a-z]+)+$/.test(s)) return false; // css-ish tokens
|
|
96
103
|
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
104
|
if ((s.match(/%[A-Za-z-]/g) || []).length >= 2 || /:$/.test(s)) return false; // date formats, yaml parents
|
|
@@ -110,7 +117,7 @@ function extractFromCode(src, file) {
|
|
|
110
117
|
const out = [];
|
|
111
118
|
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
119
|
// JSX/HTML text between tags; element from the tag name
|
|
113
|
-
const tagText = /<([A-Za-z][\w.]*)[^<>]*>([^<>{}]{2,400})
|
|
120
|
+
const tagText = /<([A-Za-z][\w.]*)[^<>]*>([^<>{}]{2,400})(?=<)/g; // lookahead, so "<p>A<br />B</p>" yields both A and B
|
|
114
121
|
let m;
|
|
115
122
|
while ((m = tagText.exec(src))) {
|
|
116
123
|
const tag = m[1].toLowerCase();
|
|
@@ -183,7 +190,7 @@ export function collectStrings(root, sub) {
|
|
|
183
190
|
const ignore = readConfig(root).ignore.map((g) => g.replace(/^\.\//, ""));
|
|
184
191
|
for (const f of files) {
|
|
185
192
|
const rel = relative(root, f);
|
|
186
|
-
if (TEST_FILE.test("/" + rel) || VENDOR_PATH.test("/" + rel) || ignore.some((g) => rel.startsWith(g))) continue;
|
|
193
|
+
if (TEST_FILE.test("/" + rel) || VENDOR_PATH.test("/" + rel) || NON_PRODUCT_PATH.test("/" + rel) || ignore.some((g) => rel.startsWith(g))) continue;
|
|
187
194
|
if (LOCALE_FILE.test(rel)) { if (isEnglishLocale(rel)) strings.push(...extractFromLocale(readSafe(f), rel)); continue; }
|
|
188
195
|
if (CODE_EXT.has(extname(f))) { const src = readSafe(f); if (!VENDOR_HEAD.test(src.slice(0, 400))) strings.push(...extractFromCode(src, rel)); }
|
|
189
196
|
else if (SERVER_EXT.has(extname(f)) && (isClientScript(rel) || !/(^|\/)(config|db|migrations?|spec|test|api)\//.test(rel))) strings.push(...extractFromServer(readSafe(f), rel));
|
|
@@ -267,12 +274,13 @@ export function readProduct({ root = process.cwd(), sample = 18 } = {}) {
|
|
|
267
274
|
readme: saved ? undefined : rd,
|
|
268
275
|
landing_copy: landing,
|
|
269
276
|
voice,
|
|
277
|
+
...(() => { const p = productPosition(strings); if (!p) return {}; const m = momentPositions(strings, p); return { position: { ...p, ...(m ? { by_moment: m } : {}), how_to_use: POSITION_NOTE } }; })(),
|
|
270
278
|
industry: { ...guess, profile: guess.industry ? industryProfile(guess.industry, voice) : null },
|
|
271
279
|
sample_lines: [...byUse, ...sentences].map((s) => ({ text: s.text, element: s.element, where: `${s.file}:${s.line}` })),
|
|
272
280
|
slots, questions, ask_policy: ASK_POLICY,
|
|
273
|
-
next: first + (saved
|
|
281
|
+
next: first + (strings.length ? "Write new copy in the product's own style: follow every verdict in `position`. " : "") + "Before you write, list what the request claims about the product (deletion and restore, emails and notifications, money, timing, who can see what) and open the code for each. Where the request and the code disagree, the code wins: write from it and tell the person. " + (saved
|
|
274
282
|
? "A saved brief exists: use it, fill any slot still marked unknown, and don't re-ask what it answers. Call save_product_brief only if something changed."
|
|
275
|
-
: "Fill every slot: read-and-fill slots from the README and strings, inferred slots by checking them against the sample lines. Then write a brief of at most six lines: (1) what the product is, in its own words; (2) who uses it and the niche; (3) the main job; (4) its current voice, quoting 2 or 3 sample lines, and how it differs from the industry baseline; (5) its own words for its things (reuse them); (6) what is at stake for its users. Mark what you inferred. Handle `questions` by the ask_policy (ask_person shows a form where the client supports it). Then call save_product_brief so the next session starts from it. Use the industry examples as evidence of what comparable products do, not as wording to copy. Keep the product's voice unless the person asks to change it; fix tics, not personality.") + (guess.industry ? ` Save industry "${guess.industry}" in the brief (or correct it), so find_reference and find_examples stay with comparable products.` : ""),
|
|
283
|
+
: "Fill every slot: read-and-fill slots from the README and strings, inferred slots by checking them against the sample lines. Then write a brief of at most six lines: (1) what the product is, in its own words; (2) who uses it and the niche; (3) the main job; (4) its current voice, quoting 2 or 3 sample lines and the habits in `position` (contractions, full stop, case), and how it differs from the industry baseline; (5) its own words for its things (reuse them); (6) what is at stake for its users. Mark what you inferred. Handle `questions` by the ask_policy (ask_person shows a form where the client supports it). Then call save_product_brief so the next session starts from it. Use the industry examples as evidence of what comparable products do, not as wording to copy. Keep the product's voice unless the person asks to change it; fix tics, not personality.") + (guess.industry ? ` Save industry "${guess.industry}" in the brief (or correct it), so find_reference and find_examples stay with comparable products.` : ""),
|
|
276
284
|
};
|
|
277
285
|
}
|
|
278
286
|
|
|
@@ -293,8 +301,10 @@ export function auditCopy({ root = process.cwd(), strings, limit = 25, path_filt
|
|
|
293
301
|
}
|
|
294
302
|
if (path_filter) list = list.filter((s) => (s.file || "").includes(path_filter.replace(/\/$/, "")));
|
|
295
303
|
const scored = list.map((s) => {
|
|
304
|
+
const admin = s.file && ADMIN_PATH.test(s.file);
|
|
296
305
|
const findings = lintCopy({ units: [{ element: s.element, text: s.text }], allow: [...cfg.allow, ...(allow || [])] })
|
|
297
|
-
.filter((f) => !["variable", "long", "punctuation"].includes(f.rule))
|
|
306
|
+
.filter((f) => !["variable", "long", "punctuation"].includes(f.rule))
|
|
307
|
+
.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
308
|
const base = findings.reduce((a, f) => a + SEV[f.severity], 0);
|
|
299
309
|
const stakes = STAKES.test(s.text);
|
|
300
310
|
const reach = Math.min(3, Math.log2(1 + (s.uses || 1)));
|
package/src/server.js
CHANGED
|
@@ -8,7 +8,12 @@ import { findReferenceV2Async, decideTone, HAS_ENRICHED, INDUSTRIES } from "./re
|
|
|
8
8
|
import { readProduct, auditCopy } from "./product.js";
|
|
9
9
|
import { saveProductBrief, askPerson, readSavedBrief } from "./context.js";
|
|
10
10
|
import { readConfig } from "./repo.js";
|
|
11
|
+
import { checkClaims } from "./claims.js";
|
|
12
|
+
import { positionFor, checkPosition } from "./position.js";
|
|
13
|
+
import { existsSync as exists } from "node:fs";
|
|
14
|
+
import { join as pjoin } from "node:path";
|
|
11
15
|
import { normElement, META, PATTERNS, ELEMENTS, HAS_EXAMPLES, findExamples, findRules, getGuide, lintCopy, findReference, compareToReference } from "./tools.js";
|
|
16
|
+
let productRead = false; // get_guide reminds the agent to read the product first
|
|
12
17
|
|
|
13
18
|
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
14
19
|
|
|
@@ -18,17 +23,17 @@ Write from the rules, the tone decision and the pattern playbook. Shipped copy i
|
|
|
18
23
|
0. In a codebase, call read_product once per session. Use the saved brief if there is one; otherwise fill its slots from the repo, write the short brief, ask the person at most two questions that would change the copy (ask_person; otherwise state your assumption), and save it with save_product_brief (it writes .content-md/product.md, not your instruction files) unless the person said not to touch files. Write for that product, its audience and its own words, and keep its voice. To improve existing copy, call audit_copy and fix the worst lines first; leave unflagged lines alone.
|
|
19
24
|
1. Call get_guide with the pattern once per task and follow it.
|
|
20
25
|
2. If the moment has stakes or feeling (an error, money, a deletion, a success), call decide_tone with the facts of the moment, and use its tone words and instruction.
|
|
21
|
-
3. State-check before you write: name the screen state and what the product actually knows.
|
|
22
|
-
4. Write every piece the screen needs. When rewriting, keep labels, buttons and titles that already work.
|
|
26
|
+
3. State-check before you write: name the screen state and what the product actually knows, from the code. The request is a brief, not the truth: when it says something about the product that the code contradicts (a trash that doesn't exist, a refund timeline, an email that isn't sent), the code wins. Write from the code and tell the person what the request got wrong. When the code doesn't settle it, leave the claim out and ask.
|
|
27
|
+
4. Write every piece the screen needs. When rewriting, keep labels, buttons and titles that already work. When asked to tighten or review copy that already works, "no change" is a valid answer, and never add a claim, promise or reassurance the original didn't make. Keep string keys, ids and element names exactly as given (primary_cta stays primary_cta); change only the text.
|
|
23
28
|
5. Optional: call find_reference when you want evidence for a decision, or pass the tool state when the copy describes progress or an outcome, to get a correction example. If it returns nothing, write from the rules.
|
|
24
|
-
6. Run lint_copy on every draft and fix each block and warn, or say why you kept it.
|
|
29
|
+
6. Run lint_copy on every draft, with the original when rewriting, and fix each block and warn, or say why you kept it. It lists every claim the copy makes; in a codebase pass evidence with the file:line that backs each one, and cut any claim you can't back. Never invent a source, name, date or figure as an example. Score each string 1-3 with the rubric in the guide and return nothing below 2.
|
|
25
30
|
Lead with paste-ready copy. If you quote a shipped line, quote it exactly as a tool returned it.`;
|
|
26
31
|
const INSTRUCTIONS = HAS_EXAMPLES ? INSTRUCTIONS_FULL : `Use these tools whenever you write or review interface copy, including strings in code.
|
|
27
32
|
The repo's own copy rules, glossary and voice guide come first: where they differ from this guidance, follow them.
|
|
28
33
|
0. In a codebase, call read_product once and write the product brief it asks for; to improve existing copy, call audit_copy and fix the worst lines first.
|
|
29
34
|
1. Call get_guide with the pattern once per task and follow it.
|
|
30
35
|
2. If the moment has stakes or feeling, call decide_tone first.
|
|
31
|
-
3. State-check, write every piece the screen needs, then run lint_copy on every draft and fix each block and warn, or say why you kept it. Score each string 1-3 with the rubric in the guide and return nothing below 2.
|
|
36
|
+
3. State-check from the code: where the request and the code disagree, write from the code and say so. Write every piece the screen needs ("no change" is a valid answer for copy that works; keep keys and element names as given), then run lint_copy on every draft with evidence (file:line) for each claim, and fix each block and warn, or say why you kept it. Score each string 1-3 with the rubric in the guide and return nothing below 2.
|
|
32
37
|
Lead with paste-ready copy, recommend one option, and cite the rule behind it.`;
|
|
33
38
|
|
|
34
39
|
// the repo's industry, from .content-md.json or the saved product brief, so references stay on-domain by default
|
|
@@ -56,7 +61,14 @@ export async function serve() {
|
|
|
56
61
|
full: z.boolean().optional().describe("Also return every topic in the pattern index (about 18,000 more characters). Rarely needed."),
|
|
57
62
|
},
|
|
58
63
|
annotations: { readOnlyHint: true },
|
|
59
|
-
}, async ({ pattern, full }) =>
|
|
64
|
+
}, async ({ pattern, full }) => {
|
|
65
|
+
const root = process.cwd();
|
|
66
|
+
const inRepo = [".git", "package.json", "pyproject.toml", "Gemfile", "go.mod", "Cargo.toml", "composer.json"].some((f) => exists(pjoin(root, f)));
|
|
67
|
+
const first = !productRead && inRepo
|
|
68
|
+
? "Before you write: call read_product. It shows what this product says, who uses it and what its code does; agents who skip it leave out facts the copy needs. Then list what the request claims about the product and open the code for each.\n\n"
|
|
69
|
+
: "";
|
|
70
|
+
return { content: [{ type: "text", text: first + getGuide({ pattern, full }) }] };
|
|
71
|
+
});
|
|
60
72
|
|
|
61
73
|
if (HAS_EXAMPLES) server.registerTool("find_examples", {
|
|
62
74
|
title: "Find shipped examples",
|
|
@@ -144,7 +156,7 @@ export async function serve() {
|
|
|
144
156
|
|
|
145
157
|
server.registerTool("lint_copy", {
|
|
146
158
|
title: "Lint copy",
|
|
147
|
-
description: "Deterministic pass/fail checks on one screen's copy
|
|
159
|
+
description: "Deterministic pass/fail checks on one screen's copy. It pulls every claim out of the copy (sent, refunded, deleted, restorable, takes N days, saved, visible to) and, in a repo, needs a file:line in `evidence` for each, which it reads to check. Pass `original` when rewriting to catch claims the original didn't make. Also: tone fence at high stakes, plural handling, verb-only buttons, missing pieces, template leaks, raw error codes, filler, generic buttons, blame words, 'Are you sure', body repeating headline, casing, length, emoji at high stakes, colon or semicolon joining clauses, a trailing 'yet', and, in a repo, departures from the product's own habits (read_product's position). Severity block > warn > note. Run on every draft before presenting it.",
|
|
148
160
|
inputSchema: {
|
|
149
161
|
pattern: pattern.optional(),
|
|
150
162
|
units: z.array(z.object({ element, text: z.string() })).min(1).describe("Every piece of copy on the screen, in order"),
|
|
@@ -153,23 +165,39 @@ export async function serve() {
|
|
|
153
165
|
expected_pieces: z.array(element).optional().describe("The pieces the screen needs; any missing one is blocked."),
|
|
154
166
|
original: z.array(z.object({ element: z.string(), text: z.string() })).optional().describe("When rewriting: the old pieces. Short originals that were changed are noted."),
|
|
155
167
|
allow: z.array(z.string()).optional().describe("Words or whole lines the repo's own rules or glossary accept (e.g. 'Continue', 'Inbox'); they are never flagged. Entries in the repo's .content-md.json are added automatically."),
|
|
168
|
+
evidence: z.array(z.object({ claim: z.string().describe("The words of the claim, as they appear in the copy"), where: z.string().describe("file:line (or file:start-end) in this repo where the code does it; 'request' if only the request says so") })).optional()
|
|
169
|
+
.describe("One entry per claim the copy makes: that something was sent, refunded, deleted, can be restored, takes N days, is saved or visible to someone. In a repo every claim needs a file:line; the cited lines are read and must mention it."),
|
|
156
170
|
},
|
|
157
171
|
annotations: { readOnlyHint: true },
|
|
158
172
|
}, async (args) => {
|
|
159
|
-
const
|
|
173
|
+
const root = process.cwd();
|
|
174
|
+
const findings = lintCopy({ ...args, allow: [...(args.allow || []), ...readConfig(root).allow] });
|
|
175
|
+
// claims need file:line evidence in a repo; outside one there is no code to cite, so they are listed as notes
|
|
176
|
+
const inRepo = [".git", "package.json", "pyproject.toml", "Gemfile", "go.mod", "Cargo.toml", "composer.json"].some((f) => exists(pjoin(root, f)));
|
|
177
|
+
const units = args.units.map((u) => ({ ...u, element: normElement(u.element) }));
|
|
178
|
+
const original = args.original?.map((o) => ({ ...o, element: normElement(o.element) }));
|
|
179
|
+
const cc = checkClaims({ units, evidence: args.evidence, stakes: args.stakes, original, root });
|
|
180
|
+
for (const f of cc.findings) findings.push(inRepo || f.rule === "added-claim" ? f : { ...f, severity: "note" });
|
|
181
|
+
// the product's own style habits (read_product's `position`): departures are flagged, and its casing wins over the generic sentence-case note
|
|
182
|
+
if (inRepo) {
|
|
183
|
+
const pos = positionFor(root, args.pattern);
|
|
184
|
+
if (pos?.short?.case?.call === "Title Case") for (let k = findings.length - 1; k >= 0; k--) if (findings[k].rule === "title-case") findings.splice(k, 1);
|
|
185
|
+
findings.push(...checkPosition(units, pos));
|
|
186
|
+
}
|
|
160
187
|
const pass = !findings.some((f) => f.severity === "block" || f.severity === "warn");
|
|
161
|
-
return json({ pass, findings: findings.length ? findings : "No findings.", ...(
|
|
188
|
+
return json({ pass, findings: findings.length ? findings : "No findings.", ...(cc.claims.length ? { claims: cc.claims } : {}),
|
|
189
|
+
...(pass ? {} : { next: "Fix every block and warn, then run lint_copy again, or say why you kept one. For an unbacked claim: open the code that does it and pass {claim, where: \"file:line\"}; if the code doesn't do it, cut the claim or ask. If the request and the code disagree, write from the code and say so." }) });
|
|
162
190
|
});
|
|
163
191
|
|
|
164
192
|
server.registerTool("read_product", {
|
|
165
193
|
title: "Read the product",
|
|
166
|
-
description: "Read the codebase you are working in to learn what the product is, who uses it and how it already sounds: manifest, README, landing copy, a sample of its own UI strings with file:line,
|
|
194
|
+
description: "Read the codebase you are working in to learn what the product is, who uses it and how it already sounds: manifest, README, landing copy, a sample of its own UI strings with file:line, voice numbers, and `position`: this product's own habits (contractions, final full stop, case, 'you'/'we', length) as verdicts to follow in new copy. Call it once per session before writing or reviewing copy in a repo, then write the short product brief it asks for.",
|
|
167
195
|
inputSchema: {
|
|
168
196
|
root: z.string().optional().describe("Project root; defaults to the folder the server was started in"),
|
|
169
197
|
sample: z.number().int().min(5).max(80).optional(),
|
|
170
198
|
},
|
|
171
199
|
annotations: { readOnlyHint: true },
|
|
172
|
-
}, async (args) => json(readProduct(args)));
|
|
200
|
+
}, async (args) => { productRead = true; return json(readProduct(args)); });
|
|
173
201
|
|
|
174
202
|
server.registerTool("save_product_brief", {
|
|
175
203
|
title: "Save the product brief",
|
package/src/tools.js
CHANGED
|
@@ -257,8 +257,20 @@ 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))
|
|
261
|
-
|
|
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
|
+
// a colon or semicolon stitching two clauses together reads as written-by-a-model in short UI copy (picked against 2 of 2 times in blind review)
|
|
265
|
+
if (u.element !== "label" && u.element !== "legal-fineprint" && /[A-Za-z0-9)'"\]][;:]\s+[A-Za-z0-9'"{(]/.test(x) && !/^\S+:\s*$/.test(x) && !/^[^\s:;]+( [^\s:;]+)?:\s[^;]*$/.test(x))
|
|
266
|
+
add(i, "warn", "clause-join", `'${(x.match(/[^\s]*[;:]\s+\S+/) || [""])[0]}': a ${x.includes(";") ? "semicolon" : "colon"} joins two clauses; write two sentences, or join them with a word ("so", "and", "because")`);
|
|
267
|
+
// a permanent delete hedged as "you can't restore it yourself": the person reads that someone else can. Say it can't be undone, or name the restore they can reach
|
|
268
|
+
for (const m of x.match(/\b(?:can't|cannot|can not|won't be able to|will not be able to|unable to)\s+(?:restore|recover|undo|undelete|get back|bring back|retrieve)\b[^.!?]{0,30}?\b(?:yourself|on your own|by yourself)\b/gi) || [])
|
|
269
|
+
add(i, "warn", "restore-hedge", `'${m}' suggests someone else can restore it. If nobody the person can reach can restore it, say it can't be undone; if someone can, say who`);
|
|
270
|
+
// "yet" promises that something is coming; the model adds it (a note: shipped products use it too, so it is a prompt to check the facts) to empty and absence lines whether or not the facts say so
|
|
271
|
+
if (!out.some((f) => f.unit === i && f.rule === "no-x-yet") && /\byet\s*[.!?]?\s*$|\byet[.,;:]\s/i.test(x))
|
|
272
|
+
add(i, "note", "filler-yet", `'yet' suggests it will happen soon; cut it unless the facts say it will ("None of the 9 repositories has published a release.")`);
|
|
273
|
+
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
274
|
if (u.element === "body") {
|
|
263
275
|
const sents = x.split(/(?<=[.!?])\s+/).filter((t) => t.split(/\s+/).length > 1);
|
|
264
276
|
const wc = sents.map((z) => z.split(/\s+/).length);
|