architecture-harness 0.25.0 → 0.26.0

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.
Files changed (244) hide show
  1. package/package.json +3 -22
  2. package/src/cli/ask.mjs +42 -0
  3. package/src/cli/ask.test.mjs +40 -0
  4. package/src/cli/branch-sync.mjs +126 -0
  5. package/src/cli/branch-sync.test.mjs +428 -0
  6. package/src/cli/budget-guard.mjs +74 -5
  7. package/src/cli/budget-guard.test.mjs +185 -2
  8. package/src/cli/budget-report.mjs +85 -0
  9. package/src/cli/budget-report.test.mjs +173 -0
  10. package/src/cli/budget.mjs +8 -5
  11. package/src/cli/check-commands.mjs +123 -11
  12. package/src/cli/check-commands.test.mjs +360 -6
  13. package/src/cli/check-feature-switches.test.mjs +110 -0
  14. package/src/cli/check-full.test.mjs +152 -0
  15. package/src/cli/check-verdict.mjs +46 -0
  16. package/src/cli/check-verdict.test.mjs +32 -0
  17. package/src/cli/check.mjs +137 -4
  18. package/src/cli/check.test.mjs +45 -0
  19. package/src/cli/checkpoint.mjs +143 -0
  20. package/src/cli/checkpoint.test.mjs +146 -0
  21. package/src/cli/child-run.mjs +7 -2
  22. package/src/cli/child-run.test.mjs +17 -2
  23. package/src/cli/ci-failures.mjs +304 -0
  24. package/src/cli/ci-failures.test.mjs +615 -0
  25. package/src/cli/ci-preview.mjs +62 -0
  26. package/src/cli/ci-preview.test.mjs +85 -0
  27. package/src/cli/ci-state.mjs +25 -29
  28. package/src/cli/ci-state.test.mjs +174 -2
  29. package/src/cli/ci-template.test.mjs +86 -0
  30. package/src/cli/claude-core.test.mjs +37 -0
  31. package/src/cli/codex-implement.mjs +580 -47
  32. package/src/cli/codex-implement.test.mjs +1946 -29
  33. package/src/cli/codex-limit.mjs +85 -0
  34. package/src/cli/codex-limit.test.mjs +179 -0
  35. package/src/cli/codex-reset.mjs +78 -0
  36. package/src/cli/codex-reset.test.mjs +192 -0
  37. package/src/cli/codex-verify.mjs +230 -0
  38. package/src/cli/codex-verify.test.mjs +402 -0
  39. package/src/cli/comment-watch.mjs +391 -0
  40. package/src/cli/comment-watch.test.mjs +392 -0
  41. package/src/cli/commit-guard.mjs +219 -0
  42. package/src/cli/commit-guard.test.mjs +809 -0
  43. package/src/cli/context-budgets.mjs +47 -0
  44. package/src/cli/context-budgets.test.mjs +96 -0
  45. package/src/cli/context-watch.mjs +116 -0
  46. package/src/cli/context-watch.test.mjs +395 -0
  47. package/src/cli/contract-history.mjs +1 -1
  48. package/src/cli/controller-guard.mjs +38 -0
  49. package/src/cli/controller-guard.test.mjs +66 -2
  50. package/src/cli/cost-stop.mjs +5 -1
  51. package/src/cli/cost-stop.test.mjs +26 -0
  52. package/src/cli/diff-shape.mjs +162 -0
  53. package/src/cli/diff-shape.test.mjs +200 -0
  54. package/src/cli/direct-lane.mjs +32 -19
  55. package/src/cli/direct-lane.test.mjs +21 -3
  56. package/src/cli/dispatch-guard.mjs +11 -0
  57. package/src/cli/dispatch-guard.test.mjs +145 -10
  58. package/src/cli/dispatch-reminder.mjs +23 -10
  59. package/src/cli/dispatch-reminder.test.mjs +63 -11
  60. package/src/cli/dispatch-route.mjs +54 -0
  61. package/src/cli/dispatch-route.test.mjs +101 -0
  62. package/src/cli/dispatch-slot.mjs +2 -2
  63. package/src/cli/dispatch-slot.test.mjs +18 -19
  64. package/src/cli/dispatch.test.mjs +3 -3
  65. package/src/cli/e2e-affected.mjs +15 -0
  66. package/src/cli/e2e-affected.test.mjs +73 -0
  67. package/src/cli/fleet.mjs +180 -0
  68. package/src/cli/fleet.test.mjs +213 -0
  69. package/src/cli/gate-slot.mjs +2 -1
  70. package/src/cli/gh-merge-command.mjs +96 -31
  71. package/src/cli/gh-merge-command.test.mjs +74 -0
  72. package/src/cli/gh-run.mjs +64 -3
  73. package/src/cli/gh-run.test.mjs +66 -1
  74. package/src/cli/git-hooks.test.mjs +25 -3
  75. package/src/cli/git-read.mjs +2 -1
  76. package/src/cli/integrate-tree.mjs +47 -0
  77. package/src/cli/integrate.mjs +143 -40
  78. package/src/cli/integrate.test.mjs +347 -1
  79. package/src/cli/integration-lane.mjs +62 -0
  80. package/src/cli/integration-lane.test.mjs +213 -0
  81. package/src/cli/ledger.mjs +4 -2
  82. package/src/cli/ledger.test.mjs +12 -3
  83. package/src/cli/legs.mjs +53 -0
  84. package/src/cli/legs.test.mjs +70 -0
  85. package/src/cli/lint-changed.mjs +59 -10
  86. package/src/cli/lint-changed.test.mjs +112 -1
  87. package/src/cli/locked-tests.mjs +134 -0
  88. package/src/cli/locked-tests.test.mjs +188 -0
  89. package/src/cli/merge-guard.mjs +234 -62
  90. package/src/cli/merge-guard.test.mjs +768 -39
  91. package/src/cli/metrics.mjs +53 -0
  92. package/src/cli/metrics.test.mjs +73 -0
  93. package/src/cli/milestone.mjs +297 -0
  94. package/src/cli/milestone.test.mjs +294 -0
  95. package/src/cli/mutate.mjs +203 -0
  96. package/src/cli/mutate.test.mjs +134 -0
  97. package/src/cli/output-redaction.mjs +26 -0
  98. package/src/cli/output-redaction.test.mjs +117 -0
  99. package/src/cli/overview.mjs +131 -0
  100. package/src/cli/overview.test.mjs +137 -0
  101. package/src/cli/pause.mjs +93 -0
  102. package/src/cli/pause.test.mjs +109 -0
  103. package/src/cli/plan-check.mjs +84 -12
  104. package/src/cli/plan-check.test.mjs +152 -2
  105. package/src/cli/plan-stop.mjs +7 -4
  106. package/src/cli/plan-stop.test.mjs +87 -0
  107. package/src/cli/platform-risk.mjs +46 -0
  108. package/src/cli/platform-risk.test.mjs +38 -0
  109. package/src/cli/plugin-skills.test.mjs +25 -0
  110. package/src/cli/pr-guard.mjs +128 -0
  111. package/src/cli/pr-guard.test.mjs +154 -0
  112. package/src/cli/promotion-branch.mjs +2 -0
  113. package/src/cli/qc.mjs +160 -27
  114. package/src/cli/qc.test.mjs +93 -0
  115. package/src/cli/report-stop.mjs +5 -0
  116. package/src/cli/report-stop.test.mjs +23 -1
  117. package/src/cli/retry-failed.mjs +3 -1
  118. package/src/cli/review-gate.mjs +24 -6
  119. package/src/cli/review-gate.test.mjs +116 -0
  120. package/src/cli/review-promotion.mjs +107 -0
  121. package/src/cli/review-promotion.test.mjs +251 -0
  122. package/src/cli/role-budget.mjs +50 -0
  123. package/src/cli/role-budget.test.mjs +91 -0
  124. package/src/cli/run-log.mjs +73 -0
  125. package/src/cli/run-log.test.mjs +121 -0
  126. package/src/cli/secret-patterns.mjs +16 -0
  127. package/src/cli/secret-patterns.test.mjs +73 -0
  128. package/src/cli/setup-block.mjs +24 -0
  129. package/src/cli/setup-block.test.mjs +96 -0
  130. package/src/cli/setup-checks.mjs +65 -0
  131. package/src/cli/setup-checks.test.mjs +158 -0
  132. package/src/cli/setup-compaction.mjs +55 -0
  133. package/src/cli/setup-compaction.test.mjs +115 -0
  134. package/src/cli/setup-skills.mjs +65 -0
  135. package/src/cli/setup-skills.test.mjs +171 -0
  136. package/src/cli/setup.mjs +107 -0
  137. package/src/cli/setup.test.mjs +275 -0
  138. package/src/cli/skill-length.test.mjs +8 -0
  139. package/src/cli/spawn-command.mjs +47 -0
  140. package/src/cli/spawn-command.test.mjs +64 -0
  141. package/src/cli/task-gate-review.test.mjs +21 -2
  142. package/src/cli/task-gate.mjs +25 -12
  143. package/src/cli/task-gate.test.mjs +43 -5
  144. package/src/cli/tokens.mjs +46 -3
  145. package/src/cli/tokens.test.mjs +103 -3
  146. package/src/cli/tools.mjs +49 -0
  147. package/src/cli/tools.test.mjs +89 -0
  148. package/src/cli/transcript-usage.mjs +27 -0
  149. package/src/cli/transcript-usage.test.mjs +34 -0
  150. package/src/cli/user-config-package.mjs +1 -1
  151. package/src/cli/user-config-toml.mjs +63 -7
  152. package/src/cli/user-config.mjs +39 -7
  153. package/src/cli/user-config.test.mjs +238 -5
  154. package/src/cli/watch-arm.mjs +39 -0
  155. package/src/cli/watch-arm.test.mjs +87 -0
  156. package/src/cli/watch.mjs +80 -35
  157. package/src/cli/watch.test.mjs +233 -27
  158. package/src/cli/work-order-guard.mjs +2 -1
  159. package/src/cli/workflow-hooks.test.mjs +18 -4
  160. package/src/cli/workflow-settings.mjs +44 -8
  161. package/src/cli/workflow-settings.test.mjs +124 -1
  162. package/src/cli/worktree.mjs +14 -1
  163. package/src/cli/worktree.test.mjs +20 -1
  164. package/src/config.mjs +174 -7
  165. package/src/config.test.mjs +327 -5
  166. package/src/consumer-package.mjs +31 -0
  167. package/src/consumer-package.test.mjs +54 -0
  168. package/src/descriptions.mjs +2 -0
  169. package/src/eslint/index.mjs +12 -0
  170. package/src/eslint/jsx.mjs +20 -0
  171. package/src/eslint/preset.mjs +26 -2
  172. package/src/eslint/preset.test.mjs +104 -2
  173. package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
  174. package/src/eslint/rules/no-literal-color.mjs +94 -0
  175. package/src/eslint/rules/no-static-inline-style.mjs +41 -0
  176. package/src/eslint/rules/one-component-per-file.mjs +70 -0
  177. package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
  178. package/src/eslint/rules/timeless-comment.mjs +92 -0
  179. package/src/eslint/rules.test.mjs +189 -0
  180. package/src/eslint/ui-regressions.test.mjs +39 -0
  181. package/src/gates/contract-operations.mjs +3 -3
  182. package/src/gates/contract-operations.test.mjs +28 -0
  183. package/src/gates/feature-switches.mjs +19 -0
  184. package/src/gates/feature-switches.test.mjs +55 -0
  185. package/src/gates/plain-language.mjs +396 -0
  186. package/src/gates/plain-language.test.mjs +210 -0
  187. package/src/gates/runtime-imports.test.mjs +114 -0
  188. package/src/gates/saga-key.test.mjs +1 -1
  189. package/src/global-skills.mjs +9 -0
  190. package/src/global-skills.test.mjs +53 -0
  191. package/src/plugin.test.mjs +3 -2
  192. package/src/ui/class-sites.mjs +38 -6
  193. package/src/ui/codemod.mjs +4 -1
  194. package/src/ui/codemod.test.mjs +52 -0
  195. package/src/ui/components.mjs +5 -3
  196. package/src/ui/components.test.mjs +8 -0
  197. package/src/ui/dupes.test.mjs +18 -0
  198. package/templates/docs/enforcement.md +12 -2
  199. package/templates/docs/ui.md +33 -0
  200. package/templates/githooks/pre-commit +1 -0
  201. package/templates/githooks/pre-push +11 -2
  202. package/templates/github/workflows/ci.yml +57 -3
  203. package/user-config/claude/CLAUDE.core.md +28 -0
  204. package/user-config/claude/settings.shared.json +41 -1
  205. package/src/cli/screens-discovery.mjs +0 -60
  206. package/src/cli/screens.mjs +0 -84
  207. package/src/cli/stack.mjs +0 -14
  208. package/src/cli/throwaway-db.mjs +0 -127
  209. package/src/cli/throwaway-db.test.mjs +0 -83
  210. package/src/screens/auth-context.test.mjs +0 -41
  211. package/src/screens/auth-run.test.mjs +0 -147
  212. package/src/screens/auth.mjs +0 -223
  213. package/src/screens/auth.test.mjs +0 -76
  214. package/src/screens/capture-idle.test.mjs +0 -27
  215. package/src/screens/capture.browser-test.mjs +0 -73
  216. package/src/screens/capture.mjs +0 -175
  217. package/src/screens/capture.test.mjs +0 -28
  218. package/src/screens/catalog.browser-test.mjs +0 -32
  219. package/src/screens/catalog.mjs +0 -72
  220. package/src/screens/catalog.test.mjs +0 -36
  221. package/src/screens/chrome.mjs +0 -21
  222. package/src/screens/compare.mjs +0 -40
  223. package/src/screens/compare.test.mjs +0 -30
  224. package/src/screens/discovery.browser-test.mjs +0 -29
  225. package/src/screens/discovery.mjs +0 -158
  226. package/src/screens/discovery.test.mjs +0 -27
  227. package/src/screens/inventory.mjs +0 -69
  228. package/src/screens/inventory.test.mjs +0 -10
  229. package/src/screens/map.mjs +0 -63
  230. package/src/screens/map.test.mjs +0 -35
  231. package/src/screens/open.browser-test.mjs +0 -50
  232. package/src/screens/regions.mjs +0 -137
  233. package/src/screens/regions.test.mjs +0 -38
  234. package/src/screens/session-files.mjs +0 -39
  235. package/src/screens/session-files.test.mjs +0 -39
  236. package/src/screens/setup.browser-test.mjs +0 -49
  237. package/src/screens/setup.mjs +0 -78
  238. package/src/screens/stack-auth.browser-test.mjs +0 -30
  239. package/src/screens/stack-auth.mjs +0 -106
  240. package/src/screens/stack-auth.test.mjs +0 -65
  241. package/src/screens/write-guard.mjs +0 -26
  242. package/src/stack/stack.mjs +0 -131
  243. package/src/stack/stack.test.mjs +0 -40
  244. package/src/stack/supervisor.mjs +0 -30
