dislop 0.9.1 → 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.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +2 -2
- package/.codex-plugin/plugin.json +7 -8
- package/.cursor-plugin/plugin.json +2 -3
- package/.pre-commit-hooks.yaml +5 -12
- package/PRODUCT.md +19 -63
- package/README.md +360 -252
- package/README.zh-CN.md +390 -240
- package/action.yml +30 -39
- package/bin/dislop-mcp.mjs +3 -4
- package/bin/dislop.mjs +4 -4594
- package/gemini-extension.json +2 -2
- package/llms-install.md +68 -0
- package/package.json +17 -63
- package/packs/common/artifact-qa/pack.json +5 -0
- package/packs/common/artifact-qa/prompts/rules.md +11 -0
- package/packs/common/artifact-qa/scripts/index.mjs +173 -0
- package/packs/common/slide-deck/pack.json +6 -0
- package/packs/common/slide-deck/prompts/rules.md +11 -0
- package/packs/common/slide-deck/scripts/index.mjs +62 -0
- package/packs/common/web-ui/pack.json +6 -0
- package/packs/common/web-ui/prompts/rules.md +11 -0
- package/packs/common/web-ui/scripts/index.mjs +80 -0
- package/packs/en/artifact-qa/pack.json +6 -0
- package/packs/en/artifact-qa/prompts/rules.md +14 -0
- package/packs/en/artifact-qa/scripts/index.mjs +90 -0
- package/packs/en/prose/pack.json +7 -0
- package/packs/en/prose/prompts/rules.md +26 -0
- package/packs/en/prose/scripts/index.mjs +290 -0
- package/packs/en/slide-deck/pack.json +7 -0
- package/packs/en/slide-deck/prompts/rules.md +17 -0
- package/packs/en/slide-deck/scripts/index.mjs +81 -0
- package/packs/en/web-ui/pack.json +7 -0
- package/packs/en/web-ui/prompts/rules.md +20 -0
- package/packs/en/web-ui/scripts/index.mjs +103 -0
- package/packs/zh/artifact-qa/pack.json +6 -0
- package/packs/zh/artifact-qa/prompts/rules.md +14 -0
- package/packs/zh/artifact-qa/scripts/index.mjs +89 -0
- package/packs/zh/prose/pack.json +7 -0
- package/packs/zh/prose/prompts/rules.md +26 -0
- package/packs/zh/prose/scripts/index.mjs +305 -0
- package/packs/zh/slide-deck/pack.json +7 -0
- package/packs/zh/slide-deck/prompts/rules.md +17 -0
- package/packs/zh/slide-deck/scripts/index.mjs +75 -0
- package/packs/zh/web-ui/pack.json +7 -0
- package/packs/zh/web-ui/prompts/rules.md +20 -0
- package/packs/zh/web-ui/scripts/index.mjs +98 -0
- package/plugin.json +5 -6
- package/server.json +2 -2
- package/skills/deslop-docs/SKILL.md +10 -8
- package/skills/deslop-slides-docx/SKILL.md +7 -8
- package/skills/deslop-verify/SKILL.md +7 -8
- package/skills/deslop-web-ui/SKILL.md +7 -8
- package/skills/dislop/SKILL.md +16 -28
- package/skills/dislop/references/essay.md +1 -1
- package/skills/dislop/references/essay.zh-CN.md +1 -1
- package/skills/dislop/references/office.md +1 -1
- package/skills/dislop/references/office.zh-CN.md +1 -1
- package/skills/dislop/references/web-ui.md +1 -1
- package/skills/dislop/references/web-ui.zh-CN.md +1 -1
- package/skills/dislop/references/work-docs.md +1 -1
- package/skills/dislop/references/work-docs.zh-CN.md +1 -1
- package/src/cli-main.mjs +210 -0
- package/src/commands/check-fix.mjs +169 -0
- package/src/commands/doctor.mjs +110 -0
- package/src/commands/init.mjs +49 -0
- package/src/commands/login.mjs +82 -0
- package/src/commands/model.mjs +130 -0
- package/src/commands/packs.mjs +44 -0
- package/src/commands/verify.mjs +133 -0
- package/src/commands/voice.mjs +84 -0
- package/src/kernel/config.mjs +232 -0
- package/src/kernel/document-model.mjs +1412 -0
- package/src/kernel/fact-gate.mjs +615 -0
- package/src/kernel/file-discovery.mjs +139 -0
- package/src/{binary-node.mjs → kernel/ooxml-binary.mjs} +532 -893
- package/src/kernel/pack-loader.mjs +715 -0
- package/src/kernel/patcher.mjs +341 -0
- package/src/kernel/pipeline.mjs +267 -0
- package/src/kernel/prompt-assembler.mjs +307 -0
- package/src/kernel/voice-profile.mjs +177 -0
- package/src/mcp/stdio-server.mjs +372 -0
- package/src/runners/auto-fix.mjs +59 -0
- package/src/runners/interactive-tty.mjs +461 -0
- package/src/runners/reporters.mjs +256 -0
- package/src/runtime/chunker.mjs +87 -0
- package/src/runtime/json-extract.mjs +144 -0
- package/src/runtime/privacy-gate.mjs +97 -0
- package/src/runtime/providers/anthropic.mjs +65 -0
- package/src/runtime/providers/cloud.mjs +136 -0
- package/src/runtime/providers/gemini.mjs +91 -0
- package/src/runtime/providers/local-model.mjs +139 -0
- package/src/runtime/providers/openai-compat.mjs +130 -0
- package/src/runtime/router.mjs +315 -0
- package/src/sdk/index.mjs +137 -0
- package/models/manifest.json +0 -90
- package/models/pocket-slop-v1.json +0 -1
- package/packs/business-brief/pack.json +0 -937
- package/packs/core/pack.json +0 -209
- package/packs/deck-and-ui/pack.json +0 -539
- package/packs/engineering-spec/pack.json +0 -144
- package/packs/executive-deck/pack.json +0 -98
- package/packs/literary-essay/pack.json +0 -344
- package/packs/regulated-comms/pack.json +0 -99
- package/patterns/ai-tic-rubric.json +0 -252
- package/patterns/banks/composite-fusion.json +0 -48
- package/patterns/banks/discourse-rhythm.json +0 -95
- package/patterns/banks/lexical-signals.json +0 -92
- package/patterns/banks/syntactic-frames.json +0 -52
- package/patterns/banks/visual-deck.json +0 -44
- package/patterns/dimensions/artifacts.json +0 -121
- package/patterns/dimensions/discourse.json +0 -438
- package/patterns/dimensions/lexical.json +0 -198
- package/patterns/dimensions/rhythm.json +0 -258
- package/patterns/dimensions/syntactic.json +0 -285
- package/patterns/dimensions/visual-and-deck.json +0 -530
- package/patterns/taxonomy.json +0 -112
- package/src/core.mjs +0 -5497
- package/src/dislop/review-picker.vim +0 -114
- package/src/local-model.mjs +0 -997
- package/src/pattern-engine.mjs +0 -1003
- package/src/pocket-model.mjs +0 -729
- package/src/review-apply.mjs +0 -151
- package/src/review-client.mjs +0 -1073
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
const SENTENCE_INITIAL_STOPWORDS = new Set([
|
|
2
|
+
"A",
|
|
3
|
+
"An",
|
|
4
|
+
"And",
|
|
5
|
+
"Are",
|
|
6
|
+
"As",
|
|
7
|
+
"At",
|
|
8
|
+
"After",
|
|
9
|
+
"Although",
|
|
10
|
+
"Also",
|
|
11
|
+
"Assign",
|
|
12
|
+
"Based",
|
|
13
|
+
"Because",
|
|
14
|
+
"Before",
|
|
15
|
+
"Beyond",
|
|
16
|
+
"Both",
|
|
17
|
+
"But",
|
|
18
|
+
"By",
|
|
19
|
+
"Certainly",
|
|
20
|
+
"Despite",
|
|
21
|
+
"During",
|
|
22
|
+
"Each",
|
|
23
|
+
"Even",
|
|
24
|
+
"Every",
|
|
25
|
+
"Finally",
|
|
26
|
+
"First",
|
|
27
|
+
"For",
|
|
28
|
+
"From",
|
|
29
|
+
"Furthermore",
|
|
30
|
+
"Generally",
|
|
31
|
+
"Given",
|
|
32
|
+
"Here",
|
|
33
|
+
"However",
|
|
34
|
+
"If",
|
|
35
|
+
"Importantly",
|
|
36
|
+
"In",
|
|
37
|
+
"Indeed",
|
|
38
|
+
"Instead",
|
|
39
|
+
"It",
|
|
40
|
+
"Its",
|
|
41
|
+
"Let",
|
|
42
|
+
"Looking",
|
|
43
|
+
"Many",
|
|
44
|
+
"Meanwhile",
|
|
45
|
+
"Moreover",
|
|
46
|
+
"Most",
|
|
47
|
+
"Naturally",
|
|
48
|
+
"Needless",
|
|
49
|
+
"Nevertheless",
|
|
50
|
+
"Next",
|
|
51
|
+
"No",
|
|
52
|
+
"Nor",
|
|
53
|
+
"Not",
|
|
54
|
+
"Notably",
|
|
55
|
+
"Now",
|
|
56
|
+
"Of",
|
|
57
|
+
"Often",
|
|
58
|
+
"On",
|
|
59
|
+
"Once",
|
|
60
|
+
"One",
|
|
61
|
+
"Only",
|
|
62
|
+
"Or",
|
|
63
|
+
"Overall",
|
|
64
|
+
"Perhaps",
|
|
65
|
+
"Please",
|
|
66
|
+
"Rather",
|
|
67
|
+
"Second",
|
|
68
|
+
"Simply",
|
|
69
|
+
"Since",
|
|
70
|
+
"So",
|
|
71
|
+
"Some",
|
|
72
|
+
"Specifically",
|
|
73
|
+
"Still",
|
|
74
|
+
"Such",
|
|
75
|
+
"Sure",
|
|
76
|
+
"That",
|
|
77
|
+
"The",
|
|
78
|
+
"Their",
|
|
79
|
+
"Then",
|
|
80
|
+
"There",
|
|
81
|
+
"Therefore",
|
|
82
|
+
"These",
|
|
83
|
+
"They",
|
|
84
|
+
"This",
|
|
85
|
+
"Those",
|
|
86
|
+
"Though",
|
|
87
|
+
"Through",
|
|
88
|
+
"Thus",
|
|
89
|
+
"To",
|
|
90
|
+
"Today",
|
|
91
|
+
"Ultimately",
|
|
92
|
+
"Under",
|
|
93
|
+
"Unless",
|
|
94
|
+
"Unlike",
|
|
95
|
+
"Until",
|
|
96
|
+
"Upon",
|
|
97
|
+
"Use",
|
|
98
|
+
"Using",
|
|
99
|
+
"We",
|
|
100
|
+
"What",
|
|
101
|
+
"When",
|
|
102
|
+
"Where",
|
|
103
|
+
"Whether",
|
|
104
|
+
"Which",
|
|
105
|
+
"While",
|
|
106
|
+
"Who",
|
|
107
|
+
"Why",
|
|
108
|
+
"With",
|
|
109
|
+
"Within",
|
|
110
|
+
"Without",
|
|
111
|
+
"Yet",
|
|
112
|
+
"You",
|
|
113
|
+
"Your",
|
|
114
|
+
"Zero",
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
function normalizeNumericToken(raw) {
|
|
118
|
+
return raw.replace(/,/g, "");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const ZH_DIGIT_MAP = {
|
|
122
|
+
"\u96f6": 0,
|
|
123
|
+
"\u3007": 0,
|
|
124
|
+
"\u4e00": 1,
|
|
125
|
+
"\u4e8c": 2,
|
|
126
|
+
"\u4e24": 2,
|
|
127
|
+
"\u4e09": 3,
|
|
128
|
+
"\u56db": 4,
|
|
129
|
+
"\u4e94": 5,
|
|
130
|
+
"\u516d": 6,
|
|
131
|
+
"\u4e03": 7,
|
|
132
|
+
"\u516b": 8,
|
|
133
|
+
"\u4e5d": 9,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
function parseChineseNumeral(str) {
|
|
137
|
+
const s = String(str || "").trim();
|
|
138
|
+
if (!s) return null;
|
|
139
|
+
if (/^[\u96f6\u3007\u4e00\u4e8c\u4e24\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d]+$/.test(s)) {
|
|
140
|
+
return Number(Array.from(s).map((c) => ZH_DIGIT_MAP[c]).join(""));
|
|
141
|
+
}
|
|
142
|
+
const m = s.match(
|
|
143
|
+
/^([\u4e00\u4e8c\u4e24\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d])?\u5341([\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d])?$/,
|
|
144
|
+
);
|
|
145
|
+
if (m) {
|
|
146
|
+
const tens = m[1] ? ZH_DIGIT_MAP[m[1]] : 1;
|
|
147
|
+
const ones = m[2] ? ZH_DIGIT_MAP[m[2]] : 0;
|
|
148
|
+
return tens * 10 + ones;
|
|
149
|
+
}
|
|
150
|
+
const m2 = s.match(
|
|
151
|
+
/^([\u4e00\u4e8c\u4e24\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d])\u767e(?:([\u96f6\u4e00\u4e8c\u4e24\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d])?\u5341?([\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d])?)?$/,
|
|
152
|
+
);
|
|
153
|
+
if (m2) {
|
|
154
|
+
const hundreds = ZH_DIGIT_MAP[m2[1]] * 100;
|
|
155
|
+
if (!m2[2] && !m2[3]) return hundreds;
|
|
156
|
+
if (s.includes("\u5341")) {
|
|
157
|
+
const tens = m2[2] && m2[2] !== "\u96f6" ? ZH_DIGIT_MAP[m2[2]] * 10 : 10;
|
|
158
|
+
const ones = m2[3] ? ZH_DIGIT_MAP[m2[3]] : 0;
|
|
159
|
+
return hundreds + tens + ones;
|
|
160
|
+
}
|
|
161
|
+
const last = m2[3] || m2[2];
|
|
162
|
+
return hundreds + (last && last !== "\u96f6" ? ZH_DIGIT_MAP[last] : 0);
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function stripMarkupForFacts(text) {
|
|
168
|
+
const raw = String(text || "");
|
|
169
|
+
if (!/<[a-zA-Z/][^>]*>/.test(raw)) return raw;
|
|
170
|
+
return raw
|
|
171
|
+
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, " ")
|
|
172
|
+
.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, " ")
|
|
173
|
+
.replace(/<[^>]+>/g, " ")
|
|
174
|
+
.replace(/ /gi, " ")
|
|
175
|
+
.replace(/&/gi, "&")
|
|
176
|
+
.replace(/</gi, "<")
|
|
177
|
+
.replace(/>/gi, ">")
|
|
178
|
+
.replace(/"/gi, '"')
|
|
179
|
+
.replace(/'/gi, "'");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function normalizeProperNounKey(noun) {
|
|
183
|
+
if (/^[A-Z]{2,}s$/.test(noun)) {
|
|
184
|
+
return noun.slice(0, -1);
|
|
185
|
+
}
|
|
186
|
+
return noun;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const GENERIC_NON_ENTITY_CAPS = new Set(["AI", "TODO", "TBD", "FIXME", "XXX", "OK"]);
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Extract protected factual anchors from a text span:
|
|
193
|
+
* - Numbers, decimals, percentages, currencies, version tags, Chinese classifier quantities
|
|
194
|
+
* - Measurement units paired with numbers (`ms`, `KB`, `GB`, `%`, `hours`, etc.)
|
|
195
|
+
* - URLs (`https://...`, `http://...`, `mailto:...`)
|
|
196
|
+
* - Inline code spans (`` `...` ``)
|
|
197
|
+
* - Mid-clause proper nouns, mixed-case identifiers, and ALL-CAPS / alphanumeric acronyms (`OAuth`, `PostgreSQL`, `GDPR`, `Q3`)
|
|
198
|
+
*/
|
|
199
|
+
export function extractProtectedFacts(text) {
|
|
200
|
+
const input = stripMarkupForFacts(text);
|
|
201
|
+
|
|
202
|
+
// 1. Inline code spans
|
|
203
|
+
const codeSpans = [];
|
|
204
|
+
const codeMask = new Uint8Array(input.length);
|
|
205
|
+
const codeRe = /`+([^`]+)`+/g;
|
|
206
|
+
let m;
|
|
207
|
+
while ((m = codeRe.exec(input)) !== null) {
|
|
208
|
+
codeSpans.push(m[1].trim());
|
|
209
|
+
codeMask.fill(1, m.index, m.index + m[0].length);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 2. URLs
|
|
213
|
+
const urls = [];
|
|
214
|
+
const urlRe = /\bhttps?:\/\/[^\s)>\]"']+/gi;
|
|
215
|
+
while ((m = urlRe.exec(input)) !== null) {
|
|
216
|
+
if (codeMask[m.index]) continue;
|
|
217
|
+
const cleanUrl = m[0].replace(/[.,;:!?]+$/, "");
|
|
218
|
+
urls.push(cleanUrl);
|
|
219
|
+
codeMask.fill(1, m.index, m.index + cleanUrl.length);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Mask unfilled placeholder tokens ([TODO], [Company Name], {{var}}, [oaicite:1]) so resolving/deleting artifacts is never flagged
|
|
223
|
+
const placeholderRe =
|
|
224
|
+
/\[(?:TODO|TBD|FIXME|XXX|oaicite:\d+|turn\d+search\d+|citation:[^\]]+|Company Name|Recipient Name|Client Name|Author Name|Project Name|insert\s+[^\]]+|add\s+[^\]]+|placeholder[^\]]*|\u5f85\u8865\u5145[^\]]*|\u5f85\u586b\u5199[^\]]*|\u6b64\u5904\u63d2\u5165[^\]]*)\](?!\s*\()|\{\{\s*[A-Za-z_][A-Za-z0-9_.-]*\s*\}\}/gi;
|
|
225
|
+
while ((m = placeholderRe.exec(input)) !== null) {
|
|
226
|
+
codeMask.fill(1, m.index, m.index + m[0].length);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const unmasked = Array.from(input)
|
|
230
|
+
.map((ch, idx) => (codeMask[idx] ? " " : ch))
|
|
231
|
+
.join("");
|
|
232
|
+
|
|
233
|
+
// 3. Numbers & numeric-unit compounds
|
|
234
|
+
const numbers = [];
|
|
235
|
+
const units = [];
|
|
236
|
+
const numUnitRe =
|
|
237
|
+
/(?:[$€£¥]\s*)?\b\d{1,3}(?:,\d{3})+(?:\.\d+)?(?:\s*(?:%|ms|s|sec|mins?|hrs?|hours?|days?|weeks?|months?|years?|kb|mb|gb|tb|bps|kbps|mbps|gbps|hz|khz|mhz|ghz|px|pt|x))?\b|(?:[$€£¥]\s*)?\b\d+(?:\.\d+)?(?:\s*(?:%|ms|s|sec|mins?|hrs?|hours?|days?|weeks?|months?|years?|kb|mb|gb|tb|bps|kbps|mbps|gbps|hz|khz|mhz|ghz|px|pt|x))?(?![A-Za-z0-9_])/gi;
|
|
238
|
+
|
|
239
|
+
while ((m = numUnitRe.exec(unmasked)) !== null) {
|
|
240
|
+
const token = m[0].trim();
|
|
241
|
+
const numPart = token.match(/\d[\d,]*(?:\.\d+)?/);
|
|
242
|
+
if (numPart) {
|
|
243
|
+
numbers.push(normalizeNumericToken(numPart[0]));
|
|
244
|
+
}
|
|
245
|
+
const unitPart = token.match(
|
|
246
|
+
/(?:[$€£¥]|%|ms|s|sec|mins?|hrs?|hours?|days?|weeks?|months?|years?|kb|mb|gb|tb|bps|kbps|mbps|gbps|hz|khz|mhz|ghz|px|pt|x)$/i,
|
|
247
|
+
);
|
|
248
|
+
if (unitPart) {
|
|
249
|
+
units.push(unitPart[0].toLowerCase());
|
|
250
|
+
}
|
|
251
|
+
const prefixCurrency = token.match(/^[$€£¥]/);
|
|
252
|
+
if (prefixCurrency) {
|
|
253
|
+
units.push(prefixCurrency[0]);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// CJK numeric units via Unicode escapes so src/ remains strictly English/ASCII
|
|
258
|
+
const cjkUnitRe =
|
|
259
|
+
/\d+(?:\.\d+)?\s*(?:\u4e07|\u4ebf|\u500d|\u6beb\u79d2|\u79d2|\u5206\u949f|\u5c0f\u65f6|\u5929|\u5468|\u4e2a\u6708|\u5e74|%|\u4e2a\u767e\u5206\u70b9)/g;
|
|
260
|
+
while ((m = cjkUnitRe.exec(unmasked)) !== null) {
|
|
261
|
+
const u = m[0].replace(/[\d.\s]+/g, "");
|
|
262
|
+
if (u) units.push(u);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// CJK spelled quantities followed by explicit classifiers (2+ always count; standalone "\u4e00" only counts with explicit quantifier or measurement unit)
|
|
266
|
+
const cjkQtyRe =
|
|
267
|
+
/(?:[\u4e8c\u4e24\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e]{1,4}\s*(?=\u4e2a|\u6b21|\u6761|\u9879|\u6a21\u5757|\u53f0|\u5957|\u5f20|\u4efd|\u9875|\u5468|\u5929|\u5c0f\u65f6|\u5206\u949f|\u79d2|\u500d|\u6735|\u679a|\u5bb6|\u4eba|\u5904|\u5c42|\u9636\u6bb5)|(?<=\u5171|\u4ec5|\u53ea\u6709|\u81f3\u5c11|\u6700\u591a|\u7b2c)\u4e00\s*(?=\u4e2a|\u6b21|\u6761|\u9879|\u6a21\u5757|\u53f0|\u5957|\u5f20|\u4efd|\u9875|\u5468|\u5929|\u5c0f\u65f6|\u5206\u949f|\u79d2|\u500d|\u6735|\u679a|\u5bb6|\u4eba|\u5904|\u5c42|\u9636\u6bb5)|\u4e00(?=\s*(?:\u5c0f\u65f6|\u5206\u949f|\u79d2|\u5468|\u5929|\u500d)))/g;
|
|
268
|
+
while ((m = cjkQtyRe.exec(unmasked)) !== null) {
|
|
269
|
+
const val = parseChineseNumeral(m[0]);
|
|
270
|
+
if (val !== null) {
|
|
271
|
+
numbers.push(String(val));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// 4. Proper nouns: always protect ALL-CAPS/mixed-case/alphanumeric tokens (excluding generic badges like 'AI'),
|
|
276
|
+
// and protect plain TitleCase words only when they appear mid-clause (never solely at sentence/heading/label starts)
|
|
277
|
+
const properNouns = [];
|
|
278
|
+
const plainStartOnly = new Set();
|
|
279
|
+
const plainMidClause = new Set();
|
|
280
|
+
const wordRe = /\b(?:[A-Z][a-zA-Z0-9]+|[A-Z]{2,}[0-9]*|[a-z]+[A-Z][a-zA-Z0-9]*)\b/g;
|
|
281
|
+
while ((m = wordRe.exec(unmasked)) !== null) {
|
|
282
|
+
const word = m[0];
|
|
283
|
+
if (GENERIC_NON_ENTITY_CAPS.has(word)) continue;
|
|
284
|
+
|
|
285
|
+
const idx = m.index;
|
|
286
|
+
const beforeRaw = unmasked.slice(0, idx);
|
|
287
|
+
const beforeSlice = beforeRaw.trimEnd();
|
|
288
|
+
const isBoundaryStart =
|
|
289
|
+
beforeSlice.length === 0 ||
|
|
290
|
+
/[.!?\u3002\uff01\uff1f:\uff1a"\u201c\u201d'(\[\n\r\-*•·\u2014\u2013\/]$/.test(beforeSlice) ||
|
|
291
|
+
/\*\*$/.test(beforeSlice);
|
|
292
|
+
|
|
293
|
+
const isAllCapsOrMixed =
|
|
294
|
+
/^[A-Z]{2,}[0-9]*$/.test(word) ||
|
|
295
|
+
/[a-z][A-Z]/.test(word) ||
|
|
296
|
+
/[A-Z].*\d|\d.*[A-Z]/.test(word);
|
|
297
|
+
|
|
298
|
+
if (!isAllCapsOrMixed) {
|
|
299
|
+
if (SENTENCE_INITIAL_STOPWORDS.has(word)) continue;
|
|
300
|
+
if (isBoundaryStart) {
|
|
301
|
+
plainStartOnly.add(word);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const prevTokenMatch = beforeSlice.match(/([A-Za-z]+)$/);
|
|
305
|
+
const prevIsStopwordTitle = prevTokenMatch && SENTENCE_INITIAL_STOPWORDS.has(prevTokenMatch[1]);
|
|
306
|
+
// Mid-clause single-capital word: protect when preceded by lowercase word, CJK, comma, or non-stopword entity
|
|
307
|
+
if (!prevIsStopwordTitle && /(?:^|\s)[a-z][a-z0-9,)\-]*\s+$|[\u4e00-\u9fff,)]\s+$|[A-Z][A-Za-z0-9]+\s+$/.test(beforeRaw)) {
|
|
308
|
+
plainMidClause.add(word);
|
|
309
|
+
properNouns.push(word);
|
|
310
|
+
}
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
properNouns.push(word);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
for (const w of plainStartOnly) {
|
|
318
|
+
if (plainMidClause.has(w)) {
|
|
319
|
+
properNouns.push(w);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return {
|
|
324
|
+
numbers,
|
|
325
|
+
units,
|
|
326
|
+
urls,
|
|
327
|
+
codeSpans,
|
|
328
|
+
properNouns: Array.from(new Set(properNouns)),
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function setMissing(expectedList, actualList) {
|
|
333
|
+
const actualSet = new Set(actualList);
|
|
334
|
+
const missing = [];
|
|
335
|
+
for (const req of expectedList) {
|
|
336
|
+
if (!actualSet.has(req)) {
|
|
337
|
+
missing.push(req);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return Array.from(new Set(missing));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function missingProperNouns(origNouns, candNouns, candRaw) {
|
|
344
|
+
const candNormSet = new Set(candNouns.map(normalizeProperNounKey));
|
|
345
|
+
const candLower = candRaw.toLowerCase();
|
|
346
|
+
const missing = [];
|
|
347
|
+
for (const noun of origNouns) {
|
|
348
|
+
const norm = normalizeProperNounKey(noun);
|
|
349
|
+
if (candNouns.includes(noun) || candNormSet.has(norm) || candRaw.includes(noun)) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (noun === "RAM" && /\bmemory\b/.test(candLower)) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
missing.push(noun);
|
|
356
|
+
}
|
|
357
|
+
return Array.from(new Set(missing));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Run the Kernel Baseline Fact Gate comparing `originalText` against `candidateText`.
|
|
362
|
+
* When `checkFabrication` is true (used on automated LLM `suggestedReplacement`s), also blocks
|
|
363
|
+
* newly injected URLs, inline code spans, or fabricated numbers absent from `originalText`.
|
|
364
|
+
*/
|
|
365
|
+
export function verifyBaselineFacts(originalText, candidateText, { checkFabrication = false } = {}) {
|
|
366
|
+
const orig = extractProtectedFacts(originalText);
|
|
367
|
+
const cand = extractProtectedFacts(candidateText);
|
|
368
|
+
const origRaw = stripMarkupForFacts(originalText);
|
|
369
|
+
const candRaw = stripMarkupForFacts(candidateText);
|
|
370
|
+
|
|
371
|
+
const reasons = [];
|
|
372
|
+
|
|
373
|
+
const missingNums = setMissing(orig.numbers, cand.numbers);
|
|
374
|
+
if (missingNums.length > 0) {
|
|
375
|
+
reasons.push(`dropped number(s): ${missingNums.join(", ")}`);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const missingUnits = setMissing(orig.units, cand.units);
|
|
379
|
+
if (missingUnits.length > 0) {
|
|
380
|
+
reasons.push(`dropped unit/symbol(s): ${missingUnits.join(", ")}`);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const missingUrls = orig.urls.filter((u) => !cand.urls.includes(u) && !candRaw.includes(u));
|
|
384
|
+
if (missingUrls.length > 0) {
|
|
385
|
+
reasons.push(`dropped URL(s): ${missingUrls.join(", ")}`);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const missingCode = orig.codeSpans.filter(
|
|
389
|
+
(c) => !cand.codeSpans.includes(c) && !candRaw.includes(c),
|
|
390
|
+
);
|
|
391
|
+
if (missingCode.length > 0) {
|
|
392
|
+
reasons.push(`dropped inline code: ${missingCode.map((c) => `\`${c}\``).join(", ")}`);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const missingNouns = missingProperNouns(orig.properNouns, cand.properNouns, candRaw);
|
|
396
|
+
if (missingNouns.length > 0) {
|
|
397
|
+
reasons.push(`dropped proper noun/entity: ${missingNouns.join(", ")}`);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Deterministic anti-injection / anti-fabrication check for automated replacements
|
|
401
|
+
if (checkFabrication && candRaw.trim() !== "") {
|
|
402
|
+
const fabricatedUrls = cand.urls.filter((u) => !orig.urls.includes(u) && !origRaw.includes(u));
|
|
403
|
+
if (fabricatedUrls.length > 0) {
|
|
404
|
+
reasons.push(`injected unverified URL(s): ${fabricatedUrls.join(", ")}`);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const fabricatedCode = cand.codeSpans.filter(
|
|
408
|
+
(c) => !orig.codeSpans.includes(c) && !origRaw.includes(c),
|
|
409
|
+
);
|
|
410
|
+
if (fabricatedCode.length > 0) {
|
|
411
|
+
reasons.push(`injected unverified inline code: ${fabricatedCode.map((c) => `\`${c}\``).join(", ")}`);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const fabricatedNums = setMissing(cand.numbers, orig.numbers);
|
|
415
|
+
if (fabricatedNums.length > 0) {
|
|
416
|
+
reasons.push(`fabricated number(s): ${fabricatedNums.join(", ")}`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return {
|
|
421
|
+
ok: reasons.length === 0,
|
|
422
|
+
reasons,
|
|
423
|
+
summary: reasons.join("; "),
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Execute Step 5 Dual Post-LLM Fact Gate across all candidate items:
|
|
429
|
+
* 1. Kernel Baseline Fact Gate (`verifyBaselineFacts`)
|
|
430
|
+
* 2. Originating Pack Custom Gate (`pack.verifyFix(item, candidateText, doc)`)
|
|
431
|
+
*
|
|
432
|
+
* Items that fail either gate have `suggestedReplacement` cleared, `fixSafety` downgraded
|
|
433
|
+
* to `"manual"`, and `verificationNote` attached.
|
|
434
|
+
*/
|
|
435
|
+
export async function applyDualFactGate(items, doc, activePacks) {
|
|
436
|
+
const packMap = new Map(activePacks.map((p) => [p.name, p]));
|
|
437
|
+
const gated = [];
|
|
438
|
+
|
|
439
|
+
for (const item of items) {
|
|
440
|
+
// Only gate items that propose an automatic/reviewable edit or deletion
|
|
441
|
+
const hasReplacement = Boolean(item.suggestedReplacement && item.suggestedReplacement.trim() !== "");
|
|
442
|
+
const isAutoDelete = item.actionType === "delete" && item.fixSafety !== "manual";
|
|
443
|
+
if (!hasReplacement && !isAutoDelete) {
|
|
444
|
+
gated.push(item);
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Deterministic `defect` artifact deletions (chatbot wrappers & leaked tool citations) intentionally strip meta-wrappers
|
|
449
|
+
if (
|
|
450
|
+
item.kind === "defect" &&
|
|
451
|
+
item.actionType === "delete" &&
|
|
452
|
+
(item.ruleId.endsWith("/chatbot-artifact") || item.ruleId.endsWith("/chatbot-citation-leak"))
|
|
453
|
+
) {
|
|
454
|
+
gated.push(item);
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const candidateText = hasReplacement ? item.suggestedReplacement : "";
|
|
459
|
+
const baseline = verifyBaselineFacts(item.originalQuote, candidateText, {
|
|
460
|
+
checkFabrication: hasReplacement,
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
if (!baseline.ok) {
|
|
464
|
+
gated.push({
|
|
465
|
+
...item,
|
|
466
|
+
suggestedReplacement: "",
|
|
467
|
+
fixSafety: "manual",
|
|
468
|
+
actionType: item.rewritePrompt ? "prompt" : item.actionType,
|
|
469
|
+
verificationNote: `Fact Gate withheld replacement (${baseline.summary}).`,
|
|
470
|
+
});
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const pack = packMap.get(item.pack);
|
|
475
|
+
let customRejected = null;
|
|
476
|
+
if (pack) {
|
|
477
|
+
if (typeof pack.verifyFix === "function") {
|
|
478
|
+
const res = pack.verifyFix(item, candidateText, doc);
|
|
479
|
+
if (res && res.ok === false) customRejected = res;
|
|
480
|
+
} else if (pack.hasScripts && typeof pack.loadScripts === "function") {
|
|
481
|
+
const scriptModules = await pack.loadScripts();
|
|
482
|
+
for (const sm of scriptModules) {
|
|
483
|
+
if (typeof sm.verifyFix === "function") {
|
|
484
|
+
const res = sm.verifyFix(item, candidateText, doc);
|
|
485
|
+
if (res && res.ok === false) {
|
|
486
|
+
customRejected = res;
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (customRejected) {
|
|
495
|
+
gated.push({
|
|
496
|
+
...item,
|
|
497
|
+
suggestedReplacement: "",
|
|
498
|
+
fixSafety: "manual",
|
|
499
|
+
actionType: item.rewritePrompt ? "prompt" : item.actionType,
|
|
500
|
+
verificationNote: `Pack '${pack.name}' withheld replacement (${customRejected.reason || "failed custom verifyFix"}).`,
|
|
501
|
+
});
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
gated.push(item);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return gated;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Standalone revision verification used by `dislop verify <before> <after>` and local MCP `dislop_verify`.
|
|
513
|
+
*/
|
|
514
|
+
export function verifyDocumentRevision(beforeText, afterText) {
|
|
515
|
+
const factCheck = verifyBaselineFacts(beforeText, afterText);
|
|
516
|
+
const secondOrderSlopHits = [];
|
|
517
|
+
|
|
518
|
+
const regressions = [
|
|
519
|
+
{
|
|
520
|
+
id: "introduced-negation-slogan",
|
|
521
|
+
re: /\b(?:this )?(?:isn't|is not) (?:just|merely|simply)\b[\s\S]{1,60}\bit(?:'s| is)\b/i,
|
|
522
|
+
beforeRe: /\b(?:isn't|is not) (?:just|merely|simply)\b/i,
|
|
523
|
+
message: "Introduced a 'not just X — it's Y' slogan frame not present in original.",
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
id: "introduced-zh-negation-slogan",
|
|
527
|
+
re: /(?:\u8fd9)?(?:\u4e0d\u662f|\u5e76\u975e)(?:\u5355\u7eaf\u7684?|\u7b80\u5355\u7684?)?[^\uff0c\u3002\uff1b\n]{1,24}[\uff0c,]\s*\u800c\u662f[^\u3002\uff01\uff1f\n]{1,36}/,
|
|
528
|
+
beforeRe: /(?:\u4e0d\u662f|\u5e76\u975e)[^\uff0c\u3002\uff1b\n]{1,24}[\uff0c,]\s*\u800c\u662f/,
|
|
529
|
+
message: "Introduced an unprompted Chinese 'not X, but Y' slogan pivot.",
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
id: "introduced-placeholder",
|
|
533
|
+
re: /\[(?:TODO|TBD|FIXME|insert [^\]]+)\]/i,
|
|
534
|
+
beforeRe: /\[(?:TODO|TBD|FIXME|insert [^\]]+)\]/i,
|
|
535
|
+
message: "Introduced an unfilled bracketed placeholder into revised text.",
|
|
536
|
+
},
|
|
537
|
+
];
|
|
538
|
+
|
|
539
|
+
for (const rule of regressions) {
|
|
540
|
+
if (rule.re.test(afterText) && !rule.beforeRe.test(beforeText)) {
|
|
541
|
+
secondOrderSlopHits.push({ id: rule.id, message: rule.message });
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// Metric direction reversal guard (`from A to B` -> `from B to A`, `\u4ece A \u964d\u81f3 B` -> `\u4ece B \u5347\u81f3 A`)
|
|
546
|
+
const normBefore = String(beforeText || "").replace(/,/g, "");
|
|
547
|
+
const normAfter = String(afterText || "").replace(/,/g, "");
|
|
548
|
+
const dirPairs = [];
|
|
549
|
+
const enDirRe = /\bfrom\s+(\d+(?:\.\d+)?)\s*(?:%|ms|s|sec|mins?|hrs?|hours?|kb|mb|gb|x)?(?![A-Za-z0-9_])\s+to\s+(\d+(?:\.\d+)?)\s*(?:%|ms|s|sec|mins?|hrs?|hours?|kb|mb|gb|x)?(?![A-Za-z0-9_])/gi;
|
|
550
|
+
let dm;
|
|
551
|
+
while ((dm = enDirRe.exec(normBefore)) !== null) {
|
|
552
|
+
if (dm[1] !== dm[2]) dirPairs.push({ fromVal: dm[1], toVal: dm[2], lang: "en" });
|
|
553
|
+
}
|
|
554
|
+
const zhDirRe = /\u4ece\s*(\d+(?:\.\d+)?)\s*(?:%|ms|s|\u6beb\u79d2|\u79d2|\u5206\u949f|\u5c0f\u65f6|\u500d)?[^\u3002\uff01\uff1f\n]{0,12}?(?:\u964d\u5230|\u964d\u81f3|\u5347\u5230|\u5347\u81f3|\u5230|\u81f3|\u53d8\u4e3a)\s*(\d+(?:\.\d+)?)/g;
|
|
555
|
+
while ((dm = zhDirRe.exec(normBefore)) !== null) {
|
|
556
|
+
if (dm[1] !== dm[2]) dirPairs.push({ fromVal: dm[1], toVal: dm[2], lang: "zh" });
|
|
557
|
+
}
|
|
558
|
+
for (const pair of dirPairs) {
|
|
559
|
+
const escA = pair.fromVal.replace(/\./g, "\\.");
|
|
560
|
+
const escB = pair.toVal.replace(/\./g, "\\.");
|
|
561
|
+
const revRe =
|
|
562
|
+
pair.lang === "en"
|
|
563
|
+
? new RegExp(`\\bfrom\\s+${escB}[^.\\n]{0,20}?\\bto\\s+${escA}(?:\\s*(?:%|ms|s|sec|mins?|hrs?|hours?|kb|mb|gb|x))?(?![A-Za-z0-9_])`, "i")
|
|
564
|
+
: new RegExp(`\\u4ece\\s*${escB}[^\\u3002\\uff01\\uff1f\\n]{0,12}?(?:\\u964d\\u5230|\\u964d\\u81f3|\\u5347\\u5230|\\u5347\\u81f3|\\u5230|\\u81f3|\\u53d8\\u4e3a)\\s*${escA}`);
|
|
565
|
+
if (revRe.test(normAfter)) {
|
|
566
|
+
secondOrderSlopHits.push({
|
|
567
|
+
id: "metric-direction-reversed",
|
|
568
|
+
message: `Reversed metric direction from '${pair.fromVal} -> ${pair.toVal}' to '${pair.toVal} -> ${pair.fromVal}'.`,
|
|
569
|
+
});
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Hard negation / prohibition polarity flip guard
|
|
575
|
+
const enNegClaim = String(beforeText || "").match(
|
|
576
|
+
/\b([A-Za-z][A-Za-z0-9_-]{2,24}(?:\s+[A-Za-z0-9_-]{2,20}){0,2})\s+(?:does not|do not|cannot|can't|must not|never)\s+([a-z]{3,20})\b/i,
|
|
577
|
+
);
|
|
578
|
+
if (enNegClaim) {
|
|
579
|
+
const subj = enNegClaim[1].replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
580
|
+
const verb = enNegClaim[2].replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
581
|
+
const flippedEn = new RegExp(`\\b${subj}\\s+${verb}s?\\b`, "i");
|
|
582
|
+
const hasNegInAfter = /\b(?:not|never|no|zero|without|cannot|can't|won't|don't|doesn't|mustn't)\b/i.test(
|
|
583
|
+
afterText,
|
|
584
|
+
);
|
|
585
|
+
if (flippedEn.test(afterText) && !hasNegInAfter) {
|
|
586
|
+
secondOrderSlopHits.push({
|
|
587
|
+
id: "polarity-negation-dropped",
|
|
588
|
+
message: `Dropped mandatory negation around '${enNegClaim[1]} ... ${enNegClaim[2]}'.`,
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const zhProhibClaim = String(beforeText || "").match(
|
|
594
|
+
/(?:\u4e25\u7981|\u7981\u6b62|\u4e0d\u5f97|\u5207\u52ff|\u7edd\u4e0d|\u4e0d(?:\u4f1a|\u518d)?)([^\uff0c\u3002\uff1b\n]{0,12}?(?:\u4e0a\u4f20|\u5916\u53d1|\u8054\u7f51|\u5199\u5165|\u53d1\u9001|\u4fee\u6539|\u5220\u9664))/,
|
|
595
|
+
);
|
|
596
|
+
if (zhProhibClaim) {
|
|
597
|
+
const action = zhProhibClaim[1].slice(-2);
|
|
598
|
+
const hasZhNegAfter = /(?:\u4e25\u7981|\u7981\u6b62|\u4e0d\u5f97|\u5207\u52ff|\u7edd\u4e0d|\u4e0d|\u672a|\u96f6|\u65e0)/.test(
|
|
599
|
+
afterText,
|
|
600
|
+
);
|
|
601
|
+
if (action && afterText.includes(action) && !hasZhNegAfter) {
|
|
602
|
+
secondOrderSlopHits.push({
|
|
603
|
+
id: "polarity-prohibition-dropped",
|
|
604
|
+
message: "Dropped mandatory Chinese prohibition/negation marker from revised claim.",
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const ok = factCheck.ok && secondOrderSlopHits.length === 0;
|
|
610
|
+
return {
|
|
611
|
+
ok,
|
|
612
|
+
droppedFacts: factCheck.reasons,
|
|
613
|
+
regressions: secondOrderSlopHits,
|
|
614
|
+
};
|
|
615
|
+
}
|