pi-web-ui 0.99.0 → 0.101.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 (109) hide show
  1. package/CHANGELOG.md +90 -1
  2. package/README.md +48 -45
  3. package/README.zh-CN.md +43 -40
  4. package/bin/pi-web-ui.mjs +172 -40
  5. package/dist/server/agent-formatters.js +191 -0
  6. package/dist/server/agent-service-daemon.js +1266 -0
  7. package/dist/server/agent-service.js +9851 -11892
  8. package/dist/server/approval-default-rules.js +158 -0
  9. package/dist/server/approval-rules.js +130 -184
  10. package/dist/server/ask-user-question-tool.js +94 -0
  11. package/dist/server/attachment-store.js +38 -1
  12. package/dist/server/attachments.js +55 -0
  13. package/dist/server/bash-tool.js +83 -0
  14. package/dist/server/bg-servers.js +82 -2
  15. package/dist/server/browser-page-tool.js +207 -0
  16. package/dist/server/claim-files-tool.js +4 -4
  17. package/dist/server/client-id-utils.js +51 -0
  18. package/dist/server/client-state.js +63 -1
  19. package/dist/server/compact-context-tool.js +10 -9
  20. package/dist/server/compaction-markers.js +34 -1
  21. package/dist/server/context-budget-runner.js +43 -0
  22. package/dist/server/conversation-read-tool.js +7 -8
  23. package/dist/server/conversation-touches.js +19 -0
  24. package/dist/server/dangling-tools.js +18 -5
  25. package/dist/server/delegate-mode.js +1 -0
  26. package/dist/server/delegate-task.js +10 -14
  27. package/dist/server/dispatch-domain-handlers.js +631 -0
  28. package/dist/server/dispatch-plugin-handlers.js +300 -0
  29. package/dist/server/dsh/dsh-agent-service.js +125 -13
  30. package/dist/server/edit-soft-tool.js +10 -12
  31. package/dist/server/eval-tool.js +4 -5
  32. package/dist/server/goal-evidence.js +180 -0
  33. package/dist/server/goal-service.js +49 -9
  34. package/dist/server/hashline-engine.js +199 -32
  35. package/dist/server/index.js +212 -944
  36. package/dist/server/left-panel-running.js +115 -0
  37. package/dist/server/load-tools-tool.js +100 -0
  38. package/dist/server/lsp-tool.js +50 -28
  39. package/dist/server/marker-service.js +53 -12
  40. package/dist/server/markers/builtins/action.js +108 -0
  41. package/dist/server/markers/index.js +4 -1
  42. package/dist/server/markers-list-tool.js +34 -0
  43. package/dist/server/market-service.js +277 -0
  44. package/dist/server/mcp-bridge.js +137 -30
  45. package/dist/server/mcp-hot-reload.js +84 -27
  46. package/dist/server/mcp-manager.js +215 -0
  47. package/dist/server/message-entry-resolver.js +32 -0
  48. package/dist/server/orphan-manager.js +44 -0
  49. package/dist/server/patch-remote-catalog.js +28 -10
  50. package/dist/server/patch-tool.js +9 -8
  51. package/dist/server/persona-chain.js +63 -0
  52. package/dist/server/plan-mode.js +9 -6
  53. package/dist/server/plan-update-tool.js +96 -0
  54. package/dist/server/plugin-api-catalog.js +30 -3
  55. package/dist/server/plugin-conversation-view.js +47 -0
  56. package/dist/server/plugin-facilities.js +13 -3
  57. package/dist/server/plugin-ui-slots.js +39 -0
  58. package/dist/server/plugins.js +183 -63
  59. package/dist/server/present-files-tool.js +10 -11
  60. package/dist/server/preset-fields.js +700 -0
  61. package/dist/server/preset-share.js +1179 -0
  62. package/dist/server/process-utils.js +30 -0
  63. package/dist/server/prompt-assembler.js +80 -0
  64. package/dist/server/prompt-composer.js +23 -9
  65. package/dist/server/protocol-version.js +1 -1
  66. package/dist/server/read-tool.js +8 -10
  67. package/dist/server/resolve-global-sdk.js +80 -18
  68. package/dist/server/schedule-agent-tool.js +147 -146
  69. package/dist/server/scm-commitmsg.js +74 -0
  70. package/dist/server/sdk-origin.js +125 -37
  71. package/dist/server/serialize.js +97 -7
  72. package/dist/server/session-branch.js +367 -0
  73. package/dist/server/session-parser.js +235 -0
  74. package/dist/server/session-search.js +158 -0
  75. package/dist/server/settings-service.js +115 -84
  76. package/dist/server/skill-content-filler.js +33 -0
  77. package/dist/server/skill-tool.js +3 -4
  78. package/dist/server/subagent-handoff.js +18 -0
  79. package/dist/server/subagent-helpers.js +88 -0
  80. package/dist/server/subagents.js +15 -22
  81. package/dist/server/terminals.js +171 -91
  82. package/dist/server/tool-approval.js +3 -1
  83. package/dist/server/tool-guards.js +527 -0
  84. package/dist/server/tool-host-factories.js +217 -0
  85. package/dist/server/tool-manager.js +84 -23
  86. package/dist/server/tool-prompt-overrides.js +158 -0
  87. package/dist/server/tool-prompts.js +42 -0
  88. package/dist/server/tool-signature.js +104 -0
  89. package/dist/server/wait-subscription-scan.js +46 -1
  90. package/dist/server/workspace-snapshot.js +60 -11
  91. package/extensions/webui.ts +90 -24
  92. package/package.json +5 -3
  93. package/plugin-sdk/README.md +25 -4
  94. package/plugin-sdk/import-check.mjs +210 -0
  95. package/plugin-sdk/index.d.ts +21 -1
  96. package/plugin-sdk/index.mjs +6 -0
  97. package/plugins/catalog.json +53 -2
  98. package/themes/aetheris.css +3 -1
  99. package/themes/translucent.css +8 -1
  100. package/themes/transparent.css +9 -1
  101. package/themes/zhupi-dark.css +1 -1
  102. package/themes/zhupi.css +1 -1
  103. package/web/dist/assets/{TerminalPanel-NerrJlTS.js → TerminalPanel-DD7I5_aC.js} +2 -2
  104. package/web/dist/assets/index-CpjA1YdT.css +1 -0
  105. package/web/dist/assets/index-nKn87VuM.js +678 -0
  106. package/web/dist/index.html +2 -2
  107. package/web/dist/sw.js +1 -1
  108. package/web/dist/assets/index-BdMaGCcs.css +0 -1
  109. package/web/dist/assets/index-ByCBN4Kt.js +0 -368
