dislop 0.9.1 → 1.1.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/.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 +358 -249
- package/README.zh-CN.md +391 -237
- 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 +235 -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 +293 -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/agents/openai.yaml +1 -1
- package/skills/dislop/references/essay.md +6 -6
- package/skills/dislop/references/essay.zh-CN.md +6 -6
- package/skills/dislop/references/office.md +5 -5
- package/skills/dislop/references/office.zh-CN.md +5 -5
- package/skills/dislop/references/web-ui.md +4 -4
- package/skills/dislop/references/web-ui.zh-CN.md +4 -4
- package/skills/dislop/references/work-docs.md +7 -7
- package/skills/dislop/references/work-docs.zh-CN.md +7 -7
- package/src/cli-main.mjs +292 -0
- package/src/commands/check-fix.mjs +324 -0
- package/src/commands/doctor.mjs +132 -0
- package/src/commands/init.mjs +55 -0
- package/src/commands/login.mjs +82 -0
- package/src/commands/model.mjs +130 -0
- package/src/commands/packs.mjs +81 -0
- package/src/commands/verify.mjs +165 -0
- package/src/commands/voice.mjs +84 -0
- package/src/commands/worklog.mjs +424 -0
- package/src/kernel/config.mjs +759 -0
- package/src/kernel/document-model.mjs +1432 -0
- package/src/kernel/fact-gate.mjs +775 -0
- package/src/kernel/file-discovery.mjs +296 -0
- package/src/{binary-node.mjs → kernel/ooxml-binary.mjs} +615 -890
- package/src/kernel/pack-loader.mjs +801 -0
- package/src/kernel/pack-validator.mjs +491 -0
- package/src/kernel/patcher.mjs +471 -0
- package/src/kernel/pipeline.mjs +530 -0
- package/src/kernel/prompt-assembler.mjs +336 -0
- package/src/kernel/version.mjs +7 -0
- package/src/kernel/voice-profile.mjs +180 -0
- package/src/mcp/stdio-server.mjs +442 -0
- package/src/runners/auto-fix.mjs +74 -0
- package/src/runners/interactive-tty.mjs +488 -0
- package/src/runners/reporters.mjs +272 -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 +138 -0
- package/src/runtime/providers/gemini.mjs +91 -0
- package/src/runtime/providers/local-model.mjs +147 -0
- package/src/runtime/providers/openai-compat.mjs +130 -0
- package/src/runtime/router.mjs +324 -0
- package/src/runtime/worklog.mjs +904 -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,530 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { DislopConfigError } from "./config.mjs";
|
|
4
|
+
import { parseDocumentBuffer, parseDocumentFile, parseDocumentText } from "./document-model.mjs";
|
|
5
|
+
import { applyDualFactGate } from "./fact-gate.mjs";
|
|
6
|
+
import { compileIgnoreMatchers } from "./file-discovery.mjs";
|
|
7
|
+
import { resolveActivePacks, runDeterministicPackChecks } from "./pack-loader.mjs";
|
|
8
|
+
import {
|
|
9
|
+
assemblePromptPayload,
|
|
10
|
+
collectPackPromptRules,
|
|
11
|
+
normalizeLlmResponseItems,
|
|
12
|
+
} from "./prompt-assembler.mjs";
|
|
13
|
+
import { DISLOP_VERSION } from "./version.mjs";
|
|
14
|
+
import { buildSlidingWindowChunks } from "../runtime/chunker.mjs";
|
|
15
|
+
|
|
16
|
+
const DEFECT_SEVERITY_RANK = Object.freeze({
|
|
17
|
+
error: 1,
|
|
18
|
+
warning: 2,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const SUGGESTION_PRIORITY_RANK = Object.freeze({
|
|
22
|
+
strong: 1,
|
|
23
|
+
moderate: 2,
|
|
24
|
+
hint: 3,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const LEVEL_THRESHOLD_MAX_RANK = Object.freeze({
|
|
28
|
+
strong: 1,
|
|
29
|
+
moderate: 2,
|
|
30
|
+
hint: 3,
|
|
31
|
+
all: 3,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export function getItemTierKey(item) {
|
|
35
|
+
if (item.kind === "defect") {
|
|
36
|
+
return `defect:${item.severity || "error"}`;
|
|
37
|
+
}
|
|
38
|
+
return `suggestion:${item.priority || "moderate"}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function buildSegmentOrderMap(doc) {
|
|
42
|
+
const map = new Map();
|
|
43
|
+
doc.segments.forEach((seg, idx) => {
|
|
44
|
+
map.set(seg.id, idx);
|
|
45
|
+
});
|
|
46
|
+
return map;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function finalizeReportItems(rawItems, doc, { level = "all" } = {}) {
|
|
50
|
+
const maxSuggestionRank = LEVEL_THRESHOLD_MAX_RANK[level] ?? 3;
|
|
51
|
+
const segOrder = buildSegmentOrderMap(doc);
|
|
52
|
+
const segById = new Map(doc.segments.map((s) => [s.id, s]));
|
|
53
|
+
|
|
54
|
+
// Collect segments that already have a deterministic full-segment safe DELETE,
|
|
55
|
+
// and (targetId, ruleId) pairs already reported deterministically.
|
|
56
|
+
const fullyDeletedTargets = new Set();
|
|
57
|
+
const deterministicTargetRules = new Set();
|
|
58
|
+
for (const item of rawItems) {
|
|
59
|
+
if (item._source !== "llm" && item.targetId && item.ruleId) {
|
|
60
|
+
deterministicTargetRules.add(`${item.targetId}::${item.ruleId}`);
|
|
61
|
+
}
|
|
62
|
+
if (item.fixSafety === "safe" && item.actionType === "delete" && item.targetId) {
|
|
63
|
+
const seg = segById.get(item.targetId);
|
|
64
|
+
if (seg && String(item.originalQuote || "").trim() === seg.text.trim()) {
|
|
65
|
+
fullyDeletedTargets.add(item.targetId);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const seen = new Set();
|
|
71
|
+
const deduped = [];
|
|
72
|
+
|
|
73
|
+
for (const item of rawItems) {
|
|
74
|
+
if (item.kind === "suggestion") {
|
|
75
|
+
if (item.fixSafety !== "safe" && item.targetId && fullyDeletedTargets.has(item.targetId)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (item._source === "llm" && item.targetId && deterministicTargetRules.has(`${item.targetId}::${item.ruleId}`)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const pRank = SUGGESTION_PRIORITY_RANK[item.priority] ?? 2;
|
|
82
|
+
if (pRank > maxSuggestionRank) continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const dedupeKey = `${item.targetId || `line:${item.line || 0}`}::${item.ruleId}::${item.originalQuote || ""}`;
|
|
86
|
+
if (seen.has(dedupeKey)) continue;
|
|
87
|
+
seen.add(dedupeKey);
|
|
88
|
+
deduped.push(item);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
deduped.sort((a, b) => {
|
|
92
|
+
if (a.kind !== b.kind) {
|
|
93
|
+
return a.kind === "defect" ? -1 : 1;
|
|
94
|
+
}
|
|
95
|
+
if (a.kind === "defect") {
|
|
96
|
+
const sa = DEFECT_SEVERITY_RANK[a.severity] ?? 9;
|
|
97
|
+
const sb = DEFECT_SEVERITY_RANK[b.severity] ?? 9;
|
|
98
|
+
if (sa !== sb) return sa - sb;
|
|
99
|
+
} else {
|
|
100
|
+
const pa = SUGGESTION_PRIORITY_RANK[a.priority] ?? 9;
|
|
101
|
+
const pb = SUGGESTION_PRIORITY_RANK[b.priority] ?? 9;
|
|
102
|
+
if (pa !== pb) return pa - pb;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const ordA = a.targetId && segOrder.has(a.targetId) ? segOrder.get(a.targetId) : Number.MAX_SAFE_INTEGER;
|
|
106
|
+
const ordB = b.targetId && segOrder.has(b.targetId) ? segOrder.get(b.targetId) : Number.MAX_SAFE_INTEGER;
|
|
107
|
+
if (ordA !== ordB) return ordA - ordB;
|
|
108
|
+
return (a.line || 0) - (b.line || 0);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return deduped.map((item, idx) => ({
|
|
112
|
+
id: `item-${idx + 1}`,
|
|
113
|
+
...item,
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function computeSummaryCounts(items) {
|
|
118
|
+
const summary = {
|
|
119
|
+
defects: { error: 0, warning: 0 },
|
|
120
|
+
suggestions: { strong: 0, moderate: 0, hint: 0 },
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
for (const item of items) {
|
|
124
|
+
if (item._applied) continue;
|
|
125
|
+
if (item.kind === "defect") {
|
|
126
|
+
if (item.severity === "error") summary.defects.error += 1;
|
|
127
|
+
else summary.defects.warning += 1;
|
|
128
|
+
} else if (item.kind === "suggestion") {
|
|
129
|
+
if (item.priority === "strong") summary.suggestions.strong += 1;
|
|
130
|
+
else if (item.priority === "hint") summary.suggestions.hint += 1;
|
|
131
|
+
else summary.suggestions.moderate += 1;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return summary;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function serializeCleanReportItem(item) {
|
|
139
|
+
return {
|
|
140
|
+
id: item.id,
|
|
141
|
+
kind: item.kind,
|
|
142
|
+
pack: item.pack,
|
|
143
|
+
ruleId: item.ruleId,
|
|
144
|
+
targetId: item.targetId,
|
|
145
|
+
...(item.line !== undefined ? { line: item.line } : {}),
|
|
146
|
+
...(item.kind === "defect" ? { severity: item.severity } : { priority: item.priority }),
|
|
147
|
+
fixSafety: item.fixSafety,
|
|
148
|
+
actionType: item.actionType,
|
|
149
|
+
originalQuote: item.originalQuote,
|
|
150
|
+
suggestedReplacement: item.suggestedReplacement,
|
|
151
|
+
reason: item.reason,
|
|
152
|
+
...(item.rewritePrompt ? { rewritePrompt: item.rewritePrompt } : {}),
|
|
153
|
+
...(item.verificationNote ? { verificationNote: item.verificationNote } : {}),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function resolveComparablePath(targetPath) {
|
|
158
|
+
const abs = path.resolve(targetPath);
|
|
159
|
+
if (fs.existsSync(abs)) {
|
|
160
|
+
return fs.realpathSync(abs);
|
|
161
|
+
}
|
|
162
|
+
const parent = path.dirname(abs);
|
|
163
|
+
if (fs.existsSync(parent)) {
|
|
164
|
+
return path.join(fs.realpathSync(parent), path.basename(abs));
|
|
165
|
+
}
|
|
166
|
+
return abs;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function resolvePerFileSettings(filePath, cwd, config) {
|
|
170
|
+
const realProjectBase = resolveComparablePath(config.projectDir || cwd);
|
|
171
|
+
const realCwd = resolveComparablePath(cwd);
|
|
172
|
+
const realTarget = resolveComparablePath(path.resolve(cwd, filePath));
|
|
173
|
+
const relFromProject = path.relative(realProjectBase, realTarget).replace(/\\/g, "/");
|
|
174
|
+
const relFromCwd = path.relative(realCwd, realTarget).replace(/\\/g, "/");
|
|
175
|
+
|
|
176
|
+
let routing = config.routing || "local";
|
|
177
|
+
let packs = config.packs || null;
|
|
178
|
+
let packOrigin = config.packOrigin || "default";
|
|
179
|
+
const extraPackSpecs =
|
|
180
|
+
config.extraPackSpecs && config.extraPackSpecs.length > 0
|
|
181
|
+
? config.extraPackSpecs.map((x) => ({ ...x }))
|
|
182
|
+
: (config.extraPacks || []).map((spec) => ({ spec, origin: config.packOrigin || "default" }));
|
|
183
|
+
const rules = { ...(config.rules || {}) };
|
|
184
|
+
let failOn = config.failOn || "error";
|
|
185
|
+
let lang = config.lang || "auto";
|
|
186
|
+
let level = config.level || "all";
|
|
187
|
+
let ignored = false;
|
|
188
|
+
let overrideLocal = false;
|
|
189
|
+
|
|
190
|
+
for (const ov of config.overrides || []) {
|
|
191
|
+
const matcher = compileIgnoreMatchers(ov.files || []);
|
|
192
|
+
if (!matcher(relFromProject, false) && !matcher(relFromCwd, false)) continue;
|
|
193
|
+
if (ov.ignore && ov.ignore.length > 0) {
|
|
194
|
+
const ovIgnoreMatcher = compileIgnoreMatchers(ov.ignore);
|
|
195
|
+
if (ovIgnoreMatcher(relFromProject, false) || ovIgnoreMatcher(relFromCwd, false)) {
|
|
196
|
+
ignored = true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (ov.routing !== undefined) {
|
|
200
|
+
routing = ov.routing;
|
|
201
|
+
overrideLocal = ov.routing === "local";
|
|
202
|
+
}
|
|
203
|
+
if (ov.packs !== undefined) {
|
|
204
|
+
packs = ov.packs;
|
|
205
|
+
if (packOrigin !== "cli") packOrigin = ov.origin || "project";
|
|
206
|
+
}
|
|
207
|
+
if (ov.extraPacks !== undefined) {
|
|
208
|
+
for (const ep of ov.extraPacks) {
|
|
209
|
+
const epOrigin = ov.origin || "project";
|
|
210
|
+
const existing = extraPackSpecs.find((x) => x.spec === ep);
|
|
211
|
+
if (!existing) {
|
|
212
|
+
extraPackSpecs.push({ spec: ep, origin: epOrigin });
|
|
213
|
+
} else if (epOrigin === "project" || epOrigin === "mcp") {
|
|
214
|
+
existing.origin = epOrigin;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (ov.rules) {
|
|
219
|
+
Object.assign(rules, ov.rules);
|
|
220
|
+
}
|
|
221
|
+
if (ov.failOn !== undefined) failOn = ov.failOn;
|
|
222
|
+
if (ov.lang !== undefined) lang = ov.lang;
|
|
223
|
+
if (ov.level !== undefined) level = ov.level;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
routing,
|
|
228
|
+
packs,
|
|
229
|
+
packOrigin,
|
|
230
|
+
extraPackSpecs,
|
|
231
|
+
rules,
|
|
232
|
+
failOn,
|
|
233
|
+
lang,
|
|
234
|
+
level,
|
|
235
|
+
ignored,
|
|
236
|
+
overrideLocal,
|
|
237
|
+
relFromProject,
|
|
238
|
+
relFromCwd,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function evaluateDeclarativeRules(doc, relPath, declarativeRules = []) {
|
|
243
|
+
if (!declarativeRules || declarativeRules.length === 0) return [];
|
|
244
|
+
const found = [];
|
|
245
|
+
|
|
246
|
+
for (const rule of declarativeRules) {
|
|
247
|
+
if (rule.formats && rule.formats.length > 0 && !rule.formats.includes(doc.format)) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (rule.languages && rule.languages.length > 0 && !rule.languages.includes(doc.language)) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (rule.files && rule.files.length > 0) {
|
|
254
|
+
const matcher = compileIgnoreMatchers(rule.files);
|
|
255
|
+
if (!matcher(relPath, false)) continue;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const matchers = [];
|
|
259
|
+
if (rule.pattern) {
|
|
260
|
+
const cleanFlags = `${rule.flags || "i"}`.replace(/g/g, "") + "g";
|
|
261
|
+
matchers.push(new RegExp(rule.pattern, cleanFlags));
|
|
262
|
+
}
|
|
263
|
+
for (const term of rule.terms || []) {
|
|
264
|
+
const escaped = term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
265
|
+
matchers.push(new RegExp(escaped, `${rule.flags || "i"}`.replace(/g/g, "") + "g"));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
for (const seg of doc.segments || []) {
|
|
269
|
+
for (const rx of matchers) {
|
|
270
|
+
rx.lastIndex = 0;
|
|
271
|
+
const m = rx.exec(seg.text);
|
|
272
|
+
if (!m) continue;
|
|
273
|
+
const quote = m[0];
|
|
274
|
+
const hasReplacement = rule.replacement !== undefined;
|
|
275
|
+
found.push({
|
|
276
|
+
kind: rule.kind,
|
|
277
|
+
pack: "project/rules",
|
|
278
|
+
ruleId: rule.id.includes("/") ? rule.id : `project/${rule.id}`,
|
|
279
|
+
targetId: seg.id,
|
|
280
|
+
...(seg.line !== undefined ? { line: seg.line } : {}),
|
|
281
|
+
...(rule.kind === "defect" ? { severity: rule.severity } : { priority: rule.priority }),
|
|
282
|
+
fixSafety: rule.fixSafety,
|
|
283
|
+
actionType: rule.actionType || (hasReplacement ? (rule.replacement === "" ? "delete" : "replace") : "prompt"),
|
|
284
|
+
originalQuote: quote,
|
|
285
|
+
suggestedReplacement: hasReplacement ? rule.replacement : "",
|
|
286
|
+
reason: rule.reason,
|
|
287
|
+
locator: seg.locator || null,
|
|
288
|
+
});
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return found;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function applyRuleConfigOverrides(items, ruleOverrides = {}) {
|
|
298
|
+
if (!ruleOverrides || Object.keys(ruleOverrides).length === 0) return items;
|
|
299
|
+
const out = [];
|
|
300
|
+
for (const item of items) {
|
|
301
|
+
const bareId = item.ruleId.includes("/") ? item.ruleId.split("/").pop() : item.ruleId;
|
|
302
|
+
const setting = ruleOverrides[item.ruleId] ?? ruleOverrides[bareId];
|
|
303
|
+
if (setting === undefined) {
|
|
304
|
+
out.push(item);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const mode =
|
|
308
|
+
typeof setting === "object"
|
|
309
|
+
? setting.enabled === false
|
|
310
|
+
? "off"
|
|
311
|
+
: setting.severity || setting.level || "on"
|
|
312
|
+
: String(setting);
|
|
313
|
+
if (mode === "off") continue;
|
|
314
|
+
const next = { ...item };
|
|
315
|
+
if (next.kind === "defect" && (mode === "error" || mode === "warning")) {
|
|
316
|
+
next.severity = mode;
|
|
317
|
+
} else if (
|
|
318
|
+
next.kind === "suggestion" &&
|
|
319
|
+
(mode === "strong" || mode === "moderate" || mode === "hint")
|
|
320
|
+
) {
|
|
321
|
+
next.priority = mode;
|
|
322
|
+
}
|
|
323
|
+
out.push(next);
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Execute Steps 2-6 of the 7-Step Kernel Pipeline for a single target file.
|
|
330
|
+
* Enforces lazy stage-gated loading:
|
|
331
|
+
* - Step 3 imports `scripts/` ONLY for admitted Packs with `hasScripts`.
|
|
332
|
+
* - Step 4 reads/compiles `prompts/` ONLY when `!config.noLlm` AND `route.execute` is active!
|
|
333
|
+
*/
|
|
334
|
+
export async function runDocumentPipeline({
|
|
335
|
+
filePath,
|
|
336
|
+
textContent = null,
|
|
337
|
+
bufferContent = null,
|
|
338
|
+
config,
|
|
339
|
+
route,
|
|
340
|
+
voiceProfile = null,
|
|
341
|
+
cwd = process.cwd(),
|
|
342
|
+
}) {
|
|
343
|
+
const startedAt = Date.now();
|
|
344
|
+
const effective = resolvePerFileSettings(filePath, cwd, config);
|
|
345
|
+
const relDisplayPath = effective.relFromCwd || filePath;
|
|
346
|
+
|
|
347
|
+
if (effective.ignored) {
|
|
348
|
+
return {
|
|
349
|
+
doc: null,
|
|
350
|
+
activePacks: [],
|
|
351
|
+
skippedByIgnore: true,
|
|
352
|
+
effectiveFailOn: effective.failOn,
|
|
353
|
+
report: null,
|
|
354
|
+
items: [],
|
|
355
|
+
routeHint: null,
|
|
356
|
+
routeFallback: false,
|
|
357
|
+
durationMs: Date.now() - startedAt,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Step 2: Document Parsing & Physical Coordinate Modeling
|
|
362
|
+
let doc;
|
|
363
|
+
try {
|
|
364
|
+
doc =
|
|
365
|
+
bufferContent !== null
|
|
366
|
+
? parseDocumentBuffer(bufferContent, filePath)
|
|
367
|
+
: textContent !== null
|
|
368
|
+
? parseDocumentText(textContent, filePath)
|
|
369
|
+
: parseDocumentFile(filePath);
|
|
370
|
+
} catch (err) {
|
|
371
|
+
throw new DislopConfigError(err.message);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const diagnosticLang = effective.lang && effective.lang !== "auto" ? effective.lang : doc.language;
|
|
375
|
+
|
|
376
|
+
// Step 3: Zero-Import Metadata Admission + Lazy `scripts/` Execution
|
|
377
|
+
// Always run deterministic Script Packs (even when `routing: "off"`, which disables LLM evaluation only)
|
|
378
|
+
let activePacks;
|
|
379
|
+
try {
|
|
380
|
+
activePacks = await resolveActivePacks(doc, {
|
|
381
|
+
packSpecifiers: effective.packs,
|
|
382
|
+
extraPackSpecifiers: effective.extraPackSpecs,
|
|
383
|
+
cwd,
|
|
384
|
+
packOrigin: effective.packOrigin,
|
|
385
|
+
projectDir: config.projectDir || cwd,
|
|
386
|
+
});
|
|
387
|
+
} catch (err) {
|
|
388
|
+
throw new DislopConfigError(err.message);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const deterministicItems = [
|
|
392
|
+
...(await runDeterministicPackChecks(doc, activePacks, {
|
|
393
|
+
diagnosticLang,
|
|
394
|
+
cwd,
|
|
395
|
+
})),
|
|
396
|
+
...evaluateDeclarativeRules(doc, effective.relFromProject, config.declarativeRules),
|
|
397
|
+
];
|
|
398
|
+
|
|
399
|
+
// Step 4: Lazy `prompts/` Loading & 3-Tier LLM Evaluation (ONLY when an LLM route is active for this file!)
|
|
400
|
+
const anyPackHasPrompts = activePacks.some((p) => p.hasPrompts);
|
|
401
|
+
let llmItems = [];
|
|
402
|
+
let documentToneAnchor = "";
|
|
403
|
+
let engineUsed = "deterministic";
|
|
404
|
+
let routeHint = null;
|
|
405
|
+
|
|
406
|
+
const isRemoteRoute = Boolean(
|
|
407
|
+
route && (route.tier === "cloud" || (route.tier === "byok" && !route.isLoopback)),
|
|
408
|
+
);
|
|
409
|
+
const suppressLlmForFile =
|
|
410
|
+
Boolean(config.noLlm) ||
|
|
411
|
+
effective.routing === "off" ||
|
|
412
|
+
(effective.overrideLocal && isRemoteRoute);
|
|
413
|
+
const fileRoute = suppressLlmForFile ? null : route;
|
|
414
|
+
|
|
415
|
+
if (!suppressLlmForFile && anyPackHasPrompts && doc.segments.length > 0) {
|
|
416
|
+
if (fileRoute && typeof fileRoute.execute === "function") {
|
|
417
|
+
// Lazily read & compile `prompts/*.md` now that we know an LLM call will actually run
|
|
418
|
+
const { rules: promptRules, roleHints } = await collectPackPromptRules(doc, activePacks, {
|
|
419
|
+
diagnosticLang,
|
|
420
|
+
cwd,
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
if (promptRules.length > 0) {
|
|
424
|
+
engineUsed = fileRoute.engineLabel;
|
|
425
|
+
const chunks = buildSlidingWindowChunks(doc, {
|
|
426
|
+
maxInputTokens: fileRoute.maxInputTokens || 12000,
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
for (const chunk of chunks) {
|
|
430
|
+
const payload = assemblePromptPayload({
|
|
431
|
+
doc,
|
|
432
|
+
promptRules,
|
|
433
|
+
roleHints,
|
|
434
|
+
voiceProfile,
|
|
435
|
+
chunk,
|
|
436
|
+
globalToneAnchor: documentToneAnchor || null,
|
|
437
|
+
diagnosticLang,
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
try {
|
|
441
|
+
const chunkDoc = {
|
|
442
|
+
...doc,
|
|
443
|
+
filePath: path.basename(doc.filePath || "document"),
|
|
444
|
+
segments: chunk.segments,
|
|
445
|
+
};
|
|
446
|
+
const rawResponse = await fileRoute.execute(payload, chunkDoc, promptRules);
|
|
447
|
+
const normalized = normalizeLlmResponseItems(rawResponse, {
|
|
448
|
+
doc,
|
|
449
|
+
chunkSegments: chunk.segments,
|
|
450
|
+
promptRules,
|
|
451
|
+
});
|
|
452
|
+
if (!documentToneAnchor && normalized.documentToneAnchor) {
|
|
453
|
+
documentToneAnchor = normalized.documentToneAnchor;
|
|
454
|
+
}
|
|
455
|
+
llmItems.push(...normalized.items.map((item) => ({ ...item, _source: "llm" })));
|
|
456
|
+
} catch (err) {
|
|
457
|
+
if (err?.authError || config.explicitEngine) {
|
|
458
|
+
throw new DislopConfigError(err.message);
|
|
459
|
+
}
|
|
460
|
+
engineUsed = "deterministic";
|
|
461
|
+
routeHint = err?.ollamaMissing
|
|
462
|
+
? "💡 Ollama is missing on this machine; showing deterministic checks only. Install Ollama (https://ollama.com) for Tier 3 local LLM checks."
|
|
463
|
+
: "💡 Local Ollama runtime unreachable (is 'ollama serve' running?); showing deterministic checks only.";
|
|
464
|
+
llmItems = [];
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
} else if (route?.hint) {
|
|
470
|
+
// Notice: `prompts/*.md` are NOT read at all when falling back to deterministic mode!
|
|
471
|
+
routeHint = route.hint;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Step 5: Dual Post-LLM Fact Gate (lazily invokes `scripts/` `verifyFix` if present)
|
|
476
|
+
const combinedRaw = [...deterministicItems, ...llmItems];
|
|
477
|
+
const gatedItems = await applyDualFactGate(combinedRaw, doc, activePacks);
|
|
478
|
+
const adjustedItems = applyRuleConfigOverrides(gatedItems, effective.rules);
|
|
479
|
+
|
|
480
|
+
const orderedItems = finalizeReportItems(adjustedItems, doc, { level: effective.level || "all" });
|
|
481
|
+
const summary = computeSummaryCounts(orderedItems);
|
|
482
|
+
const coverage =
|
|
483
|
+
doc.segments.length > 0
|
|
484
|
+
? { segmentCount: doc.segments.length, status: "inspected" }
|
|
485
|
+
: {
|
|
486
|
+
segmentCount: 0,
|
|
487
|
+
status: "container-only",
|
|
488
|
+
notice:
|
|
489
|
+
"0 inspectable text segments extracted (visual-only or scanned file); container-level checks only.",
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
const report = {
|
|
493
|
+
schema: "dislop.report/1",
|
|
494
|
+
tool: { name: "dislop", version: DISLOP_VERSION },
|
|
495
|
+
file: relDisplayPath.replace(/\\/g, "/"),
|
|
496
|
+
language: doc.language,
|
|
497
|
+
engine: engineUsed,
|
|
498
|
+
mountedPacks: activePacks.map((p) => p.name),
|
|
499
|
+
coverage,
|
|
500
|
+
documentToneAnchor,
|
|
501
|
+
summary,
|
|
502
|
+
items: orderedItems.map(serializeCleanReportItem),
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
return {
|
|
506
|
+
doc,
|
|
507
|
+
activePacks,
|
|
508
|
+
effectiveFailOn: effective.failOn,
|
|
509
|
+
report,
|
|
510
|
+
items: orderedItems,
|
|
511
|
+
routeHint,
|
|
512
|
+
routeFallback: Boolean(routeHint),
|
|
513
|
+
durationMs: Date.now() - startedAt,
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
export function arbitrateExitCode(entries, { failOn = "error", explicitFailOn = false } = {}) {
|
|
518
|
+
for (const entry of entries) {
|
|
519
|
+
const report = entry?.report || entry;
|
|
520
|
+
const mode = explicitFailOn ? failOn : (entry?.effectiveFailOn || failOn || "error");
|
|
521
|
+
if (mode === "none") continue;
|
|
522
|
+
if ((report?.summary?.defects?.error || 0) > 0) {
|
|
523
|
+
return 1;
|
|
524
|
+
}
|
|
525
|
+
if (mode === "warning" && (report?.summary?.defects?.warning || 0) > 0) {
|
|
526
|
+
return 1;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return 0;
|
|
530
|
+
}
|