@whybebabo/dsh-file-review-tab 0.7.1 → 0.7.2

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/client.js CHANGED
@@ -4042,7 +4042,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4042
4042
  /** Coordinate space, so hunks from several settlements stay separable. */
4043
4043
  mutation: number().int().min(0).optional(),
4044
4044
  /** Event sequence, so settlements merge in the order they happened. */
4045
- seq: number().int().min(0).optional()
4045
+ seq: number().int().min(0).optional(),
4046
+ /**
4047
+ * The emitting call, carried so the renderer can pair this fragment with the
4048
+ * coordinates the Host recorded for it. Ignored by the apply side.
4049
+ */
4050
+ callId: string().optional()
4046
4051
  });
4047
4052
  const requestSchema = object({
4048
4053
  action: _enum(["undo", "redo"]),
@@ -4077,6 +4082,27 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4077
4082
  const recordedResultSchema = object({ mutations: array(recordedMutationSchema) });
4078
4083
  const recordedRequestCodec = strictCodec(`${PACKAGE_NAME}#RecordedRequest`, () => recordedRequestSchema);
4079
4084
  const recordedResultCodec = strictCodec(`${PACKAGE_NAME}#RecordedResult`, () => recordedResultSchema);
4085
+ const hunkAnchorSchema = object({
4086
+ oldStart: number().int().min(0),
4087
+ newStart: number().int().min(1)
4088
+ });
4089
+ const recordedAnchorSchema = object({
4090
+ callId: string(),
4091
+ path: string(),
4092
+ anchors: array(hunkAnchorSchema)
4093
+ });
4094
+ const anchorHunkSchema = object({
4095
+ oldText: string().nullable(),
4096
+ newText: string()
4097
+ });
4098
+ const anchorRequestSchema = object({ calls: array(object({
4099
+ callId: string(),
4100
+ path: string(),
4101
+ hunks: array(anchorHunkSchema)
4102
+ })) });
4103
+ const anchorResultSchema = object({ anchors: array(recordedAnchorSchema) });
4104
+ const anchorRequestCodec = strictCodec(`${PACKAGE_NAME}#AnchorRequest`, () => anchorRequestSchema);
4105
+ const anchorResultCodec = strictCodec(`${PACKAGE_NAME}#AnchorResult`, () => anchorResultSchema);
4080
4106
  function descriptor(method) {
4081
4107
  return {
4082
4108
  id: `${PACKAGE_NAME}#fileReview/${method}`,
@@ -4129,6 +4155,32 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4129
4155
  result: recordedResultCodec
4130
4156
  };
4131
4157
  }
4158
+ function anchorsDescriptor() {
4159
+ return {
4160
+ id: `${PACKAGE_NAME}#fileReview/anchors`,
4161
+ service: "fileReview",
4162
+ namespace: "fileReview",
4163
+ method: "anchors",
4164
+ invocation: { kind: "direct" },
4165
+ scope: {
4166
+ context: "agent",
4167
+ wire: "agentId"
4168
+ },
4169
+ parameters: [{
4170
+ name: "agent",
4171
+ wire: "agentId",
4172
+ source: "lookup",
4173
+ lookup: "agent",
4174
+ codec: agentCodec
4175
+ }, {
4176
+ name: "request",
4177
+ wire: "request",
4178
+ source: "json",
4179
+ codec: anchorRequestCodec
4180
+ }],
4181
+ result: anchorResultCodec
4182
+ };
4183
+ }
4132
4184
  //#endregion
4133
4185
  //#region src/remote.ts
4134
4186
  const TYPERT_REMOTE = {
@@ -4136,7 +4188,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4136
4188
  descriptors: [
4137
4189
  descriptor("status"),
4138
4190
  descriptor("apply"),
4139
- recordedDescriptor()
4191
+ recordedDescriptor(),
4192
+ anchorsDescriptor()
4140
4193
  ]
4141
4194
  };
4142
4195
  //#endregion
@@ -5366,6 +5419,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5366
5419
  if (own.length > 0) diffs = own;
5367
5420
  }
5368
5421
  }
