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.
Files changed (129) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/.codex-plugin/plugin.json +7 -8
  4. package/.cursor-plugin/plugin.json +2 -3
  5. package/.pre-commit-hooks.yaml +5 -12
  6. package/PRODUCT.md +19 -63
  7. package/README.md +358 -249
  8. package/README.zh-CN.md +391 -237
  9. package/action.yml +30 -39
  10. package/bin/dislop-mcp.mjs +3 -4
  11. package/bin/dislop.mjs +4 -4594
  12. package/gemini-extension.json +2 -2
  13. package/llms-install.md +68 -0
  14. package/package.json +17 -63
  15. package/packs/common/artifact-qa/pack.json +5 -0
  16. package/packs/common/artifact-qa/prompts/rules.md +11 -0
  17. package/packs/common/artifact-qa/scripts/index.mjs +235 -0
  18. package/packs/common/slide-deck/pack.json +6 -0
  19. package/packs/common/slide-deck/prompts/rules.md +11 -0
  20. package/packs/common/slide-deck/scripts/index.mjs +62 -0
  21. package/packs/common/web-ui/pack.json +6 -0
  22. package/packs/common/web-ui/prompts/rules.md +11 -0
  23. package/packs/common/web-ui/scripts/index.mjs +80 -0
  24. package/packs/en/artifact-qa/pack.json +6 -0
  25. package/packs/en/artifact-qa/prompts/rules.md +14 -0
  26. package/packs/en/artifact-qa/scripts/index.mjs +90 -0
  27. package/packs/en/prose/pack.json +7 -0
  28. package/packs/en/prose/prompts/rules.md +26 -0
  29. package/packs/en/prose/scripts/index.mjs +293 -0
  30. package/packs/en/slide-deck/pack.json +7 -0
  31. package/packs/en/slide-deck/prompts/rules.md +17 -0
  32. package/packs/en/slide-deck/scripts/index.mjs +81 -0
  33. package/packs/en/web-ui/pack.json +7 -0
  34. package/packs/en/web-ui/prompts/rules.md +20 -0
  35. package/packs/en/web-ui/scripts/index.mjs +103 -0
  36. package/packs/zh/artifact-qa/pack.json +6 -0
  37. package/packs/zh/artifact-qa/prompts/rules.md +14 -0
  38. package/packs/zh/artifact-qa/scripts/index.mjs +89 -0
  39. package/packs/zh/prose/pack.json +7 -0
  40. package/packs/zh/prose/prompts/rules.md +26 -0
  41. package/packs/zh/prose/scripts/index.mjs +305 -0
  42. package/packs/zh/slide-deck/pack.json +7 -0
  43. package/packs/zh/slide-deck/prompts/rules.md +17 -0
  44. package/packs/zh/slide-deck/scripts/index.mjs +75 -0
  45. package/packs/zh/web-ui/pack.json +7 -0
  46. package/packs/zh/web-ui/prompts/rules.md +20 -0
  47. package/packs/zh/web-ui/scripts/index.mjs +98 -0
  48. package/plugin.json +5 -6
  49. package/server.json +2 -2
  50. package/skills/deslop-docs/SKILL.md +10 -8
  51. package/skills/deslop-slides-docx/SKILL.md +7 -8
  52. package/skills/deslop-verify/SKILL.md +7 -8
  53. package/skills/deslop-web-ui/SKILL.md +7 -8
  54. package/skills/dislop/SKILL.md +16 -28
  55. package/skills/dislop/agents/openai.yaml +1 -1
  56. package/skills/dislop/references/essay.md +6 -6
  57. package/skills/dislop/references/essay.zh-CN.md +6 -6
  58. package/skills/dislop/references/office.md +5 -5
  59. package/skills/dislop/references/office.zh-CN.md +5 -5
  60. package/skills/dislop/references/web-ui.md +4 -4
  61. package/skills/dislop/references/web-ui.zh-CN.md +4 -4
  62. package/skills/dislop/references/work-docs.md +7 -7
  63. package/skills/dislop/references/work-docs.zh-CN.md +7 -7
  64. package/src/cli-main.mjs +292 -0
  65. package/src/commands/check-fix.mjs +324 -0
  66. package/src/commands/doctor.mjs +132 -0
  67. package/src/commands/init.mjs +55 -0
  68. package/src/commands/login.mjs +82 -0
  69. package/src/commands/model.mjs +130 -0
  70. package/src/commands/packs.mjs +81 -0
  71. package/src/commands/verify.mjs +165 -0
  72. package/src/commands/voice.mjs +84 -0
  73. package/src/commands/worklog.mjs +424 -0
  74. package/src/kernel/config.mjs +759 -0
  75. package/src/kernel/document-model.mjs +1432 -0
  76. package/src/kernel/fact-gate.mjs +775 -0
  77. package/src/kernel/file-discovery.mjs +296 -0
  78. package/src/{binary-node.mjs → kernel/ooxml-binary.mjs} +615 -890
  79. package/src/kernel/pack-loader.mjs +801 -0
  80. package/src/kernel/pack-validator.mjs +491 -0
  81. package/src/kernel/patcher.mjs +471 -0
  82. package/src/kernel/pipeline.mjs +530 -0
  83. package/src/kernel/prompt-assembler.mjs +336 -0
  84. package/src/kernel/version.mjs +7 -0
  85. package/src/kernel/voice-profile.mjs +180 -0
  86. package/src/mcp/stdio-server.mjs +442 -0
  87. package/src/runners/auto-fix.mjs +74 -0
  88. package/src/runners/interactive-tty.mjs +488 -0
  89. package/src/runners/reporters.mjs +272 -0
  90. package/src/runtime/chunker.mjs +87 -0
  91. package/src/runtime/json-extract.mjs +144 -0
  92. package/src/runtime/privacy-gate.mjs +97 -0
  93. package/src/runtime/providers/anthropic.mjs +65 -0
  94. package/src/runtime/providers/cloud.mjs +138 -0
  95. package/src/runtime/providers/gemini.mjs +91 -0
  96. package/src/runtime/providers/local-model.mjs +147 -0
  97. package/src/runtime/providers/openai-compat.mjs +130 -0
  98. package/src/runtime/router.mjs +324 -0
  99. package/src/runtime/worklog.mjs +904 -0
  100. package/src/sdk/index.mjs +137 -0
  101. package/models/manifest.json +0 -90
  102. package/models/pocket-slop-v1.json +0 -1
  103. package/packs/business-brief/pack.json +0 -937
  104. package/packs/core/pack.json +0 -209
  105. package/packs/deck-and-ui/pack.json +0 -539
  106. package/packs/engineering-spec/pack.json +0 -144
  107. package/packs/executive-deck/pack.json +0 -98
  108. package/packs/literary-essay/pack.json +0 -344
  109. package/packs/regulated-comms/pack.json +0 -99
  110. package/patterns/ai-tic-rubric.json +0 -252
  111. package/patterns/banks/composite-fusion.json +0 -48
  112. package/patterns/banks/discourse-rhythm.json +0 -95
  113. package/patterns/banks/lexical-signals.json +0 -92
  114. package/patterns/banks/syntactic-frames.json +0 -52
  115. package/patterns/banks/visual-deck.json +0 -44
  116. package/patterns/dimensions/artifacts.json +0 -121
  117. package/patterns/dimensions/discourse.json +0 -438
  118. package/patterns/dimensions/lexical.json +0 -198
  119. package/patterns/dimensions/rhythm.json +0 -258
  120. package/patterns/dimensions/syntactic.json +0 -285
  121. package/patterns/dimensions/visual-and-deck.json +0 -530
  122. package/patterns/taxonomy.json +0 -112
  123. package/src/core.mjs +0 -5497
  124. package/src/dislop/review-picker.vim +0 -114
  125. package/src/local-model.mjs +0 -997
  126. package/src/pattern-engine.mjs +0 -1003
  127. package/src/pocket-model.mjs +0 -729
  128. package/src/review-apply.mjs +0 -151
  129. package/src/review-client.mjs +0 -1073