@@ -10,8 +10,8 @@
10
10
  * 4. 寄存器支持(CUT / PUT @reg):支持在跨文件或同文件内部移动代码段。
11
11
  */
12
12
  import { createHash } from "node:crypto";
13
- import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
14
- import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
13
+ import { existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
14
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
15
15
  export const HL_HASH_LENGTH = 4;
16
16
  /** 归一化文本换行符与尾随空白(确保哈希跨平台一致) */
17
17
  export function normalizeLineEndings(text) {
@@ -333,7 +333,7 @@ export const globalSnapshotStore = new HashlineSnapshotStore();
333
333
  *
334
334
  * 核心逻辑:若磁盘文件的改动未侵入 targetHunks 所在的锚点行,则将锚点行映射到最新文件的对应行,安全完成合并。
335
335
  */
336
- export function tryRecoverEdits(baseText, currentText, hunks, filePath) {
336
+ export function tryRecoverEdits(baseText, currentText, hunks, _filePath) {
337
337
  const baseLines = normalizeLineEndings(baseText).split("\n");
338
338
  const curLines = normalizeLineEndings(currentText).split("\n");
339
339
  // 若内容完全相同,无需恢复
@@ -376,15 +376,121 @@ export function tryRecoverEdits(baseText, currentText, hunks, filePath) {
376
376
  });
377
377
  }
378
378
  else {
379
- return {
380
- success: false,
381
- reason: `目标文件在第 ${firstDiff} 行附近发生外部修改,补丁锚点(第 ${start} 行)产生冲突`,
382
- };
379
+ // 平移后上下文仍不匹配:±6 行窗口内做 trim 归一化重锚定
380
+ const baseCtx = baseLines
381
+ .slice(Math.max(0, start - 2), Math.min(baseLines.length, end + 1))
382
+ .join("\n")
383
+ .trim();
384
+ let matched = null;
385
+ if (baseCtx) {
386
+ for (let w = 1; w <= 6 && matched === null; w++) {
387
+ for (const off of [w, -w]) {
388
+ const s2 = Math.max(1, start + delta + off);
389
+ const e2 = Math.max(1, end + delta + off);
390
+ const curCtx = curLines
391
+ .slice(Math.max(0, s2 - 2), Math.min(curLines.length, e2 + 1))
392
+ .join("\n")
393
+ .trim();
394
+ if (curCtx && curCtx === baseCtx) {
395
+ matched = off;
396
+ break;
397
+ }
398
+ }
399
+ }
400
+ }
401
+ if (matched !== null) {
402
+ remapped.push({
403
+ ...hunk,
404
+ lineStart: Math.max(1, start + delta + matched),
405
+ lineEnd: hunk.lineEnd !== undefined ? Math.max(1, end + delta + matched) : undefined,
406
+ });
407
+ }
408
+ else {
409
+ return {
410
+ success: false,
411
+ reason: `目标文件在第 ${firstDiff} 行附近发生外部修改,补丁锚点(第 ${start} 行)产生冲突`,
412
+ };
413
+ }
383
414
  }
384
415
  }
385
416
  }
