dislop 0.9.0 → 1.0.1

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 (124) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/.codex-plugin/plugin.json +7 -8
  4. package/.cursor-plugin/plugin.json +2 -3
  5. package/.pre-commit-hooks.yaml +5 -12
  6. package/PRODUCT.md +19 -57
  7. package/README.md +360 -252
  8. package/README.zh-CN.md +390 -240
  9. package/action.yml +30 -39
  10. package/bin/dislop-mcp.mjs +3 -4
  11. package/bin/dislop.mjs +4 -4582
  12. package/gemini-extension.json +2 -2
  13. package/llms-install.md +68 -0
  14. package/package.json +17 -55
  15. package/packs/common/artifact-qa/pack.json +5 -0
  16. package/packs/common/artifact-qa/prompts/rules.md +11 -0
  17. package/packs/common/artifact-qa/scripts/index.mjs +173 -0
  18. package/packs/common/slide-deck/pack.json +6 -0
  19. package/packs/common/slide-deck/prompts/rules.md +11 -0
  20. package/packs/common/slide-deck/scripts/index.mjs +62 -0
  21. package/packs/common/web-ui/pack.json +6 -0
  22. package/packs/common/web-ui/prompts/rules.md +11 -0
  23. package/packs/common/web-ui/scripts/index.mjs +80 -0
  24. package/packs/en/artifact-qa/pack.json +6 -0
  25. package/packs/en/artifact-qa/prompts/rules.md +14 -0
  26. package/packs/en/artifact-qa/scripts/index.mjs +90 -0
  27. package/packs/en/prose/pack.json +7 -0
  28. package/packs/en/prose/prompts/rules.md +26 -0
  29. package/packs/en/prose/scripts/index.mjs +290 -0
  30. package/packs/en/slide-deck/pack.json +7 -0
  31. package/packs/en/slide-deck/prompts/rules.md +17 -0
  32. package/packs/en/slide-deck/scripts/index.mjs +81 -0
  33. package/packs/en/web-ui/pack.json +7 -0
  34. package/packs/en/web-ui/prompts/rules.md +20 -0
  35. package/packs/en/web-ui/scripts/index.mjs +103 -0
  36. package/packs/zh/artifact-qa/pack.json +6 -0
  37. package/packs/zh/artifact-qa/prompts/rules.md +14 -0
  38. package/packs/zh/artifact-qa/scripts/index.mjs +89 -0
  39. package/packs/zh/prose/pack.json +7 -0
  40. package/packs/zh/prose/prompts/rules.md +26 -0
  41. package/packs/zh/prose/scripts/index.mjs +305 -0
  42. package/packs/zh/slide-deck/pack.json +7 -0
  43. package/packs/zh/slide-deck/prompts/rules.md +17 -0
  44. package/packs/zh/slide-deck/scripts/index.mjs +75 -0
  45. package/packs/zh/web-ui/pack.json +7 -0
  46. package/packs/zh/web-ui/prompts/rules.md +20 -0
  47. package/packs/zh/web-ui/scripts/index.mjs +98 -0
  48. package/plugin.json +5 -6
  49. package/server.json +8 -2
  50. package/skills/deslop-docs/SKILL.md +10 -8
  51. package/skills/deslop-slides-docx/SKILL.md +7 -8
  52. package/skills/deslop-verify/SKILL.md +7 -8
  53. package/skills/deslop-web-ui/SKILL.md +7 -8
  54. package/skills/dislop/SKILL.md +16 -28
  55. package/skills/dislop/references/essay.md +1 -1
  56. package/skills/dislop/references/essay.zh-CN.md +1 -1
  57. package/skills/dislop/references/office.md +1 -1
  58. package/skills/dislop/references/office.zh-CN.md +1 -1
  59. package/skills/dislop/references/web-ui.md +1 -1
  60. package/skills/dislop/references/web-ui.zh-CN.md +1 -1
  61. package/skills/dislop/references/work-docs.md +1 -1
  62. package/skills/dislop/references/work-docs.zh-CN.md +1 -1
  63. package/src/cli-main.mjs +210 -0
  64. package/src/commands/check-fix.mjs +169 -0
  65. package/src/commands/doctor.mjs +110 -0
  66. package/src/commands/init.mjs +49 -0
  67. package/src/commands/login.mjs +82 -0
  68. package/src/commands/model.mjs +130 -0
  69. package/src/commands/packs.mjs +44 -0
  70. package/src/commands/verify.mjs +133 -0
  71. package/src/commands/voice.mjs +84 -0
  72. package/src/kernel/config.mjs +232 -0
  73. package/src/kernel/document-model.mjs +1412 -0
  74. package/src/kernel/fact-gate.mjs +615 -0
  75. package/src/kernel/file-discovery.mjs +139 -0
  76. package/src/{binary-node.mjs → kernel/ooxml-binary.mjs} +532 -893
  77. package/src/kernel/pack-loader.mjs +715 -0
  78. package/src/kernel/patcher.mjs +341 -0
  79. package/src/kernel/pipeline.mjs +267 -0
  80. package/src/kernel/prompt-assembler.mjs +307 -0
  81. package/src/kernel/voice-profile.mjs +177 -0
  82. package/src/mcp/stdio-server.mjs +372 -0
  83. package/src/runners/auto-fix.mjs +59 -0
  84. package/src/runners/interactive-tty.mjs +461 -0
  85. package/src/runners/reporters.mjs +256 -0
  86. package/src/runtime/chunker.mjs +87 -0
  87. package/src/runtime/json-extract.mjs +144 -0
  88. package/src/runtime/privacy-gate.mjs +97 -0
  89. package/src/runtime/providers/anthropic.mjs +65 -0
  90. package/src/runtime/providers/cloud.mjs +136 -0
  91. package/src/runtime/providers/gemini.mjs +91 -0
  92. package/src/runtime/providers/local-model.mjs +139 -0
  93. package/src/runtime/providers/openai-compat.mjs +130 -0
  94. package/src/runtime/router.mjs +315 -0
  95. package/src/sdk/index.mjs +137 -0
  96. package/models/manifest.json +0 -90
  97. package/models/pocket-slop-v1.json +0 -1
  98. package/packs/business-brief/pack.json +0 -937
  99. package/packs/core/pack.json +0 -209
  100. package/packs/deck-and-ui/pack.json +0 -539
  101. package/packs/engineering-spec/pack.json +0 -144
  102. package/packs/executive-deck/pack.json +0 -98
  103. package/packs/literary-essay/pack.json +0 -344
  104. package/packs/regulated-comms/pack.json +0 -99
  105. package/patterns/ai-tic-rubric.json +0 -252
  106. package/patterns/banks/composite-fusion.json +0 -48
  107. package/patterns/banks/discourse-rhythm.json +0 -95
  108. package/patterns/banks/lexical-signals.json +0 -92
  109. package/patterns/banks/syntactic-frames.json +0 -52
  110. package/patterns/banks/visual-deck.json +0 -44
  111. package/patterns/dimensions/artifacts.json +0 -121
  112. package/patterns/dimensions/discourse.json +0 -438
  113. package/patterns/dimensions/lexical.json +0 -198
  114. package/patterns/dimensions/rhythm.json +0 -258
  115. package/patterns/dimensions/syntactic.json +0 -285
  116. package/patterns/dimensions/visual-and-deck.json +0 -530
  117. package/patterns/taxonomy.json +0 -112
  118. package/src/core.mjs +0 -5497
  119. package/src/dislop/review-picker.vim +0 -114
  120. package/src/local-model.mjs +0 -997
  121. package/src/pattern-engine.mjs +0 -1003
  122. package/src/pocket-model.mjs +0 -729
  123. package/src/review-apply.mjs +0 -151
  124. package/src/review-client.mjs +0 -1073