@@ -0,0 +1,488 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import crypto from "node:crypto";
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { verifyBaselineFacts } from "../kernel/fact-gate.mjs";
7
+ import { patchDocumentOnDisk } from "../kernel/patcher.mjs";
8
+ import {
9
+ computeSummaryCounts,
10
+ getItemTierKey,
11
+ serializeCleanReportItem,
12
+ } from "../kernel/pipeline.mjs";
13
+
14
+ function defaultClipboardCopy(text, platform = process.platform) {
15
+ const candidates =
16
+ platform === "darwin"
17
+ ? [["pbcopy", []]]
18
+ : platform === "win32"
19
+ ? [["clip", []]]
20
+ : [
21
+ ["wl-copy", []],
22
+ ["xclip", ["-selection", "clipboard"]],
23
+ ["xsel", ["--clipboard", "--input"]],
24
+ ];
25
+
26
+ for (const [cmd, args] of candidates) {
27
+ try {
28
+ const res = spawnSync(cmd, args, { input: text, encoding: "utf8", stdio: ["pipe", "ignore", "ignore"] });
29
+ if (res.status === 0) return true;
30
+ } catch {
31
+ // try next candidate
32
+ }
33
+ }
34
+ return false;
35
+ }
36
+
37
+ function defaultLaunchEditor(initialText, { env = process.env, platform = process.platform } = {}) {
38
+ const editorCmd =
39
+ env.VISUAL || env.EDITOR || (platform === "win32" ? "notepad" : "vi");
40
+ const tmpFile = path.join(
41
+ os.tmpdir(),
42
+ `dislop-edit-${process.pid}-${crypto.randomBytes(4).toString("hex")}.md`,
43
+ );
44
+ fs.writeFileSync(tmpFile, initialText, "utf8");
45
+
46
+ try {
47
+ const parts = editorCmd.trim().split(/\s+/);
48
+ const bin = parts[0];
49
+ const args = [...parts.slice(1), tmpFile];
50
+ const res = spawnSync(bin, args, { stdio: "inherit" });
51
+ if (res.error || (res.status !== 0 && res.status !== null)) {
52
+ return null;
53
+ }
54
+ return fs.readFileSync(tmpFile, "utf8");
55
+ } finally {
56
+ if (fs.existsSync(tmpFile)) {
57
+ try {
58
+ fs.unlinkSync(tmpFile);
59
+ } catch {
60
+ // ignore cleanup failure
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ function createKeypressQueue(stdin) {
67
+ const queue = [];
68
+ let waiter = null;
69
+ let closed = false;
70
+
71
+ const pushChar = (ch) => {
72
+ if (waiter) {
73
+ const w = waiter;
74
+ waiter = null;
75
+ w(ch);
76
+ } else {
77
+ queue.push(ch);
78
+ }
79
+ };
80
+
81
+ const onData = (chunk) => {
82
+ const str = Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk);
83
+ for (const ch of str) {
84
+ if (ch === "\u0003") {
85
+ // Ctrl+C -> treat as quit without applying further
86
+ pushChar("\u0003");
87
+ continue;
88
+ }
89
+ if (ch === "\r" || ch === "\n" || ch === " " || ch === "\t") continue;
90
+ pushChar(ch);
91
+ }
92
+ };
93
+
94
+ const onEnd = () => {
95
+ closed = true;
96
+ if (waiter) {
97
+ const w = waiter;
98
+ waiter = null;
99
+ w("q");
100
+ }
101
+ };
102
+
103
+ const wasRaw = Boolean(stdin.isRaw);
104
+ if (typeof stdin.setRawMode === "function" && stdin.isTTY) {
105
+ stdin.setRawMode(true);
106
+ }
107
+ if (typeof stdin.resume === "function") {
108
+ stdin.resume();
109
+ }
110
+ stdin.on("data", onData);
111
+ stdin.on("end", onEnd);
112
+
113
+ return {
114
+ async nextKey() {
115
+ if (queue.length > 0) return queue.shift();
116
+ if (closed) return "q";
117
+ return new Promise((resolve) => {
118
+ waiter = resolve;
119
+ });
120
+ },
121
+ dispose() {
122
+ stdin.off("data", onData);
123
+ stdin.off("end", onEnd);
124
+ if (typeof stdin.setRawMode === "function" && stdin.isTTY) {
125
+ stdin.setRawMode(wasRaw);
126
+ }
127
+ if (typeof stdin.pause === "function") {
128
+ stdin.pause();
129
+ }
130
+ },
131
+ };
132
+ }
133
+
134
+ function renderHunkBanner(item, index, total) {
135
+ const kindLabel = item.kind.toUpperCase();
136
+ const levelLabel = (item.kind === "defect" ? item.severity : item.priority).toUpperCase();
137
+ const coordParts = [item.targetId, item.line ? `L${item.line}` : null].filter(Boolean).join(" | ");
138
+ const coordDisplay = coordParts ? ` (${coordParts})` : "";
139
+
140
+ const lines = [
141
+ `\n── [${index + 1}/${total}] [${kindLabel} · ${levelLabel} · ${item.fixSafety}] ${item.ruleId}${coordDisplay} ──`,
142
+ `Reason: ${item.reason}`,
143
+ ];
144
+ if (item.verificationNote) {
145
+ lines.push(`Note : ${item.verificationNote}`);
146
+ }
147
+ lines.push("");
148
+ lines.push(`- ${item.originalQuote}`);
149
+ if (item.actionType === "delete" && item.fixSafety !== "manual") {
150
+ lines.push("+ (Delete sentence)");
151
+ } else if (item.suggestedReplacement) {
152
+ lines.push(`+ ${item.suggestedReplacement}`);
153
+ } else if (item.rewritePrompt) {
154
+ lines.push(`? Prompt: ${item.rewritePrompt}`);
155
+ } else {
156
+ lines.push("? (Manual edit required)");
157
+ }
158
+ lines.push("");
159
+ lines.push(
160
+ "Action: [y] accept [n] skip [e] edit ($EDITOR) [p] copy rewrite prompt",
161
+ );
162
+ lines.push(
163
+ "Batch : [a] accept remaining safe in tier [A] accept all safe/review [s] skip tier [u] undo [q] save & quit > ",
164
+ );
165
+ return lines.join("\n");
166
+ }
167
+
168
+ function canAutoAcceptItem(item) {
169
+ if (item.fixSafety === "manual") return false;
170
+ if (item.actionType === "delete") return Boolean(item.targetId || item._locator);
171
+ if (item.actionType === "replace") {
172
+ return Boolean(item.suggestedReplacement !== "" && (item.targetId || item._locator));
173
+ }
174
+ return false;
175
+ }
176
+
177
+ /**
178
+ * Interactive TTY Hunk State Machine (`y/n/e/p/a/A/s/u/q`).
179
+ */
180
+ export async function runInteractiveTtySession(
181
+ docResult,
182
+ {
183
+ stdin = process.stdin,
184
+ stdout = process.stdout,
185
+ env = process.env,
186
+ dryRun = false,
187
+ backup = false,
188
+ keyReader = null,
189
+ editorRunner = null,
190
+ clipboardRunner = null,
191
+ } = {},
192
+ ) {
193
+ const { doc, items, report } = docResult;
194
+ if (items.length === 0) {
195
+ stdout.write(`${report.file}: clean (0 items)\n`);
196
+ return { appliedCount: 0, modified: false, diff: "", decisions: {}, undoCount: 0, report };
197
+ }
198
+
199
+ let reader = keyReader || createKeypressQueue(stdin);
200
+ const ownedReader = !keyReader;
201
+
202
+ // Map itemIndex -> decision `{ status: 'accepted' | 'skipped' | 'edited', copiedPrompt?: boolean, patch?: Object }`
203
+ let decisions = new Map();
204
+ const undoStack = [];
205
+ let undoCount = 0;
206
+ let idx = 0;
207
+
208
+ const snapshotState = () => {
209
+ undoStack.push({
210
+ idx,
211
+ decisions: new Map(decisions),
212
+ });
213
+ };
214
+
215
+ try {
216
+ while (idx < items.length) {
217
+ const item = items[idx];
218
+ stdout.write(renderHunkBanner(item, idx, items.length));
219
+
220
+ const key = await reader.nextKey();
221
+ stdout.write(`${key === "\u0003" ? "^C" : key}\n`);
222
+
223
+ if (key === "\u0003") {
224
+ // Abort immediately without saving
225
+ return {
226
+ appliedCount: 0,
227
+ modified: false,
228
+ diff: "",
229
+ aborted: true,
230
+ decisions: {},
231
+ undoCount,
232
+ report,
233
+ };
234
+ }
235
+
236
+ if (key === "q") {
237
+ break;
238
+ }
239
+
240
+ if (key === "u") {
241
+ if (undoStack.length === 0) {
242
+ stdout.write(" (Already at the first hunk; nothing to undo.)\n");
243
+ } else {
244
+ const prev = undoStack.pop();
245
+ idx = prev.idx;
246
+ decisions = prev.decisions;
247
+ undoCount += 1;
248
+ stdout.write(` (Reverted back to hunk ${idx + 1}.)\n`);
249
+ }
250
+ continue;
251
+ }
252
+
253
+ if (key === "y") {
254
+ if (!canAutoAcceptItem(item)) {
255
+ stdout.write(
256
+ " Cannot auto-accept a 'manual' item without a verified replacement. Press [e] to edit or [p] to copy prompt.\n",
257
+ );
258
+ continue;
259
+ }
260
+ snapshotState();
261
+ decisions.set(idx, {
262
+ status: "accepted",
263
+ patch: {
264
+ targetId: item.targetId,
265
+ locator: item._locator || null,
266
+ originalQuote: item.originalQuote,
267
+ replacement: item.actionType === "delete" ? "" : item.suggestedReplacement,
268
+ },
269
+ });
270
+ idx += 1;
271
+ continue;
272
+ }
273
+
274
+ if (key === "n") {
275
+ snapshotState();
276
+ decisions.set(idx, { status: "skipped" });
277
+ idx += 1;
278
+ continue;
279
+ }
280
+
281
+ if (key === "p") {
282
+ const promptText =
283
+ item.rewritePrompt ||
284
+ `Revise "${item.originalQuote}" — ${item.reason}`;
285
+ const copied = clipboardRunner
286
+ ? await clipboardRunner(promptText)
287
+ : defaultClipboardCopy(promptText);
288
+ if (copied) {
289
+ stdout.write(" Copied rewrite prompt to clipboard.\n");
290
+ } else {
291
+ stdout.write(` Rewrite prompt:\n ${promptText}\n`);
292
+ }
293
+ snapshotState();
294
+ decisions.set(idx, { status: "skipped", copiedPrompt: true });
295
+ idx += 1;
296
+ continue;
297
+ }
298
+
299
+ if (key === "e") {
300
+ const seg = item.targetId ? doc.segments.find((s) => s.id === item.targetId) : null;
301
+ const para = seg
302
+ ? doc.paragraphs?.find((p) => p.id === seg.paragraphId)
303
+ : null;
304
+ const originalText = para ? para.text : item.originalQuote;
305
+ const editTargetId = para ? para.id : item.targetId;
306
+
307
+ if (!editTargetId && !item._locator) {
308
+ stdout.write(" This item has no editable text span locator.\n");
309
+ continue;
310
+ }
311
+
312
+ // Pause raw mode while spawning external interactive terminal editor, then resume cleanly
313
+ if (ownedReader) reader.dispose();
314
+ let editedRaw;
315
+ try {
316
+ editedRaw = editorRunner
317
+ ? await editorRunner(originalText, item)
318
+ : defaultLaunchEditor(originalText, { env });
319
+ } finally {
320
+ if (ownedReader) {
321
+ reader = createKeypressQueue(stdin);
322
+ }
323
+ }
324
+
325
+ if (editedRaw === null || editedRaw === undefined) {
326
+ stdout.write(" Editor cancelled; keeping hunk undecided.\n");
327
+ continue;
328
+ }
329
+
330
+ const trimmedEdited = String(editedRaw).replace(/\r?\n$/, "");
331
+ if (trimmedEdited === originalText) {
332
+ stdout.write(" No changes made in editor.\n");
333
+ continue;
334
+ }
335
+
336
+ const factRes = verifyBaselineFacts(originalText, trimmedEdited);
337
+ let keepManualEdit = true;
338
+ if (!factRes.ok) {
339
+ stdout.write(
340
+ ` Fact check notice: ${factRes.summary}. Keep manual edit anyway? [y/N] `,
341
+ );
342
+ const confirmKey = await reader.nextKey();
343
+ stdout.write(`${confirmKey}\n`);
344
+ keepManualEdit = confirmKey.toLowerCase() === "y";
345
+ }
346
+
347
+ if (!keepManualEdit) {
348
+ stdout.write(" Discarded manual edit.\n");
349
+ continue;
350
+ }
351
+
352
+ snapshotState();
353
+ decisions.set(idx, {
354
+ status: "edited",
355
+ patch: {
356
+ targetId: editTargetId,
357
+ locator: para ? para.locator : item._locator || null,
358
+ originalQuote: originalText,
359
+ replacement: trimmedEdited,
360
+ },
361
+ });
362
+ idx += 1;
363
+ continue;
364
+ }
365
+
366
+ if (key === "a") {
367
+ snapshotState();
368
+ const currentTier = getItemTierKey(item);
369
+ let cursor = idx;
370
+ while (cursor < items.length && getItemTierKey(items[cursor]) === currentTier) {
371
+ const curItem = items[cursor];
372
+ if (curItem.fixSafety === "safe" && canAutoAcceptItem(curItem)) {
373
+ decisions.set(cursor, {
374
+ status: "accepted",
375
+ patch: {
376
+ targetId: curItem.targetId,
377
+ locator: curItem._locator || null,
378
+ originalQuote: curItem.originalQuote,
379
+ replacement:
380
+ curItem.actionType === "delete" ? "" : curItem.suggestedReplacement,
381
+ },
382
+ });
383
+ } else {
384
+ decisions.set(cursor, { status: "skipped" });
385
+ }
386
+ cursor += 1;
387
+ }
388
+ idx = cursor;
389
+ continue;
390
+ }
391
+
392
+ if (key === "A") {
393
+ snapshotState();
394
+ for (let cursor = idx; cursor < items.length; cursor += 1) {
395
+ const curItem = items[cursor];
396
+ if (
397
+ (curItem.fixSafety === "safe" || curItem.fixSafety === "review") &&
398
+ canAutoAcceptItem(curItem)
399
+ ) {
400
+ decisions.set(cursor, {
401
+ status: "accepted",
402
+ patch: {
403
+ targetId: curItem.targetId,
404
+ locator: curItem._locator || null,
405
+ originalQuote: curItem.originalQuote,
406
+ replacement:
407
+ curItem.actionType === "delete" ? "" : curItem.suggestedReplacement,
408
+ },
409
+ });
410
+ } else {
411
+ decisions.set(cursor, { status: "skipped" });
412
+ }
413
+ }
414
+ idx = items.length;
415
+ continue;
416
+ }
417
+
418
+ if (key === "s") {
419
+ snapshotState();
420
+ const currentTier = getItemTierKey(item);
421
+ let cursor = idx;
422
+ while (cursor < items.length && getItemTierKey(items[cursor]) === currentTier) {
423
+ decisions.set(cursor, { status: "skipped" });
424
+ cursor += 1;
425
+ }
426
+ idx = cursor;
427
+ continue;
428
+ }
429
+
430
+ stdout.write(" Unknown key. Choose one of [y, n, e, p, a, A, s, u, q].\n");
431
+ }
432
+ } finally {
433
+ if (ownedReader) {
434
+ reader.dispose();
435
+ }
436
+ }
437
+
438
+ const patches = [];
439
+ const appliedIndices = new Set();
440
+ const decisionsSummary = {};
441
+ for (const [itemIdx, dec] of decisions.entries()) {
442
+ const itemId = items[itemIdx]?.id;
443
+ if (itemId) {
444
+ if (dec.status === "accepted") decisionsSummary[itemId] = "accepted";
445
+ else if (dec.status === "edited") decisionsSummary[itemId] = "edited";
446
+ else if (dec.copiedPrompt) decisionsSummary[itemId] = "prompt_copied";
447
+ else decisionsSummary[itemId] = "skipped";
448
+ }
449
+ if ((dec.status === "accepted" || dec.status === "edited") && dec.patch) {
450
+ patches.push(dec.patch);
451
+ appliedIndices.add(itemIdx);
452
+ }
453
+ }
454
+
455
+ if (patches.length === 0) {
456
+ stdout.write("\nNo edits accepted; file left unchanged.\n");
457
+ return {
458
+ appliedCount: 0,
459
+ modified: false,
460
+ diff: "",
461
+ decisions: decisionsSummary,
462
+ undoCount,
463
+ report,
464
+ };
465
+ }
466
+
467
+ const patchRes = patchDocumentOnDisk(doc, patches, { dryRun, backup });
468
+ if (patchRes.modified && !dryRun) {
469
+ for (const itemIdx of appliedIndices) {
470
+ items[itemIdx]._applied = true;
471
+ }
472
+ const remaining = items.filter((i) => !i._applied);
473
+ report.summary = computeSummaryCounts(remaining);
474
+ report.items = remaining.map(serializeCleanReportItem);
475
+ stdout.write(`\nSaved ${patches.length} change(s) to ${report.file}.\n`);
476
+ } else if (dryRun && patchRes.diff) {
477
+ stdout.write(`\n${patchRes.diff}\n`);
478
+ }
479
+
480
+ return {
481
+ appliedCount: patchRes.modified ? patches.length : 0,
482
+ modified: patchRes.modified,
483
+ diff: patchRes.diff,
484
+ decisions: decisionsSummary,
485
+ undoCount,
486
+ report,
487
+ };
488
+ }