386
417
  return { success: true, remappedHunks: remapped };
387
418
  }
419
+ /**
420
+ * 错误消息附带当前内容摘录(行号: 内容,锚点附近 ±2 行),
421
+ * 让模型基于现内容一次重试到位,而不是被迫整文件重读。
422
+ */
423
+ function patchFileExcerpt(lines, aroundLine, filePath, hash) {
424
+ let n = lines.length;
425
+ if (n > 0 && lines[n - 1] === "")
426
+ n--; // 尾随换行 split 出的幻影空行不计入行数(与引擎 lines 口径一致)
427
+ const head = `当前共 ${n} 行,最新锚点:[${filePath}#${hash}]`;
428
+ if (n === 0)
429
+ return `${head}(空文件)`;
430
+ const center = Math.max(1, Math.min(n, aroundLine ?? n));
431
+ const lo = Math.max(1, center - 2);
432
+ const hi = Math.min(n, center + 2);
433
+ const rows = [];
434
+ for (let i = lo; i <= hi; i++)
435
+ rows.push(`${i}: ${String(lines[i - 1]).slice(0, 160)}`);
436
+ return `${head};第 ${lo}-${hi} 行现内容:\n${rows.join("\n")}`;
437
+ }
438
+ /** 同名文件解析时跳过的高风险/重目录 */
439
+ const SAME_BASENAME_SKIP_DIRS = new Set([
440
+ "node_modules",
441
+ ".git",
442
+ "__pycache__",
443
+ ".venv",
444
+ "venv",
445
+ "dist",
446
+ "build",
447
+ ".pytest_cache",
448
+ ".mypy_cache",
449
+ "target",
450
+ ".next",
451
+ ]);
452
+ /**
453
+ * 带锚头但文件读不到时:工作区内找同名唯一文件(典型场景:模型写错目录层级)。
454
+ * 只接受唯一命中;歧义/无命中交回原错误路径并附候选清单。
455
+ */
456
+ function findUniqueSameBasename(cwd, targetPath) {
457
+ const base = basename(targetPath);
458
+ if (!base || base.startsWith("."))
459
+ return { status: "none", candidates: [] };
460
+ const same = [];
461
+ const ci = [];
462
+ const walk = (dir, depth) => {
463
+ if (depth > 6 || same.length + ci.length > 16)
464
+ return;
465
+ let entries;
466
+ try {
467
+ entries = readdirSync(dir, { withFileTypes: true });
468
+ }
469
+ catch {
470
+ return;
471
+ }
472
+ for (const e of entries) {
473
+ if (e.name.startsWith("."))
474
+ continue;
475
+ const full = join(dir, e.name);
476
+ if (e.isDirectory()) {
477
+ if (!SAME_BASENAME_SKIP_DIRS.has(e.name))
478
+ walk(full, depth + 1);
479
+ continue;
480
+ }
481
+ if (e.name === base)
482
+ same.push(full);
483
+ else if (e.name.toLowerCase() === base.toLowerCase())
484
+ ci.push(full);
485
+ }
486
+ };
487
+ walk(cwd, 0);
488
+ if (same.length === 1)
489
+ return { status: "resolved", path: relative(cwd, same[0]) || same[0], candidates: same };
490
+ if (same.length === 0 && ci.length === 1)
491
+ return { status: "resolved", path: relative(cwd, ci[0]) || ci[0], candidates: ci };
492
+ return { status: same.length + ci.length > 1 ? "ambiguous" : "none", candidates: [...same, ...ci].slice(0, 8) };
493
+ }
388
494
  /**
389
495
  * 应用 Hashline 补丁
390
496
  * 支持传入虚拟或物理文件读写器(便于单元测试或沙箱执行)
@@ -420,8 +526,12 @@ export function applyHashlinePatch(patchText, options = {}) {
420
526
  return { ok: false, summary: "未能从输入中解析出有效的 [path#TAG] 补丁段", results: [] };
421
527
  }
422
528
  const clipboard = new Map(); // 命名剪切板寄存器
423
- const plannedWrites = new Map(); // path -> 新内容
529
+ const plannedWrites = new Map(); // foldKey(absPath) -> 新内容
424
530
  const plannedDeletes = new Set();
531
+ // Windows 文件系统大小写不敏感:键做大小写折叠,避免 [a]/[A] 变体绕过路径归一化造成双写覆盖;
532
+ // plannedPaths 记录首次见到的原始路径(保持相对/绝对形态)供落盘与自定义读写器使用。
533
+ const foldKey = (abs) => (process.platform === "win32" ? abs.toLowerCase() : abs);
534
+ const plannedPaths = new Map();
425
535
  const results = [];
426
536
  // ===== 阶段 1: 预检所有文件并计算目标内容 =====
427
537
  for (const sec of sections) {
@@ -439,15 +549,45 @@ export function applyHashlinePatch(patchText, options = {}) {
439
549
  error: `Path traversal denied: ${sec.filePath}`,
440
550
  };
441
551
  }
442
- // 同一次 patch 内对同文件的后续段落,优先使用前面段落生成的新内容
443
- const currentText = plannedWrites.get(sec.filePath) ?? read(sec.filePath);
552
+ // 同一次 patch 内对同文件的后续段落,优先使用前面段落生成的新内容。
553
+ // plannedWrites/plannedDeletes 一律按折叠绝对路径做键:[a] 与 [./a]、大小写变体视为同一文件。
554
+ let currentText = plannedWrites.get(foldKey(resolve(cwd, sec.filePath))) ?? read(sec.filePath);
555
+ let fuzzyNote = "";
556
+ if (currentText === null && sec.expectedHash) {
557
+ // 带 #TAG 却读不到:先尝试工作区内同名唯一文件解析(典型:模型写错目录层级)
558
+ const cand = findUniqueSameBasename(cwd, sec.filePath);
559
+ if (cand.status === "resolved" && cand.path) {
560
+ fuzzyNote = `(路径 ${sec.filePath} 不存在,已解析为同名文件 ${cand.path})`;
561
+ sec.filePath = cand.path;
562
+ currentText = plannedWrites.get(foldKey(resolve(cwd, sec.filePath))) ?? read(cand.path);
563
+ }
564
+ }
565
+ const isNewFile = currentText === null;
444
566
  if (currentText === null) {
445
- return {
446
- ok: false,
447
- summary: `文件不存在:${sec.filePath}(hashline 仅支持修改已存在的文件,新建文件请使用 write 工具)`,
448
- results: [],
449
- error: `File not found: ${sec.filePath}`,
450
- };
567
+ // [path] 段头(无 #TAG)+ 内容 hunk = 创建新文件
568
+ if (sec.hunks.some((h) => h.kind === "remove_file" || h.kind === "move_file")) {
569
+ return {
570
+ ok: false,
571
+ summary: `文件不存在,无法 REM/MV:${sec.filePath}(新建文件请用 [path] 段头 + PUT <1: 提供内容)`,
572
+ results: [],
573
+ error: `File not found: ${sec.filePath}`,
574
+ };
575
+ }
576
+ if (sec.expectedHash) {
577
+ // 附工作区相近文件候选(相对路径),有候选时不建议新建遮蔽
578
+ const cand = findUniqueSameBasename(cwd, sec.filePath);
579
+ const candRel = cand.candidates.map((c) => relative(cwd, c) || c);
580
+ const advice = candRel.length
581
+ ? `工作区内相近文件:${candRel.join("、")}。请核对目录层级后用上述路径重试,勿新建同名文件遮蔽。`
582
+ : `新建文件时段头不能带 #TAG(无法对不存在的文件校验哈希),请写 [${sec.filePath}] 并用 PUT <1: 提供内容。`;
583
+ return {
584
+ ok: false,
585
+ summary: `文件不存在:${sec.filePath}。${advice}`,
586
+ results: [],
587
+ error: `Tagged header on nonexistent file: ${sec.filePath}`,
588
+ };
589
+ }
590
+ currentText = ""; // 新建:从空文件起步
451
591
  }
452
592
  const isCrlf = currentText.includes("\r\n");
453
593
  const eol = isCrlf ? "\r\n" : "\n";
@@ -465,18 +605,24 @@ export function applyHashlinePatch(patchText, options = {}) {
465
605
  isRecovered = true;
466
606
  }
467
607
  else {
608
+ // 附现内容摘录,模型可基于现内容一次重锚定
609
+ const excerptLines = normalizeLineEndings(currentText).split("\n");
610
+ const firstHunk = sec.hunks.find((h) => h.kind !== "remove_file" && h.kind !== "move_file");
468
611
  return {
469
612
  ok: false,
470
- summary: `文件内容已发生变动,且三方合流失败:${sec.filePath}(预期哈希 #${sec.expectedHash},实际哈希 #${liveHash};${recovery.reason ?? "冲突"})\n请重新使用 read 工具查看该文件最新内容后再提交 patch。`,
613
+ summary: `文件内容已发生变动,且三方合流失败:${sec.filePath}(预期哈希 #${sec.expectedHash},实际哈希 #${liveHash};${recovery.reason ?? "冲突"})\n${patchFileExcerpt(excerptLines, firstHunk?.lineStart, sec.filePath, liveHash)}\n请基于上述现内容修正行号后重提交,或重新使用 read 工具查看该文件。`,
471
614
  results: [],
472
615
  error: `Hash mismatch and recovery failed on ${sec.filePath}`,
473
616
  };
474
617
  }
475
618
  }
476
619
  else {
620
+ // 附现内容摘录,模型可基于现内容一次重锚定
621
+ const excerptLines = normalizeLineEndings(currentText).split("\n");
622
+ const firstHunk = sec.hunks.find((h) => h.kind !== "remove_file" && h.kind !== "move_file");
477
623
  return {
478
624
  ok: false,
479
- summary: `文件内容与锚点不一致:${sec.filePath}(预期哈希 #${sec.expectedHash},实际哈希 #${liveHash})\n请重新使用 read 工具读取该文件以获取最新行号与 #TAG。`,
625
+ summary: `文件内容与锚点不一致:${sec.filePath}(预期哈希 #${sec.expectedHash},实际哈希 #${liveHash})${fuzzyNote}\n${patchFileExcerpt(excerptLines, firstHunk?.lineStart, sec.filePath, liveHash)}\n请基于上述现内容修正行号后重提交,或重新使用 read 工具读取该文件。`,
480
626
  results: [],
481
627
  error: `Hash mismatch on ${sec.filePath} (#${sec.expectedHash} vs #${liveHash})`,
482
628
  };
@@ -487,6 +633,9 @@ export function applyHashlinePatch(patchText, options = {}) {
487
633
  if (hasTrailingNewline && lines.length > 0 && lines[lines.length - 1] === "") {
488
634
  lines.pop();
489
635
  }
636
+ if (isNewFile) {
637
+ lines = []; // 新文件按 0 行处理,PUT <1: / PUT >$: 直接写入内容
638
+ }
490
639
  let isDeleted = false;
491
640
  let moveDest = undefined;
492
641
  // 倒序/顺序处理 hunks。为了保证行号不受前面 hunk 影响,从后往前执行行号替换;
@@ -536,10 +685,12 @@ export function applyHashlinePatch(patchText, options = {}) {
536
685
  }
537
686
  }
538
687
  if (isDeleted) {
539
- plannedDeletes.add(sec.filePath);
688
+ plannedDeletes.add(foldKey(absFilePath));
689
+ plannedPaths.set(foldKey(absFilePath), sec.filePath);
540
690
  results.push({
541
691
  filePath: sec.filePath,
542
692
  op: "deleted",
693
+ note: fuzzyNote || undefined,
543
694
  oldHash: liveHash,
544
695
  linesChanged: lines.length,
545
696
  });
@@ -551,9 +702,10 @@ export function applyHashlinePatch(patchText, options = {}) {
551
702
  continue;
552
703
  if (h.lineStart !== -1 && typeof h.lineStart === "number") {
553
704
  if (h.lineStart < 1 || h.lineStart > Math.max(1, lines.length)) {
705
+ // 附文件尾部摘录,模型可自行改用 PUT >$ 或修正行号
554
706
  return {
555
707
  ok: false,
556
- summary: `行号越界:${sec.filePath} 第 ${h.lineStart} 行(文件总共只有 ${lines.length} 行)。请重新使用 read 工具核验行号。`,
708
+ summary: `行号越界:${sec.filePath} 第 ${h.lineStart} 行(文件总共只有 ${lines.length} 行)。${patchFileExcerpt(lines, lines.length, sec.filePath, liveHash)}`,
557
709
  results: [],
558
710
  error: `Line out of bounds: line ${h.lineStart} in ${sec.filePath} (${lines.length} lines total)`,
559
711
  };
@@ -561,7 +713,7 @@ export function applyHashlinePatch(patchText, options = {}) {
561
713
  if (h.lineEnd !== undefined && h.lineEnd > Math.max(1, lines.length)) {
562
714
  return {
563
715
  ok: false,
564
- summary: `行号越界:${sec.filePath} 结束行 ${h.lineEnd} 超过文件总行数(总共 ${lines.length} 行)。`,
716
+ summary: `行号越界:${sec.filePath} 结束行 ${h.lineEnd} 超过文件总行数(总共 ${lines.length} 行)。${patchFileExcerpt(lines, h.lineStart, sec.filePath, liveHash)}`,
565
717
  results: [],
566
718
  error: `Line out of bounds: end line ${h.lineEnd} in ${sec.filePath} (${lines.length} lines total)`,
567
719
  };
@@ -650,13 +802,21 @@ export function applyHashlinePatch(patchText, options = {}) {
650
802
  linesChangedCount += Math.max(count, contentToInsert.length);
651
803
  }
652
804
  }
653
- const newContent = lines.join(eol) + (hasTrailingNewline ? eol : "");
805
+ const newContent = isNewFile
806
+ ? lines.length > 0
807
+ ? lines.join(eol) + eol
808
+ : ""
809
+ : lines.join(eol) + (hasTrailingNewline ? eol : "");
654
810
  if (moveDest) {
655
- plannedDeletes.add(sec.filePath);
656
- plannedWrites.set(moveDest, newContent);
811
+ const moveKey = foldKey(resolve(cwd, moveDest));
812
+ plannedDeletes.add(foldKey(absFilePath));
813
+ plannedPaths.set(foldKey(absFilePath), sec.filePath);
814
+ plannedWrites.set(moveKey, newContent);
815
+ plannedPaths.set(moveKey, moveDest);
657
816
  results.push({
658
817
  filePath: sec.filePath,
659
818
  op: "moved",
819
+ note: fuzzyNote || undefined,
660
820
  oldHash: liveHash,
661
821
  newHash: computeFileHash(newContent),
662
822
  linesChanged: linesChangedCount,
@@ -665,10 +825,14 @@ export function applyHashlinePatch(patchText, options = {}) {
665
825
  });
666
826
  }
667
827
  else {
668
- plannedWrites.set(sec.filePath, newContent);
828
+ const updateKey = foldKey(absFilePath);
829
+ plannedWrites.set(updateKey, newContent);
830
+ plannedPaths.set(updateKey, sec.filePath);
669
831
  results.push({
670
832
  filePath: sec.filePath,
671
833
  op: "updated",
834
+ created: isNewFile,
835
+ note: fuzzyNote || undefined,
672
836
  oldHash: liveHash,
673
837
  newHash: computeFileHash(newContent),
674
838
  linesChanged: linesChangedCount,
@@ -678,22 +842,25 @@ export function applyHashlinePatch(patchText, options = {}) {
678
842
  }
679
843
  // ===== 阶段 2: 全部校验通过,统一落盘 =====
680
844
  // 先执行所有写入,确保新文件与移动目标成功落盘,避免先删后写异常时永久丢失源文件
681
- for (const [p, content] of plannedWrites.entries()) {
845
+ for (const [key, content] of plannedWrites.entries()) {
846
+ const p = plannedPaths.get(key) ?? key;
682
847
  write(p, content);
683
848
  // 记住新快照(统一采用绝对路径隔离多工作区)
684
849
  store.record(resolve(cwd, p), content);
685
850
  }
686
- for (const p of plannedDeletes) {
687
- if (!plannedWrites.has(p)) {
688
- remove(p);
851
+ for (const key of plannedDeletes) {
852
+ if (!plannedWrites.has(key)) {
853
+ remove(plannedPaths.get(key) ?? key);
689
854
  }
690
855
  }
691
856
  const summaryParts = results.map((r) => {
692
857
  if (r.op === "deleted")
693
- return `删除 ${r.filePath}`;
858
+ return `删除 ${r.filePath}${r.note ?? ""}`;
859
+ if (r.created)
860
+ return `新建 ${r.filePath}(${r.linesChanged} 行,新哈希 #${r.newHash})${r.note ?? ""}`;
694
861
  if (r.op === "moved")
695
- return `移动 ${r.filePath} -> ${r.newPath}(新哈希 #${r.newHash})`;
696
- return `修改 ${r.filePath}(${r.linesChanged} 行变动,新哈希 #${r.newHash}${r.recovered ? ",三方自愈" : ""})`;
862
+ return `移动 ${r.filePath} -> ${r.newPath}(新哈希 #${r.newHash})${r.note ?? ""}`;
863
+ return `修改 ${r.filePath}(${r.linesChanged} 行变动,新哈希 #${r.newHash}${r.recovered ? ",三方自愈" : ""})${r.note ?? ""}`;
697
864
  });
698
865
  return {
699
866
  ok: true,