dsh-vscode-mode 0.4.2 → 0.4.3

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/lib/index.js CHANGED
@@ -4240,7 +4240,8 @@ async function revertHunk(ctx, session, record, idx) {
4240
4240
  const location = locateHunks(content, [precise])[0];
4241
4241
  if (!location?.matched) return {
4242
4242
  ok: false,
4243
- error: "回滚失败:该区域可能已被后续修改影响"
4243
+ stale: true,
4244
+ error: "回滚失败:该区域在文件中已不存在(可能已被后续修改覆盖)"
4244
4245
  };
4245
4246
  const result = applyLocations(content, [location], true);
4246
4247
  await fs.writeText(target, result.content, void 0, void 0, policyOf(ctx, session));
@@ -6991,8 +6992,9 @@ async function afterManualSave(ctx, registry, sc, path) {
6991
6992
  }
6992
6993
  /**
6993
6994
  * 批量决策核心:一次会话/桶解析 + 逐项处理 + 统一落盘(accept/reject 单条与 decideBatch 共用)。
6994
- * rejected 项先做回滚,失败记入该项 error 且不改决策;本批次新增"已解决"记录一次性归档,
6995
- * 有任何成功项则整桶只写盘一次,避免逐条读写整个 sidecar。
6995
+ * rejected 项先做回滚,失败记入该项 error 且不改决策;hunk 的新文本已不在文件中
6996
+ * (被后续修改覆盖/撤销)时不算失败:不写文件,按已回滚记录决策并归档(结果项带 stale)。
6997
+ * 本批次新增"已解决"记录一次性归档,有任何成功项则整桶只写盘一次,避免逐条读写整个 sidecar。
6996
6998
  * @author ddj 2026年08月25号
6997
6999
  * @param items 决策项(按数组顺序处理,rejected 的先后即回滚顺序)
6998
7000
  * @returns 逐项结果(ok 项含更新后的记录视图)
@@ -7011,26 +7013,33 @@ async function applyDecisions(ctx, session, cwd, bucket, items) {
7011
7013
  });
7012
7014
  continue;
7013
7015
  }
7016
+ let revertedStale = false;
7014
7017
  if (item.decision === "rejected") {
7015
- const outcome = (item.scope ?? "call") === "hunk" ? await revertHunk(ctx, session, record, item.hunkIndex ?? -1) : await revertCall(ctx, session, record);
7018
+ const scope = item.scope ?? "call";
7019
+ const outcome = scope === "hunk" ? await revertHunk(ctx, session, record, item.hunkIndex ?? -1) : await revertCall(ctx, session, record);
7016
7020
  if (!outcome.ok) {
7017
- results.push({
7018
- callId: item.callId,
7019
- ok: false,
7020
- error: outcome.error
7021
- });
7022
- continue;
7021
+ if (scope !== "hunk" || outcome.stale !== true) {
7022
+ results.push({
7023
+ callId: item.callId,
7024
+ ok: false,
7025
+ error: outcome.error
7026
+ });
7027
+ continue;
7028
+ }
7029
+ revertedStale = true;
7023
7030
  }
7024
7031
  }
7025
7032
  const wasResolved = recordResolved(record);
7026
7033
  markDecision(record, item.scope ?? "call", item.hunkIndex, item.decision);
7027
7034
  changed = true;
7028
7035
  if (!wasResolved && recordResolved(record)) resolved.push(record);
7029
- results.push({
7036
+ const result = {
7030
7037
  callId: item.callId,
7031
7038
  ok: true,
7032
7039
  record: recView(record)
7033
- });
7040
+ };
7041
+ if (revertedStale) result.stale = true;
7042
+ results.push(result);
7034
7043
  }
7035
7044
  if (resolved.length) await archiveRecords(ctx, session, cwd, bucket, resolved, items.some((item) => item.decision === "rejected") ? "已处理(回滚)" : "已处理", { deferSave: true });
7036
7045
  if (changed) await saveBucket(ctx, cwd, bucket, session);