dislop 1.0.1 → 1.1.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 +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/PRODUCT.md +2 -2
- package/README.md +34 -33
- package/README.zh-CN.md +65 -61
- package/action.yml +17 -2
- package/gemini-extension.json +1 -1
- package/package.json +2 -2
- package/packs/common/artifact-qa/scripts/index.mjs +64 -2
- package/packs/en/artifact-qa/scripts/index.mjs +1 -1
- package/packs/en/prose/scripts/index.mjs +3 -0
- package/plugin.json +1 -1
- package/server.json +2 -2
- package/skills/dislop/SKILL.md +1 -1
- package/skills/dislop/agents/openai.yaml +1 -1
- package/skills/dislop/references/essay.md +5 -5
- package/skills/dislop/references/essay.zh-CN.md +5 -5
- package/skills/dislop/references/office.md +4 -4
- package/skills/dislop/references/office.zh-CN.md +4 -4
- 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 +6 -6
- package/skills/dislop/references/work-docs.zh-CN.md +6 -6
- package/src/cli-main.mjs +88 -6
- package/src/commands/check-fix.mjs +170 -15
- package/src/commands/doctor.mjs +23 -1
- package/src/commands/init.mjs +24 -18
- package/src/commands/packs.mjs +41 -4
- package/src/commands/verify.mjs +36 -4
- package/src/commands/voice.mjs +1 -1
- package/src/commands/worklog.mjs +424 -0
- package/src/kernel/config.mjs +546 -19
- package/src/kernel/document-model.mjs +30 -10
- package/src/kernel/fact-gate.mjs +160 -0
- package/src/kernel/file-discovery.mjs +168 -11
- package/src/kernel/ooxml-binary.mjs +86 -0
- package/src/kernel/pack-loader.mjs +107 -21
- package/src/kernel/pack-validator.mjs +491 -0
- package/src/kernel/patcher.mjs +177 -47
- package/src/kernel/pipeline.mjs +284 -21
- package/src/kernel/prompt-assembler.mjs +37 -8
- package/src/kernel/version.mjs +7 -0
- package/src/kernel/voice-profile.mjs +3 -0
- package/src/mcp/stdio-server.mjs +71 -1
- package/src/runners/auto-fix.mjs +17 -2
- package/src/runners/interactive-tty.mjs +32 -5
- package/src/runners/reporters.mjs +18 -2
- package/src/runtime/providers/cloud.mjs +4 -2
- package/src/runtime/providers/local-model.mjs +8 -0
- package/src/runtime/router.mjs +11 -2
- package/src/runtime/worklog.mjs +904 -0
package/src/kernel/patcher.mjs
CHANGED
|
@@ -48,13 +48,16 @@ function adjustTextSpanForDeletion(source, start, end) {
|
|
|
48
48
|
return { start: s, end: e };
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
function normalizePostPatchWhitespace(patched, eol) {
|
|
51
|
+
function normalizePostPatchWhitespace(patched, eol, { hadLeadingNewline = false } = {}) {
|
|
52
52
|
const lf = patched.replace(/\r\n/g, "\n");
|
|
53
|
-
|
|
53
|
+
let cleaned = lf
|
|
54
54
|
// Strip orphaned leading comma/semicolon after sentence/clause deletion on a line
|
|
55
55
|
.replace(/(^|\n)([ \t]*)[,;:,;:]+[ \t]*/g, "$1$2")
|
|
56
56
|
// Collapse 3+ consecutive blank lines into a single blank line (2 newlines)
|
|
57
57
|
.replace(/\n{3,}/g, "\n\n");
|
|
58
|
+
if (!hadLeadingNewline) {
|
|
59
|
+
cleaned = cleaned.replace(/^\n+/, "");
|
|
60
|
+
}
|
|
58
61
|
return eol === "\r\n" ? cleaned.replace(/\n/g, "\r\n") : cleaned;
|
|
59
62
|
}
|
|
60
63
|
|
|
@@ -63,16 +66,23 @@ function resolveLocatorForPatch(doc, patch) {
|
|
|
63
66
|
if (!patch.targetId) return null;
|
|
64
67
|
const seg = doc.segments.find((s) => s.id === patch.targetId);
|
|
65
68
|
if (seg?.locator) {
|
|
66
|
-
|
|
67
|
-
if (patch.originalQuote && patch.originalQuote !== seg.text && seg.locator.kind !== "ooxml-span") {
|
|
69
|
+
if (patch.originalQuote && patch.originalQuote !== seg.text) {
|
|
68
70
|
const idx = seg.text.indexOf(patch.originalQuote);
|
|
69
|
-
if (idx
|
|
71
|
+
if (idx === -1 || seg.text.indexOf(patch.originalQuote, idx + 1) !== -1) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (seg.locator.kind === "ooxml-span") {
|
|
70
75
|
return {
|
|
71
76
|
...seg.locator,
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
charStart: seg.locator.charStart + idx,
|
|
78
|
+
charEnd: seg.locator.charStart + idx + patch.originalQuote.length,
|
|
74
79
|
};
|
|
75
80
|
}
|
|
81
|
+
return {
|
|
82
|
+
...seg.locator,
|
|
83
|
+
start: seg.locator.start + idx,
|
|
84
|
+
end: seg.locator.start + idx + patch.originalQuote.length,
|
|
85
|
+
};
|
|
76
86
|
}
|
|
77
87
|
return seg.locator;
|
|
78
88
|
}
|
|
@@ -81,15 +91,17 @@ function resolveLocatorForPatch(doc, patch) {
|
|
|
81
91
|
}
|
|
82
92
|
|
|
83
93
|
/**
|
|
84
|
-
* Apply accepted patches
|
|
85
|
-
*
|
|
94
|
+
* Apply accepted patches to an in-memory UTF-8 text/markup document string,
|
|
95
|
+
* returning both the patched text and exact set of applied patch indices.
|
|
86
96
|
*/
|
|
87
|
-
export function
|
|
88
|
-
|
|
97
|
+
export function applyPatchesToTextDetailed(sourceText, doc, patches) {
|
|
98
|
+
const appliedIndices = new Set();
|
|
99
|
+
if (!patches || patches.length === 0) return { text: sourceText, appliedIndices };
|
|
89
100
|
const eol = detectEol(sourceText);
|
|
90
101
|
|
|
91
102
|
const resolved = [];
|
|
92
|
-
for (
|
|
103
|
+
for (let patchIdx = 0; patchIdx < patches.length; patchIdx += 1) {
|
|
104
|
+
const patch = patches[patchIdx];
|
|
93
105
|
const loc = resolveLocatorForPatch(doc, patch);
|
|
94
106
|
if (!loc || (loc.kind !== "text-span" && loc.kind !== "html-span")) continue;
|
|
95
107
|
let replacement = String(patch.replacement ?? "");
|
|
@@ -97,8 +109,6 @@ export function applyPatchesToText(sourceText, doc, patches) {
|
|
|
97
109
|
replacement === "" && loc.kind === "text-span"
|
|
98
110
|
? adjustTextSpanForDeletion(sourceText, loc.start, loc.end)
|
|
99
111
|
: { start: loc.start, end: loc.end };
|
|
100
|
-
// Narrow non-empty text-span replacements to their minimal differing slice so enclosing sentence rewrites
|
|
101
|
-
// never collide with non-overlapping inner defect deletions (e.g., trailing leaked citation tokens).
|
|
102
112
|
if (replacement !== "" && loc.kind === "text-span") {
|
|
103
113
|
const orig = sourceText.slice(span.start, span.end);
|
|
104
114
|
const minLen = Math.min(orig.length, replacement.length);
|
|
@@ -112,47 +122,130 @@ export function applyPatchesToText(sourceText, doc, patches) {
|
|
|
112
122
|
}
|
|
113
123
|
}
|
|
114
124
|
resolved.push({
|
|
125
|
+
patchIdx,
|
|
115
126
|
start: span.start,
|
|
116
127
|
end: span.end,
|
|
117
128
|
replacement,
|
|
118
129
|
});
|
|
119
130
|
}
|
|
120
131
|
|
|
121
|
-
if (resolved.length === 0) return sourceText;
|
|
132
|
+
if (resolved.length === 0) return { text: sourceText, appliedIndices };
|
|
122
133
|
|
|
123
|
-
// Sort in descending offset order and skip overlapping edits cleanly
|
|
124
134
|
resolved.sort((a, b) => b.start - a.start || b.end - a.end);
|
|
125
135
|
|
|
126
136
|
let out = sourceText;
|
|
127
137
|
let minAppliedStart = Infinity;
|
|
128
138
|
for (const edit of resolved) {
|
|
129
139
|
if (edit.end > minAppliedStart) continue; // overlap guard
|
|
140
|
+
const beforeSlice = out.slice(edit.start, edit.end);
|
|
141
|
+
if (beforeSlice === edit.replacement) continue;
|
|
130
142
|
out = out.slice(0, edit.start) + edit.replacement + out.slice(edit.end);
|
|
131
143
|
minAppliedStart = edit.start;
|
|
144
|
+
appliedIndices.add(edit.patchIdx);
|
|
132
145
|
}
|
|
133
146
|
|
|
134
|
-
|
|
147
|
+
const finalText = normalizePostPatchWhitespace(out, eol, {
|
|
148
|
+
hadLeadingNewline: /^\r?\n/.test(sourceText),
|
|
149
|
+
});
|
|
150
|
+
return { text: finalText, appliedIndices };
|
|
135
151
|
}
|
|
136
152
|
|
|
137
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Apply accepted patches (`Array<{ targetId?, locator?, originalQuote?, replacement: string }>`)
|
|
155
|
+
* to an in-memory UTF-8 text/markup document string.
|
|
156
|
+
*/
|
|
157
|
+
export function applyPatchesToText(sourceText, doc, patches) {
|
|
158
|
+
return applyPatchesToTextDetailed(sourceText, doc, patches).text;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function patchSingleOoxmlParagraphXmlDetailed(pXml, nsPrefix, charEdits) {
|
|
138
162
|
const rTagRe = nsPrefix === "w" ? /<w:r\b[^>]*>[\s\S]*?<\/w:r>/g : /<a:r\b[^>]*>[\s\S]*?<\/a:r>/g;
|
|
139
163
|
const rPrTagRe = nsPrefix === "w" ? /<w:rPr\b[\s\S]*?<\/w:rPr>/ : /<a:rPr\b[\s\S]*?(?:\/>|<\/a:rPr>)/;
|
|
140
164
|
const tTagRe = nsPrefix === "w" ? /<w:t(?:\s+[^>]*)?>([\s\S]*?)<\/w:t>/g : /<a:t(?:\s+[^>]*)?>([\s\S]*?)<\/a:t>/g;
|
|
141
165
|
|
|
142
|
-
|
|
166
|
+
const hasProtectedNodes = /<(?:w:hyperlink|a:hlinkClick|w:fldSimple|w:instrText)\b/.test(pXml);
|
|
167
|
+
const runMatches = Array.from(pXml.matchAll(rTagRe));
|
|
168
|
+
const distinctRPr = new Set(
|
|
169
|
+
runMatches.map((rm) => {
|
|
170
|
+
const m = rm[0].match(rPrTagRe);
|
|
171
|
+
return m ? m[0] : "";
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
// Locate each <w:t> / <a:t> slice in fullText and pXml
|
|
176
|
+
const tNodes = [];
|
|
177
|
+
let cursor = 0;
|
|
178
|
+
let tm;
|
|
179
|
+
while ((tm = tTagRe.exec(pXml)) !== null) {
|
|
180
|
+
const decoded = decodeXmlEntities(tm[1]);
|
|
181
|
+
const whole = tm[0];
|
|
182
|
+
const openEnd = whole.indexOf(">") + 1;
|
|
183
|
+
const closeStart = whole.lastIndexOf("</");
|
|
184
|
+
tNodes.push({
|
|
185
|
+
xmlStart: tm.index,
|
|
186
|
+
xmlEnd: tm.index + whole.length,
|
|
187
|
+
openTag: whole.slice(0, openEnd),
|
|
188
|
+
closeTag: whole.slice(closeStart),
|
|
189
|
+
textStart: cursor,
|
|
190
|
+
textEnd: cursor + decoded.length,
|
|
191
|
+
decoded,
|
|
192
|
+
});
|
|
193
|
+
cursor += decoded.length;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// If the paragraph holds hyperlinks, field codes, or mixed run styling, ONLY allow edits contained
|
|
197
|
+
// cleanly within a single <w:t>/<a:t> run (declining cross-run edits so formatting & links survive).
|
|
198
|
+
if (hasProtectedNodes || distinctRPr.size > 1) {
|
|
199
|
+
const sorted = [...charEdits].sort((a, b) => b.charStart - a.charStart);
|
|
200
|
+
const nodeTexts = tNodes.map((n) => n.decoded);
|
|
201
|
+
const appliedIndices = new Set();
|
|
202
|
+
|
|
203
|
+
for (const ed of sorted) {
|
|
204
|
+
const targetIdx = tNodes.findIndex((n) => ed.charStart >= n.textStart && ed.charEnd <= n.textEnd);
|
|
205
|
+
if (targetIdx === -1) continue;
|
|
206
|
+
const node = tNodes[targetIdx];
|
|
207
|
+
let s = ed.charStart - node.textStart;
|
|
208
|
+
let e = ed.charEnd - node.textStart;
|
|
209
|
+
let curStr = nodeTexts[targetIdx];
|
|
210
|
+
if (ed.replacement === "") {
|
|
211
|
+
if (e < curStr.length && curStr[e] === " ") e += 1;
|
|
212
|
+
else if (s > 0 && curStr[s - 1] === " ") s -= 1;
|
|
213
|
+
}
|
|
214
|
+
nodeTexts[targetIdx] = curStr.slice(0, s) + ed.replacement + curStr.slice(e);
|
|
215
|
+
if (ed.patchIndex !== undefined) appliedIndices.add(ed.patchIndex);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (appliedIndices.size === 0) {
|
|
219
|
+
return { xml: pXml, appliedIndices };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
let rebuilt = "";
|
|
223
|
+
let lastXml = 0;
|
|
224
|
+
for (let idx = 0; idx < tNodes.length; idx += 1) {
|
|
225
|
+
const node = tNodes[idx];
|
|
226
|
+
rebuilt += pXml.slice(lastXml, node.xmlStart);
|
|
227
|
+
const nextRaw = nodeTexts[idx];
|
|
228
|
+
const needsPreserve =
|
|
229
|
+
nsPrefix === "w" && (/^\s|\s$/.test(nextRaw) || /xml:space="preserve"/.test(node.openTag));
|
|
230
|
+
const openTag =
|
|
231
|
+
needsPreserve && !/xml:space=/.test(node.openTag)
|
|
232
|
+
? node.openTag.replace(/^<w:t\b/, '<w:t xml:space="preserve"')
|
|
233
|
+
: node.openTag;
|
|
234
|
+
rebuilt += `${openTag}${escapeXmlText(nextRaw)}${node.closeTag}`;
|
|
235
|
+
lastXml = node.xmlEnd;
|
|
236
|
+
}
|
|
237
|
+
rebuilt += pXml.slice(lastXml);
|
|
238
|
+
return { xml: rebuilt, appliedIndices };
|
|
239
|
+
}
|
|
240
|
+
|
|
143
241
|
let firstRPr = "";
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const rPrMatch = rMatch[0].match(rPrTagRe);
|
|
242
|
+
if (runMatches.length > 0) {
|
|
243
|
+
const rPrMatch = runMatches[0][0].match(rPrTagRe);
|
|
147
244
|
if (rPrMatch) firstRPr = rPrMatch[0];
|
|
148
245
|
}
|
|
149
246
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
while ((tm = tTagRe.exec(pXml)) !== null) {
|
|
153
|
-
pieces.push(decodeXmlEntities(tm[1]));
|
|
154
|
-
}
|
|
155
|
-
let fullText = pieces.join("");
|
|
247
|
+
let fullText = tNodes.map((n) => n.decoded).join("");
|
|
248
|
+
const appliedIndices = new Set();
|
|
156
249
|
|
|
157
250
|
// Apply edits in descending charStart order
|
|
158
251
|
const sorted = [...charEdits].sort((a, b) => b.charStart - a.charStart);
|
|
@@ -167,6 +260,7 @@ function patchSingleOoxmlParagraphXml(pXml, nsPrefix, charEdits) {
|
|
|
167
260
|
}
|
|
168
261
|
fullText = fullText.slice(0, s) + ed.replacement + fullText.slice(e);
|
|
169
262
|
minStart = s;
|
|
263
|
+
if (ed.patchIndex !== undefined) appliedIndices.add(ed.patchIndex);
|
|
170
264
|
}
|
|
171
265
|
|
|
172
266
|
const pPrRe = nsPrefix === "w" ? /<w:pPr\b[\s\S]*?<\/w:pPr>/ : /<a:pPr\b[\s\S]*?(?:\/>|<\/a:pPr>)/;
|
|
@@ -176,26 +270,35 @@ function patchSingleOoxmlParagraphXml(pXml, nsPrefix, charEdits) {
|
|
|
176
270
|
const pPr = pPrMatch ? pPrMatch[0] : "";
|
|
177
271
|
|
|
178
272
|
if (!fullText.trim()) {
|
|
179
|
-
return `${openTag}${pPr}</${nsPrefix}:p
|
|
273
|
+
return { xml: `${openTag}${pPr}</${nsPrefix}:p>`, appliedIndices };
|
|
180
274
|
}
|
|
181
275
|
|
|
182
276
|
const escaped = escapeXmlText(fullText);
|
|
183
277
|
if (nsPrefix === "w") {
|
|
184
|
-
return
|
|
278
|
+
return {
|
|
279
|
+
xml: `${openTag}${pPr}<w:r>${firstRPr}<w:t xml:space="preserve">${escaped}</w:t></w:r></w:p>`,
|
|
280
|
+
appliedIndices,
|
|
281
|
+
};
|
|
185
282
|
}
|
|
186
|
-
return
|
|
283
|
+
return {
|
|
284
|
+
xml: `${openTag}${pPr}<a:r>${firstRPr}<a:t>${escaped}</a:t></a:r></a:p>`,
|
|
285
|
+
appliedIndices,
|
|
286
|
+
};
|
|
187
287
|
}
|
|
188
288
|
|
|
189
289
|
/**
|
|
190
290
|
* Apply accepted patches to an OOXML (`.docx` / `.pptx`) archive buffer, returning a new Buffer.
|
|
191
291
|
*/
|
|
192
|
-
export function
|
|
193
|
-
if (!patches || patches.length === 0)
|
|
292
|
+
export function applyPatchesToOoxmlBufferDetailed(originalBuffer, doc, patches) {
|
|
293
|
+
if (!patches || patches.length === 0) {
|
|
294
|
+
return { buffer: originalBuffer, appliedIndices: new Set() };
|
|
295
|
+
}
|
|
194
296
|
const { xmlEntries } = readZipArchive(originalBuffer);
|
|
195
297
|
|
|
196
298
|
// Group edits by entryName -> paragraphOrd
|
|
197
299
|
const byEntry = new Map();
|
|
198
|
-
for (
|
|
300
|
+
for (let patchIdx = 0; patchIdx < patches.length; patchIdx += 1) {
|
|
301
|
+
const patch = patches[patchIdx];
|
|
199
302
|
const loc = resolveLocatorForPatch(doc, patch);
|
|
200
303
|
if (!loc || loc.kind !== "ooxml-span") continue;
|
|
201
304
|
let entryGroup = byEntry.get(loc.entryName);
|
|
@@ -212,12 +315,16 @@ export function applyPatchesToOoxmlBuffer(originalBuffer, doc, patches) {
|
|
|
212
315
|
charStart: loc.charStart,
|
|
213
316
|
charEnd: loc.charEnd,
|
|
214
317
|
replacement: String(patch.replacement ?? ""),
|
|
318
|
+
patchIndex: patchIdx,
|
|
215
319
|
});
|
|
216
320
|
}
|
|
217
321
|
|
|
218
|
-
if (byEntry.size === 0)
|
|
322
|
+
if (byEntry.size === 0) {
|
|
323
|
+
return { buffer: originalBuffer, appliedIndices: new Set() };
|
|
324
|
+
}
|
|
219
325
|
|
|
220
326
|
const updatedXml = {};
|
|
327
|
+
const appliedIndices = new Set();
|
|
221
328
|
for (const [entryName, group] of byEntry.entries()) {
|
|
222
329
|
const xml = xmlEntries[entryName];
|
|
223
330
|
if (!xml) continue;
|
|
@@ -229,11 +336,22 @@ export function applyPatchesToOoxmlBuffer(originalBuffer, doc, patches) {
|
|
|
229
336
|
pOrd += 1;
|
|
230
337
|
const edits = group.byPara.get(idx);
|
|
231
338
|
if (!edits || edits.length === 0) return pXml;
|
|
232
|
-
|
|
339
|
+
const res = patchSingleOoxmlParagraphXmlDetailed(pXml, group.nsPrefix, edits);
|
|
340
|
+
if (res.xml !== pXml) {
|
|
341
|
+
for (const aIdx of res.appliedIndices) appliedIndices.add(aIdx);
|
|
342
|
+
}
|
|
343
|
+
return res.xml;
|
|
233
344
|
});
|
|
234
345
|
}
|
|
235
346
|
|
|
236
|
-
|
|
347
|
+
if (appliedIndices.size === 0) {
|
|
348
|
+
return { buffer: originalBuffer, appliedIndices };
|
|
349
|
+
}
|
|
350
|
+
return { buffer: repackZipArchive(originalBuffer, updatedXml), appliedIndices };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export function applyPatchesToOoxmlBuffer(originalBuffer, doc, patches) {
|
|
354
|
+
return applyPatchesToOoxmlBufferDetailed(originalBuffer, doc, patches).buffer;
|
|
237
355
|
}
|
|
238
356
|
|
|
239
357
|
/**
|
|
@@ -278,18 +396,20 @@ export function renderUnifiedDiff(filePath, beforeText, afterText) {
|
|
|
278
396
|
*/
|
|
279
397
|
export function patchDocumentOnDisk(doc, patches, { dryRun = false, backup = false, displayPath = null } = {}) {
|
|
280
398
|
if (!patches || patches.length === 0) {
|
|
281
|
-
return { modified: false, diff: "" };
|
|
399
|
+
return { modified: false, appliedIndices: new Set(), appliedCount: 0, diff: "" };
|
|
282
400
|
}
|
|
283
401
|
|
|
284
402
|
const filePath = doc.filePath;
|
|
285
403
|
const diffLabel = (displayPath || filePath).replace(/^\/+/, "");
|
|
286
404
|
if (doc.format === "docx" || doc.format === "pptx") {
|
|
287
405
|
const origBuf = fs.readFileSync(filePath);
|
|
288
|
-
const nextBuf =
|
|
289
|
-
if (origBuf.equals(nextBuf)) {
|
|
290
|
-
return { modified: false, diff: "" };
|
|
406
|
+
const { buffer: nextBuf, appliedIndices } = applyPatchesToOoxmlBufferDetailed(origBuf, doc, patches);
|
|
407
|
+
if (origBuf.equals(nextBuf) || appliedIndices.size === 0) {
|
|
408
|
+
return { modified: false, appliedIndices: new Set(), appliedCount: 0, diff: "" };
|
|
291
409
|
}
|
|
292
|
-
const diffSummary =
|
|
410
|
+
const diffSummary = Array.from(appliedIndices)
|
|
411
|
+
.sort((a, b) => a - b)
|
|
412
|
+
.map((idx) => patches[idx])
|
|
293
413
|
.map(
|
|
294
414
|
(p) =>
|
|
295
415
|
`--- a/${diffLabel} [${p.targetId || "ooxml"}]\n+++ b/${diffLabel} [${p.targetId || "ooxml"}]\n-${p.originalQuote || ""}\n+${p.replacement || "(deleted)"}`,
|
|
@@ -298,20 +418,30 @@ export function patchDocumentOnDisk(doc, patches, { dryRun = false, backup = fal
|
|
|
298
418
|
if (!dryRun) {
|
|
299
419
|
atomicWriteBuffer(filePath, nextBuf, { backup });
|
|
300
420
|
}
|
|
301
|
-
return {
|
|
421
|
+
return {
|
|
422
|
+
modified: true,
|
|
423
|
+
appliedIndices,
|
|
424
|
+
appliedCount: appliedIndices.size,
|
|
425
|
+
diff: diffSummary,
|
|
426
|
+
};
|
|
302
427
|
}
|
|
303
428
|
|
|
304
429
|
const origText = fs.readFileSync(filePath, "utf8");
|
|
305
|
-
const nextText =
|
|
306
|
-
if (origText === nextText) {
|
|
307
|
-
return { modified: false, diff: "" };
|
|
430
|
+
const { text: nextText, appliedIndices } = applyPatchesToTextDetailed(origText, doc, patches);
|
|
431
|
+
if (origText === nextText || appliedIndices.size === 0) {
|
|
432
|
+
return { modified: false, appliedIndices: new Set(), appliedCount: 0, diff: "" };
|
|
308
433
|
}
|
|
309
434
|
|
|
310
435
|
const diff = renderUnifiedDiff(diffLabel, origText, nextText);
|
|
311
436
|
if (!dryRun) {
|
|
312
437
|
atomicWriteBuffer(filePath, Buffer.from(nextText, "utf8"), { backup });
|
|
313
438
|
}
|
|
314
|
-
return {
|
|
439
|
+
return {
|
|
440
|
+
modified: true,
|
|
441
|
+
appliedIndices,
|
|
442
|
+
appliedCount: appliedIndices.size,
|
|
443
|
+
diff,
|
|
444
|
+
};
|
|
315
445
|
}
|
|
316
446
|
|
|
317
447
|
function atomicWriteBuffer(filePath, buffer, { backup = false } = {}) {
|