@@ -0,0 +1,396 @@
1
+ // Prose a person reads is written in Simplified Technical English (ASD-STE100), in the Google
2
+ // developer documentation style. The approved dictionary is licensed and needs a part-of-speech
3
+ // tagger, so this gate carries the part a regular expression can prove: sentence and paragraph
4
+ // length, the voice, the words this repository replaced, and the heading and link forms.
5
+ //
6
+ // The rest of the standard -- approved meaning, approved part of speech, noun clusters -- stays a
7
+ // review rule. A gate that guesses at grammar teaches a writer to fight the gate.
8
+
9
+ import { commentLines, matchesAny } from "./english-source.mjs";
10
+
11
+ // Left is what a writer reaches for; right is the word that costs a reader less. An empty string
12
+ // means the word carries nothing and comes out. A repository adds its own under
13
+ // plainLanguage.replace, and removes one the kit ships by setting its value to null.
14
+ export const DEFAULT_REPLACE = Object.freeze({
15
+ // A longer word for a shorter act.
16
+ utilize: "use",
17
+ utilise: "use",
18
+ leverage: "use",
19
+ facilitate: "help",
20
+ commence: "start",
21
+ initiate: "start",
22
+ terminate: "stop",
23
+ demonstrate: "show",
24
+ endeavour: "try",
25
+ endeavor: "try",
26
+ ascertain: "find out",
27
+ obtain: "get",
28
+ purchase: "buy",
29
+ assist: "help",
30
+ attempt: "try",
31
+ provide: "give",
32
+ require: "need",
33
+ sufficient: "enough",
34
+ additional: "more",
35
+ approximately: "about",
36
+ subsequent: "later",
37
+ prior: "earlier",
38
+ methodology: "method",
39
+ functionality: "the function",
40
+ component: "part",
41
+ granular: "detailed",
42
+ paradigm: "model",
43
+ cognizant: "aware",
44
+ aforementioned: "this",
45
+ myriad: "many",
46
+ plethora: "many",
47
+ orchestrate: "run",
48
+ architected: "designed",
49
+ delve: "look at",
50
+ // Words that read as measurement and are opinion.
51
+ robust: "",
52
+ seamless: "",
53
+ seamlessly: "",
54
+ holistic: "",
55
+ elegant: "",
56
+ powerful: "",
57
+ comprehensive: "",
58
+ "cutting-edge": "",
59
+ "state-of-the-art": "",
60
+ // Words that tell the reader how to feel about the work.
61
+ simply: "",
62
+ just: "",
63
+ easily: "",
64
+ easy: "",
65
+ obviously: "",
66
+ clearly: "",
67
+ basically: "",
68
+ actually: "",
69
+ please: "",
70
+ // More words than the sentence needs.
71
+ "in order to": "to",
72
+ "so as to": "to",
73
+ "due to the fact that": "because",
74
+ "in the event that": "if",
75
+ "in the event of": "if",
76
+ "at this point in time": "now",
77
+ "at this time": "now",
78
+ "a number of": "some",
79
+ "the majority of": "most",
80
+ "is able to": "can",
81
+ "are able to": "can",
82
+ "has the ability to": "can",
83
+ "have the ability to": "can",
84
+ "make use of": "use",
85
+ "perform a check": "check",
86
+ "in terms of": "for",
87
+ "with regard to": "about",
88
+ "with respect to": "about",
89
+ "prior to": "before",
90
+ "subsequent to": "after",
91
+ "it is worth noting that": "",
92
+ "it should be noted that": "",
93
+ "note that": "",
94
+ "allows you to": "lets you",
95
+ "in a timely manner": "on time",
96
+ // Latin a reader translates before they read.
97
+ "e.g.": "for example",
98
+ "i.e.": "that is",
99
+ "etc.": "and so on",
100
+ "vs.": "compared with",
101
+ "n.b.": "note",
102
+ "ad hoc": "unplanned",
103
+ via: "through",
104
+ // One meaning per word: these carry two.
105
+ should: "must, or can",
106
+ may: "can, or is permitted to",
107
+ might: "can",
108
+ once: "after",
109
+ since: "because, or after",
110
+ while: "at the same time as, or although",
111
+ // Violence and disability as metaphor, which the Google style guide removes.
112
+ "sanity check": "quick check",
113
+ "sanity-check": "quick check",
114
+ "dummy value": "placeholder value",
115
+ blacklist: "denylist",
116
+ whitelist: "allowlist",
117
+ "master branch": "main branch",
118
+ cripple: "slow down",
119
+ crippled: "slowed down",
120
+ // Metaphor where a plain word exists.
121
+ "deep dive": "detailed look",
122
+ unpack: "explain",
123
+ ecosystem: "the set of tools",
124
+ journey: "sequence of steps",
125
+ "under the hood": "inside",
126
+ "out of the box": "with no setup",
127
+ });
128
+
129
+ // Skipped by the heading rule: a name is capitalised wherever it stands. All-capital words, words
130
+ // carrying a digit, and words carrying a dot or a slash are read as identifiers and skipped too.
131
+ export const DEFAULT_PROPER_NOUNS = Object.freeze([
132
+ "Anthropic", "Claude", "Docker", "Git", "GitHub", "GitLab", "Google", "JavaScript", "Kubernetes",
133
+ "Linux", "Markdown", "Node", "Postgres", "PostgreSQL", "Python", "React", "Simplified",
134
+ "Technical", "English", "TypeScript", "Windows", "macOS", "Terraform", "Drizzle", "Fastify",
135
+ ]);
136
+
137
+ const DEFAULTS = {
138
+ maxInstructionWords: 20,
139
+ maxDescriptiveWords: 25,
140
+ maxParagraphSentences: 6,
141
+ passive: true,
142
+ headings: true,
143
+ links: true,
144
+ punctuation: true,
145
+ };
146
+
147
+ // A form of "to be" and a past participle, which is the shape a reader has to turn round to find
148
+ // the actor. The generic tail is `-ed` only: an `-en` pattern reads "often" and "even" as verbs.
149
+ const BE = "(?:am|is|are|was|were|be|been|being|gets|got)";
150
+ const IRREGULAR =
151
+ "built|done|made|sent|set|put|kept|held|read|run|lost|left|found|told|brought|caught|taught|" +
152
+ "thought|bought|dealt|meant|met|paid|said|sold|felt|written|given|taken|seen|known|shown|driven|" +
153
+ "drawn|chosen|broken|spoken|hidden|frozen|forgotten";
154
+ // `un-` is dropped from the generic tail: "is uncommitted" and "is unchanged" are states a
155
+ // reader already reads as states, and flagging them teaches nobody to name an actor.
156
+ const PASSIVE = new RegExp(`\\b${BE}\\s+(?:(?!un)\\w{3,}ed|${IRREGULAR})\\b`, "i");
157
+
158
+ // A dash and a semicolon are where two sentences hide inside one. Both are a full stop that a
159
+ // writer did not take, and both are what makes a paragraph need a second reading.
160
+ const EM_DASH = /\u2014|\s--\s/;
161
+ const SEMICOLON = /;/;
162
+
163
+ const VAGUE_LINK = /\[\s*(?:here|this|link|more|read more|learn more|click here|this link|this page)\s*\]\(/i;
164
+
165
+ function escape(text) {
166
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
167
+ }
168
+
169
+ /** A word list becomes one matcher per entry, so a phrase and a word are found the same way. */
170
+ function wordMatchers(replace) {
171
+ return Object.entries(replace)
172
+ .filter(([, better]) => typeof better === "string")
173
+ .map(([word, better]) => ({
174
+ word,
175
+ better,
176
+ pattern: new RegExp(`(?<![\\w-])${escape(word)}(?![\\w-])`, "i"),
177
+ }));
178
+ }
179
+
180
+ /**
181
+ * Removes what is not prose from a line: code spans, link targets, bare URLs and HTML. A reader
182
+ * does not read these as sentences, and a path counts as neither a word nor a capital letter.
183
+ */
184
+ export function stripInline(text) {
185
+ return text
186
+ .replace(/`[^`]*`/g, " ")
187
+ .replace(/\]\([^)]*\)/g, "] ")
188
+ .replace(/<[^>\s]+>/g, " ")
189
+ .replace(/https?:\/\/\S+/g, " ");
190
+ }
191
+
192
+ /** Splits on a stop that a capital follows, so `config.json is read` stays one sentence. */
193
+ export function sentences(text) {
194
+ return text
195
+ .split(/(?<=[.!?])["')\]]?\s+(?=[A-Z"'(\[])/)
196
+ .map((part) => part.trim())
197
+ .filter((part) => part !== "");
198
+ }
199
+
200
+ function wordCount(text) {
201
+ return text.split(/\s+/).filter((word) => /[A-Za-z0-9]/.test(word)).length;
202
+ }
203
+
204
+ /**
205
+ * A document's prose, in blocks. A hard-wrapped paragraph is one block, not one block a line:
206
+ * a sentence a writer broke over two lines is still one sentence to the reader.
207
+ *
208
+ * A fence, a table, a front matter block, a quote and an indented block are not prose. Reporting
209
+ * a sentence inside one teaches a writer to break the fence instead.
210
+ * @returns {{line: number, text: string, kind: "heading"|"item"|"text"}[]}
211
+ */
212
+ export function markdownProse(contents) {
213
+ const out = [];
214
+ let fence = null;
215
+ let front = false;
216
+ let open = null;
217
+
218
+ const flush = () => {
219
+ if (open !== null) out.push({ line: open.line, text: open.parts.join(" "), kind: open.kind });
220
+ open = null;
221
+ };
222
+
223
+ contents.split("\n").forEach((raw, index) => {
224
+ const line = index + 1;
225
+ const trimmed = raw.trim();
226
+ if (index === 0 && trimmed === "---") {
227
+ front = true;
228
+ return;
229
+ }
230
+ if (front) {
231
+ if (trimmed === "---") front = false;
232
+ return;
233
+ }
234
+ const opener = /^(```+|~~~+)/.exec(trimmed);
235
+ if (fence !== null) {
236
+ if (opener !== null && opener[1][0] === fence[0]) fence = null;
237
+ return;
238
+ }
239
+ if (opener !== null) {
240
+ flush();
241
+ fence = opener[1];
242
+ return;
243
+ }
244
+ const skipped =
245
+ trimmed === "" ||
246
+ trimmed.startsWith("|") ||
247
+ trimmed.startsWith(">") ||
248
+ trimmed.startsWith("<!--") ||
249
+ /^(?: {4,}|\t)/.test(raw) ||
250
+ /^([-*_])\s*(?:\1\s*){2,}$/.test(trimmed);
251
+ if (skipped) {
252
+ flush();
253
+ return;
254
+ }
255
+ const heading = /^#{1,6}\s+(.*)$/.exec(trimmed);
256
+ if (heading !== null) {
257
+ flush();
258
+ out.push({ line, text: heading[1], kind: "heading" });
259
+ return;
260
+ }
261
+ const item = /^(?:[-*+]|\d+[.)])\s+(.*)$/.exec(trimmed);
262
+ if (item !== null) {
263
+ flush();
264
+ open = { line, parts: [item[1]], kind: "item" };
265
+ return;
266
+ }
267
+ if (open === null) open = { line, parts: [], kind: "text" };
268
+ open.parts.push(trimmed);
269
+ });
270
+ flush();
271
+ return out;
272
+ }
273
+
274
+ /** A source file's prose is its comments, read with the same heuristic the language gate uses. */
275
+ function commentProse(contents) {
276
+ return commentLines(contents).map(({ line, text }) => ({
277
+ line,
278
+ text: text.trim().replace(/^(?:\/\/+|#+|--+|\/\*+|\*+\/?)\s*/, "").replace(/\*\/\s*$/, "").trim(),
279
+ kind: "text",
280
+ }));
281
+ }
282
+
283
+ function headingProblems(text, proper) {
284
+ const words = stripInline(text)
285
+ .split(/\s+/)
286
+ .filter((word) => word !== "")
287
+ // A numbered heading carries its number as a token. The word after it is the first word.
288
+ .filter((word, index) => !(index === 0 && /^\d+[.)]?$/.test(word)));
289
+ return words.slice(1).filter((raw) => {
290
+ const word = raw.replace(/^[("'\[]+|[)"'\],.:;!?]+$/g, "");
291
+ if (!/^[A-Z][a-z]/.test(word)) return false;
292
+ if (/[\d./\\_]/.test(word)) return false;
293
+ return !proper.has(word);
294
+ });
295
+ }
296
+
297
+ /**
298
+ * @param {{path: string, contents: string}[]} files paths relative to the repository root
299
+ * @param {object} [options] see `plainLanguage` in the kit's config defaults
300
+ * @returns {{path: string, rule: string, detail: string}[]}
301
+ */
302
+ export function checkPlainLanguage(files, options = {}) {
303
+ const config = { ...DEFAULTS, ...options };
304
+ const matchers = wordMatchers({ ...DEFAULT_REPLACE, ...(options.replace ?? {}) });
305
+ const proper = new Set([...DEFAULT_PROPER_NOUNS, ...(options.properNouns ?? [])]);
306
+ const allow = options.allow ?? [];
307
+ const problems = [];
308
+
309
+ for (const { path, contents } of files) {
310
+ if (matchesAny(path, allow)) continue;
311
+ const units = path.endsWith(".md") ? markdownProse(contents) : commentProse(contents);
312
+ for (const unit of units) {
313
+ const prose = stripInline(unit.text);
314
+ const parts = sentences(prose);
315
+ const limit = unit.kind === "item" ? config.maxInstructionWords : config.maxDescriptiveWords;
316
+
317
+ if (unit.kind === "text" && parts.length > config.maxParagraphSentences) {
318
+ problems.push({
319
+ path,
320
+ rule: "paragraph-too-long",
321
+ detail: `line ${unit.line}: ${parts.length} sentences, max ${config.maxParagraphSentences}. Split it, or make it a list.`,
322
+ });
323
+ }
324
+
325
+ if (unit.kind !== "heading") {
326
+ for (const part of parts) {
327
+ const words = wordCount(part);
328
+ if (words > limit) {
329
+ const kind = unit.kind === "item" ? "an instruction" : "a description";
330
+ problems.push({
331
+ path,
332
+ rule: "sentence-too-long",
333
+ detail: `line ${unit.line}: ${words} words in ${kind}, max ${limit}. One idea per sentence.`,
334
+ });
335
+ }
336
+ if (config.passive && PASSIVE.test(part)) {
337
+ problems.push({
338
+ path,
339
+ rule: "passive-voice",
340
+ detail: `line ${unit.line}: "${PASSIVE.exec(part)[0]}" is passive. Name who acts, then the act.`,
341
+ });
342
+ }
343
+ }
344
+ }
345
+
346
+ for (const { word, better, pattern } of matchers) {
347
+ if (!pattern.test(prose)) continue;
348
+ problems.push({
349
+ path,
350
+ rule: "unapproved-word",
351
+ detail:
352
+ better === ""
353
+ ? `line ${unit.line}: "${word}" carries nothing a reader needs. Delete it.`
354
+ : `line ${unit.line}: "${word}" is not the approved word. Write "${better}".`,
355
+ });
356
+ }
357
+
358
+ if (config.headings && unit.kind === "heading") {
359
+ const capitals = headingProblems(unit.text, proper);
360
+ if (capitals.length > 0) {
361
+ problems.push({
362
+ path,
363
+ rule: "heading-case",
364
+ detail: `line ${unit.line}: a heading is sentence case. Lowercase ${capitals.map((word) => `"${word}"`).join(", ")}.`,
365
+ });
366
+ }
367
+ }
368
+
369
+ if (config.punctuation) {
370
+ if (EM_DASH.test(prose)) {
371
+ problems.push({
372
+ path,
373
+ rule: "em-dash",
374
+ detail: `line ${unit.line}: a dash holds two sentences in one. Use a full stop, a comma or a colon.`,
375
+ });
376
+ }
377
+ if (SEMICOLON.test(prose)) {
378
+ problems.push({
379
+ path,
380
+ rule: "semicolon",
381
+ detail: `line ${unit.line}: a semicolon joins two sentences. Write two sentences.`,
382
+ });
383
+ }
384
+ }
385
+
386
+ if (config.links && VAGUE_LINK.test(unit.text)) {
387
+ problems.push({
388
+ path,
389
+ rule: "link-text",
390
+ detail: `line ${unit.line}: link text says where to click, not what is there. Name the page.`,
391
+ });
392
+ }
393
+ }
394
+ }
395
+ return problems;
396
+ }
@@ -0,0 +1,210 @@
1
+ import { strict as assert } from "node:assert";
2
+ import { test } from "node:test";
3
+ import { checkPlainLanguage, markdownProse, sentences, stripInline } from "./plain-language.mjs";
4
+
5
+ const doc = (contents) => [{ path: "docs/a.md", contents }];
6
+ const only = (problems, rule) => problems.filter((problem) => problem.rule === rule);
7
+
8
+ test("a short active sentence in the approved words passes", () => {
9
+ const problems = checkPlainLanguage(doc("The gate reads the file and names the line.\n"));
10
+ assert.deepEqual(problems, []);
11
+ });
12
+
13
+ test("a description over the word limit fails and names the count", () => {
14
+ const long = `The gate counts ${"words ".repeat(30)}here.`;
15
+ const problems = only(checkPlainLanguage(doc(long)), "sentence-too-long");
16
+ assert.equal(problems.length, 1);
17
+ assert.match(problems[0].detail, /34 words in a description, max 25/);
18
+ });
19
+
20
+ test("a list item takes the shorter instruction limit", () => {
21
+ const item = `- Run the ${"step ".repeat(20)}now.\n`;
22
+ const problems = only(checkPlainLanguage(doc(item)), "sentence-too-long");
23
+ assert.equal(problems.length, 1);
24
+ assert.match(problems[0].detail, /in an instruction, max 20/);
25
+ });
26
+
27
+ test("a paragraph over the sentence limit fails once, at its first line", () => {
28
+ const problems = only(checkPlainLanguage(doc("One. Two. Three. Four. Five. Six. Seven.\n")), "paragraph-too-long");
29
+ assert.equal(problems.length, 1);
30
+ assert.match(problems[0].detail, /line 1: 7 sentences, max 6/);
31
+ });
32
+
33
+ test("an unapproved word fails and names the word that replaces it", () => {
34
+ const problems = only(checkPlainLanguage(doc("The runner will utilize the cache.\n")), "unapproved-word");
35
+ assert.equal(problems.length, 1);
36
+ assert.match(problems[0].detail, /"utilize" is not the approved word. Write "use"/);
37
+ });
38
+
39
+ test("a word that carries nothing is reported as a deletion", () => {
40
+ const problems = only(checkPlainLanguage(doc("This is simply the cache.\n")), "unapproved-word");
41
+ assert.equal(problems.length, 1);
42
+ assert.match(problems[0].detail, /Delete it/);
43
+ });
44
+
45
+ test("a multi-word phrase is found the same way a word is", () => {
46
+ const problems = only(checkPlainLanguage(doc("Run the check in order to find the line.\n")), "unapproved-word");
47
+ assert.equal(problems.length, 1);
48
+ assert.match(problems[0].detail, /"in order to"/);
49
+ });
50
+
51
+ test("a repository removes a word the kit ships by setting it to null", () => {
52
+ const problems = checkPlainLanguage(doc("The runner will utilize the cache.\n"), { replace: { utilize: null } });
53
+ assert.deepEqual(only(problems, "unapproved-word"), []);
54
+ });
55
+
56
+ test("the passive voice fails and quotes the phrase that hides the actor", () => {
57
+ const problems = only(checkPlainLanguage(doc("The file is read by the gate.\n")), "passive-voice");
58
+ assert.equal(problems.length, 1);
59
+ assert.match(problems[0].detail, /"is read" is passive/);
60
+ });
61
+
62
+ test("the passive check is switchable", () => {
63
+ const problems = checkPlainLanguage(doc("The file is read by the gate.\n"), { passive: false });
64
+ assert.deepEqual(only(problems, "passive-voice"), []);
65
+ });
66
+
67
+ test("a title-case heading fails and names each word to lowercase", () => {
68
+ const problems = only(checkPlainLanguage(doc("## How The Gate Reads\n")), "heading-case");
69
+ assert.equal(problems.length, 1);
70
+ assert.match(problems[0].detail, /"The", "Gate", "Reads"/);
71
+ });
72
+
73
+ test("a heading keeps the capital on a name", () => {
74
+ const problems = checkPlainLanguage(doc("## Working with TypeScript\n"));
75
+ assert.deepEqual(only(problems, "heading-case"), []);
76
+ });
77
+
78
+ test("a repository names its own proper nouns", () => {
79
+ const problems = checkPlainLanguage(doc("## Working with Fastly\n"), { properNouns: ["Fastly"] });
80
+ assert.deepEqual(only(problems, "heading-case"), []);
81
+ });
82
+
83
+ test("link text that says where to click, not what is there, fails", () => {
84
+ const problems = only(checkPlainLanguage(doc("Read [here](https://example.com) first.\n")), "link-text");
85
+ assert.equal(problems.length, 1);
86
+ });
87
+
88
+ test("a fenced block is code, not prose", () => {
89
+ const contents = `\`\`\`js\n// The runner will utilize ${"the cache ".repeat(20)}now.\n\`\`\`\n`;
90
+ assert.deepEqual(checkPlainLanguage(doc(contents)), []);
91
+ });
92
+
93
+ test("an inline code span counts as neither a word nor a capital", () => {
94
+ assert.deepEqual(checkPlainLanguage(doc("## Reading `Utilize.json`\n")), []);
95
+ });
96
+
97
+ test("a table row is data, not a sentence", () => {
98
+ const row = `| ${"word ".repeat(40)} | x |\n`;
99
+ assert.deepEqual(checkPlainLanguage(doc(row)), []);
100
+ });
101
+
102
+ test("front matter is metadata, not prose", () => {
103
+ assert.deepEqual(checkPlainLanguage(doc("---\ndescription: utilize the cache\n---\n\nThe gate runs.\n")), []);
104
+ });
105
+
106
+ test("a source file is read through its comments, not its code", () => {
107
+ const contents = '// The runner will utilize the cache\nconst label = "utilize";\n';
108
+ const problems = only(checkPlainLanguage([{ path: "src/a.mjs", contents }]), "unapproved-word");
109
+ assert.equal(problems.length, 1);
110
+ assert.equal(problems[0].detail.startsWith("line 1:"), true);
111
+ });
112
+
113
+ test("an allowed path is not read", () => {
114
+ const files = [{ path: "docs/legacy.md", contents: "The runner will utilize the cache.\n" }];
115
+ assert.deepEqual(checkPlainLanguage(files, { allow: ["docs/legacy.md"] }), []);
116
+ });
117
+
118
+ test("a stop inside an identifier does not end a sentence", () => {
119
+ assert.deepEqual(sentences("The file config.json holds the roots."), ["The file config.json holds the roots."]);
120
+ });
121
+
122
+ test("stripInline removes a link target and keeps its text", () => {
123
+ assert.equal(stripInline("Read [the guide](https://example.com) now.").includes("example.com"), false);
124
+ });
125
+
126
+ test("markdownProse labels a heading, an item and a paragraph line", () => {
127
+ const units = markdownProse("# Title\n\n- Step one\n\nA line.\n");
128
+ assert.deepEqual(units.map((unit) => unit.kind), ["heading", "item", "text"]);
129
+ });
130
+
131
+ test("a hard-wrapped sentence is counted once, not once a line", () => {
132
+ const wrapped = `The gate counts ${"words ".repeat(15)}\nand then it counts ${"more ".repeat(15)}here.\n`;
133
+ const problems = only(checkPlainLanguage(doc(wrapped)), "sentence-too-long");
134
+ assert.equal(problems.length, 1);
135
+ assert.match(problems[0].detail, /line 1: 3[0-9] words/);
136
+ });
137
+
138
+ test("a blank line ends a paragraph, so two short ones do not join", () => {
139
+ const problems = checkPlainLanguage(doc("One. Two. Three.\n\nFour. Five. Six.\n"));
140
+ assert.deepEqual(only(problems, "paragraph-too-long"), []);
141
+ });
142
+
143
+ test("a state that reads as a state is not reported as passive", () => {
144
+ const problems = checkPlainLanguage(doc("The branch is uncommitted.\n"));
145
+ assert.deepEqual(only(problems, "passive-voice"), []);
146
+ });
147
+
148
+ test("a numbered heading keeps the capital on its first real word", () => {
149
+ const problems = checkPlainLanguage(doc("### 1. Set up a repository\n"));
150
+ assert.deepEqual(only(problems, "heading-case"), []);
151
+ });
152
+
153
+ test("an em dash fails, because it holds two sentences in one", () => {
154
+ const problems = only(checkPlainLanguage(doc("The gate reads the file — it names the line.\n")), "em-dash");
155
+ assert.equal(problems.length, 1);
156
+ });
157
+
158
+ test("a spaced double hyphen reads as the same dash", () => {
159
+ const problems = only(checkPlainLanguage(doc("The gate reads the file -- it names the line.\n")), "em-dash");
160
+ assert.equal(problems.length, 1);
161
+ });
162
+
163
+ test("a hyphenated word is not a dash", () => {
164
+ assert.deepEqual(only(checkPlainLanguage(doc("The gate is well-known.\n")), "em-dash"), []);
165
+ });
166
+
167
+ test("a semicolon fails", () => {
168
+ const problems = only(checkPlainLanguage(doc("The gate reads it; the runner prints it.\n")), "semicolon");
169
+ assert.equal(problems.length, 1);
170
+ });
171
+
172
+ test("the punctuation check is switchable", () => {
173
+ const problems = checkPlainLanguage(doc("The gate reads it; it prints it.\n"), { punctuation: false });
174
+ assert.deepEqual(only(problems, "semicolon"), []);
175
+ });
176
+
177
+ test("a dash inside code is not prose", () => {
178
+ assert.deepEqual(checkPlainLanguage(doc("Run `qc check --fix` now.\n")), []);
179
+ });
180
+
181
+
182
+ test("runCheck reads the configured prose roots only when enabled", async (t) => {
183
+ const { mkdtempSync, mkdirSync, writeFileSync, rmSync } = await import("node:fs");
184
+ const { tmpdir } = await import("node:os");
185
+ const { join } = await import("node:path");
186
+ const { execFileSync } = await import("node:child_process");
187
+ const { defaults, merge } = await import("../config.mjs");
188
+ const { runCheck } = await import("../cli/check.mjs");
189
+ const root = mkdtempSync(join(tmpdir(), "qc-prose-"));
190
+ t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
191
+ execFileSync("git", ["init", "-q"], { cwd: root });
192
+ mkdirSync(join(root, "prose"));
193
+ writeFileSync(join(root, "prose", "note.md"), "The runner will utilize the cache.\n");
194
+ writeFileSync(join(root, "outside.md"), "The runner will utilize the cache.\n");
195
+ const config = { ...merge(defaults, {
196
+ featureRoots: [],
197
+ gates: Object.fromEntries(Object.keys(defaults.gates).map((name) => [name, false])),
198
+ plainLanguage: { roots: ["prose"] },
199
+ }), root };
200
+ assert.equal(defaults.gates["plain-language"], false);
201
+ const off = await runCheck(config);
202
+ assert.deepEqual(off.problems, []);
203
+ assert.ok(off.lines.every((line) => !line.startsWith("OK prose")));
204
+ config.gates["plain-language"] = true;
205
+ const on = await runCheck(config);
206
+ assert.deepEqual(on.problems.map(({ path, rule }) => ({ path, rule })), [
207
+ { path: "prose/note.md", rule: "unapproved-word" },
208
+ ]);
209
+ assert.ok(on.lines.some((line) => line.startsWith("OK prose")));
210
+ });