5422
+ const callId = block.callId;
5423
+ if (typeof callId === "string") diffs = diffs.map((diff) => ({
5424
+ ...diff,
5425
+ callId
5426
+ }));
5369
5427
  if (diffs.length > 0) changes.push({
5370
5428
  path: intent.path,
5371
5429
  diffs
@@ -5702,12 +5760,20 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5702
5760
  function isOneSided(hunks) {
5703
5761
  return hunks.some((hunk) => hunk.lines.some((line) => line.startsWith("+"))) !== hunks.some((hunk) => hunk.lines.some((line) => line.startsWith("-")));
5704
5762
  }
5705
- /** Pair one recorded before/after snapshot into numbered lines. */
5706
- function pairLines(diff) {
5763
+ /**
5764
+ * Pair one recorded before/after snapshot into numbered lines.
5765
+ *
5766
+ * `anchor` overrides where the pairing starts. The wire hunks the conversation
5767
+ * snapshot carries are context fragments with no line numbers at all, so without
5768
+ * an anchor their numbering can only start at 1 — a per-hunk counter, not the
5769
+ * file's lines. The Host knows each mutation's real coordinates (see
5770
+ * {@link HunkAnchor}) and this is where they enter the drawing.
5771
+ */
5772
+ function pairLines(diff, anchor) {
5707
5773
  const changes = diffArrays(diff.oldText === null ? [] : diffContentLines(diff.oldText), diffContentLines(diff.newText));
5708
5774
  const lines = [];
5709
- let oldNumber = diff.oldStart ?? 1;
5710
- let newNumber = diff.newStart ?? 1;
5775
+ let oldNumber = anchor?.oldStart ?? diff.oldStart ?? 1;
5776
+ let newNumber = anchor?.newStart ?? diff.newStart ?? 1;
5711
5777
  for (const change of changes) if (change.removed) for (const text of change.value) {
5712
5778
  lines.push({
5713
5779
  kind: "del",
@@ -5827,14 +5893,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5827
5893
  return fallback;
5828
5894
  }
5829
5895
  /** Convert one paired comparison into the hunks dsh's FileDiff renders. */
5830
- function comparisonToHunks(diff, contextLines) {
5831
- const lines = pairLines(diff);
5896
+ function comparisonToHunks(diff, contextLines, anchor) {
5897
+ const lines = pairLines(diff, anchor);
5832
5898
  return contextRanges(lines, contextLines).map((range) => {
5833
5899
  const kept = lines.slice(range.start, range.end);
5834
5900
  return {
5835
- oldStart: startOf(lines, range, "oldNumber", diff.oldStart ?? 1),
5901
+ oldStart: startOf(lines, range, "oldNumber", anchor?.oldStart ?? diff.oldStart ?? 1),
5836
5902
  oldLines: kept.filter((line) => line.oldNumber !== null).length,
5837
- newStart: startOf(lines, range, "newNumber", diff.newStart ?? 1),
5903
+ newStart: startOf(lines, range, "newNumber", anchor?.newStart ?? diff.newStart ?? 1),
5838
5904
  newLines: kept.filter((line) => line.newNumber !== null).length,
5839
5905
  lines: kept.map((line) => {
5840
5906
  return `${line.kind === "del" ? "-" : line.kind === "add" ? "+" : " "}${line.text}`;
@@ -5843,13 +5909,200 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5843
5909
  });
5844
5910
  }
5845
5911
  /**
5912
+ * Pair every hunk with the coordinates recorded for its call.
5913
+ *
5914
+ * A call's fragments are consecutive in `diffs` and were produced by the same
5915
+ * patch the anchors come from, so they map positionally. That mapping is only
5916
+ * trustworthy when the two counts agree: a mismatch means the anchor list
5917
+ * describes a different patch, and using it anyway would shift every number in
5918
+ * the file instead of merely leaving them hunk-local. Such a call is refused
5919
+ * outright rather than partially applied.
5920
+ * @param diffs - the file's hunks, in settlement order.
5921
+ * @param lookup - recorded coordinates by call id, or undefined when none loaded.
5922
+ * @returns one optional anchor per hunk, aligned with `diffs`.
5923
+ */
5924
+ function anchorPlan(diffs, lookup) {
5925
+ if (lookup === void 0 || lookup.size === 0) return diffs.map(() => void 0);
5926
+ const totals = /* @__PURE__ */ new Map();
5927
+ for (const diff of diffs) {
5928
+ if (diff.callId === void 0) continue;
5929
+ totals.set(diff.callId, (totals.get(diff.callId) ?? 0) + 1);
5930
+ }
5931
+ const seen = /* @__PURE__ */ new Map();
5932
+ return diffs.map((diff) => {
5933
+ const callId = diff.callId;
5934
+ if (callId === void 0) return void 0;
5935
+ const list = lookup.get(callId);
5936
+ if (list === void 0 || list.length !== totals.get(callId)) return void 0;
5937
+ const at = seen.get(callId) ?? 0;
5938
+ seen.set(callId, at + 1);
5939
+ return list[at];
5940
+ });
5941
+ }
5942
+ /**
5846
5943
  * Convert recorded comparisons into dsh's served hunk shape.
5847
5944
  * @param diffs - the recorded before/after snapshots for one file.
5848
5945
  * @param contextLines - unchanged lines kept on each side of a change.
5946
+ * @param anchors - recorded absolute coordinates by call id, when known.
5849
5947
  * @returns the hunks to render, in order.
5850
5948
  */
5851
- function toNativeHunks(diffs, contextLines = 3) {
5852
- return diffs.flatMap((diff) => comparisonToHunks(diff, contextLines));
5949
+ function toNativeHunks(diffs, contextLines = 3, anchors) {
5950
+ const plan = anchorPlan(diffs, anchors);
5951
+ return diffs.flatMap((diff, at) => comparisonToHunks(diff, contextLines, plan[at]));
5952
+ }
5953
+ //#endregion
5954
+ //#region src/client/hunk-anchors.ts
5955
+ /**
5956
+ * Client cache and hook for the Host's per-mutation hunk coordinates.
5957
+ *
5958
+ * The comparison surfaces read the conversation snapshot, and its hunks are the
5959
+ * engine's context fragments — text only, no line numbers. Numbering those from
5960
+ * 1 puts a change at the end of a long file on "line 1". The Host recorded each
5961
+ * mutation's real coordinates at settlement (see the node half's hunk-anchors
5962
+ * module); this module fetches them once per session and hands them to the
5963
+ * renderer.
5964
+ *
5965
+ * Deliberately a cache rather than view state: a call's coordinates never change
5966
+ * once recorded, so the sidebar tab, a chat hover preview and every remount reuse
5967
+ * the same answer. Only the FIRST lookup of a call id costs a round trip, and a
5968
+ * call the recorder never saw stays marked as asked — a session whose mutations
5969
+ * happened outside the tool pipeline must not turn every render into a request.
5970
+ */
5971
+ /** Immutable per-session lookup: a new map identity whenever it gains entries. */
5972
+ const anchorsBySession = /* @__PURE__ */ new Map();
5973
+ /** Call ids already asked about, including the ones the Host had nothing for. */
5974
+ const askedBySession = /* @__PURE__ */ new Map();
5975
+ const EMPTY = /* @__PURE__ */ new Map();
5976
+ /**
5977
+ * Group one file's hunks into the calls that produced them.
5978
+ *
5979
+ * Fragments of a call are consecutive and keep the engine's hunk order, so this
5980
+ * both names the calls to ask about and supplies the text the Host needs to place
5981
+ * a hunk whose coordinates were never recorded. Hunks without a call id (the
5982
+ * recorded Code Mode path, which already carries coordinates) are skipped.
5983
+ * @param diffs - the file's hunks, in settlement order.
5984
+ * @returns one entry per call, in first-seen order.
5985
+ */
5986
+ function anchorCalls(diffs) {
5987
+ const byCall = /* @__PURE__ */ new Map();
5988
+ for (const diff of diffs) {
5989
+ if (diff.callId === void 0) continue;
5990
+ let call = byCall.get(diff.callId);
5991
+ if (call === void 0) {
5992
+ call = {
5993
+ path: diff.path,
5994
+ hunks: []
5995
+ };
5996
+ byCall.set(diff.callId, call);
5997
+ }
5998
+ call.hunks.push({
5999
+ oldText: diff.oldText,
6000
+ newText: diff.newText
6001
+ });
6002
+ }
6003
+ return [...byCall.entries()].map(([callId, call]) => ({
6004
+ callId,
6005
+ path: call.path,
6006
+ hunks: call.hunks
6007
+ }));
6008
+ }
6009
+ /**
6010
+ * Coordinates remembered for one session, as the lookup the renderer takes.
6011
+ * @param sessionId - the session whose anchors are wanted.
6012
+ * @returns the cached map (empty before any lookup completes).
6013
+ */
6014
+ function cachedHunkAnchors(sessionId) {
6015
+ return anchorsBySession.get(sessionId) ?? EMPTY;
6016
+ }
6017
+ /** Merge a Host answer into the cache and return the new lookup. */
6018
+ function rememberHunkAnchors(sessionId, entries) {
6019
+ const next = new Map(anchorsBySession.get(sessionId) ?? []);
6020
+ for (const entry of entries) next.set(entry.callId, entry.anchors);
6021
+ anchorsBySession.set(sessionId, next);
6022
+ return next;
6023
+ }
6024
+ /**
6025
+ * Claim the ids that still need a lookup, marking them as asked.
6026
+ *
6027
+ * Claiming before the request is what stops two surfaces painting the same hunk
6028
+ * in one commit from fetching it twice. An id marked this way is never asked
6029
+ * again unless {@link releaseCallIds} returns it: a call the recorder never saw
6030
+ * answers successfully with no coordinates, and that must not become a request
6031
+ * per render.
6032
+ * @param sessionId - session key for the shared cache.
6033
+ * @param callIds - the calls the painted hunks came from.
6034
+ * @returns the ids to ask about now; empty when nothing new is wanted.
6035
+ */
6036
+ function claimCallIds(sessionId, callIds) {
6037
+ const asked = askedFor(sessionId);
6038
+ const wanted = [];
6039
+ for (const id of callIds) {
6040
+ if (asked.has(id) || wanted.includes(id)) continue;
6041
+ asked.add(id);
6042
+ wanted.push(id);
6043
+ }
6044
+ return wanted;
6045
+ }
6046
+ /**
6047
+ * Un-claim ids whose lookup failed.
6048
+ *
6049
+ * A thrown lookup is NOT the Host saying "this call has no coordinates" — it is
6050
+ * the Host not answering (an unmounted Remote, a transport error). Releasing the
6051
+ * ids is what lets a later attempt (new hunks, a now-visible tab, a remount) ask
6052
+ * again instead of leaving those hunks permanently unanchored.
6053
+ * @param sessionId - session key for the shared cache.
6054
+ * @param callIds - the ids whose request failed.
6055
+ */
6056
+ function releaseCallIds(sessionId, callIds) {
6057
+ const asked = askedFor(sessionId);
6058
+ for (const id of callIds) asked.delete(id);
6059
+ }
6060
+ /** The ids of one session already looked up (recorded or not). */
6061
+ function askedFor(sessionId) {
6062
+ const existing = askedBySession.get(sessionId);
6063
+ if (existing !== void 0) return existing;
6064
+ const created = /* @__PURE__ */ new Set();
6065
+ askedBySession.set(sessionId, created);
6066
+ return created;
6067
+ }
6068
+ /**
6069
+ * Coordinates for the calls a set of painted hunks came from, fetched on demand.
6070
+ *
6071
+ * Call it unconditionally from the component that draws the hunks; the request
6072
+ * lives in an effect, so a surface that never paints a diff never asks the Host.
6073
+ * @param sessionId - session key for the shared cache.
6074
+ * @param callIds - the calls the painted hunks came from, in any order.
6075
+ * @param load - Host lookup; undefined while the Remote is unavailable.
6076
+ * @param enabled - false pauses the lookup (a hidden tab, a closed preview).
6077
+ * @returns the lookup `toNativeHunks` takes.
6078
+ */
6079
+ function useHunkAnchors(sessionId, callIds, load, enabled = true) {
6080
+ const key = (0, react.useMemo)(() => [...new Set(callIds)].sort().join("\0"), [callIds]);
6081
+ const [lookup, setLookup] = (0, react.useState)(() => cachedHunkAnchors(sessionId));
6082
+ (0, react.useEffect)(() => {
6083
+ setLookup(cachedHunkAnchors(sessionId));
6084
+ }, [sessionId]);
6085
+ (0, react.useEffect)(() => {
6086
+ if (!enabled || load === void 0) return;
6087
+ const wanted = claimCallIds(sessionId, key === "" ? [] : key.split("\0"));
6088
+ if (wanted.length === 0) return;
6089
+ let active = true;
6090
+ load(wanted).then((entries) => {
6091
+ const next = rememberHunkAnchors(sessionId, entries);
6092
+ if (active) setLookup(next);
6093
+ }).catch(() => {
6094
+ releaseCallIds(sessionId, wanted);
6095
+ });
6096
+ return () => {
6097
+ active = false;
6098
+ };
6099
+ }, [
6100
+ sessionId,
6101
+ key,
6102
+ enabled,
6103
+ load
6104
+ ]);
6105
+ return lookup;
5853
6106
  }
5854
6107
  /**
5855
6108
  * Delay before the next `recorded` fetch.
@@ -5864,7 +6117,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5864
6117
  }
5865
6118
  //#endregion
5866
6119
  //#region \0@whybebabo/dsh-file-review-tab-css:C:\Users\wuzhiwei\Documents\dsh_file_review_tab\dsh-file-review-tab\src\client\NativeDiff.module.css.mjs
5867
- const css$3 = "._3_Jlsa_body{--diff-empty-fill:color-mix(in srgb, var(--dsw-alias-interactive-bg-hover) 50%, transparent);min-height:0;font:var(--dsw-font-markdown-code-block);flex-direction:column;flex:auto;padding:8px 0 16px;display:flex;overflow:auto}._3_Jlsa_status{color:var(--dsw-alias-label-secondary);align-items:center;gap:12px;margin:0;padding:16px;font-size:13px;display:flex}._3_Jlsa_columns{flex:auto;grid-template-columns:minmax(0,1fr) minmax(0,1fr);min-height:0;display:grid}._3_Jlsa_column,._3_Jlsa_body[data-review-view=unified]:not([data-review-wrap]){grid-template-columns:minmax(max-content,100%);align-content:start;display:grid}._3_Jlsa_column{overscroll-behavior:none;min-width:0;overflow-x:scroll}._3_Jlsa_column+._3_Jlsa_column{border-left:.5px solid var(--dsw-alias-border-l3)}._3_Jlsa_sideLine{box-sizing:border-box;white-space:pre;grid-template-columns:3.5em max-content;width:max-content;min-width:100%;min-height:22px;line-height:22px;display:grid}._3_Jlsa_note{color:var(--dsw-alias-label-tertiary);font:var(--dsw-font-xs-13);margin:0;padding:4px 16px 8px}._3_Jlsa_hunk{margin-bottom:8px}._3_Jlsa_hunkHeader{color:var(--dsw-alias-label-tertiary);white-space:pre;padding:4px 16px}._3_Jlsa_line{box-sizing:border-box;white-space:pre;grid-template-columns:3.5em 3.5em 1.2em minmax(0,1fr);min-height:22px;line-height:22px;display:grid}._3_Jlsa_splitLine{white-space:pre;grid-template-columns:minmax(0,1fr) minmax(0,1fr);min-height:22px;line-height:22px;display:grid}._3_Jlsa_cell{box-sizing:border-box;grid-template-columns:3.5em minmax(0,1fr);min-width:0;display:grid}._3_Jlsa_cell+._3_Jlsa_cell{border-left:.5px solid var(--dsw-alias-border-l3)}._3_Jlsa_number{color:var(--dsw-alias-label-tertiary);text-align:right;user-select:none;padding-right:8px}._3_Jlsa_sign{text-align:center;user-select:none}._3_Jlsa_text{padding-right:16px}._3_Jlsa_body[data-review-wrap] ._3_Jlsa_line,._3_Jlsa_body[data-review-wrap] ._3_Jlsa_splitLine{white-space:pre-wrap}._3_Jlsa_body[data-review-wrap] ._3_Jlsa_text{overflow-wrap:anywhere}._3_Jlsa_add{--diff-gutter-fill:var(--dsw-alias-file-diff-added-gutter);--diff-marker:var(--dsw-alias-file-diff-added-marker);background:var(--dsw-alias-file-diff-added-bg)}._3_Jlsa_del{--diff-gutter-fill:var(--dsw-alias-file-diff-deleted-gutter);--diff-marker:var(--dsw-alias-file-diff-deleted-marker);background:var(--dsw-alias-file-diff-deleted-bg)}._3_Jlsa_add ._3_Jlsa_number,._3_Jlsa_del ._3_Jlsa_number{background:var(--diff-gutter-fill);color:var(--diff-marker)}._3_Jlsa_add ._3_Jlsa_number:first-child,._3_Jlsa_del ._3_Jlsa_number:first-child{box-shadow:inset 3px 0 0 var(--diff-marker)}._3_Jlsa_add ._3_Jlsa_sign,._3_Jlsa_del ._3_Jlsa_sign{color:var(--diff-marker)}._3_Jlsa_context ._3_Jlsa_text{color:var(--dsw-alias-label-secondary)}._3_Jlsa_empty{background:var(--diff-empty-fill)}";
6120
+ const css$3 = "._3_Jlsa_body{--diff-empty-fill:color-mix(in srgb, var(--dsw-alias-interactive-bg-hover) 50%, transparent);min-height:0;font:var(--dsw-font-markdown-code-block);flex-direction:column;flex:auto;padding:8px 0 16px;display:flex;overflow:auto}._3_Jlsa_status{color:var(--dsw-alias-label-secondary);align-items:center;gap:12px;margin:0;padding:16px;font-size:13px;display:flex}._3_Jlsa_columns{flex:auto;grid-template-columns:minmax(0,1fr) minmax(0,1fr);min-height:0;display:grid}._3_Jlsa_column,._3_Jlsa_body[data-review-view=unified]:not([data-review-wrap]){grid-template-columns:minmax(max-content,100%);align-content:start;display:grid}._3_Jlsa_column{overscroll-behavior-x:none;min-width:0;overflow-x:scroll}._3_Jlsa_column+._3_Jlsa_column{border-left:.5px solid var(--dsw-alias-border-l3)}._3_Jlsa_sideLine{box-sizing:border-box;white-space:pre;grid-template-columns:3.5em max-content;width:max-content;min-width:100%;min-height:22px;line-height:22px;display:grid}._3_Jlsa_note{color:var(--dsw-alias-label-tertiary);font:var(--dsw-font-xs-13);margin:0;padding:4px 16px 8px}._3_Jlsa_hunk{margin-bottom:8px}._3_Jlsa_hunkHeader{color:var(--dsw-alias-label-tertiary);white-space:pre;padding:4px 16px}._3_Jlsa_line{box-sizing:border-box;white-space:pre;grid-template-columns:3.5em 3.5em 1.2em minmax(0,1fr);min-height:22px;line-height:22px;display:grid}._3_Jlsa_splitLine{white-space:pre;grid-template-columns:minmax(0,1fr) minmax(0,1fr);min-height:22px;line-height:22px;display:grid}._3_Jlsa_cell{box-sizing:border-box;grid-template-columns:3.5em minmax(0,1fr);min-width:0;display:grid}._3_Jlsa_cell+._3_Jlsa_cell{border-left:.5px solid var(--dsw-alias-border-l3)}._3_Jlsa_number{color:var(--dsw-alias-label-tertiary);text-align:right;user-select:none;padding-right:8px}._3_Jlsa_sign{text-align:center;user-select:none}._3_Jlsa_text{padding-right:16px}._3_Jlsa_body[data-review-wrap] ._3_Jlsa_line,._3_Jlsa_body[data-review-wrap] ._3_Jlsa_splitLine{white-space:pre-wrap}._3_Jlsa_body[data-review-wrap] ._3_Jlsa_text{overflow-wrap:anywhere}._3_Jlsa_add{--diff-gutter-fill:var(--dsw-alias-file-diff-added-gutter);--diff-marker:var(--dsw-alias-file-diff-added-marker);background:var(--dsw-alias-file-diff-added-bg)}._3_Jlsa_del{--diff-gutter-fill:var(--dsw-alias-file-diff-deleted-gutter);--diff-marker:var(--dsw-alias-file-diff-deleted-marker);background:var(--dsw-alias-file-diff-deleted-bg)}._3_Jlsa_add ._3_Jlsa_number,._3_Jlsa_del ._3_Jlsa_number{background:var(--diff-gutter-fill);color:var(--diff-marker)}._3_Jlsa_add ._3_Jlsa_number:first-child,._3_Jlsa_del ._3_Jlsa_number:first-child{box-shadow:inset 3px 0 0 var(--diff-marker)}._3_Jlsa_add ._3_Jlsa_sign,._3_Jlsa_del ._3_Jlsa_sign{color:var(--diff-marker)}._3_Jlsa_context ._3_Jlsa_text{color:var(--dsw-alias-label-secondary)}._3_Jlsa_empty{background:var(--diff-empty-fill)}";
5868
6121
  const styleId$3 = "@whybebabo/dsh-file-review-tab/NativeDiff.module.css";
5869
6122
  if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(styleId$3) + "]") === null) {
5870
6123
  const style = document.createElement("style");
@@ -6392,6 +6645,31 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6392
6645
  return text;
6393
6646
  }
6394
6647
  //#endregion
6648
+ //#region src/reversible.ts
6649
+ /**
6650
+ * Whether one hunk carries both sides completely enough to replay exactly.
6651
+ * @param diff - the hunk under test.
6652
+ * @param path - the file the hunk claims to belong to.
6653
+ * @returns true when the hunk can be undone/redone by exact replacement.
6654
+ */
6655
+ function hunkReversible(diff, path) {
6656
+ if (diff.path !== path) return false;
6657
+ if (diff.oldText === null || diff.oldText === diff.newText) return false;
6658
+ if (diff.oldText === "" && diff.oldStart === void 0) return false;
6659
+ if (diff.newText === "" && diff.newStart === void 0) return false;
6660
+ return true;
6661
+ }
6662
+ /**
6663
+ * Whether a file's whole change set is reversible: non-empty and every hunk
6664
+ * passes {@link hunkReversible}.
6665
+ * @param path - the path every hunk must name.
6666
+ * @param diffs - the file's hunks, in settlement order.
6667
+ * @returns true when the Host can replay the complete change.
6668
+ */
6669
+ function changeReversible(path, diffs) {
6670
+ return diffs.length > 0 && diffs.every((diff) => hunkReversible(diff, path));
6671
+ }
6672
+ //#endregion
6395
6673
  //#region src/client/deep-link.ts
6396
6674
  /**
6397
6675
  * Chat → sidebar deep-link channel.
@@ -6499,7 +6777,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6499
6777
  }
6500
6778
  //#endregion
6501
6779
  //#region \0@whybebabo/dsh-file-review-tab-css:C:\Users\wuzhiwei\Documents\dsh_file_review_tab\dsh-file-review-tab\src\client\FileReviewTab.module.css.mjs
6502
- const css$2 = ".r1eXuW_root{height:100%;min-height:0;color:var(--dsw-alias-label-primary);flex-direction:column;display:flex;container-type:inline-size}.r1eXuW_header{box-sizing:border-box;border-bottom:.5px solid var(--dsw-alias-border-l3);flex:none;align-items:center;gap:6px;height:38px;padding:0 6px 0 8px;display:flex}.r1eXuW_selectorLabel{text-overflow:ellipsis;white-space:nowrap;flex:auto;min-width:0;font-size:12px;overflow:hidden}.r1eXuW_selector{flex:0 auto;min-width:0}.r1eXuW_selectorButton{box-sizing:border-box;border-radius:var(--dsw-radius-sm);max-width:100%;height:28px;color:var(--dsw-alias-label-primary);cursor:pointer;font:inherit;background:0 0;border:0;align-items:center;gap:4px;padding:0 6px 0 8px;font-size:12px;line-height:20px;display:inline-flex}.r1eXuW_selectorButton:hover,.r1eXuW_selectorButton[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover)}.r1eXuW_selectorButton svg{flex:none;display:block}.r1eXuW_item{justify-content:space-between;align-items:center;gap:12px;min-width:0;display:flex}.r1eXuW_itemPath{text-overflow:ellipsis;white-space:nowrap;min-width:0;line-height:20px;overflow:hidden}.r1eXuW_itemCounts{color:var(--dsw-alias-label-tertiary);font-family:var(--ds-font-family-code);flex:none;align-items:center;gap:6px;font-size:12px;line-height:20px;display:inline-flex}.r1eXuW_counts{min-width:0;color:var(--dsw-alias-label-tertiary);font-family:var(--ds-font-family-code);align-items:center;gap:6px;margin-right:auto;font-size:12px;line-height:20px;display:inline-flex}.r1eXuW_added{color:var(--dsw-alias-state-success-primary)}.r1eXuW_deleted{color:var(--dsw-alias-state-error-primary)}.r1eXuW_label{color:var(--dsw-alias-label-tertiary)}.r1eXuW_tools{flex:none;align-items:center;gap:2px;margin-left:auto;display:inline-flex}.r1eXuW_tool{border-radius:var(--dsw-radius-sm);width:28px;height:28px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:0;flex:none;justify-content:center;align-items:center;padding:6px;display:inline-flex}.r1eXuW_tool svg{width:15px;height:15px}.r1eXuW_tool:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.r1eXuW_tool[aria-pressed=true] .r1eXuW_compareIcon{transform:rotate(90deg)}.r1eXuW_tool:disabled{cursor:progress}.r1eXuW_tool[data-pending] svg{animation:.9s linear infinite r1eXuW_reviewToolSpin}@keyframes r1eXuW_reviewToolSpin{to{transform:rotate(360deg)}}@media (prefers-reduced-motion:reduce){.r1eXuW_tool[data-pending] svg{animation:none}}.r1eXuW_tool[data-error]{color:var(--dsw-alias-state-error-primary)}.r1eXuW_notice{border-radius:var(--dsw-radius-sm);flex:none;margin:8px 10px 0;padding:6px 10px;font-size:12px}.r1eXuW_noticeSuccess{color:var(--dsw-alias-state-success-primary);background:var(--dsw-alias-bg-layer-1);border:.5px solid var(--dsw-alias-border-l2)}.r1eXuW_noticeError{color:var(--dsw-alias-state-error-primary);background:var(--dsw-alias-bg-layer-1);border:.5px solid var(--dsw-alias-border-l2)}.r1eXuW_body{flex:1;min-height:0;padding:8px 0 16px;overflow-y:auto}.r1eXuW_empty{color:var(--dsw-alias-label-tertiary);text-align:center;padding:24px 12px}.r1eXuW_turnGroup{--changes-fill:var(--dsw-static-neutral-50);border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-1);margin:0 8px 8px;overflow:hidden}body[data-ds-dark-theme] .r1eXuW_turnGroup{--changes-fill:var(--dsw-static-neutral-850)}.r1eXuW_turnHeader{background:var(--changes-fill);flex-wrap:wrap;align-items:center;gap:4px 8px;min-height:34px;padding:0 8px 0 10px;display:flex}.r1eXuW_turnTitle{white-space:nowrap;font-weight:500}.r1eXuW_liveBadge{color:var(--dsw-alias-state-warning-primary,#d9a13b);white-space:nowrap;border-radius:999px;padding:0 6px;font-size:11px;line-height:18px}.r1eXuW_turnCount{color:var(--dsw-alias-label-tertiary);white-space:nowrap}.r1eXuW_stats{font-family:var(--ds-font-family-code);gap:6px;font-size:12px;display:inline-flex}.r1eXuW_removed{color:var(--dsw-alias-state-error-primary)}.r1eXuW_actionButton{border-radius:var(--dsw-radius-sm);height:24px;color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;white-space:nowrap;background:0 0;border:0;flex:none;align-items:center;gap:4px;padding:0 8px;font-size:12px;display:inline-flex}.r1eXuW_actionButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.r1eXuW_actionButton:disabled{cursor:progress;opacity:.55}.r1eXuW_buttonIcon{fill:none;stroke:currentColor;stroke-width:1.5px;stroke-linecap:round;stroke-linejoin:round;width:14px;height:14px}.r1eXuW_fileList{border-top:.5px solid var(--dsw-alias-border-l2);margin:0;padding:0;list-style:none}.r1eXuW_fileItem{border-top:.5px solid var(--dsw-alias-border-l1)}.r1eXuW_fileItem:first-child{border-top:0}.r1eXuW_fileRow{cursor:pointer;align-items:center;gap:8px;min-height:30px;padding:0 8px 0 10px;display:flex}.r1eXuW_fileRow:hover{background:var(--dsw-alias-interactive-bg-hover)}.r1eXuW_fileRow:focus-visible{box-shadow:inset 0 0 0 2px var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline:none}.r1eXuW_chevron{fill:none;width:12px;height:12px;stroke:var(--dsw-alias-label-tertiary);stroke-width:2px;stroke-linecap:round;stroke-linejoin:round;flex:none;transition:transform .12s}.r1eXuW_chevronOpen{transform:rotate(90deg)}.r1eXuW_fileName{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.r1eXuW_stateBadge{white-space:nowrap;border-radius:999px;flex:none;padding:0 6px;font-size:11px;line-height:18px}.r1eXuW_badgeUndone,.r1eXuW_badgeMuted{color:var(--dsw-alias-label-tertiary)}.r1eXuW_badgeError{color:var(--dsw-alias-state-error-primary)}.r1eXuW_deletedBadge{color:var(--dsw-alias-state-error-primary);white-space:nowrap;border-radius:999px;flex:none;padding:0 6px;font-size:11px;line-height:18px}.r1eXuW_smallButton{border-radius:var(--dsw-radius-sm);height:24px;color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;white-space:nowrap;background:0 0;border:0;flex:none;padding:0 8px;font-size:12px}.r1eXuW_smallButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.r1eXuW_smallButton:disabled{cursor:progress;opacity:.55}.r1eXuW_editorButton{margin-left:auto}.r1eXuW_diffWrap{border-top:.5px solid var(--dsw-alias-border-l1);overflow:hidden}.r1eXuW_reviewDiff{padding-bottom:8px}.r1eXuW_diffUnavailable{color:var(--dsw-alias-label-tertiary);margin:0;padding:10px 12px;font-size:12px}.r1eXuW_archiveSection{margin:0 8px 10px}.r1eXuW_archiveHeader{width:100%;color:var(--dsw-alias-label-tertiary);cursor:pointer;font:inherit;text-align:left;background:0 0;border:0;align-items:center;gap:4px;padding:8px 2px;font-size:12px;display:inline-flex}.r1eXuW_archiveHeader:hover{color:var(--dsw-alias-label-primary)}.r1eXuW_archiveTitle{min-width:0}.r1eXuW_archiveLoadMore{border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm);width:100%;color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;background:0 0;margin-top:6px;padding:6px;font-size:12px;display:block}.r1eXuW_archiveLoadMore:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}@container (width<=260px){.r1eXuW_counts{display:none}}";
6780
+ const css$2 = ".r1eXuW_root{height:100%;min-height:0;color:var(--dsw-alias-label-primary);flex-direction:column;display:flex;container-type:inline-size}.r1eXuW_header{box-sizing:border-box;border-bottom:.5px solid var(--dsw-alias-border-l3);flex:none;align-items:center;gap:6px;height:38px;padding:0 6px 0 8px;display:flex}.r1eXuW_selectorLabel{text-overflow:ellipsis;white-space:nowrap;flex:auto;min-width:0;font-size:12px;overflow:hidden}.r1eXuW_selector{flex:0 auto;min-width:0}.r1eXuW_selectorButton{box-sizing:border-box;border-radius:var(--dsw-radius-sm);max-width:100%;height:28px;color:var(--dsw-alias-label-primary);cursor:pointer;font:inherit;background:0 0;border:0;align-items:center;gap:4px;padding:0 6px 0 8px;font-size:12px;line-height:20px;display:inline-flex}.r1eXuW_selectorButton:hover,.r1eXuW_selectorButton[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover)}.r1eXuW_selectorButton svg{flex:none;display:block}.r1eXuW_item{justify-content:space-between;align-items:center;gap:12px;min-width:0;display:flex}.r1eXuW_itemPath{text-overflow:ellipsis;white-space:nowrap;min-width:0;line-height:20px;overflow:hidden}.r1eXuW_itemCounts{color:var(--dsw-alias-label-tertiary);font-family:var(--ds-font-family-code);flex:none;align-items:center;gap:6px;font-size:12px;line-height:20px;display:inline-flex}.r1eXuW_counts{min-width:0;color:var(--dsw-alias-label-tertiary);font-family:var(--ds-font-family-code);align-items:center;gap:6px;margin-right:auto;font-size:12px;line-height:20px;display:inline-flex}.r1eXuW_added{color:var(--dsw-alias-state-success-primary)}.r1eXuW_deleted{color:var(--dsw-alias-state-error-primary)}.r1eXuW_label{color:var(--dsw-alias-label-tertiary)}.r1eXuW_tools{flex:none;align-items:center;gap:2px;margin-left:auto;display:inline-flex}.r1eXuW_tool{border-radius:var(--dsw-radius-sm);width:28px;height:28px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:0;flex:none;justify-content:center;align-items:center;padding:6px;display:inline-flex}.r1eXuW_tool svg{width:15px;height:15px}.r1eXuW_tool:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.r1eXuW_tool[aria-pressed=true] .r1eXuW_compareIcon{transform:rotate(90deg)}.r1eXuW_tool:disabled{cursor:progress}.r1eXuW_tool[data-pending] svg{animation:.9s linear infinite r1eXuW_reviewToolSpin}@keyframes r1eXuW_reviewToolSpin{to{transform:rotate(360deg)}}@media (prefers-reduced-motion:reduce){.r1eXuW_tool[data-pending] svg{animation:none}}.r1eXuW_tool[data-error]{color:var(--dsw-alias-state-error-primary)}.r1eXuW_notice{border-radius:var(--dsw-radius-sm);flex:none;margin:8px 10px 0;padding:6px 10px;font-size:12px}.r1eXuW_noticeSuccess{color:var(--dsw-alias-state-success-primary);background:var(--dsw-alias-bg-layer-1);border:.5px solid var(--dsw-alias-border-l2)}.r1eXuW_noticeError{color:var(--dsw-alias-state-error-primary);background:var(--dsw-alias-bg-layer-1);border:.5px solid var(--dsw-alias-border-l2)}.r1eXuW_body{flex:1;min-height:0;padding:8px 0 16px;overflow-y:auto}.r1eXuW_empty{color:var(--dsw-alias-label-tertiary);text-align:center;padding:24px 12px}.r1eXuW_turnGroup{--changes-fill:var(--dsw-static-neutral-50);border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-1);margin:0 8px 8px;overflow:hidden}body[data-ds-dark-theme] .r1eXuW_turnGroup{--changes-fill:var(--dsw-static-neutral-850)}.r1eXuW_turnHeader{background:var(--changes-fill);flex-wrap:wrap;align-items:center;gap:4px 8px;min-height:34px;padding:0 8px 0 10px;display:flex}.r1eXuW_turnTitle{white-space:nowrap;font-weight:500}.r1eXuW_liveBadge{color:var(--dsw-alias-state-warning-primary,#d9a13b);white-space:nowrap;border-radius:999px;padding:0 6px;font-size:11px;line-height:18px}.r1eXuW_turnCount{color:var(--dsw-alias-label-tertiary);white-space:nowrap}.r1eXuW_stats{font-family:var(--ds-font-family-code);gap:6px;font-size:12px;display:inline-flex}.r1eXuW_removed{color:var(--dsw-alias-state-error-primary)}.r1eXuW_actionButton{border-radius:var(--dsw-radius-sm);height:24px;color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;white-space:nowrap;background:0 0;border:0;flex:none;align-items:center;gap:4px;padding:0 8px;font-size:12px;display:inline-flex}.r1eXuW_actionButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.r1eXuW_actionButton:disabled{cursor:progress;opacity:.55}.r1eXuW_buttonIcon{fill:none;stroke:currentColor;stroke-width:1.5px;stroke-linecap:round;stroke-linejoin:round;width:14px;height:14px}.r1eXuW_fileList{border-top:.5px solid var(--dsw-alias-border-l2);margin:0;padding:0;list-style:none}.r1eXuW_fileItem{border-top:.5px solid var(--dsw-alias-border-l1)}.r1eXuW_fileItem:first-child{border-top:0}.r1eXuW_fileRow{align-items:center;gap:8px;min-height:30px;padding:0 8px 0 0;display:flex}.r1eXuW_fileRow:hover{background:var(--dsw-alias-interactive-bg-hover)}.r1eXuW_rowToggle{min-width:0;min-height:30px;color:inherit;cursor:pointer;font:inherit;text-align:left;background:0 0;border:0;flex:auto;align-items:center;gap:8px;padding:0 0 0 10px;display:flex}.r1eXuW_rowToggle:focus-visible{box-shadow:inset 0 0 0 2px var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline:none}.r1eXuW_chevron{fill:none;width:12px;height:12px;stroke:var(--dsw-alias-label-tertiary);stroke-width:2px;stroke-linecap:round;stroke-linejoin:round;flex:none;transition:transform .12s}.r1eXuW_chevronOpen{transform:rotate(90deg)}.r1eXuW_fileName{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.r1eXuW_stateBadge{white-space:nowrap;border-radius:999px;flex:none;padding:0 6px;font-size:11px;line-height:18px}.r1eXuW_badgeUndone,.r1eXuW_badgeMuted{color:var(--dsw-alias-label-tertiary)}.r1eXuW_badgeError{color:var(--dsw-alias-state-error-primary)}.r1eXuW_deletedBadge{color:var(--dsw-alias-state-error-primary);white-space:nowrap;border-radius:999px;flex:none;padding:0 6px;font-size:11px;line-height:18px}.r1eXuW_smallButton{border-radius:var(--dsw-radius-sm);height:24px;color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;white-space:nowrap;background:0 0;border:0;flex:none;padding:0 8px;font-size:12px}.r1eXuW_smallButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.r1eXuW_smallButton:disabled{cursor:progress;opacity:.55}.r1eXuW_editorButton{margin-left:auto}.r1eXuW_diffWrap{border-top:.5px solid var(--dsw-alias-border-l1);overflow:hidden}.r1eXuW_reviewDiff{padding-bottom:8px}.r1eXuW_diffUnavailable{color:var(--dsw-alias-label-tertiary);margin:0;padding:10px 12px;font-size:12px}.r1eXuW_archiveSection{margin:0 8px 10px}.r1eXuW_archiveHeader{width:100%;color:var(--dsw-alias-label-tertiary);cursor:pointer;font:inherit;text-align:left;background:0 0;border:0;align-items:center;gap:4px;padding:8px 2px;font-size:12px;display:inline-flex}.r1eXuW_archiveHeader:hover{color:var(--dsw-alias-label-primary)}.r1eXuW_archiveTitle{min-width:0}.r1eXuW_archiveLoadMore{border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm);width:100%;color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;background:0 0;margin-top:6px;padding:6px;font-size:12px;display:block}.r1eXuW_archiveLoadMore:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}@container (width<=260px){.r1eXuW_counts{display:none}}";
6503
6781
  const styleId$2 = "@whybebabo/dsh-file-review-tab/FileReviewTab.module.css";
6504
6782
  if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(styleId$2) + "]") === null) {
6505
6783
  const style = document.createElement("style");
@@ -6547,6 +6825,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6547
6825
  "reviewDiff": "r1eXuW_reviewDiff",
6548
6826
  "reviewToolSpin": "r1eXuW_reviewToolSpin",
6549
6827
  "root": "r1eXuW_root",
6828
+ "rowToggle": "r1eXuW_rowToggle",
6550
6829
  "selector": "r1eXuW_selector",
6551
6830
  "selectorButton": "r1eXuW_selectorButton",
6552
6831
  "selectorLabel": "r1eXuW_selectorLabel",
@@ -6570,9 +6849,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6570
6849
  function stateKey(turn, path) {
6571
6850
  return `${turn}|${path}`;
6572
6851
  }
6573
- /** A change group is reversible only with complete contextual hunks. */
6852
+ /**
6853
+ * A change group is reversible only with complete contextual hunks — the same
6854
+ * rule the Host applies before touching disk (see `src/reversible.ts`), so the
6855
+ * rows and turn batches this tab offers are exactly the ones it will accept.
6856
+ */
6574
6857
  function isReversible(file) {
6575
- return file.diffs.length > 0 && file.diffs.every((diff) => diff.path === file.path && diff.oldText !== null && diff.oldText !== diff.newText && (diff.oldText !== "" || diff.oldStart !== void 0) && (diff.newText !== "" || diff.newStart !== void 0));
6858
+ return changeReversible(file.path, file.diffs);
6576
6859
  }
6577
6860
  function addStats$1(left, right) {
6578
6861
  return {
@@ -6751,6 +7034,25 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6751
7034
  roots,
6752
7035
  recorded
6753
7036
  ]);
7037
+ const anchorCallIds = (0, react.useMemo)(() => turns.flatMap((turn) => turn.files.flatMap((file) => file.diffs.flatMap((diff) => diff.callId === void 0 ? [] : [diff.callId]))), [turns]);
7038
+ const anchorCalls$1 = (0, react.useMemo)(() => new Map(turns.flatMap((turn) => turn.files.flatMap((file) => anchorCalls(file.diffs).map((call) => [call.callId, call])))), [turns]);
7039
+ const anchors = useHunkAnchors(sessionId, anchorCallIds, (0, react.useCallback)(async (callIds) => {
7040
+ const scope = sessions.scope(sessionId);
7041
+ const remote = scope?.get("remote.fileReview");
7042
+ if (scope === void 0 || remote === void 0) throw new Error("File review Remote is unavailable");
7043
+ const calls = callIds.flatMap((id) => {
7044
+ const call = anchorCalls$1.get(id);
7045
+ return call === void 0 ? [] : [call];
7046
+ });
7047
+ if (calls.length === 0) return [];
7048
+ const result = await remote.anchors({ calls });
7049
+ if (!result.ok) throw new Error(result.error.message);
7050
+ return result.value.anchors;
7051
+ }, [
7052
+ sessions,
7053
+ sessionId,
7054
+ anchorCalls$1
7055
+ ]), visible);
6754
7056
  const { main: mainTurns, archived: archivedTurns } = (0, react.useMemo)(() => splitArchivedTurns(turns), [turns]);
6755
7057
  const [archiveOpen, setArchiveOpen] = (0, react.useState)(false);
6756
7058
  const [archivePages, setArchivePages] = (0, react.useState)(1);
@@ -7057,7 +7359,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7057
7359
  disabled: statusPending || busyKey !== null || reversible.length === 0,
7058
7360
  title: reversible.length === 0 ? t("toggleUnavailable") : void 0,
7059
7361
  onClick: () => {
7060
- runToggle(turnKey, turn.files.filter((file) => file.deleted !== true).map((file) => ({
7362
+ runToggle(turnKey, reversible.map((file) => ({
7061
7363
  turn: turn.turn,
7062
7364
  path: file.path,
7063
7365
  diffs: file.diffs
@@ -7081,7 +7383,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7081
7383
  const fileAction = state === "undone" ? "redo" : "undo";
7082
7384
  const fileBusy = busyKey === key;
7083
7385
  const stats = summarizeDiffs(file.diffs);
7084
- const hunks = isOpen ? toNativeHunks(file.diffs, 3) : [];
7386
+ const hunks = isOpen ? toNativeHunks(file.diffs, 3, anchors) : [];
7387
+ const diffId = `file-review-diff-${turn.turn}-${encodeURIComponent(file.path)}`;
7085
7388
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
7086
7389
  className: FileReviewTab_module_css_default.fileItem,
7087
7390
  ref: (element) => {
@@ -7090,35 +7393,35 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7090
7393
  },
7091
7394
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
7092
7395
  className: FileReviewTab_module_css_default.fileRow,
7093
- role: "button",
7094
- tabIndex: 0,
7095
- title: file.path,
7096
- "aria-expanded": isOpen,
7097
- onClick: () => {
7098
- toggleExpanded(key);
7099
- },
7100
- onKeyDown: (event) => {
7101
- if (event.key === "Enter" || event.key === " ") {
7102
- event.preventDefault();
7103
- toggleExpanded(key);
7104
- }
7105
- },
7396
+ "data-review-row": file.path,
7106
7397
  children: [
7107
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chevron, { open: isOpen }),
7108
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7109
- className: FileReviewTab_module_css_default.fileName,
7110
- children: basename$1(file.path)
7398
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
7399
+ type: "button",
7400
+ className: FileReviewTab_module_css_default.rowToggle,
7401
+ "data-review-row-toggle": "",
7402
+ "aria-expanded": isOpen,
7403
+ "aria-controls": isOpen ? diffId : void 0,
7404
+ title: file.path,
7405
+ onClick: () => {
7406
+ toggleExpanded(key);
7407
+ },
7408
+ children: [
7409
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chevron, { open: isOpen }),
7410
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7411
+ className: FileReviewTab_module_css_default.fileName,
7412
+ children: basename$1(file.path)
7413
+ }),
7414
+ file.deleted === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7415
+ className: FileReviewTab_module_css_default.deletedBadge,
7416
+ children: t("deleted")
7417
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Stats, { stats }),
7418
+ file.deleted !== true && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StateBadge, { state })
7419
+ ]
7111
7420
  }),
7112
- file.deleted === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7113
- className: FileReviewTab_module_css_default.deletedBadge,
7114
- children: t("deleted")
7115
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Stats, { stats }),
7116
- file.deleted !== true && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StateBadge, { state }),
7117
7421
  file.deleted !== true && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
7118
7422
  type: "button",
7119
7423
  className: `${FileReviewTab_module_css_default.smallButton} ${FileReviewTab_module_css_default.editorButton}`,
7120
- onClick: (event) => {
7121
- event.stopPropagation();
7424
+ onClick: () => {
7122
7425
  openInEditor(file.path);
7123
7426
  },
7124
7427
  children: t("openInEditor")
@@ -7128,8 +7431,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7128
7431
  className: FileReviewTab_module_css_default.smallButton,
7129
7432
  disabled: statusPending || busyKey !== null || !reversible,
7130
7433
  title: file.deleted === true ? t("deletedHint") : !reversible ? t("toggleUnavailable") : void 0,
7131
- onClick: (event) => {
7132
- event.stopPropagation();
7434
+ onClick: () => {
7133
7435
  runToggle(key, [{
7134
7436
  turn: turn.turn,
7135
7437
  path: file.path,
@@ -7141,6 +7443,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7141
7443
  ]
7142
7444
  }), isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
7143
7445
  className: FileReviewTab_module_css_default.diffWrap,
7446
+ id: diffId,
7144
7447
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LazyDiff, { children: file.deleted === true || file.diffs.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NativeDiff, {
7145
7448
  hunks: [],
7146
7449
  path: file.path,
@@ -7441,10 +7744,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7441
7744
  const additions = [];
7442
7745
  if (intent.path !== null) {
7443
7746
  const own = applied === null ? intent.diffs : applied.filter((diff) => diff.path === intent.path);
7747
+ const diffs = own.length > 0 ? own : intent.diffs;
7444
7748
  additions.push({
7445
7749
  seq,
7446
7750
  path: intent.path,
7447
- diffs: own.length > 0 ? own : intent.diffs
7751
+ diffs: diffs.map((diff) => ({
7752
+ ...diff,
7753
+ callId: result.callId
7754
+ }))
7448
7755
  });
7449
7756
  }
7450
7757
  for (const path of intent.deletions) additions.push({
@@ -7760,9 +8067,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7760
8067
  });
7761
8068
  }
7762
8069
  /** The hover preview: path label plus the same comparison the sidebar shows. */
7763
- function ChangedFilePreview({ display, reviews, t }) {
8070
+ function ChangedFilePreview({ display, reviews, reviewSessionId, loadHunkAnchors, t }) {
7764
8071
  const diffs = reviews.flatMap((review) => review.diffs);
7765
- const hunks = toNativeHunks(diffs, 2);
8072
+ const calls = (0, react.useMemo)(() => anchorCalls(diffs), [diffs]);
8073
+ const callIds = (0, react.useMemo)(() => calls.map((call) => call.callId), [calls]);
8074
+ const callsRef = (0, react.useRef)(calls);
8075
+ callsRef.current = calls;
8076
+ const load = (0, react.useMemo)(() => loadHunkAnchors === void 0 ? void 0 : (ids) => loadHunkAnchors(callsRef.current.filter((call) => ids.includes(call.callId))), [loadHunkAnchors]);
8077
+ const hunks = toNativeHunks(diffs, 2, useHunkAnchors(reviewSessionId ?? "", callIds, load, reviewSessionId !== void 0 && loadHunkAnchors !== void 0));
7766
8078
  const note = diffNote(diffs, hunks, reviews.every((review) => review.deleted === true));
7767
8079
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
7768
8080
  className: ProducedCard_module_css_default.preview,
@@ -7817,7 +8129,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7817
8129
  * The card itself: the native ChangedFiles layout plus the two action buttons
7818
8130
  * in the header's top-right corner.
7819
8131
  */
7820
- function ProducedFilesCard({ reviews, openFile, turn: turnLocation, projectRoot, reviewSessionId, inspectChanges = unavailableChanges, applyChanges = unavailableChanges, openInSidebarTab, t }) {
8132
+ function ProducedFilesCard({ reviews, openFile, turn: turnLocation, projectRoot, reviewSessionId, inspectChanges = unavailableChanges, applyChanges = unavailableChanges, loadHunkAnchors, openInSidebarTab, t }) {
7821
8133
  const turnNumber = turnLocation.turn;
7822
8134
  const [expanded, setExpanded] = (0, react.useState)(false);
7823
8135
  const [toggleAction, setToggleAction] = (0, react.useState)("undo");
@@ -7835,12 +8147,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7835
8147
  added: 0,
7836
8148
  removed: 0
7837
8149
  }), [reviewsWithStats]);
7838
- const toggleFiles = (0, react.useMemo)(() => reviews.filter((review) => review.deleted !== true).map((review) => ({
8150
+ const toggleFiles = (0, react.useMemo)(() => reviews.filter((review) => review.deleted !== true && changeReversible(review.path, review.diffs)).map((review) => ({
7839
8151
  path: review.path,
7840
8152
  diffs: review.diffs
7841
8153
  })), [reviews]);
7842
- const reversiblePaths = (0, react.useMemo)(() => new Set(reviews.filter((review) => review.diffs.length > 0 && review.diffs.every((diff) => diff.path === review.path && diff.oldText !== null && diff.oldText !== diff.newText && (diff.oldText !== "" || diff.oldStart !== void 0) && (diff.newText !== "" || diff.newStart !== void 0))).map((review) => review.path)), [reviews]);
7843
- const hasReversibleFiles = reversiblePaths.size > 0;
8154
+ const reversiblePaths = (0, react.useMemo)(() => new Set(toggleFiles.map((file) => file.path)), [toggleFiles]);
8155
+ const hasReversibleFiles = toggleFiles.length > 0;
7844
8156
  const singleFile = reviewsWithStats.length === 1 ? reviewsWithStats[0] : void 0;
7845
8157
  const foldable = reviewsWithStats.length > COLLAPSED_ROWS;
7846
8158
  const rows = foldable && !expanded ? reviewsWithStats.slice(0, COLLAPSED_ROWS) : reviewsWithStats;
@@ -7868,15 +8180,24 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7868
8180
  const target = currentAction === "undo" ? "undone" : "applied";
7869
8181
  return [...reversiblePaths].every((path) => byPath.get(path)?.state === target) ? currentAction === "undo" ? "redo" : "undo" : currentAction;
7870
8182
  }, [reversiblePaths]);
8183
+ const toggleKey = (0, react.useMemo)(() => toggleFiles.map((file) => `${file.path}\u0000${file.diffs.length}`).join(""), [toggleFiles]);
8184
+ const inspectRef = (0, react.useRef)(inspectChanges);
8185
+ inspectRef.current = inspectChanges;
7871
8186
  (0, react.useEffect)(() => {
8187
+ if (toggleKey === "") {
8188
+ setStatusPending(false);
8189
+ setToggleAction("undo");
8190
+ return;
8191
+ }
7872
8192
  let active = true;
7873
8193
  setStatusPending(true);
7874
- inspectChanges({
8194
+ const files = toggleFiles;
8195
+ inspectRef.current({
7875
8196
  action: "undo",
7876
- files: toggleFiles
8197
+ files
7877
8198
  }).then((result) => {
7878
8199
  if (!active) return;
7879
- const allUndone = reversiblePaths.size > 0 && [...reversiblePaths].every((path) => result.files.find((file) => file.path === path)?.state === "undone");
8200
+ const allUndone = files.length > 0 && files.every((file) => result.files.find((entry) => entry.path === file.path)?.state === "undone");
7880
8201
  setToggleAction(allUndone ? "redo" : "undo");
7881
8202
  }).catch(() => {}).finally(() => {
7882
8203
  if (active) setStatusPending(false);
@@ -7884,12 +8205,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7884
8205
  return () => {
7885
8206
  active = false;
7886
8207
  };
7887
- }, [
7888
- inspectChanges,
7889
- reversiblePaths,
7890
- statusVersion,
7891
- toggleFiles
7892
- ]);
8208
+ }, [toggleKey, statusVersion]);
7893
8209
  const runToggle = (0, react.useCallback)(() => {
7894
8210
  if (statusPending || togglePending || !hasReversibleFiles) return;
7895
8211
  const action = toggleAction;
@@ -7999,6 +8315,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
7999
8315
  content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChangedFilePreview, {
8000
8316
  display: displayPath(projectRoot, singleFile.review.path),
8001
8317
  reviews: [singleFile.review],
8318
+ reviewSessionId,
8319
+ loadHunkAnchors,
8002
8320
  t
8003
8321
  })
8004
8322
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -8031,6 +8349,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
8031
8349
  content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChangedFilePreview, {
8032
8350
  display: displayPath(projectRoot, review.path),
8033
8351
  reviews: [review],
8352
+ reviewSessionId,
8353
+ loadHunkAnchors,
8034
8354
  t
8035
8355
  }),
8036
8356
  anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
@@ -8330,6 +8650,20 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
8330
8650
  if (!result.ok) throw new Error(result.error.message);
8331
8651
  return result.value;
8332
8652
  };
8653
+ /**
8654
+ * Line coordinates for the calls the card's hover preview draws. The
8655
+ * conversation snapshot only carries context fragments, so without these
8656
+ * the preview would number every hunk from 1.
8657
+ */
8658
+ const loadHunkAnchors = async (calls) => {
8659
+ if (calls.length === 0) return [];
8660
+ const scope = sessions.scope(sessionId);
8661
+ const fileReview = scope?.get("remote.fileReview");
8662
+ if (scope === void 0 || fileReview === void 0) throw new Error("File review Remote is unavailable");
8663
+ const result = await fileReview.anchors({ calls });
8664
+ if (!result.ok) throw new Error(result.error.message);
8665
+ return result.value.anchors;
8666
+ };
8333
8667
  return {
8334
8668
  projectRoot,
8335
8669
  reviewSessionId: sessionId,
@@ -8339,6 +8673,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
8339
8673
  publishFileReviewInvalidation(sessionId);
8340
8674
  return result;
8341
8675
  },
8676
+ loadHunkAnchors,
8342
8677
  openInSidebarTab: (paths, turn) => {
8343
8678
  const sidebar = ctx.betterSidebar;
8344
8679
  if (sidebar === void 0 || paths.length === 0) return;