@@ -1,1003 +0,0 @@
1
- /**
2
- * dislop AI-Slop Pattern Library Multi-Angle Detection Engine (zero external dependencies).
3
- * Data-driven from `patterns/banks/*.json`.
4
- * Mirrors `src/dislop/pattern_engine.py` with 100% deterministic parity.
5
- */
6
- import {
7
- buildLineStarts,
8
- buildZones,
9
- deriveFixStrategy,
10
- detectModality,
11
- fnv1aHex,
12
- isAllowedMatch,
13
- isSentenceBreakAt,
14
- offsetToLineCol,
15
- parseSuppressions,
16
- sliceCodepoints,
17
- stripParentheticals,
18
- } from "./core.mjs";
19
-
20
- export const PATTERN_ENGINE_VERSION = "1.0.0";
21
-
22
- const TEXT_MODALITIES = new Set(["markdown", "text", "html", "docx"]);
23
- const UI_MODALITIES = new Set(["html", "css", "jsx"]);
24
-
25
- function blankPreserveLines(s) {
26
- return s.replace(/[^\r\n]/g, " ");
27
- }
28
-
29
- function maskUiMarkup(rawText) {
30
- return String(rawText || "")
31
- .replace(/\uFEFF/g, " ")
32
- .replace(/<!--\s*dislop-quote-start\s*-->[\s\S]*?<!--\s*dislop-quote-end\s*-->/gi, blankPreserveLines)
33
- .replace(/<!--[\s\S]*?-->/g, blankPreserveLines)
34
- .replace(/\/\*[\s\S]*?\*\//g, blankPreserveLines)
35
- .replace(/<(script|code|pre)\b[^>]*>[\s\S]*?<\/\1>/gi, blankPreserveLines);
36
- }
37
-
38
- // ---------- Shared Linguistic Measurement Helpers ----------
39
-
40
- function stripFormattedNumbersAndCode(s) {
41
- return String(s || "")
42
- .replace(/\d{1,3}(?:,\d{3})+/g, "0")
43
- .replace(/`[^`\n]+`/g, "CODE");
44
- }
45
-
46
- export function detectPrimaryLang(s) {
47
- const cjk = (s.match(/[\u4e00-\u9fff]/gu) || []).length;
48
- const enWords = s.split(/\s+/).filter((w) => /[A-Za-z]/.test(w)).length;
49
- return cjk >= enWords * 2 ? "zh" : "en";
50
- }
51
-
52
- export function measureUnits(text, lang) {
53
- const clean = stripFormattedNumbersAndCode(text).replace(/[.!?。!?]+$/u, "").trim();
54
- const cjk = (clean.match(/[\u4e00-\u9fff]/gu) || []).length;
55
- const enWords = clean.split(/\s+/).filter((w) => /[A-Za-z0-9]/.test(w)).length;
56
- return lang === "zh" ? cjk + Math.round(enWords * 1.5) : enWords + Math.round(cjk * 0.6);
57
- }
58
-
59
- function isSkippableProseBlock(trimmed) {
60
- return !trimmed || /^(?:#{1,6}\s|[-*+]\s|\d+[.)]\s|\||>)/.test(trimmed);
61
- }
62
-
63
- function iterProseParagraphs(proseText) {
64
- const out = [];
65
- const re = /[^\n]+(?:\n(?!\s*\n)[^\n]+)*/g;
66
- let m;
67
- while ((m = re.exec(proseText)) !== null) {
68
- const raw = m[0];
69
- const trimmed = raw.trim();
70
- const firstNonWs = raw.search(/\S/);
71
- out.push({
72
- raw,
73
- trimmed,
74
- index: m.index + (firstNonWs >= 0 ? firstNonWs : 0),
75
- blockStart: m.index,
76
- skippable: isSkippableProseBlock(trimmed),
77
- });
78
- }
79
- return out;
80
- }
81
-
82
- function escapeRegExp(str) {
83
- return String(str).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
84
- }
85
-
86
- function makePatternFinding({
87
- ruleId,
88
- dimension,
89
- detectionAngle,
90
- severity = "info",
91
- filename,
92
- modality,
93
- line = 1,
94
- col = 1,
95
- location = null,
96
- match,
97
- metric = "",
98
- message,
99
- deletionTest = null,
100
- }) {
101
- const loc = location || `${line}:${col}`;
102
- const cleanMatch = sliceCodepoints(String(match || "").replace(/\s+/g, " ").trim(), 140);
103
- const fp = `${ruleId}:${fnv1aHex(`${ruleId}|${cleanMatch.toLowerCase()}|${loc}`)}`;
104
- return {
105
- fingerprint: fp,
106
- ruleId,
107
- source: "pattern-library",
108
- dimension,
109
- detectionAngle,
110
- severity,
111
- fixStrategy: deriveFixStrategy({ id: ruleId, severity }),
112
- file: filename,
113
- modality,
114
- location: loc,
115
- line,
116
- col,
117
- match: cleanMatch,
118
- metric,
119
- message,
120
- ...(deletionTest ? { deletionTest } : {}),
121
- };
122
- }
123
-
124
- function iterSentenceSpansInPara(rawPara) {
125
- const spans = [];
126
- let start = 0;
127
- for (let i = 0; i < rawPara.length; i += 1) {
128
- if (rawPara[i] === "\n") {
129
- start = i + 1;
130
- continue;
131
- }
132
- if (isSentenceBreakAt(rawPara, i)) {
133
- const text = rawPara.slice(start, i + 1);
134
- if (text.trim().length > 0) {
135
- spans.push({ text, index: start });
136
- }
137
- start = i + 1;
138
- }
139
- }
140
- return spans;
141
- }
142
-
143
- // ---------- Angle: Rhythm & Cadence Statistics ----------
144
-
145
- function probeCommaChain(proseText, rawText, cfg) {
146
- const hits = [];
147
- for (const para of iterProseParagraphs(proseText)) {
148
- if (para.skippable) continue;
149
- for (const sm of iterSentenceSpansInPara(para.raw)) {
150
- const sent = sm.text;
151
- const normalized = stripFormattedNumbersAndCode(sent);
152
- const lang = detectPrimaryLang(normalized);
153
- const noParens = stripParentheticals(normalized);
154
- const commas = noParens.match(/[,,]/g) || [];
155
- if (commas.length < (cfg.minCommas || 5)) continue;
156
-
157
- const clauses = noParens
158
- .split(/[,,]/)
159
- .map((c) => c.trim())
160
- .filter(Boolean);
161
- const langCfg = lang === "zh" ? cfg.zh : cfg.en;
162
- const lens = clauses.map((c) => measureUnits(c, lang));
163
- const longClauses = lens.filter((n) => n >= langCfg.minClauseUnits).length;
164
- const avgUnits = lens.reduce((a, b) => a + b, 0) / Math.max(1, lens.length);
165
-
166
- if (longClauses >= (cfg.minLongClauses || 4) && avgUnits >= langCfg.minAvgClauseUnits) {
167
- const leadWs = sent.search(/\S/);
168
- const startOffset = para.blockStart + sm.index + (leadWs >= 0 ? leadWs : 0);
169
- const rawSlice = rawText.slice(startOffset, startOffset + sent.trim().length);
170
- const linkCount = (rawSlice.match(/\]\(/g) || []).length;
171
- if (linkCount > (cfg.maxMarkdownLinks ?? 2)) continue;
172
- hits.push({
173
- index: startOffset,
174
- length: sent.trim().length,
175
- metric: `lang=${lang}, commas=${commas.length}, avgUnits=${avgUnits.toFixed(1)}`,
176
- });
177
- }
178
- }
179
- }
180
- return hits;
181
- }
182
-
183
- function probeSentenceLengthMonotony(proseText, cfg) {
184
- const hits = [];
185
- for (const para of iterProseParagraphs(proseText)) {
186
- if (para.skippable) continue;
187
- const lang = detectPrimaryLang(para.trimmed);
188
- const lengths = [];
189
- for (const sm of iterSentenceSpansInPara(para.raw)) {
190
- const u = measureUnits(sm.text, lang);
191
- if (u >= (cfg.minSentenceUnits || 4)) lengths.push(u);
192
- }
193
- if (lengths.length < (cfg.minSentences || 5)) continue;
194
- const mean = lengths.reduce((a, b) => a + b, 0) / lengths.length;
195
- const minMean = lang === "zh" ? cfg.minMeanUnitsZh || 14 : cfg.minMeanUnitsEn || 10;
196
- if (mean < minMean) continue;
197
- const variance = lengths.reduce((acc, x) => acc + (x - mean) ** 2, 0) / lengths.length;
198
- const cv = Math.sqrt(variance) / mean;
199
- if (cv < (cfg.maxCv || 0.16)) {
200
- hits.push({
201
- index: para.index,
202
- length: Math.min(para.trimmed.length, 100),
203
- metric: `lang=${lang}, sentences=${lengths.length}, mean=${mean.toFixed(1)}, cv=${cv.toFixed(3)}`,
204
- });
205
- }
206
- }
207
- return hits;
208
- }
209
-
210
- function extractSentenceOpener(sentence, lang, cfg) {
211
- const clean = sentence.trim().replace(/^["'“‘((]+/, "");
212
- if (!clean) return "";
213
- if (lang === "zh") {
214
- const m = clean.match(/^([\u4e00-\u9fff]{2,3})/);
215
- if (!m) return "";
216
- return m[1].slice(0, cfg.minOpenerCharsZh || 2);
217
- }
218
- const words = clean
219
- .toLowerCase()
220
- .replace(/[^a-z0-9\s'-]/g, " ")
221
- .trim()
222
- .split(/\s+/)
223
- .filter(Boolean);
224
- const need = cfg.minOpenerWordsEn || 2;
225
- if (words.length < need + 1) return "";
226
- return words.slice(0, need).join(" ");
227
- }
228
-
229
- function probeOpenerAnaphora(proseText, cfg) {
230
- const hits = [];
231
- const minRun = cfg.minConsecutive || 4;
232
- for (const para of iterProseParagraphs(proseText)) {
233
- if (para.skippable) continue;
234
- const lang = detectPrimaryLang(para.trimmed);
235
- const sentences = [];
236
- for (const sm of iterSentenceSpansInPara(para.raw)) {
237
- const s = sm.text.trim();
238
- const opener = extractSentenceOpener(s, lang, cfg);
239
- const lead = sm.text.search(/\S/);
240
- sentences.push({
241
- opener,
242
- start: para.blockStart + sm.index + (lead >= 0 ? lead : 0),
243
- end: para.blockStart + sm.index + (lead >= 0 ? lead : 0) + s.length,
244
- });
245
- }
246
- let runKey = "";
247
- let runStart = 0;
248
- let runLen = 0;
249
- for (let i = 0; i <= sentences.length; i += 1) {
250
- const cur = sentences[i];
251
- if (cur && cur.opener && cur.opener === runKey) {
252
- runLen += 1;
253
- } else {
254
- if (runLen >= minRun && runKey) {
255
- const first = sentences[runStart];
256
- const last = sentences[i - 1];
257
- hits.push({
258
- index: first.start,
259
- length: Math.min(120, last.end - first.start),
260
- metric: `opener="${runKey}", consecutive=${runLen}`,
261
- });
262
- }
263
- runKey = cur?.opener || "";
264
- runStart = i;
265
- runLen = runKey ? 1 : 0;
266
- }
267
- }
268
- }
269
- return hits;
270
- }
271
-
272
- function probeInlineBoldSaturation(proseText, rawText, cfg) {
273
- const hits = [];
274
- const minSpans = cfg.minBoldSpans || 4;
275
- for (const para of iterProseParagraphs(proseText)) {
276
- if (para.skippable) continue;
277
- const rawSlice = rawText.slice(para.blockStart, para.blockStart + para.raw.length);
278
- // Only inspect genuine markdown prose paragraphs (skip lines that are mostly list/table)
279
- if (/^\s*(?:#{1,6}\s|[-*+]\s|\d+[.)]\s|\||>)/m.test(rawSlice)) continue;
280
- const boldMatches = [];
281
- const boldRe = /\*\*([^*\n`]{1,40})\*\*/g;
282
- let bm;
283
- while ((bm = boldRe.exec(rawSlice)) !== null) {
284
- // Ensure this span isn't inside masked code zone
285
- const proseSpan = para.raw.slice(bm.index, bm.index + bm[0].length);
286
- if (proseSpan.trim().length > 0) {
287
- boldMatches.push({ index: para.blockStart + bm.index, length: bm[0].length });
288
- }
289
- }
290
- if (boldMatches.length < minSpans) continue;
291
- const lang = detectPrimaryLang(para.trimmed);
292
- const plainLen =
293
- lang === "zh"
294
- ? (para.trimmed.match(/[\u4e00-\u9fff]/gu) || []).length
295
- : para.trimmed.split(/\s+/).filter((w) => /[A-Za-z0-9]/.test(w)).length;
296
- const ratio = plainLen / boldMatches.length;
297
- const maxPerBold = lang === "zh" ? cfg.maxCjkPerBoldZh || 55 : cfg.maxWordsPerBoldEn || 28;
298
- if (ratio <= maxPerBold) {
299
- hits.push({
300
- index: boldMatches[0].index,
301
- length: Math.min(100, para.trimmed.length),
302
- metric: `lang=${lang}, boldSpans=${boldMatches.length}, unitsPerBold=${ratio.toFixed(1)}`,
303
- });
304
- }
305
- }
306
- return hits;
307
- }
308
-
309
- function probeParagraphLengthUniformity(proseText, cfg) {
310
- const paras = iterProseParagraphs(proseText).filter((p) => !p.skippable);
311
- if (paras.length < (cfg.minParagraphs || 5)) return [];
312
- const lang = detectPrimaryLang(proseText);
313
- const scored = paras
314
- .map((p) => ({ para: p, units: measureUnits(p.trimmed, lang) }))
315
- .filter((x) => x.units >= 15);
316
- if (scored.length < (cfg.minParagraphs || 5)) return [];
317
- const mean = scored.reduce((a, x) => a + x.units, 0) / scored.length;
318
- if (mean < (cfg.minMeanUnits || 35)) return [];
319
- const variance = scored.reduce((acc, x) => acc + (x.units - mean) ** 2, 0) / scored.length;
320
- const cv = Math.sqrt(variance) / mean;
321
- if (cv < (cfg.maxCv || 0.13)) {
322
- return [
323
- {
324
- index: scored[0].para.index,
325
- length: Math.min(100, scored[0].para.trimmed.length),
326
- metric: `lang=${lang}, paragraphs=${scored.length}, mean=${mean.toFixed(1)}, cv=${cv.toFixed(3)}`,
327
- },
328
- ];
329
- }
330
- return [];
331
- }
332
-
333
- // ---------- Angle: Discourse Signpost Cluster ----------
334
-
335
- function probeDiscourseMarkerCluster(proseText, cfg) {
336
- const hits = [];
337
- const zhAlts = (cfg.zhLeadMarkers || []).map(escapeRegExp).join("|");
338
- const enAlts = (cfg.enLeadMarkers || []).map(escapeRegExp).join("|");
339
- const zhLeadRe = zhAlts ? new RegExp(`^(?:${zhAlts})[,,::\\s]`, "u") : null;
340
- const enLeadRe = enAlts ? new RegExp(`^(?:${enAlts})[,\\s]`, "i") : null;
341
- const zhInnerRe = zhAlts ? new RegExp(`(?:^|[。!?;\\n]\\s*)(?:${zhAlts})[,,::]`, "gu") : null;
342
- const enInnerRe = enAlts ? new RegExp(`(?:^|[.!?;]\\s+)(?:${enAlts}),`, "gi") : null;
343
-
344
- const paras = iterProseParagraphs(proseText).map((p) => {
345
- if (p.skippable) return { ...p, isMarked: false };
346
- const isMarked = Boolean((zhLeadRe && zhLeadRe.test(p.trimmed)) || (enLeadRe && enLeadRe.test(p.trimmed)));
347
- return { ...p, isMarked };
348
- });
349
-
350
- const minParas = cfg.minConsecutiveParagraphs || 3;
351
- let runStart = -1;
352
- let runCount = 0;
353
- for (let i = 0; i <= paras.length; i += 1) {
354
- const cur = paras[i];
355
- if (cur && cur.isMarked) {
356
- if (runCount === 0) runStart = i;
357
- runCount += 1;
358
- } else {
359
- if (runCount >= minParas) {
360
- const first = paras[runStart];
361
- hits.push({
362
- index: first.index,
363
- length: Math.min(80, first.trimmed.length),
364
- metric: `consecutiveMarkedParagraphs=${runCount}`,
365
- });
366
- }
367
- runCount = 0;
368
- }
369
- }
370
-
371
- const minInPara = cfg.minMarkersInParagraph || 3;
372
- for (const p of paras) {
373
- if (p.skippable) continue;
374
- const zhHits = zhInnerRe ? (p.trimmed.match(zhInnerRe) || []).length : 0;
375
- const enHits = enInnerRe ? (p.trimmed.match(enInnerRe) || []).length : 0;
376
- const total = zhHits + enHits;
377
- if (total >= minInPara && !hits.some((h) => h.index === p.index)) {
378
- hits.push({
379
- index: p.index,
380
- length: Math.min(80, p.trimmed.length),
381
- metric: `markersInParagraph=${total}`,
382
- });
383
- }
384
- }
385
- return hits;
386
- }
387
-
388
- // ---------- Angle: Weighted Lexical & Calque Cluster ----------
389
-
390
- function probeLexicalCluster(proseText, cfg) {
391
- const hits = [];
392
- const compiled = (cfg.signals || []).map((s) => ({
393
- id: s.id,
394
- weight: Number(s.weight ?? 1.0),
395
- re: new RegExp(s.pattern, "iu"),
396
- }));
397
- const minDistinct = cfg.minDistinctHits || 2;
398
- const minScore = cfg.minWeightedScore ?? minDistinct;
399
-
400
- for (const para of iterProseParagraphs(proseText)) {
401
- if (para.skippable) continue;
402
- const matched = [];
403
- let score = 0;
404
- let firstIdx = -1;
405
- let firstLen = 0;
406
- for (const sig of compiled) {
407
- const m = sig.re.exec(para.raw);
408
- if (m) {
409
- matched.push(sig.id);
410
- score += sig.weight;
411
- const absIdx = para.blockStart + m.index;
412
- if (firstIdx === -1 || absIdx < firstIdx) {
413
- firstIdx = absIdx;
414
- firstLen = m[0].length;
415
- }
416
- }
417
- }
418
- if (matched.length >= minDistinct && score >= minScore && firstIdx !== -1) {
419
- hits.push({
420
- index: firstIdx,
421
- length: Math.max(firstLen, Math.min(100, para.trimmed.length)),
422
- metric: `signals=${matched.length}, score=${score.toFixed(1)}, ids=${matched.slice(0, 4).join("+")}`,
423
- });
424
- }
425
- }
426
- return hits;
427
- }
428
-
429
- // ---------- Angle: Syntactic & Rhetorical Frames ----------
430
-
431
- function isInsideQuotation(text, start, end) {
432
- const before = text.slice(Math.max(0, start - 32), start);
433
- const after = text.slice(end, Math.min(text.length, end + 16));
434
- const openZh = (before.match(/“/g) || []).length - (before.match(/”/g) || []).length;
435
- if (openZh > 0 && /”/.test(after)) return true;
436
- const openCorner = (before.match(/「/g) || []).length - (before.match(/」/g) || []).length;
437
- if (openCorner > 0 && /」/.test(after)) return true;
438
- if (/(?:例如|比如|如)\s*[“"「]?$/.test(before)) return true;
439
- return false;
440
- }
441
-
442
- function probeProseRegexPatterns(proseText, patterns = [], { skipQuoted = false } = {}) {
443
- const hits = [];
444
- const compiled = patterns.map((p) => new RegExp(p, "giu"));
445
- for (const para of iterProseParagraphs(proseText)) {
446
- if (para.skippable) continue;
447
- for (const re of compiled) {
448
- re.lastIndex = 0;
449
- let m;
450
- while ((m = re.exec(para.raw)) !== null) {
451
- if (m[0].length === 0) {
452
- re.lastIndex += 1;
453
- continue;
454
- }
455
- let idx = para.blockStart + m.index;
456
- let len = m[0].length;
457
- const lead = m[0].match(/^[.!?。!?\s]+/);
458
- if (lead && lead[0].length < len) {
459
- idx += lead[0].length;
460
- len -= lead[0].length;
461
- }
462
- if (skipQuoted && isInsideQuotation(proseText, idx, idx + len)) {
463
- continue;
464
- }
465
- hits.push({ index: idx, length: len, metric: `matchedLen=${len}` });
466
- }
467
- }
468
- }
469
- // Deduplicate overlapping hits
470
- hits.sort((a, b) => a.index - b.index || b.length - a.length);
471
- const dedup = [];
472
- for (const h of hits) {
473
- const prev = dedup[dedup.length - 1];
474
- if (prev && h.index < prev.index + prev.length) continue;
475
- dedup.push(h);
476
- }
477
- return dedup;
478
- }
479
-
480
- // ---------- Angle: Visual / UI & PPTX Structural Templates ----------
481
-
482
- function probeUiPatternCount(rawText, cfg) {
483
- const clean = maskUiMarkup(rawText);
484
- const re = new RegExp(cfg.pattern, "gi");
485
- const exemptRe = cfg.exemptPattern ? new RegExp(cfg.exemptPattern, "i") : null;
486
- const lookbehind = cfg.exemptLookbehindChars || 48;
487
- const matches = [];
488
- let m;
489
- while ((m = re.exec(clean)) !== null) {
490
- if (exemptRe) {
491
- const before = clean.slice(Math.max(0, m.index - lookbehind), m.index);
492
- if (exemptRe.test(before)) continue;
493
- }
494
- matches.push({ index: m.index, length: m[0].length });
495
- }
496
- const minOcc = cfg.minOccurrences || 3;
497
- if (matches.length >= minOcc) {
498
- return [{ index: matches[0].index, length: matches[0].length, metric: `occurrences=${matches.length}` }];
499
- }
500
- return [];
501
- }
502
-
503
- function decodeXmlSimple(s) {
504
- return String(s || "")
505
- .replace(/&lt;/g, "<")
506
- .replace(/&gt;/g, ">")
507
- .replace(/&quot;/g, '"')
508
- .replace(/&apos;/g, "'")
509
- .replace(/&amp;/g, "&");
510
- }
511
-
512
- function resolveOrderedSlides(entries) {
513
- const presXml = entries["ppt/presentation.xml"] || "";
514
- const presRels = entries["ppt/_rels/presentation.xml.rels"] || "";
515
- const relMap = new Map();
516
- const relRe =
517
- /<Relationship\b[^>]*\bId="([^"]+)"[^>]*\bTarget="([^"]+)"|<Relationship\b[^>]*\bTarget="([^"]+)"[^>]*\bId="([^"]+)"/g;
518
- let rm;
519
- while ((rm = relRe.exec(presRels)) !== null) {
520
- const id = rm[1] || rm[4];
521
- const rawTarget = (rm[2] || rm[3] || "").replace(/^\/+/, "").replace(/^\.\.\//, "ppt/");
522
- const target = rawTarget.startsWith("ppt/") ? rawTarget : `ppt/${rawTarget}`;
523
- relMap.set(id, target);
524
- }
525
- const ordered = [];
526
- const sldIdRe = /<p:sldId\b[^>]*\br:id="([^"]+)"/g;
527
- let sm;
528
- while ((sm = sldIdRe.exec(presXml)) !== null) {
529
- const target = relMap.get(sm[1]);
530
- if (target && entries[target]) ordered.push(target);
531
- }
532
- if (ordered.length === 0) {
533
- const fallback = Object.keys(entries)
534
- .filter((k) => /^ppt\/slides\/slide\d+\.xml$/.test(k))
535
- .sort((a, b) => Number(a.match(/\d+/)[0]) - Number(b.match(/\d+/)[0]));
536
- ordered.push(...fallback);
537
- }
538
- return ordered;
539
- }
540
-
541
- function probePptxLayoutMonotony(ooxmlEntries, cfg) {
542
- if (!ooxmlEntries || typeof ooxmlEntries !== "object") return [];
543
- const slides = resolveOrderedSlides(ooxmlEntries);
544
- const contentSlides = [];
545
- const minWords = cfg.minSlideLatinWords || 12;
546
- const minCjk = cfg.minSlideCjkChars || 25;
547
-
548
- slides.forEach((entryKey, idx) => {
549
- const slideNum = idx + 1;
550
- const xml = String(ooxmlEntries[entryKey] || "");
551
- if (/<p:sld\b[^>]*\bshow="0"/.test(xml)) return;
552
-
553
- const textParts = [];
554
- let bodyTextShapes = 0;
555
- let hasBullets = false;
556
- const spRe = /<p:sp\b[\s\S]*?<\/p:sp>/g;
557
- let spm;
558
- while ((spm = spRe.exec(xml)) !== null) {
559
- const sp = spm[0];
560
- const isTitle = /<p:ph\b[^>]*\btype="(?:title|ctrTitle)"/.test(sp);
561
- const isFooter = /<p:ph\b[^>]*\btype="(?:sldNum|ftr|dt)"/.test(sp);
562
- if (isFooter) continue;
563
- const runs = [];
564
- const tRe = /<a:t(?:\s[^>]*)?>([\s\S]*?)<\/a:t>/g;
565
- let tm;
566
- while ((tm = tRe.exec(sp)) !== null) {
567
- runs.push(decodeXmlSimple(tm[1]));
568
- }
569
- const joined = runs.join("").trim();
570
- if (!joined) continue;
571
- textParts.push(joined);
572
- if (!isTitle) {
573
- bodyTextShapes += 1;
574
- if (/<a:buChar\b|<a:buAutoNum\b/.test(sp)) hasBullets = true;
575
- }
576
- }
577
- const full = textParts.join(" ");
578
- const cjk = (full.match(/[\u4e00-\u9fff]/gu) || []).length;
579
- const latin = full.split(/\s+/).filter((w) => /[A-Za-z0-9]/.test(w)).length;
580
- const hasVisual = /<c:chart\b|<a:tbl\b|<p:pic\b/.test(xml);
581
- if (!hasVisual && latin < minWords && cjk < minCjk) return;
582
-
583
- const isPlainBulletOnly = !hasVisual && hasBullets && bodyTextShapes <= 1;
584
- contentSlides.push({ slideNum, isPlainBulletOnly });
585
- });
586
-
587
- if (contentSlides.length < (cfg.minContentSlides || 5)) return [];
588
- const needRun = cfg.minConsecutivePlainBulletSlides || 4;
589
- let run = 0;
590
- for (const s of contentSlides) {
591
- if (s.isPlainBulletOnly) {
592
- run += 1;
593
- if (run === needRun) {
594
- return [
595
- {
596
- slideNum: s.slideNum,
597
- match: `${needRun}+ consecutive plain-bullet slides (out of ${contentSlides.length} content slides)`,
598
- metric: `contentSlides=${contentSlides.length}, consecutivePlainBullet=${run}`,
599
- },
600
- ];
601
- }
602
- } else {
603
- run = 0;
604
- }
605
- }
606
- return [];
607
- }
608
-
609
- // ---------- Angle: Multi-Dimension Composite Stealth-Slop Fusion ----------
610
-
611
- function countConcreteFacts(rawSlice, factRes) {
612
- let count = 0;
613
- for (const re of factRes) {
614
- re.lastIndex = 0;
615
- const m = rawSlice.match(re);
616
- if (m) count += m.length;
617
- }
618
- return count;
619
- }
620
-
621
- function probeCompositeMultiSignal(proseText, rawText, banks, existingFindings) {
622
- const comp = banks["composite-fusion"];
623
- if (!comp) return [];
624
- const lex = banks["lexical-signals"] || {};
625
- const dr = banks["discourse-rhythm"] || {};
626
-
627
- const lexSignals = [
628
- ...(lex.zhCalqueCluster?.signals || []),
629
- ...(lex.enPhraseCluster?.signals || []),
630
- ].map((s) => ({ id: s.id, re: new RegExp(s.pattern, "iu") }));
631
-
632
- const zhAlts = (dr.discourseMarkers?.zhLeadMarkers || []).map(escapeRegExp).join("|");
633
- const enAlts = (dr.discourseMarkers?.enLeadMarkers || []).map(escapeRegExp).join("|");
634
- const discZhRe = zhAlts ? new RegExp(`(?:^|[。!?;\\n]\\s*)(?:${zhAlts})[,,::]`, "gu") : null;
635
- const discEnRe = enAlts ? new RegExp(`(?:^|[.!?;\\n]\\s*)(?:${enAlts})[,\\s]`, "gi") : null;
636
-
637
- const framingRes = (comp.weakFramingPatterns || []).map((p) => new RegExp(p, "iu"));
638
- const factRes = (comp.concreteFactPatterns || []).map((p) => new RegExp(p, "giu"));
639
-
640
- const lineStarts = buildLineStarts(rawText);
641
- const existingLines = new Set(existingFindings.map((f) => f.line));
642
- const minDims = comp.minDistinctDimensions || 3;
643
- const maxFacts = comp.maxFactSignals ?? 1;
644
- const hits = [];
645
-
646
- for (const para of iterProseParagraphs(proseText)) {
647
- if (para.skippable) continue;
648
- const { line: paraLine } = offsetToLineCol(rawText, lineStarts, para.index);
649
- if (existingLines.has(paraLine)) continue;
650
-
651
- const rawSlice = rawText.slice(para.blockStart, para.blockStart + para.raw.length);
652
- const factCount = countConcreteFacts(rawSlice, factRes);
653
- if (factCount > maxFacts) continue;
654
-
655
- const activeDims = [];
656
-
657
- // 1. Weak lexical signal (even 1 hit below cluster threshold)
658
- const lexMatched = lexSignals.filter((s) => s.re.test(para.raw)).map((s) => s.id);
659
- if (lexMatched.length >= 1) activeDims.push(`lexical(${lexMatched[0]})`);
660
-
661
- // 2. Weak discourse signpost (even 1-2 hits below 3-hit cluster threshold)
662
- const discHits =
663
- (discZhRe ? (para.trimmed.match(discZhRe) || []).length : 0) +
664
- (discEnRe ? (para.trimmed.match(discEnRe) || []).length : 0);
665
- if (discHits >= 1) activeDims.push(`discourse(${discHits})`);
666
-
667
- // 3. Weak abstract framing cue
668
- const framingHit = framingRes.some((re) => re.test(para.raw));
669
- if (framingHit) activeDims.push("framing");
670
-
671
- // 4. Weak cadence signal (4+ commas in one sentence OR 3+ bold spans OR flat >=4 sentences)
672
- const sents = para.raw.match(/[^.!?。!?\n]+[.!?。!?]/gu) || [];
673
- const hasMildComma = sents.some((s) => (stripFormattedNumbersAndCode(s).match(/[,,]/g) || []).length >= 4);
674
- const hasMildBold = (rawSlice.match(/\*\*[^*\n`]{1,40}\*\*/g) || []).length >= 3;
675
- if (hasMildComma || hasMildBold) activeDims.push("cadence");
676
-
677
- if (activeDims.length >= minDims) {
678
- hits.push({
679
- index: para.index,
680
- length: Math.min(110, para.trimmed.length),
681
- metric: `dims=${activeDims.length} [${activeDims.join("+")}], facts=${factCount}`,
682
- });
683
- }
684
- }
685
- return hits;
686
- }
687
-
688
- function probeUiGen2TastefulSlop(rawText, cfg) {
689
- const clean = maskUiMarkup(rawText);
690
- const minSignals = cfg.minSignals || 2;
691
- const signals = [];
692
- let firstHit = null;
693
-
694
- // Signal 1: Warm cream ground + terracotta/clay accent
695
- const creamMatch = clean.match(/#(?:faf8f5|f7f5f0|fbf9f6|f5f2eb|f9f6f0|fdfbf7|f4efe6)\b|\bbg-(?:stone|amber)-50\b/i);
696
- const terraMatch = clean.match(/#(?:c45a3b|d97757|b85038|c85a32|c2410c|b45309)\b|\bterracotta\b|\b(?:text|bg)-orange-700\b/i);
697
- if (creamMatch && terraMatch) {
698
- signals.push("cream-terracotta");
699
- firstHit = { index: creamMatch.index, length: creamMatch[0].length };
700
- }
701
-
702
- // Signal 2: Serif italic accent word inside display heading
703
- const italicMatch = clean.match(/<h[1-3]\b[^>]*>[\s\S]{0,160}<(?:em|i|span[^>]*\bitalic\b)[^>]*>[^<]{2,40}<\/(?:em|i|span)>/i);
704
- if (italicMatch) {
705
- signals.push("serif-italic-headline");
706
- if (!firstHit) firstHit = { index: italicMatch.index, length: Math.min(80, italicMatch[0].length) };
707
- }
708
-
709
- // Signal 3: Inter default font stack
710
- const interMatch = clean.match(/font-family\s*:[^;\n]{0,80}['"]?Inter['"]?|font-\[\s*['"]?Inter['"]?\s*\]/i);
711
- if (interMatch) {
712
- signals.push("inter-default");
713
- if (!firstHit) firstHit = { index: interMatch.index, length: interMatch[0].length };
714
- }
715
-
716
- // Signal 4: Tracked uppercase eyebrow + rounded-2xl / shadow-xl combo
717
- const eyebrowMatch = clean.match(/\b(?:tracking-(?:widest|wider|\[0\.[12]\d*em\])[^"'\n>]{0,40}\buppercase\b|\buppercase[^"'\n>]{0,40}\btracking-(?:widest|wider|\[0\.[12]\d*em\]))|letter-spacing\s*:\s*0\.[1-3]\d*em[^;]{0,60}text-transform\s*:\s*uppercase/i);
718
- const shellMatch = /\b(?:rounded-2xl|rounded-3xl|shadow-xl|shadow-lg)\b/.test(clean);
719
- if (eyebrowMatch && shellMatch) {
720
- signals.push("tracked-eyebrow-shell");
721
- if (!firstHit) firstHit = { index: eyebrowMatch.index, length: eyebrowMatch[0].length };
722
- }
723
-
724
- if (signals.length >= minSignals && firstHit) {
725
- return [{ ...firstHit, metric: `gen2Signals=${signals.length} [${signals.join("+")}]` }];
726
- }
727
- return [];
728
- }
729
-
730
- // ---------- Main Pattern Library Multi-Angle Auditor ----------
731
-
732
- export function auditPatterns(text, { filename = "<memory>", modality = null, banks = {}, angles = null, ooxml = null, config = {} } = {}) {
733
- const mod = modality || detectModality(filename) || "markdown";
734
- const lineStarts = buildLineStarts(text);
735
- const zones = buildZones(text, mod, {
736
- proseFences: config?.proseFences,
737
- maskBlockquotes: config?.maskBlockquotes,
738
- });
739
- const { byTargetLine } = parseSuppressions(text);
740
- const allowList = config?.allow || [];
741
- const ruleOverrides = config?.rules || {};
742
- const allowAngle = (a) => !angles || angles.includes(a);
743
- const findings = [];
744
-
745
- const isRuleSuppressedOrOff = (ruleId, line, rawMatch) => {
746
- const ov = ruleOverrides[ruleId];
747
- if (ov === "off" || ov === false) return true;
748
- if (rawMatch && isAllowedMatch(rawMatch, allowList)) return true;
749
- const sups = byTargetLine.get(line) || [];
750
- for (const sup of sups) {
751
- if (sup.ruleIds.includes("all") || sup.ruleIds.includes("*") || sup.ruleIds.includes(ruleId)) {
752
- return true;
753
- }
754
- }
755
- return false;
756
- };
757
-
758
- const resolveSeverity = (ruleId, baseSev) => {
759
- const ov = ruleOverrides[ruleId];
760
- if (ov === "error" || ov === "warning" || ov === "info") return ov;
761
- return baseSev || "info";
762
- };
763
-
764
- const emitHits = (ruleMeta, hits, message, deletionTest = null) => {
765
- if (ruleOverrides[ruleMeta.ruleId] === "off" || ruleOverrides[ruleMeta.ruleId] === false) return;
766
- for (const h of hits) {
767
- const rawMatch = text.slice(h.index, h.index + h.length);
768
- const { line, col } = offsetToLineCol(text, lineStarts, h.index);
769
- if (isRuleSuppressedOrOff(ruleMeta.ruleId, line, rawMatch)) continue;
770
- findings.push(
771
- makePatternFinding({
772
- ruleId: ruleMeta.ruleId,
773
- dimension: ruleMeta.dimension,
774
- detectionAngle: ruleMeta.detectionAngle,
775
- severity: resolveSeverity(ruleMeta.ruleId, ruleMeta.severity),
776
- filename,
777
- modality: mod,
778
- line,
779
- col,
780
- match: rawMatch,
781
- metric: h.metric || "",
782
- message,
783
- deletionTest,
784
- })
785
- );
786
- }
787
- };
788
-
789
- const dr = banks["discourse-rhythm"];
790
- if (dr && TEXT_MODALITIES.has(mod)) {
791
- if (allowAngle("rhythm-statistics")) {
792
- if (dr.commaChain) {
793
- emitHits(dr.commaChain, probeCommaChain(zones.prose, text, dr.commaChain), {
794
- en: "Single sentence chains 5+ comma-separated clauses in a flat cadence.",
795
- zh: "单句连续串联 5 个及以上逗号分句,形成平铺拖沓的逗号链节奏。",
796
- }, {
797
- en: "Split into 2–3 shorter sentences at causal or chronological boundaries without dropping numbers.",
798
- zh: "按因果或时间停顿拆成 2 到 3 句,保留全部条件与数字,删掉多余顺承逗号。",
799
- });
800
- }
801
- if (dr.sentenceLengthMonotony) {
802
- emitHits(dr.sentenceLengthMonotony, probeSentenceLengthMonotony(zones.prose, dr.sentenceLengthMonotony), {
803
- en: "Paragraph exhibits metronome sentence-length uniformity (CV < 0.16 across >= 5 sentences).",
804
- zh: "段落内连续 5 句以上句长高度均一(CV < 0.16),呈现节拍器生成韵律。",
805
- }, {
806
- en: "Merge related clauses or cut one sentence short to create natural length contrast.",
807
- zh: "把相邻因果合并成长句,并收短关键结论句,拉开长短句起伏。",
808
- });
809
- }
810
- if (dr.openerAnaphora) {
811
- emitHits(dr.openerAnaphora, probeOpenerAnaphora(zones.prose, dr.openerAnaphora), {
812
- en: "4+ consecutive prose sentences open with the identical mechanical prefix.",
813
- zh: "段落内连续 4 句及以上使用完全相同的机械句首开头。",
814
- }, {
815
- en: "Vary sentence openings or move shared context into one topic sentence or clean list.",
816
- zh: "改写句首起笔,或把并列动作收拢成一句话或真实列表。",
817
- });
818
- }
819
- if (dr.inlineBoldSaturation && (mod === "markdown" || mod === "text")) {
820
- emitHits(dr.inlineBoldSaturation, probeInlineBoldSaturation(zones.prose, text, dr.inlineBoldSaturation), {
821
- en: "Dense inline `**bold**` highlight confetti inside a normal prose paragraph.",
822
- zh: "普通自然段内高密度堆砌 `**加粗词**` 高亮,呈现助手式排版噪点。",
823
- }, {
824
- en: "Unbold inline phrases and keep emphasis only on 1 genuine key decision or caveat.",
825
- zh: "去掉多余行内加粗,仅保留最关键的一处结论或风险提示。",
826
- });
827
- }
828
- if (dr.paragraphLengthUniformity) {
829
- emitHits(dr.paragraphLengthUniformity, probeParagraphLengthUniformity(zones.prose, dr.paragraphLengthUniformity), {
830
- en: "Long document allocates nearly identical word budgets across >= 5 consecutive paragraphs.",
831
- zh: "连续 5 段及以上正文自然段字数高度均一(CV < 0.13),呈现均匀切块模板感。",
832
- }, {
833
- en: "Combine two thin subsections or expand the load-bearing section with concrete details.",
834
- zh: "合并偏薄的过渡段落,把篇幅集中到真正有数据或机制的核心段落。",
835
- });
836
- }
837
- }
838
- if (allowAngle("discourse-structure") && dr.discourseMarkers) {
839
- emitHits(dr.discourseMarkers, probeDiscourseMarkerCluster(zones.prose, dr.discourseMarkers), {
840
- en: "Mechanical transition signposts stacked across consecutive paragraphs or sentences.",
841
- zh: "连续段落或句子堆砌机械过渡路标词(如“首先/其次/此外/最后”或连续“Furthermore/Moreover/Additionally”)。",
842
- }, {
843
- en: "Delete additive signposts (`Moreover`, `Furthermore`) and connect steps by causal order.",
844
- zh: "删掉“首先/其次/此外/最后”一类空路标词,直接按动作先后或因果衔接。",
845
- });
846
- }
847
- }
848
-
849
- const lex = banks["lexical-signals"];
850
- if (lex && TEXT_MODALITIES.has(mod) && allowAngle("lexicon-cluster")) {
851
- if (lex.zhCalqueCluster) {
852
- emitHits(lex.zhCalqueCluster, probeLexicalCluster(zones.prose, lex.zhCalqueCluster), {
853
- en: "Chinese AI translation-calque and hollow-connector cluster inside one paragraph.",
854
- zh: "单段内聚集多处中文 AI 翻译腔或空洞连接套语(如“在……的背景下/不可否认的是/扮演着重要角色”)。",
855
- }, {
856
- en: "Cut hollow wrappers (`undeniably`, `plays a vital role`) and state the subject and action directly.",
857
- zh: "直接删掉“不可否认/扮演着角色/奠定基础”等空架子,主语紧接具体动作与结果。",
858
- });
859
- }
860
- if (lex.enPhraseCluster) {
861
- emitHits(lex.enPhraseCluster, probeLexicalCluster(zones.prose, lex.enPhraseCluster), {
862
- en: "Dense cluster of empirically over-represented English AI vocabulary in one paragraph.",
863
- zh: "单段内高频聚集多个大模型超额偏好英文词组(如 `meticulous`/`pivotal`/`holistic`/`foster`/`underscore`)。",
864
- }, {
865
- en: "Swap abstract buzzwords (`foster`, `pivotal`, `seamless`) for plain verbs and concrete facts.",
866
- zh: "把虚浮高频词换成直白动词与可验证指标,不用靠叠词制造分量。",
867
- });
868
- }
869
- }
870
-
871
- const syn = banks["syntactic-frames"];
872
- if (syn && TEXT_MODALITIES.has(mod) && allowAngle("syntactic-frame")) {
873
- if (syn.concessionSymmetry) {
874
- const pats = [...(syn.concessionSymmetry.enPatterns || []), ...(syn.concessionSymmetry.zhPatterns || [])];
875
- emitHits(syn.concessionSymmetry, probeProseRegexPatterns(zones.prose, pats), {
876
- en: "Formulaic both-sides concession frame ('While X presents challenges, it also offers tremendous opportunities').",
877
- zh: "模板化两面平衡让步句式(“虽然……面临挑战,但也带来了巨大机遇”)。",
878
- }, {
879
- en: "Drop the both-sides cushion and state a clear recommendation with exact boundary conditions.",
880
- zh: "撤掉“有利有弊/既要又要”的端水套壳,直接给出明确判断或写清触发阈值。",
881
- });
882
- }
883
- if (syn.pullQuoteCloser) {
884
- emitHits(
885
- syn.pullQuoteCloser,
886
- probeProseRegexPatterns(zones.prose, syn.pullQuoteCloser.patterns || [], {
887
- skipQuoted: Boolean(syn.pullQuoteCloser.skipQuoted),
888
- }),
889
- {
890
- en: "Poster-style pull-quote punchline closer.",
891
- zh: "段尾硬加广告卡片式金句收尾(如“笔一直在你手里”“这才是……真正的温度”)。",
892
- },
893
- {
894
- en: "Cut the bumper-sticker sign-off and end on the last concrete fact or next action.",
895
- zh: "删掉结尾口号金句,让文章停在最后一条具体事实或下一步动作上。",
896
- }
897
- );
898
- }
899
- if (syn.rhetoricalSelfQa) {
900
- emitHits(syn.rhetoricalSelfQa, probeProseRegexPatterns(zones.prose, syn.rhetoricalSelfQa.patterns || []), {
901
- en: "Staged rhetorical self-Q&A transition ('Why does this matter? Because...', '这意味着什么?意味着……').",
902
- zh: "正文内使用主持词式自问自答过渡句(如“这意味着什么?意味着……”“结果呢?……”)。",
903
- }, {
904
- en: "Remove the staged question and state the consequence in one direct declarative sentence.",
905
- zh: "去掉“为什么重要?因为……”问答腔,用一句直白陈述句直接交代原因或后果。",
906
- });
907
- }
908
- }
909
-
910
- const vd = banks["visual-deck"];
911
- if (vd && allowAngle("visual-markup-ooxml")) {
912
- if (UI_MODALITIES.has(mod)) {
913
- if (vd.glassmorphismOveruse) {
914
- emitHits(vd.glassmorphismOveruse, probeUiPatternCount(text, vd.glassmorphismOveruse), {
915
- en: "Repeated `backdrop-blur` translucent panels (>= 3 per view) mimic default AI glassmorphism templates.",
916
- zh: "单视图重复堆砌 3 处及以上 `backdrop-blur` 毛玻璃半透明面板,呈现典型生成式模板特征。",
917
- }, {
918
- en: "Replace stacked blur cards with crisp 1px borders and solid surface contrast.",
919
- zh: "撤掉满屏毛玻璃半透明层,改用清晰 1px 边框与实体背景区分层级。",
920
- });
921
- }
922
- if (vd.accentStripeCard) {
923
- emitHits(vd.accentStripeCard, probeUiPatternCount(text, vd.accentStripeCard), {
924
- en: "Repeated thick left accent-stripe cards (`border-l-4` / `border-left: >=4px solid`, >= 3 per view) signal boilerplate dashboards.",
925
- zh: "单视图堆叠 3 处及以上左侧粗彩条卡片(`border-l-4` / `border-left: >=4px solid`),呈现典型 AI 后台面板套路。",
926
- }, {
927
- en: "Drop thick decorative side stripes and rely on alignment, spacing, and typography scale.",
928
- zh: "去掉卡片左侧装饰粗彩条,靠留白对齐和字阶主次划分模块。",
929
- });
930
- }
931
- if (vd.gen2TastefulSlop) {
932
- emitHits(vd.gen2TastefulSlop, probeUiGen2TastefulSlop(text, vd.gen2TastefulSlop), {
933
- en: "Second-generation 'tasteful' AI UI template cluster (>= 2 of warm-cream/terracotta, serif-italic headline accent, Inter stack, tracked-uppercase eyebrow).",
934
- zh: "第二代“伪人文精致模板”组合特征(同时命中暖米白+陶土红配色、标题斜体强调词、Inter 默认字体或宽字距全大写眉题中 2 项及以上)。",
935
- }, {
936
- en: "Cut generic template chrome (uppercase kickers, italic buzzword spans) and keep layout purposeful.",
937
- zh: "删掉宽字距全大写眉题和标题斜体装点,用项目真实品牌字体与克制版式。",
938
- });
939
- }
940
- }
941
- if (mod === "pptx" && ooxml && vd.pptxLayoutMonotony && ruleOverrides[vd.pptxLayoutMonotony.ruleId] !== "off" && ruleOverrides[vd.pptxLayoutMonotony.ruleId] !== false) {
942
- const slideHits = probePptxLayoutMonotony(ooxml, vd.pptxLayoutMonotony);
943
- for (const sh of slideHits) {
944
- if (isRuleSuppressedOrOff(vd.pptxLayoutMonotony.ruleId, sh.slideNum, sh.match)) continue;
945
- findings.push(
946
- makePatternFinding({
947
- ruleId: vd.pptxLayoutMonotony.ruleId,
948
- dimension: vd.pptxLayoutMonotony.dimension,
949
- detectionAngle: vd.pptxLayoutMonotony.detectionAngle,
950
- severity: resolveSeverity(vd.pptxLayoutMonotony.ruleId, vd.pptxLayoutMonotony.severity),
951
- filename,
952
- modality: mod,
953
- line: sh.slideNum,
954
- col: 1,
955
- location: `slide ${sh.slideNum}`,
956
- match: sh.match,
957
- metric: sh.metric,
958
- message: {
959
- en: "4+ consecutive content slides share the identical plain-bullet layout with no table, chart, or diagram.",
960
- zh: "连续 4 页及以上正文幻灯片均退化为纯字要点列表页(无图表、表格或配图),版式过于单调。",
961
- },
962
- deletionTest: {
963
- en: "Turn data points into a comparison table or chart, or pair one claim with concrete visual evidence.",
964
- zh: "把连续文字清单改排成对比表格、结构图或数据卡片,打破连页纯字版式。",
965
- },
966
- })
967
- );
968
- }
969
- }
970
- }
971
-
972
- const comp = banks["composite-fusion"];
973
- if (comp && TEXT_MODALITIES.has(mod) && allowAngle("composite-cooccurrence")) {
974
- emitHits(comp, probeCompositeMultiSignal(zones.prose, text, banks, findings), {
975
- en: "Multiple sub-threshold AI signals (lexical + discourse + framing/cadence) co-occur in one low-fact paragraph.",
976
- zh: "同一低事实段落内叠加多个跨维度弱 AI 味信号(套词 + 过渡路标 + 抽象框架/节奏),虽未单点越线但整体 AI 腔明显。",
977
- }, {
978
- en: "Trim empty framing phrases and anchor the paragraph in at least one metric, file, date, or concrete decision.",
979
- zh: "删掉空泛套词与过渡壳,至少补进一条实测指标、文件名、日期或明确取舍结论。",
980
- });
981
- }
982
-
983
- findings.sort((a, b) => (a.line || 0) - (b.line || 0) || (a.col || 0) - (b.col || 0) || a.ruleId.localeCompare(b.ruleId));
984
- return { version: PATTERN_ENGINE_VERSION, findings };
985
- }
986
-
987
- export function analyzePatternProfile(text, options = {}) {
988
- const res = auditPatterns(text, options);
989
- const byDimension = {};
990
- const byAngle = {};
991
- for (const f of res.findings) {
992
- byDimension[f.dimension] = (byDimension[f.dimension] || 0) + 1;
993
- byAngle[f.detectionAngle] = (byAngle[f.detectionAngle] || 0) + 1;
994
- }
995
- return {
996
- version: PATTERN_ENGINE_VERSION,
997
- findingCount: res.findings.length,
998
- activeDimensions: Object.keys(byDimension).sort(),
999
- byDimension,
1000
- byAngle,
1001
- findings: res.findings,
1002
- };
1003
- }