dislop 0.0.0-stage → 0.6.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.
- package/.agents/plugins/marketplace.json +20 -0
- package/.claude-plugin/marketplace.json +33 -0
- package/.claude-plugin/plugin.json +22 -0
- package/.codex-plugin/plugin.json +49 -0
- package/.mcp.json +12 -0
- package/.pre-commit-hooks.yaml +13 -0
- package/LICENSE +202 -0
- package/README.md +222 -2
- package/README.zh-CN.md +219 -0
- package/action.yml +90 -0
- package/assets/logo.svg +8 -0
- package/bin/dislop-mcp.mjs +5 -0
- package/bin/dislop.mjs +1967 -0
- package/gemini-extension.json +13 -0
- package/mcp.json +13 -0
- package/models/manifest.json +90 -0
- package/models/pocket-slop-v1.json +1 -0
- package/package.json +89 -4
- package/packs/business-brief/pack.json +598 -0
- package/packs/core/pack.json +192 -0
- package/packs/deck-and-ui/pack.json +290 -0
- package/packs/engineering-spec/pack.json +144 -0
- package/packs/executive-deck/pack.json +98 -0
- package/packs/literary-essay/pack.json +324 -0
- package/packs/regulated-comms/pack.json +99 -0
- package/patterns/README.md +39 -0
- package/patterns/banks/composite-fusion.json +36 -0
- package/patterns/banks/discourse-rhythm.json +95 -0
- package/patterns/banks/lexical-signals.json +74 -0
- package/patterns/banks/syntactic-frames.json +45 -0
- package/patterns/banks/visual-deck.json +37 -0
- package/patterns/dimensions/artifacts.json +121 -0
- package/patterns/dimensions/discourse.json +412 -0
- package/patterns/dimensions/lexical.json +172 -0
- package/patterns/dimensions/rhythm.json +206 -0
- package/patterns/dimensions/syntactic.json +285 -0
- package/patterns/dimensions/visual-and-deck.json +322 -0
- package/patterns/taxonomy.json +112 -0
- package/plugin.json +41 -0
- package/server.json +50 -0
- package/skills/dislop/SKILL.md +60 -0
- package/skills/dislop/agents/openai.yaml +6 -0
- package/skills/dislop/references/business-and-rfc.md +26 -0
- package/skills/dislop/references/editorial-and-essay.md +20 -0
- package/skills/dislop/references/regulated-and-precision.md +27 -0
- package/skills/dislop/references/web-ui-and-deck.md +26 -0
- package/src/binary-node.mjs +85 -0
- package/src/core.mjs +2488 -0
- package/src/local-model.mjs +977 -0
- package/src/pattern-engine.mjs +853 -0
- package/src/pocket-model.mjs +707 -0
|
@@ -0,0 +1,853 @@
|
|
|
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
|
+
detectModality,
|
|
10
|
+
fnv1aHex,
|
|
11
|
+
offsetToLineCol,
|
|
12
|
+
} from "./core.mjs";
|
|
13
|
+
|
|
14
|
+
export const PATTERN_ENGINE_VERSION = "1.0.0";
|
|
15
|
+
|
|
16
|
+
const TEXT_MODALITIES = new Set(["markdown", "text", "html", "docx"]);
|
|
17
|
+
const UI_MODALITIES = new Set(["html", "css", "jsx"]);
|
|
18
|
+
|
|
19
|
+
function blankPreserveLines(s) {
|
|
20
|
+
return s.replace(/[^\r\n]/g, " ");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function maskUiMarkup(rawText) {
|
|
24
|
+
return String(rawText || "")
|
|
25
|
+
.replace(/\uFEFF/g, " ")
|
|
26
|
+
.replace(/<!--\s*dislop-quote-start\s*-->[\s\S]*?<!--\s*dislop-quote-end\s*-->/gi, blankPreserveLines)
|
|
27
|
+
.replace(/<!--[\s\S]*?-->/g, blankPreserveLines)
|
|
28
|
+
.replace(/\/\*[\s\S]*?\*\//g, blankPreserveLines)
|
|
29
|
+
.replace(/<(script|code|pre)\b[^>]*>[\s\S]*?<\/\1>/gi, blankPreserveLines);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ---------- Shared Linguistic Measurement Helpers ----------
|
|
33
|
+
|
|
34
|
+
function stripFormattedNumbersAndCode(s) {
|
|
35
|
+
return String(s || "")
|
|
36
|
+
.replace(/\d{1,3}(?:,\d{3})+/g, "0")
|
|
37
|
+
.replace(/`[^`\n]+`/g, "CODE");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function detectPrimaryLang(s) {
|
|
41
|
+
const cjk = (s.match(/[\u4e00-\u9fff]/gu) || []).length;
|
|
42
|
+
const enWords = s.split(/\s+/).filter((w) => /[A-Za-z]/.test(w)).length;
|
|
43
|
+
return cjk >= enWords * 2 ? "zh" : "en";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function measureUnits(text, lang) {
|
|
47
|
+
const clean = stripFormattedNumbersAndCode(text).replace(/[.!?。!?]+$/u, "").trim();
|
|
48
|
+
const cjk = (clean.match(/[\u4e00-\u9fff]/gu) || []).length;
|
|
49
|
+
const enWords = clean.split(/\s+/).filter((w) => /[A-Za-z0-9]/.test(w)).length;
|
|
50
|
+
return lang === "zh" ? cjk + Math.round(enWords * 1.5) : enWords + Math.round(cjk * 0.6);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isSkippableProseBlock(trimmed) {
|
|
54
|
+
return !trimmed || /^(?:#{1,6}\s|[-*+]\s|\d+[.)]\s|\||>)/.test(trimmed);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function iterProseParagraphs(proseText) {
|
|
58
|
+
const out = [];
|
|
59
|
+
const re = /[^\n]+(?:\n(?!\s*\n)[^\n]+)*/g;
|
|
60
|
+
let m;
|
|
61
|
+
while ((m = re.exec(proseText)) !== null) {
|
|
62
|
+
const raw = m[0];
|
|
63
|
+
const trimmed = raw.trim();
|
|
64
|
+
const firstNonWs = raw.search(/\S/);
|
|
65
|
+
out.push({
|
|
66
|
+
raw,
|
|
67
|
+
trimmed,
|
|
68
|
+
index: m.index + (firstNonWs >= 0 ? firstNonWs : 0),
|
|
69
|
+
blockStart: m.index,
|
|
70
|
+
skippable: isSkippableProseBlock(trimmed),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function escapeRegExp(str) {
|
|
77
|
+
return String(str).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function makePatternFinding({
|
|
81
|
+
ruleId,
|
|
82
|
+
dimension,
|
|
83
|
+
detectionAngle,
|
|
84
|
+
severity = "info",
|
|
85
|
+
filename,
|
|
86
|
+
modality,
|
|
87
|
+
line = 1,
|
|
88
|
+
col = 1,
|
|
89
|
+
location = null,
|
|
90
|
+
match,
|
|
91
|
+
metric = "",
|
|
92
|
+
message,
|
|
93
|
+
}) {
|
|
94
|
+
const loc = location || `${line}:${col}`;
|
|
95
|
+
const cleanMatch = String(match || "").replace(/\s+/g, " ").trim().slice(0, 140);
|
|
96
|
+
const fp = `${ruleId}:${fnv1aHex(`${ruleId}|${cleanMatch.toLowerCase()}|${loc}`)}`;
|
|
97
|
+
return {
|
|
98
|
+
fingerprint: fp,
|
|
99
|
+
ruleId,
|
|
100
|
+
source: "pattern-library",
|
|
101
|
+
dimension,
|
|
102
|
+
detectionAngle,
|
|
103
|
+
severity,
|
|
104
|
+
file: filename,
|
|
105
|
+
modality,
|
|
106
|
+
location: loc,
|
|
107
|
+
line,
|
|
108
|
+
col,
|
|
109
|
+
match: cleanMatch,
|
|
110
|
+
metric,
|
|
111
|
+
message,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ---------- Angle: Rhythm & Cadence Statistics ----------
|
|
116
|
+
|
|
117
|
+
function probeCommaChain(proseText, rawText, cfg) {
|
|
118
|
+
const hits = [];
|
|
119
|
+
for (const para of iterProseParagraphs(proseText)) {
|
|
120
|
+
if (para.skippable) continue;
|
|
121
|
+
const sentRe = /[^.!?。!?\n]+[.!?。!?]/gu;
|
|
122
|
+
let sm;
|
|
123
|
+
while ((sm = sentRe.exec(para.raw)) !== null) {
|
|
124
|
+
const sent = sm[0];
|
|
125
|
+
const normalized = stripFormattedNumbersAndCode(sent);
|
|
126
|
+
const lang = detectPrimaryLang(normalized);
|
|
127
|
+
const noParens = normalized.replace(/\([^)\n]{1,120}\)|([^)\n]{1,120})/gu, "");
|
|
128
|
+
const commas = noParens.match(/[,,]/g) || [];
|
|
129
|
+
if (commas.length < (cfg.minCommas || 5)) continue;
|
|
130
|
+
|
|
131
|
+
const clauses = noParens
|
|
132
|
+
.split(/[,,]/)
|
|
133
|
+
.map((c) => c.trim())
|
|
134
|
+
.filter(Boolean);
|
|
135
|
+
const langCfg = lang === "zh" ? cfg.zh : cfg.en;
|
|
136
|
+
const lens = clauses.map((c) => measureUnits(c, lang));
|
|
137
|
+
const longClauses = lens.filter((n) => n >= langCfg.minClauseUnits).length;
|
|
138
|
+
const avgUnits = lens.reduce((a, b) => a + b, 0) / Math.max(1, lens.length);
|
|
139
|
+
|
|
140
|
+
if (longClauses >= (cfg.minLongClauses || 4) && avgUnits >= langCfg.minAvgClauseUnits) {
|
|
141
|
+
const leadWs = sent.search(/\S/);
|
|
142
|
+
const startOffset = para.blockStart + sm.index + (leadWs >= 0 ? leadWs : 0);
|
|
143
|
+
const rawSlice = rawText.slice(startOffset, startOffset + sent.trim().length);
|
|
144
|
+
const linkCount = (rawSlice.match(/\]\(/g) || []).length;
|
|
145
|
+
if (linkCount > (cfg.maxMarkdownLinks ?? 2)) continue;
|
|
146
|
+
hits.push({
|
|
147
|
+
index: startOffset,
|
|
148
|
+
length: sent.trim().length,
|
|
149
|
+
metric: `lang=${lang}, commas=${commas.length}, avgUnits=${avgUnits.toFixed(1)}`,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return hits;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function probeSentenceLengthMonotony(proseText, cfg) {
|
|
158
|
+
const hits = [];
|
|
159
|
+
for (const para of iterProseParagraphs(proseText)) {
|
|
160
|
+
if (para.skippable) continue;
|
|
161
|
+
const lang = detectPrimaryLang(para.trimmed);
|
|
162
|
+
const sentRe = /[^.!?。!?\n]+[.!?。!?]/gu;
|
|
163
|
+
const lengths = [];
|
|
164
|
+
let sm;
|
|
165
|
+
while ((sm = sentRe.exec(para.raw)) !== null) {
|
|
166
|
+
const u = measureUnits(sm[0], lang);
|
|
167
|
+
if (u >= (cfg.minSentenceUnits || 4)) lengths.push(u);
|
|
168
|
+
}
|
|
169
|
+
if (lengths.length < (cfg.minSentences || 5)) continue;
|
|
170
|
+
const mean = lengths.reduce((a, b) => a + b, 0) / lengths.length;
|
|
171
|
+
const minMean = lang === "zh" ? cfg.minMeanUnitsZh || 14 : cfg.minMeanUnitsEn || 10;
|
|
172
|
+
if (mean < minMean) continue;
|
|
173
|
+
const variance = lengths.reduce((acc, x) => acc + (x - mean) ** 2, 0) / lengths.length;
|
|
174
|
+
const cv = Math.sqrt(variance) / mean;
|
|
175
|
+
if (cv < (cfg.maxCv || 0.16)) {
|
|
176
|
+
hits.push({
|
|
177
|
+
index: para.index,
|
|
178
|
+
length: Math.min(para.trimmed.length, 100),
|
|
179
|
+
metric: `lang=${lang}, sentences=${lengths.length}, mean=${mean.toFixed(1)}, cv=${cv.toFixed(3)}`,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return hits;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function extractSentenceOpener(sentence, lang, cfg) {
|
|
187
|
+
const clean = sentence.trim().replace(/^["'“‘((]+/, "");
|
|
188
|
+
if (!clean) return "";
|
|
189
|
+
if (lang === "zh") {
|
|
190
|
+
const m = clean.match(/^([\u4e00-\u9fff]{2,3})/);
|
|
191
|
+
if (!m) return "";
|
|
192
|
+
return m[1].slice(0, cfg.minOpenerCharsZh || 2);
|
|
193
|
+
}
|
|
194
|
+
const words = clean
|
|
195
|
+
.toLowerCase()
|
|
196
|
+
.replace(/[^a-z0-9\s'-]/g, " ")
|
|
197
|
+
.trim()
|
|
198
|
+
.split(/\s+/)
|
|
199
|
+
.filter(Boolean);
|
|
200
|
+
const need = cfg.minOpenerWordsEn || 2;
|
|
201
|
+
if (words.length < need + 1) return "";
|
|
202
|
+
return words.slice(0, need).join(" ");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function probeOpenerAnaphora(proseText, cfg) {
|
|
206
|
+
const hits = [];
|
|
207
|
+
const minRun = cfg.minConsecutive || 4;
|
|
208
|
+
for (const para of iterProseParagraphs(proseText)) {
|
|
209
|
+
if (para.skippable) continue;
|
|
210
|
+
const lang = detectPrimaryLang(para.trimmed);
|
|
211
|
+
const sentRe = /[^.!?。!?\n]+[.!?。!?]/gu;
|
|
212
|
+
const sentences = [];
|
|
213
|
+
let sm;
|
|
214
|
+
while ((sm = sentRe.exec(para.raw)) !== null) {
|
|
215
|
+
const s = sm[0].trim();
|
|
216
|
+
const opener = extractSentenceOpener(s, lang, cfg);
|
|
217
|
+
const lead = sm[0].search(/\S/);
|
|
218
|
+
sentences.push({
|
|
219
|
+
opener,
|
|
220
|
+
start: para.blockStart + sm.index + (lead >= 0 ? lead : 0),
|
|
221
|
+
end: para.blockStart + sm.index + (lead >= 0 ? lead : 0) + s.length,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
let runKey = "";
|
|
225
|
+
let runStart = 0;
|
|
226
|
+
let runLen = 0;
|
|
227
|
+
for (let i = 0; i <= sentences.length; i += 1) {
|
|
228
|
+
const cur = sentences[i];
|
|
229
|
+
if (cur && cur.opener && cur.opener === runKey) {
|
|
230
|
+
runLen += 1;
|
|
231
|
+
} else {
|
|
232
|
+
if (runLen >= minRun && runKey) {
|
|
233
|
+
const first = sentences[runStart];
|
|
234
|
+
const last = sentences[i - 1];
|
|
235
|
+
hits.push({
|
|
236
|
+
index: first.start,
|
|
237
|
+
length: Math.min(120, last.end - first.start),
|
|
238
|
+
metric: `opener="${runKey}", consecutive=${runLen}`,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
runKey = cur?.opener || "";
|
|
242
|
+
runStart = i;
|
|
243
|
+
runLen = runKey ? 1 : 0;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return hits;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function probeInlineBoldSaturation(proseText, rawText, cfg) {
|
|
251
|
+
const hits = [];
|
|
252
|
+
const minSpans = cfg.minBoldSpans || 4;
|
|
253
|
+
for (const para of iterProseParagraphs(proseText)) {
|
|
254
|
+
if (para.skippable) continue;
|
|
255
|
+
const rawSlice = rawText.slice(para.blockStart, para.blockStart + para.raw.length);
|
|
256
|
+
// Only inspect genuine markdown prose paragraphs (skip lines that are mostly list/table)
|
|
257
|
+
if (/^\s*(?:#{1,6}\s|[-*+]\s|\d+[.)]\s|\||>)/m.test(rawSlice)) continue;
|
|
258
|
+
const boldMatches = [];
|
|
259
|
+
const boldRe = /\*\*([^*\n`]{1,40})\*\*/g;
|
|
260
|
+
let bm;
|
|
261
|
+
while ((bm = boldRe.exec(rawSlice)) !== null) {
|
|
262
|
+
// Ensure this span isn't inside masked code zone
|
|
263
|
+
const proseSpan = para.raw.slice(bm.index, bm.index + bm[0].length);
|
|
264
|
+
if (proseSpan.trim().length > 0) {
|
|
265
|
+
boldMatches.push({ index: para.blockStart + bm.index, length: bm[0].length });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (boldMatches.length < minSpans) continue;
|
|
269
|
+
const lang = detectPrimaryLang(para.trimmed);
|
|
270
|
+
const plainLen =
|
|
271
|
+
lang === "zh"
|
|
272
|
+
? (para.trimmed.match(/[\u4e00-\u9fff]/gu) || []).length
|
|
273
|
+
: para.trimmed.split(/\s+/).filter((w) => /[A-Za-z0-9]/.test(w)).length;
|
|
274
|
+
const ratio = plainLen / boldMatches.length;
|
|
275
|
+
const maxPerBold = lang === "zh" ? cfg.maxCjkPerBoldZh || 55 : cfg.maxWordsPerBoldEn || 28;
|
|
276
|
+
if (ratio <= maxPerBold) {
|
|
277
|
+
hits.push({
|
|
278
|
+
index: boldMatches[0].index,
|
|
279
|
+
length: Math.min(100, para.trimmed.length),
|
|
280
|
+
metric: `lang=${lang}, boldSpans=${boldMatches.length}, unitsPerBold=${ratio.toFixed(1)}`,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return hits;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function probeParagraphLengthUniformity(proseText, cfg) {
|
|
288
|
+
const paras = iterProseParagraphs(proseText).filter((p) => !p.skippable);
|
|
289
|
+
if (paras.length < (cfg.minParagraphs || 5)) return [];
|
|
290
|
+
const lang = detectPrimaryLang(proseText);
|
|
291
|
+
const scored = paras
|
|
292
|
+
.map((p) => ({ para: p, units: measureUnits(p.trimmed, lang) }))
|
|
293
|
+
.filter((x) => x.units >= 15);
|
|
294
|
+
if (scored.length < (cfg.minParagraphs || 5)) return [];
|
|
295
|
+
const mean = scored.reduce((a, x) => a + x.units, 0) / scored.length;
|
|
296
|
+
if (mean < (cfg.minMeanUnits || 35)) return [];
|
|
297
|
+
const variance = scored.reduce((acc, x) => acc + (x.units - mean) ** 2, 0) / scored.length;
|
|
298
|
+
const cv = Math.sqrt(variance) / mean;
|
|
299
|
+
if (cv < (cfg.maxCv || 0.13)) {
|
|
300
|
+
return [
|
|
301
|
+
{
|
|
302
|
+
index: scored[0].para.index,
|
|
303
|
+
length: Math.min(100, scored[0].para.trimmed.length),
|
|
304
|
+
metric: `lang=${lang}, paragraphs=${scored.length}, mean=${mean.toFixed(1)}, cv=${cv.toFixed(3)}`,
|
|
305
|
+
},
|
|
306
|
+
];
|
|
307
|
+
}
|
|
308
|
+
return [];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// ---------- Angle: Discourse Signpost Cluster ----------
|
|
312
|
+
|
|
313
|
+
function probeDiscourseMarkerCluster(proseText, cfg) {
|
|
314
|
+
const hits = [];
|
|
315
|
+
const zhAlts = (cfg.zhLeadMarkers || []).map(escapeRegExp).join("|");
|
|
316
|
+
const enAlts = (cfg.enLeadMarkers || []).map(escapeRegExp).join("|");
|
|
317
|
+
const zhLeadRe = zhAlts ? new RegExp(`^(?:${zhAlts})[,,::\\s]`, "u") : null;
|
|
318
|
+
const enLeadRe = enAlts ? new RegExp(`^(?:${enAlts})[,\\s]`, "i") : null;
|
|
319
|
+
const zhInnerRe = zhAlts ? new RegExp(`(?:^|[。!?;\\n]\\s*)(?:${zhAlts})[,,::]`, "gu") : null;
|
|
320
|
+
const enInnerRe = enAlts ? new RegExp(`(?:^|[.!?;]\\s+)(?:${enAlts}),`, "gi") : null;
|
|
321
|
+
|
|
322
|
+
const paras = iterProseParagraphs(proseText).map((p) => {
|
|
323
|
+
if (p.skippable) return { ...p, isMarked: false };
|
|
324
|
+
const isMarked = Boolean((zhLeadRe && zhLeadRe.test(p.trimmed)) || (enLeadRe && enLeadRe.test(p.trimmed)));
|
|
325
|
+
return { ...p, isMarked };
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const minParas = cfg.minConsecutiveParagraphs || 3;
|
|
329
|
+
let runStart = -1;
|
|
330
|
+
let runCount = 0;
|
|
331
|
+
for (let i = 0; i <= paras.length; i += 1) {
|
|
332
|
+
const cur = paras[i];
|
|
333
|
+
if (cur && cur.isMarked) {
|
|
334
|
+
if (runCount === 0) runStart = i;
|
|
335
|
+
runCount += 1;
|
|
336
|
+
} else {
|
|
337
|
+
if (runCount >= minParas) {
|
|
338
|
+
const first = paras[runStart];
|
|
339
|
+
hits.push({
|
|
340
|
+
index: first.index,
|
|
341
|
+
length: Math.min(80, first.trimmed.length),
|
|
342
|
+
metric: `consecutiveMarkedParagraphs=${runCount}`,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
runCount = 0;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const minInPara = cfg.minMarkersInParagraph || 3;
|
|
350
|
+
for (const p of paras) {
|
|
351
|
+
if (p.skippable) continue;
|
|
352
|
+
const zhHits = zhInnerRe ? (p.trimmed.match(zhInnerRe) || []).length : 0;
|
|
353
|
+
const enHits = enInnerRe ? (p.trimmed.match(enInnerRe) || []).length : 0;
|
|
354
|
+
const total = zhHits + enHits;
|
|
355
|
+
if (total >= minInPara && !hits.some((h) => h.index === p.index)) {
|
|
356
|
+
hits.push({
|
|
357
|
+
index: p.index,
|
|
358
|
+
length: Math.min(80, p.trimmed.length),
|
|
359
|
+
metric: `markersInParagraph=${total}`,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return hits;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// ---------- Angle: Weighted Lexical & Calque Cluster ----------
|
|
367
|
+
|
|
368
|
+
function probeLexicalCluster(proseText, cfg) {
|
|
369
|
+
const hits = [];
|
|
370
|
+
const compiled = (cfg.signals || []).map((s) => ({
|
|
371
|
+
id: s.id,
|
|
372
|
+
weight: Number(s.weight ?? 1.0),
|
|
373
|
+
re: new RegExp(s.pattern, "iu"),
|
|
374
|
+
}));
|
|
375
|
+
const minDistinct = cfg.minDistinctHits || 2;
|
|
376
|
+
const minScore = cfg.minWeightedScore ?? minDistinct;
|
|
377
|
+
|
|
378
|
+
for (const para of iterProseParagraphs(proseText)) {
|
|
379
|
+
if (para.skippable) continue;
|
|
380
|
+
const matched = [];
|
|
381
|
+
let score = 0;
|
|
382
|
+
let firstIdx = -1;
|
|
383
|
+
let firstLen = 0;
|
|
384
|
+
for (const sig of compiled) {
|
|
385
|
+
const m = sig.re.exec(para.raw);
|
|
386
|
+
if (m) {
|
|
387
|
+
matched.push(sig.id);
|
|
388
|
+
score += sig.weight;
|
|
389
|
+
const absIdx = para.blockStart + m.index;
|
|
390
|
+
if (firstIdx === -1 || absIdx < firstIdx) {
|
|
391
|
+
firstIdx = absIdx;
|
|
392
|
+
firstLen = m[0].length;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (matched.length >= minDistinct && score >= minScore && firstIdx !== -1) {
|
|
397
|
+
hits.push({
|
|
398
|
+
index: firstIdx,
|
|
399
|
+
length: Math.max(firstLen, Math.min(100, para.trimmed.length)),
|
|
400
|
+
metric: `signals=${matched.length}, score=${score.toFixed(1)}, ids=${matched.slice(0, 4).join("+")}`,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return hits;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// ---------- Angle: Syntactic & Rhetorical Frames ----------
|
|
408
|
+
|
|
409
|
+
function isInsideQuotation(text, start, end) {
|
|
410
|
+
const before = text.slice(Math.max(0, start - 32), start);
|
|
411
|
+
const after = text.slice(end, Math.min(text.length, end + 16));
|
|
412
|
+
const openZh = (before.match(/“/g) || []).length - (before.match(/”/g) || []).length;
|
|
413
|
+
if (openZh > 0 && /”/.test(after)) return true;
|
|
414
|
+
const openCorner = (before.match(/「/g) || []).length - (before.match(/」/g) || []).length;
|
|
415
|
+
if (openCorner > 0 && /」/.test(after)) return true;
|
|
416
|
+
if (/(?:例如|比如|如)\s*[“"「]?$/.test(before)) return true;
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function probeProseRegexPatterns(proseText, patterns = [], { skipQuoted = false } = {}) {
|
|
421
|
+
const hits = [];
|
|
422
|
+
const compiled = patterns.map((p) => new RegExp(p, "giu"));
|
|
423
|
+
for (const para of iterProseParagraphs(proseText)) {
|
|
424
|
+
if (para.skippable) continue;
|
|
425
|
+
for (const re of compiled) {
|
|
426
|
+
re.lastIndex = 0;
|
|
427
|
+
let m;
|
|
428
|
+
while ((m = re.exec(para.raw)) !== null) {
|
|
429
|
+
if (m[0].length === 0) {
|
|
430
|
+
re.lastIndex += 1;
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
let idx = para.blockStart + m.index;
|
|
434
|
+
let len = m[0].length;
|
|
435
|
+
const lead = m[0].match(/^[.!?。!?\s]+/);
|
|
436
|
+
if (lead && lead[0].length < len) {
|
|
437
|
+
idx += lead[0].length;
|
|
438
|
+
len -= lead[0].length;
|
|
439
|
+
}
|
|
440
|
+
if (skipQuoted && isInsideQuotation(proseText, idx, idx + len)) {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
hits.push({ index: idx, length: len, metric: `matchedLen=${len}` });
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
// Deduplicate overlapping hits
|
|
448
|
+
hits.sort((a, b) => a.index - b.index || b.length - a.length);
|
|
449
|
+
const dedup = [];
|
|
450
|
+
for (const h of hits) {
|
|
451
|
+
const prev = dedup[dedup.length - 1];
|
|
452
|
+
if (prev && h.index < prev.index + prev.length) continue;
|
|
453
|
+
dedup.push(h);
|
|
454
|
+
}
|
|
455
|
+
return dedup;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// ---------- Angle: Visual / UI & PPTX Structural Templates ----------
|
|
459
|
+
|
|
460
|
+
function probeUiPatternCount(rawText, cfg) {
|
|
461
|
+
const clean = maskUiMarkup(rawText);
|
|
462
|
+
const re = new RegExp(cfg.pattern, "gi");
|
|
463
|
+
const exemptRe = cfg.exemptPattern ? new RegExp(cfg.exemptPattern, "i") : null;
|
|
464
|
+
const lookbehind = cfg.exemptLookbehindChars || 48;
|
|
465
|
+
const matches = [];
|
|
466
|
+
let m;
|
|
467
|
+
while ((m = re.exec(clean)) !== null) {
|
|
468
|
+
if (exemptRe) {
|
|
469
|
+
const before = clean.slice(Math.max(0, m.index - lookbehind), m.index);
|
|
470
|
+
if (exemptRe.test(before)) continue;
|
|
471
|
+
}
|
|
472
|
+
matches.push({ index: m.index, length: m[0].length });
|
|
473
|
+
}
|
|
474
|
+
const minOcc = cfg.minOccurrences || 3;
|
|
475
|
+
if (matches.length >= minOcc) {
|
|
476
|
+
return [{ index: matches[0].index, length: matches[0].length, metric: `occurrences=${matches.length}` }];
|
|
477
|
+
}
|
|
478
|
+
return [];
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function decodeXmlSimple(s) {
|
|
482
|
+
return String(s || "")
|
|
483
|
+
.replace(/</g, "<")
|
|
484
|
+
.replace(/>/g, ">")
|
|
485
|
+
.replace(/"/g, '"')
|
|
486
|
+
.replace(/'/g, "'")
|
|
487
|
+
.replace(/&/g, "&");
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function resolveOrderedSlides(entries) {
|
|
491
|
+
const presXml = entries["ppt/presentation.xml"] || "";
|
|
492
|
+
const presRels = entries["ppt/_rels/presentation.xml.rels"] || "";
|
|
493
|
+
const relMap = new Map();
|
|
494
|
+
const relRe =
|
|
495
|
+
/<Relationship\b[^>]*\bId="([^"]+)"[^>]*\bTarget="([^"]+)"|<Relationship\b[^>]*\bTarget="([^"]+)"[^>]*\bId="([^"]+)"/g;
|
|
496
|
+
let rm;
|
|
497
|
+
while ((rm = relRe.exec(presRels)) !== null) {
|
|
498
|
+
const id = rm[1] || rm[4];
|
|
499
|
+
const rawTarget = (rm[2] || rm[3] || "").replace(/^\/+/, "").replace(/^\.\.\//, "ppt/");
|
|
500
|
+
const target = rawTarget.startsWith("ppt/") ? rawTarget : `ppt/${rawTarget}`;
|
|
501
|
+
relMap.set(id, target);
|
|
502
|
+
}
|
|
503
|
+
const ordered = [];
|
|
504
|
+
const sldIdRe = /<p:sldId\b[^>]*\br:id="([^"]+)"/g;
|
|
505
|
+
let sm;
|
|
506
|
+
while ((sm = sldIdRe.exec(presXml)) !== null) {
|
|
507
|
+
const target = relMap.get(sm[1]);
|
|
508
|
+
if (target && entries[target]) ordered.push(target);
|
|
509
|
+
}
|
|
510
|
+
if (ordered.length === 0) {
|
|
511
|
+
const fallback = Object.keys(entries)
|
|
512
|
+
.filter((k) => /^ppt\/slides\/slide\d+\.xml$/.test(k))
|
|
513
|
+
.sort((a, b) => Number(a.match(/\d+/)[0]) - Number(b.match(/\d+/)[0]));
|
|
514
|
+
ordered.push(...fallback);
|
|
515
|
+
}
|
|
516
|
+
return ordered;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function probePptxLayoutMonotony(ooxmlEntries, cfg) {
|
|
520
|
+
if (!ooxmlEntries || typeof ooxmlEntries !== "object") return [];
|
|
521
|
+
const slides = resolveOrderedSlides(ooxmlEntries);
|
|
522
|
+
const contentSlides = [];
|
|
523
|
+
const minWords = cfg.minSlideLatinWords || 12;
|
|
524
|
+
const minCjk = cfg.minSlideCjkChars || 25;
|
|
525
|
+
|
|
526
|
+
slides.forEach((entryKey, idx) => {
|
|
527
|
+
const slideNum = idx + 1;
|
|
528
|
+
const xml = String(ooxmlEntries[entryKey] || "");
|
|
529
|
+
if (/<p:sld\b[^>]*\bshow="0"/.test(xml)) return;
|
|
530
|
+
|
|
531
|
+
const textParts = [];
|
|
532
|
+
let bodyTextShapes = 0;
|
|
533
|
+
let hasBullets = false;
|
|
534
|
+
const spRe = /<p:sp\b[\s\S]*?<\/p:sp>/g;
|
|
535
|
+
let spm;
|
|
536
|
+
while ((spm = spRe.exec(xml)) !== null) {
|
|
537
|
+
const sp = spm[0];
|
|
538
|
+
const isTitle = /<p:ph\b[^>]*\btype="(?:title|ctrTitle)"/.test(sp);
|
|
539
|
+
const isFooter = /<p:ph\b[^>]*\btype="(?:sldNum|ftr|dt)"/.test(sp);
|
|
540
|
+
if (isFooter) continue;
|
|
541
|
+
const runs = [];
|
|
542
|
+
const tRe = /<a:t(?:\s[^>]*)?>([\s\S]*?)<\/a:t>/g;
|
|
543
|
+
let tm;
|
|
544
|
+
while ((tm = tRe.exec(sp)) !== null) {
|
|
545
|
+
runs.push(decodeXmlSimple(tm[1]));
|
|
546
|
+
}
|
|
547
|
+
const joined = runs.join("").trim();
|
|
548
|
+
if (!joined) continue;
|
|
549
|
+
textParts.push(joined);
|
|
550
|
+
if (!isTitle) {
|
|
551
|
+
bodyTextShapes += 1;
|
|
552
|
+
if (/<a:buChar\b|<a:buAutoNum\b/.test(sp)) hasBullets = true;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
const full = textParts.join(" ");
|
|
556
|
+
const cjk = (full.match(/[\u4e00-\u9fff]/gu) || []).length;
|
|
557
|
+
const latin = full.split(/\s+/).filter((w) => /[A-Za-z0-9]/.test(w)).length;
|
|
558
|
+
const hasVisual = /<c:chart\b|<a:tbl\b|<p:pic\b/.test(xml);
|
|
559
|
+
if (!hasVisual && latin < minWords && cjk < minCjk) return;
|
|
560
|
+
|
|
561
|
+
const isPlainBulletOnly = !hasVisual && hasBullets && bodyTextShapes <= 1;
|
|
562
|
+
contentSlides.push({ slideNum, isPlainBulletOnly });
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
if (contentSlides.length < (cfg.minContentSlides || 5)) return [];
|
|
566
|
+
const needRun = cfg.minConsecutivePlainBulletSlides || 4;
|
|
567
|
+
let run = 0;
|
|
568
|
+
for (const s of contentSlides) {
|
|
569
|
+
if (s.isPlainBulletOnly) {
|
|
570
|
+
run += 1;
|
|
571
|
+
if (run === needRun) {
|
|
572
|
+
return [
|
|
573
|
+
{
|
|
574
|
+
slideNum: s.slideNum,
|
|
575
|
+
match: `${needRun}+ consecutive plain-bullet slides (out of ${contentSlides.length} content slides)`,
|
|
576
|
+
metric: `contentSlides=${contentSlides.length}, consecutivePlainBullet=${run}`,
|
|
577
|
+
},
|
|
578
|
+
];
|
|
579
|
+
}
|
|
580
|
+
} else {
|
|
581
|
+
run = 0;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return [];
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// ---------- Angle: Multi-Dimension Composite Stealth-Slop Fusion ----------
|
|
588
|
+
|
|
589
|
+
function countConcreteFacts(rawSlice, factRes) {
|
|
590
|
+
let count = 0;
|
|
591
|
+
for (const re of factRes) {
|
|
592
|
+
re.lastIndex = 0;
|
|
593
|
+
const m = rawSlice.match(re);
|
|
594
|
+
if (m) count += m.length;
|
|
595
|
+
}
|
|
596
|
+
return count;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function probeCompositeMultiSignal(proseText, rawText, banks, existingFindings) {
|
|
600
|
+
const comp = banks["composite-fusion"];
|
|
601
|
+
if (!comp) return [];
|
|
602
|
+
const lex = banks["lexical-signals"] || {};
|
|
603
|
+
const dr = banks["discourse-rhythm"] || {};
|
|
604
|
+
|
|
605
|
+
const lexSignals = [
|
|
606
|
+
...(lex.zhCalqueCluster?.signals || []),
|
|
607
|
+
...(lex.enPhraseCluster?.signals || []),
|
|
608
|
+
].map((s) => ({ id: s.id, re: new RegExp(s.pattern, "iu") }));
|
|
609
|
+
|
|
610
|
+
const zhAlts = (dr.discourseMarkers?.zhLeadMarkers || []).map(escapeRegExp).join("|");
|
|
611
|
+
const enAlts = (dr.discourseMarkers?.enLeadMarkers || []).map(escapeRegExp).join("|");
|
|
612
|
+
const discZhRe = zhAlts ? new RegExp(`(?:^|[。!?;\\n]\\s*)(?:${zhAlts})[,,::]`, "gu") : null;
|
|
613
|
+
const discEnRe = enAlts ? new RegExp(`(?:^|[.!?;\\n]\\s*)(?:${enAlts})[,\\s]`, "gi") : null;
|
|
614
|
+
|
|
615
|
+
const framingRes = (comp.weakFramingPatterns || []).map((p) => new RegExp(p, "iu"));
|
|
616
|
+
const factRes = (comp.concreteFactPatterns || []).map((p) => new RegExp(p, "giu"));
|
|
617
|
+
|
|
618
|
+
const lineStarts = buildLineStarts(rawText);
|
|
619
|
+
const existingLines = new Set(existingFindings.map((f) => f.line));
|
|
620
|
+
const minDims = comp.minDistinctDimensions || 3;
|
|
621
|
+
const maxFacts = comp.maxFactSignals ?? 1;
|
|
622
|
+
const hits = [];
|
|
623
|
+
|
|
624
|
+
for (const para of iterProseParagraphs(proseText)) {
|
|
625
|
+
if (para.skippable) continue;
|
|
626
|
+
const { line: paraLine } = offsetToLineCol(rawText, lineStarts, para.index);
|
|
627
|
+
if (existingLines.has(paraLine)) continue;
|
|
628
|
+
|
|
629
|
+
const rawSlice = rawText.slice(para.blockStart, para.blockStart + para.raw.length);
|
|
630
|
+
const factCount = countConcreteFacts(rawSlice, factRes);
|
|
631
|
+
if (factCount > maxFacts) continue;
|
|
632
|
+
|
|
633
|
+
const activeDims = [];
|
|
634
|
+
|
|
635
|
+
// 1. Weak lexical signal (even 1 hit below cluster threshold)
|
|
636
|
+
const lexMatched = lexSignals.filter((s) => s.re.test(para.raw)).map((s) => s.id);
|
|
637
|
+
if (lexMatched.length >= 1) activeDims.push(`lexical(${lexMatched[0]})`);
|
|
638
|
+
|
|
639
|
+
// 2. Weak discourse signpost (even 1-2 hits below 3-hit cluster threshold)
|
|
640
|
+
const discHits =
|
|
641
|
+
(discZhRe ? (para.trimmed.match(discZhRe) || []).length : 0) +
|
|
642
|
+
(discEnRe ? (para.trimmed.match(discEnRe) || []).length : 0);
|
|
643
|
+
if (discHits >= 1) activeDims.push(`discourse(${discHits})`);
|
|
644
|
+
|
|
645
|
+
// 3. Weak abstract framing cue
|
|
646
|
+
const framingHit = framingRes.some((re) => re.test(para.raw));
|
|
647
|
+
if (framingHit) activeDims.push("framing");
|
|
648
|
+
|
|
649
|
+
// 4. Weak cadence signal (4+ commas in one sentence OR 3+ bold spans OR flat >=4 sentences)
|
|
650
|
+
const sents = para.raw.match(/[^.!?。!?\n]+[.!?。!?]/gu) || [];
|
|
651
|
+
const hasMildComma = sents.some((s) => (stripFormattedNumbersAndCode(s).match(/[,,]/g) || []).length >= 4);
|
|
652
|
+
const hasMildBold = (rawSlice.match(/\*\*[^*\n`]{1,40}\*\*/g) || []).length >= 3;
|
|
653
|
+
if (hasMildComma || hasMildBold) activeDims.push("cadence");
|
|
654
|
+
|
|
655
|
+
if (activeDims.length >= minDims) {
|
|
656
|
+
hits.push({
|
|
657
|
+
index: para.index,
|
|
658
|
+
length: Math.min(110, para.trimmed.length),
|
|
659
|
+
metric: `dims=${activeDims.length} [${activeDims.join("+")}], facts=${factCount}`,
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return hits;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// ---------- Main Pattern Library Multi-Angle Auditor ----------
|
|
667
|
+
|
|
668
|
+
export function auditPatterns(text, { filename = "<memory>", modality = null, banks = {}, angles = null, ooxml = null } = {}) {
|
|
669
|
+
const mod = modality || detectModality(filename) || "markdown";
|
|
670
|
+
const lineStarts = buildLineStarts(text);
|
|
671
|
+
const zones = buildZones(text, mod);
|
|
672
|
+
const allowAngle = (a) => !angles || angles.includes(a);
|
|
673
|
+
const findings = [];
|
|
674
|
+
|
|
675
|
+
const emitHits = (ruleMeta, hits, message) => {
|
|
676
|
+
for (const h of hits) {
|
|
677
|
+
const { line, col } = offsetToLineCol(text, lineStarts, h.index);
|
|
678
|
+
findings.push(
|
|
679
|
+
makePatternFinding({
|
|
680
|
+
ruleId: ruleMeta.ruleId,
|
|
681
|
+
dimension: ruleMeta.dimension,
|
|
682
|
+
detectionAngle: ruleMeta.detectionAngle,
|
|
683
|
+
severity: ruleMeta.severity || "info",
|
|
684
|
+
filename,
|
|
685
|
+
modality: mod,
|
|
686
|
+
line,
|
|
687
|
+
col,
|
|
688
|
+
match: text.slice(h.index, h.index + h.length),
|
|
689
|
+
metric: h.metric || "",
|
|
690
|
+
message,
|
|
691
|
+
})
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const dr = banks["discourse-rhythm"];
|
|
697
|
+
if (dr && TEXT_MODALITIES.has(mod)) {
|
|
698
|
+
if (allowAngle("rhythm-statistics")) {
|
|
699
|
+
if (dr.commaChain) {
|
|
700
|
+
emitHits(dr.commaChain, probeCommaChain(zones.prose, text, dr.commaChain), {
|
|
701
|
+
en: "Single sentence chains 5+ comma-separated clauses in a flat cadence.",
|
|
702
|
+
zh: "单句连续串联 5 个及以上逗号分句,形成平铺拖沓的逗号链节奏。",
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
if (dr.sentenceLengthMonotony) {
|
|
706
|
+
emitHits(dr.sentenceLengthMonotony, probeSentenceLengthMonotony(zones.prose, dr.sentenceLengthMonotony), {
|
|
707
|
+
en: "Paragraph exhibits metronome sentence-length uniformity (CV < 0.16 across >= 5 sentences).",
|
|
708
|
+
zh: "段落内连续 5 句以上句长高度均一(CV < 0.16),呈现节拍器生成韵律。",
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
if (dr.openerAnaphora) {
|
|
712
|
+
emitHits(dr.openerAnaphora, probeOpenerAnaphora(zones.prose, dr.openerAnaphora), {
|
|
713
|
+
en: "4+ consecutive prose sentences open with the identical mechanical prefix.",
|
|
714
|
+
zh: "段落内连续 4 句及以上使用完全相同的机械句首开头。",
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
if (dr.inlineBoldSaturation && (mod === "markdown" || mod === "text")) {
|
|
718
|
+
emitHits(dr.inlineBoldSaturation, probeInlineBoldSaturation(zones.prose, text, dr.inlineBoldSaturation), {
|
|
719
|
+
en: "Dense inline `**bold**` highlight confetti inside a normal prose paragraph.",
|
|
720
|
+
zh: "普通自然段内高密度堆砌 `**加粗词**` 高亮,呈现助手式排版噪点。",
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
if (dr.paragraphLengthUniformity) {
|
|
724
|
+
emitHits(dr.paragraphLengthUniformity, probeParagraphLengthUniformity(zones.prose, dr.paragraphLengthUniformity), {
|
|
725
|
+
en: "Long document allocates nearly identical word budgets across >= 5 consecutive paragraphs.",
|
|
726
|
+
zh: "连续 5 段及以上正文自然段字数高度均一(CV < 0.13),呈现均匀切块模板感。",
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
if (allowAngle("discourse-structure") && dr.discourseMarkers) {
|
|
731
|
+
emitHits(dr.discourseMarkers, probeDiscourseMarkerCluster(zones.prose, dr.discourseMarkers), {
|
|
732
|
+
en: "Mechanical transition signposts stacked across consecutive paragraphs or sentences.",
|
|
733
|
+
zh: "连续段落或句子堆砌机械过渡路标词(如“首先/其次/此外/最后”或连续“Furthermore/Moreover/Additionally”)。",
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
const lex = banks["lexical-signals"];
|
|
739
|
+
if (lex && TEXT_MODALITIES.has(mod) && allowAngle("lexicon-cluster")) {
|
|
740
|
+
if (lex.zhCalqueCluster) {
|
|
741
|
+
emitHits(lex.zhCalqueCluster, probeLexicalCluster(zones.prose, lex.zhCalqueCluster), {
|
|
742
|
+
en: "Chinese AI translation-calque and hollow-connector cluster inside one paragraph.",
|
|
743
|
+
zh: "单段内聚集多处中文 AI 翻译腔或空洞连接套语(如“在……的背景下/不可否认的是/扮演着重要角色”)。",
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
if (lex.enPhraseCluster) {
|
|
747
|
+
emitHits(lex.enPhraseCluster, probeLexicalCluster(zones.prose, lex.enPhraseCluster), {
|
|
748
|
+
en: "Dense cluster of empirically over-represented English AI vocabulary in one paragraph.",
|
|
749
|
+
zh: "单段内高频聚集多个大模型超额偏好英文词组(如 `meticulous`/`pivotal`/`holistic`/`foster`/`underscore`)。",
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
const syn = banks["syntactic-frames"];
|
|
755
|
+
if (syn && TEXT_MODALITIES.has(mod) && allowAngle("syntactic-frame")) {
|
|
756
|
+
if (syn.concessionSymmetry) {
|
|
757
|
+
const pats = [...(syn.concessionSymmetry.enPatterns || []), ...(syn.concessionSymmetry.zhPatterns || [])];
|
|
758
|
+
emitHits(syn.concessionSymmetry, probeProseRegexPatterns(zones.prose, pats), {
|
|
759
|
+
en: "Formulaic both-sides concession frame ('While X presents challenges, it also offers tremendous opportunities').",
|
|
760
|
+
zh: "模板化两面平衡让步句式(“虽然……面临挑战,但也带来了巨大机遇”)。",
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
if (syn.pullQuoteCloser) {
|
|
764
|
+
emitHits(
|
|
765
|
+
syn.pullQuoteCloser,
|
|
766
|
+
probeProseRegexPatterns(zones.prose, syn.pullQuoteCloser.patterns || [], {
|
|
767
|
+
skipQuoted: Boolean(syn.pullQuoteCloser.skipQuoted),
|
|
768
|
+
}),
|
|
769
|
+
{
|
|
770
|
+
en: "Poster-style pull-quote punchline closer.",
|
|
771
|
+
zh: "段尾硬加广告卡片式金句收尾(如“笔一直在你手里”“这才是……真正的温度”)。",
|
|
772
|
+
}
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
if (syn.rhetoricalSelfQa) {
|
|
776
|
+
emitHits(syn.rhetoricalSelfQa, probeProseRegexPatterns(zones.prose, syn.rhetoricalSelfQa.patterns || []), {
|
|
777
|
+
en: "Staged rhetorical self-Q&A transition ('Why does this matter? Because...', '这意味着什么?意味着……').",
|
|
778
|
+
zh: "正文内使用主持词式自问自答过渡句(如“这意味着什么?意味着……”“结果呢?……”)。",
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
const vd = banks["visual-deck"];
|
|
784
|
+
if (vd && allowAngle("visual-markup-ooxml")) {
|
|
785
|
+
if (UI_MODALITIES.has(mod)) {
|
|
786
|
+
if (vd.glassmorphismOveruse) {
|
|
787
|
+
emitHits(vd.glassmorphismOveruse, probeUiPatternCount(text, vd.glassmorphismOveruse), {
|
|
788
|
+
en: "Repeated `backdrop-blur` translucent panels (>= 3 per view) mimic default AI glassmorphism templates.",
|
|
789
|
+
zh: "单视图重复堆砌 3 处及以上 `backdrop-blur` 毛玻璃半透明面板,呈现典型生成式模板特征。",
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
if (vd.accentStripeCard) {
|
|
793
|
+
emitHits(vd.accentStripeCard, probeUiPatternCount(text, vd.accentStripeCard), {
|
|
794
|
+
en: "Repeated thick left accent-stripe cards (`border-l-4` / `border-left: >=3px solid`, >= 3 per view) signal boilerplate dashboards.",
|
|
795
|
+
zh: "单视图堆叠 3 处及以上左侧粗彩条卡片(`border-l-4` / `border-left: >=3px solid`),呈现典型 AI 后台面板套路。",
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (mod === "pptx" && ooxml && vd.pptxLayoutMonotony) {
|
|
800
|
+
const slideHits = probePptxLayoutMonotony(ooxml, vd.pptxLayoutMonotony);
|
|
801
|
+
for (const sh of slideHits) {
|
|
802
|
+
findings.push(
|
|
803
|
+
makePatternFinding({
|
|
804
|
+
ruleId: vd.pptxLayoutMonotony.ruleId,
|
|
805
|
+
dimension: vd.pptxLayoutMonotony.dimension,
|
|
806
|
+
detectionAngle: vd.pptxLayoutMonotony.detectionAngle,
|
|
807
|
+
severity: vd.pptxLayoutMonotony.severity || "info",
|
|
808
|
+
filename,
|
|
809
|
+
modality: mod,
|
|
810
|
+
line: sh.slideNum,
|
|
811
|
+
col: 1,
|
|
812
|
+
location: `slide ${sh.slideNum}`,
|
|
813
|
+
match: sh.match,
|
|
814
|
+
metric: sh.metric,
|
|
815
|
+
message: {
|
|
816
|
+
en: "4+ consecutive content slides share the identical plain-bullet layout with no table, chart, or diagram.",
|
|
817
|
+
zh: "连续 4 页及以上正文幻灯片均退化为纯字要点列表页(无图表、表格或配图),版式过于单调。",
|
|
818
|
+
},
|
|
819
|
+
})
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
const comp = banks["composite-fusion"];
|
|
826
|
+
if (comp && TEXT_MODALITIES.has(mod) && allowAngle("composite-cooccurrence")) {
|
|
827
|
+
emitHits(comp, probeCompositeMultiSignal(zones.prose, text, banks, findings), {
|
|
828
|
+
en: "Multiple sub-threshold AI signals (lexical + discourse + framing/cadence) co-occur in one low-fact paragraph.",
|
|
829
|
+
zh: "同一低事实段落内叠加多个跨维度弱 AI 味信号(套词 + 过渡路标 + 抽象框架/节奏),虽未单点越线但整体 AI 腔明显。",
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
findings.sort((a, b) => (a.line || 0) - (b.line || 0) || (a.col || 0) - (b.col || 0) || a.ruleId.localeCompare(b.ruleId));
|
|
834
|
+
return { version: PATTERN_ENGINE_VERSION, findings };
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
export function analyzePatternProfile(text, options = {}) {
|
|
838
|
+
const res = auditPatterns(text, options);
|
|
839
|
+
const byDimension = {};
|
|
840
|
+
const byAngle = {};
|
|
841
|
+
for (const f of res.findings) {
|
|
842
|
+
byDimension[f.dimension] = (byDimension[f.dimension] || 0) + 1;
|
|
843
|
+
byAngle[f.detectionAngle] = (byAngle[f.detectionAngle] || 0) + 1;
|
|
844
|
+
}
|
|
845
|
+
return {
|
|
846
|
+
version: PATTERN_ENGINE_VERSION,
|
|
847
|
+
findingCount: res.findings.length,
|
|
848
|
+
activeDimensions: Object.keys(byDimension).sort(),
|
|
849
|
+
byDimension,
|
|
850
|
+
byAngle,
|
|
851
|
+
findings: res.findings,
|
|
852
|
+
};
|
|
853
|
+
}
|