@openclaw/diffs 2026.5.24-beta.2 → 2026.5.26-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,18 @@ export declare function hasOnlyWinLineEndings(string: string): boolean;
13
13
  * Returns true if the string consistently uses Unix line endings.
14
14
  */
15
15
  export declare function hasOnlyUnixLineEndings(string: string): boolean;
16
- export declare function trailingWs(string: string): string;
17
- export declare function leadingWs(string: string): string;
16
+ /**
17
+ * Split a string into segments using a word segmenter, merging consecutive
18
+ * segments if they are both whitespace segments. Whitespace segments can
19
+ * appear adjacent to one another for two reasons:
20
+ * - newlines always get their own segment
21
+ * - where a diacritic is attached to a whitespace character in the text, the
22
+ * segment ends after the diacritic, so e.g. " \u0300 " becomes two segments.
23
+ * This function therefore runs the segmenter's .segment() method and then
24
+ * merges consecutive segments of whitespace into a single part.
25
+ */
26
+ export declare function segment(string: string, segmenter: Intl.Segmenter): string[];
27
+ export declare function trailingWs(string: string, segmenter?: Intl.Segmenter): string;
28
+ export declare function leadingWs(string: string, segmenter?: Intl.Segmenter): string;
29
+ export declare function leadingAndTrailingWs(string: string, segmenter?: Intl.Segmenter): [string, string];
18
30
  //# sourceMappingURL=string.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/util/string.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQtE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAgBtE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAK1F;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SA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AgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvE;AAkCD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,GAAG,MAAM,EAAE,CAW3E;AAgBD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,GAAG,MAAM,CAuB7E;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,GAAG,MAAM,CAQ5E;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,GACzB,CAAC,MAAM,EAAE,MAAM,CAAC,CAelB"}
@@ -9,8 +9,10 @@ exports.removeSuffix = removeSuffix;
9
9
  exports.maximumOverlap = maximumOverlap;
10
10
  exports.hasOnlyWinLineEndings = hasOnlyWinLineEndings;
11
11
  exports.hasOnlyUnixLineEndings = hasOnlyUnixLineEndings;
12
+ exports.segment = segment;
12
13
  exports.trailingWs = trailingWs;
13
14
  exports.leadingWs = leadingWs;
15
+ exports.leadingAndTrailingWs = leadingAndTrailingWs;
14
16
  function longestCommonPrefix(str1, str2) {
15
17
  var i;
16
18
  for (i = 0; i < str1.length && i < str2.length; i++) {
@@ -114,7 +116,47 @@ function hasOnlyWinLineEndings(string) {
114
116
  function hasOnlyUnixLineEndings(string) {
115
117
  return !string.includes('\r\n') && string.includes('\n');
116
118
  }
117
- function trailingWs(string) {
119
+ /**
120
+ * Split a string into segments using a word segmenter, merging consecutive
121
+ * segments if they are both whitespace segments. Whitespace segments can
122
+ * appear adjacent to one another for two reasons:
123
+ * - newlines always get their own segment
124
+ * - where a diacritic is attached to a whitespace character in the text, the
125
+ * segment ends after the diacritic, so e.g. " \u0300 " becomes two segments.
126
+ * This function therefore runs the segmenter's .segment() method and then
127
+ * merges consecutive segments of whitespace into a single part.
128
+ */
129
+ function segment(string, segmenter) {
130
+ var parts = [];
131
+ for (var _i = 0, _a = Array.from(segmenter.segment(string)); _i < _a.length; _i++) {
132
+ var segmentObj = _a[_i];
133
+ var segment_1 = segmentObj.segment;
134
+ if (parts.length && (/\s/).test(parts[parts.length - 1]) && (/\s/).test(segment_1)) {
135
+ parts[parts.length - 1] += segment_1;
136
+ }
137
+ else {
138
+ parts.push(segment_1);
139
+ }
140
+ }
141
+ return parts;
142
+ }
143
+ // The functions below take a `segmenter` argument so that, when called from
144
+ // diffWords when it is using a segmenter, they can use a notion of what
145
+ // constitutes "whitespace" that is consistent with the segmenter.
146
+ //
147
+ // USUALLY this will be identical to the result of the non-segmenter-based
148
+ // logic, but it differs in at least one case: when whitespace characters are
149
+ // modified by diacritics. A word segmenter considers these diacritics to be
150
+ // part of the whitespace, whereas our non-segmenter-based logic does not.
151
+ //
152
+ // Because the segmenter-based approach necessarily requires segmenting the
153
+ // entire string, we offer a leadingAndTrailingWs function to allow getting the
154
+ // whitespace prefix AND whitespace suffix with a single call to the segmenter,
155
+ // for efficiency's sake.
156
+ function trailingWs(string, segmenter) {
157
+ if (segmenter) {
158
+ return leadingAndTrailingWs(string, segmenter)[1];
159
+ }
118
160
  // Yes, this looks overcomplicated and dumb - why not replace the whole function with
119
161
  // return string.match(/\s*$/)[0]
120
162
  // you ask? Because:
@@ -134,8 +176,25 @@ function trailingWs(string) {
134
176
  }
135
177
  return string.substring(i + 1);
136
178
  }
137
- function leadingWs(string) {
179
+ function leadingWs(string, segmenter) {
180
+ if (segmenter) {
181
+ return leadingAndTrailingWs(string, segmenter)[0];
182
+ }
138
183
  // Thankfully the annoying considerations described in trailingWs don't apply here:
139
184
  var match = string.match(/^\s*/);
140
185
  return match ? match[0] : '';
141
186
  }
187
+ function leadingAndTrailingWs(string, segmenter) {
188
+ if (!segmenter) {
189
+ return [leadingWs(string), trailingWs(string)];
190
+ }
191
+ if (segmenter.resolvedOptions().granularity != 'word') {
192
+ throw new Error('The segmenter passed must have a granularity of "word"');
193
+ }
194
+ var segments = segment(string, segmenter);
195
+ var firstSeg = segments[0];
196
+ var lastSeg = segments[segments.length - 1];
197
+ var head = (/\s/).test(firstSeg) ? firstSeg : '';
198
+ var tail = (/\s/).test(lastSeg) ? lastSeg : '';
199
+ return [head, tail];
200
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"word.d.ts","sourceRoot":"","sources":["../../src/diff/word.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,4BAA4B,EAAC,MAAM,aAAa,CAAC;AAqDvL,cAAM,QAAS,SAAQ,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;IACzC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,GAAG,4BAA4B;IASrG,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,yBAAyB,GAAG,4BAAiC;IAoD9F,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE;IAerB,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG;CA6B1D;AAED,eAAO,MAAM,QAAQ,UAAiB,CAAC;AAEvC;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,wBAAwB,CAAC,MAAM,CAAC,GACxC,SAAS,CAAC;AACb,wBAAgB,SAAS,C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@@
1
1
  import Diff from './base.js';
2
- import { longestCommonPrefix, longestCommonSuffix, replacePrefix, replaceSuffix, removePrefix, removeSuffix, maximumOverlap, leadingWs, trailingWs } from '../util/string.js';
2
+ import { longestCommonPrefix, longestCommonSuffix, replacePrefix, replaceSuffix, removePrefix, removeSuffix, maximumOverlap, leadingWs, trailingWs, leadingAndTrailingWs, segment } from '../util/string.js';
3
3
  // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
4
4
  //
5
5
  // Chars/ranges counted as "word" characters by this regex are as follows:
@@ -64,22 +64,9 @@ class WordDiff extends Diff {
64
64
  // We want `parts` to be an array whose elements alternate between being
65
65
  // pure whitespace and being pure non-whitespace. This is ALMOST what the
66
66
  // segments returned by a word-based Intl.Segmenter already look like,
67
- // and therefore we can ALMOST get what we want by simply doing...
68
- // parts = Array.from(segmenter.segment(value), segment => segment.segment);
69
- // ... but not QUITE, because there's of one annoying special case: every
70
- // newline character gets its own segment, instead of sharing a segment
71
- // with other surrounding whitespace. We therefore need to manually merge
72
- // consecutive segments of whitespace into a single part:
73
- parts = [];
74
- for (const segmentObj of Array.from(segmenter.segment(value))) {
75
- const segment = segmentObj.segment;
76
- if (parts.length && (/\s/).test(parts[parts.length - 1]) && (/\s/).test(segment)) {
77
- parts[parts.length - 1] += segment;
78
- }
79
- else {
80
- parts.push(segment);
81
- }
82
- }
67
+ // but not quite - see explanation in the docs of our custom segment()
68
+ // function.
69
+ parts = segment(value, segmenter);
83
70
  }
84
71
  else {
85
72
  parts = value.match(tokenizeIncludingWhitespace) || [];
@@ -143,7 +130,7 @@ class WordDiff extends Diff {
143
130
  }
144
131
  else {
145
132
  if (insertion || deletion) { // May be false at start of text
146
- dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, change);
133
+ dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, change, options.intlSegmenter);
147
134
  }
148
135
  lastKeep = change;
149
136
  insertion = null;
@@ -151,7 +138,7 @@ class WordDiff extends Diff {
151
138
  }
152
139
  });
153
140
  if (insertion || deletion) {
154
- dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null);
141
+ dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null, options.intlSegmenter);
155
142
  }
156
143
  return changes;
157
144
  }
@@ -167,7 +154,7 @@ export function diffWords(oldStr, newStr, options) {
167
154
  }
168
155
  return wordDiff.diff(oldStr, newStr, options);
169
156
  }
170
- function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep) {
157
+ function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep, segmenter) {
171
158
  // Before returning, we tidy up the leading and trailing whitespace of the
172
159
  // change objects to eliminate cases where trailing whitespace in one object
173
160
  // is repeated as leading whitespace in the next.
@@ -210,10 +197,8 @@ function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep
210
197
  // * Just a "delete"
211
198
  // We handle the three cases separately.
212
199
  if (deletion && insertion) {
213
- const oldWsPrefix = leadingWs(deletion.value);
214
- const oldWsSuffix = trailingWs(deletion.value);
215
- const newWsPrefix = leadingWs(insertion.value);
216
- const newWsSuffix = trailingWs(insertion.value);
200
+ const [oldWsPrefix, oldWsSuffix] = leadingAndTrailingWs(deletion.value, segmenter);
201
+ const [newWsPrefix, newWsSuffix] = leadingAndTrailingWs(insertion.value, segmenter);
217
202
  if (startKeep) {
218
203
  const commonWsPrefix = longestCommonPrefix(oldWsPrefix, newWsPrefix);
219
204
  startKeep.value = replaceSuffix(startKeep.value, newWsPrefix, commonWsPrefix);
@@ -235,17 +220,17 @@ function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep
235
220
  // whitespace and deleting duplicate leading whitespace where
236
221
  // present.
237
222
  if (startKeep) {
238
- const ws = leadingWs(insertion.value);
223
+ const ws = leadingWs(insertion.value, segmenter);
239
224
  insertion.value = insertion.value.substring(ws.length);
240
225
  }
241
226
  if (endKeep) {
242
- const ws = leadingWs(endKeep.value);
227
+ const ws = leadingWs(endKeep.value, segmenter);
243
228
  endKeep.value = endKeep.value.substring(ws.length);
244
229
  }
245
230
  // otherwise we've got a deletion and no insertion
246
231
  }
247
232
  else if (startKeep && endKeep) {
248
- const newWsFull = leadingWs(endKeep.value), delWsStart = leadingWs(deletion.value), delWsEnd = trailingWs(deletion.value);
233
+ const newWsFull = leadingWs(endKeep.value, segmenter), [delWsStart, delWsEnd] = leadingAndTrailingWs(deletion.value, segmenter);
249
234
  // Any whitespace that comes straight after startKeep in both the old and
250
235
  // new texts, assign to startKeep and remove from the deletion.
251
236
  const newWsStart = longestCommonPrefix(newWsFull, delWsStart);
@@ -264,8 +249,8 @@ function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep
264
249
  // We are at the start of the text. Preserve all the whitespace on
265
250
  // endKeep, and just remove whitespace from the end of deletion to the
266
251
  // extent that it overlaps with the start of endKeep.
267
- const endKeepWsPrefix = leadingWs(endKeep.value);
268
- const deletionWsSuffix = trailingWs(deletion.value);
252
+ const endKeepWsPrefix = leadingWs(endKeep.value, segmenter);
253
+ const deletionWsSuffix = trailingWs(deletion.value, segmenter);
269
254
  const overlap = maximumOverlap(deletionWsSuffix, endKeepWsPrefix);
270
255
  deletion.value = removeSuffix(deletion.value, overlap);
271
256
  }
@@ -273,8 +258,8 @@ function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep
273
258
  // We are at the END of the text. Preserve all the whitespace on
274
259
  // startKeep, and just remove whitespace from the start of deletion to
275
260
  // the extent that it overlaps with the end of startKeep.
276
- const startKeepWsSuffix = trailingWs(startKeep.value);
277
- const deletionWsPrefix = leadingWs(deletion.value);
261
+ const startKeepWsSuffix = trailingWs(startKeep.value, segmenter);
262
+ const deletionWsPrefix = leadingWs(deletion.value, segmenter);
278
263
  const overlap = maximumOverlap(startKeepWsSuffix, deletionWsPrefix);
279
264
  deletion.value = removePrefix(deletion.value, overlap);
280
265
  }
@@ -13,6 +13,18 @@ export declare function hasOnlyWinLineEndings(string: string): boolean;
13
13
  * Returns true if the string consistently uses Unix line endings.
14
14
  */
15
15
  export declare function hasOnlyUnixLineEndings(string: string): boolean;
16
- export declare function trailingWs(string: string): string;
17
- export declare function leadingWs(string: string): string;
16
+ /**
17
+ * Split a string into segments using a word segmenter, merging consecutive
18
+ * segments if they are both whitespace segments. Whitespace segments can
19
+ * appear adjacent to one another for two reasons:
20
+ * - newlines always get their own segment
21
+ * - where a diacritic is attached to a whitespace character in the text, the
22
+ * segment ends after the diacritic, so e.g. " \u0300 " becomes two segments.
23
+ * This function therefore runs the segmenter's .segment() method and then
24
+ * merges consecutive segments of whitespace into a single part.
25
+ */
26
+ export declare function segment(string: string, segmenter: Intl.Segmenter): string[];
27
+ export declare function trailingWs(string: string, segmenter?: Intl.Segmenter): string;
28
+ export declare function leadingWs(string: string, segmenter?: Intl.Segmenter): string;
29
+ export declare function leadingAndTrailingWs(string: string, segmenter?: Intl.Segmenter): [string, string];
18
30
  //# sourceMappingURL=string.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/util/string.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQtE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAgBtE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAK1F;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAS1F;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM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sB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,GAAG,MAAM,EAAE,CAW3E;AAgBD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,GAAG,MAAM,CAuB7E;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,GAAG,MAAM,CAQ5E;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,GACzB,CAAC,MAAM,EAAE,MAAM,CAAC,CAelB"}
@@ -101,7 +101,46 @@ export function hasOnlyWinLineEndings(string) {
101
101
  export function hasOnlyUnixLineEndings(string) {
102
102
  return !string.includes('\r\n') && string.includes('\n');
103
103
  }
104
- export function trailingWs(string) {
104
+ /**
105
+ * Split a string into segments using a word segmenter, merging consecutive
106
+ * segments if they are both whitespace segments. Whitespace segments can
107
+ * appear adjacent to one another for two reasons:
108
+ * - newlines always get their own segment
109
+ * - where a diacritic is attached to a whitespace character in the text, the
110
+ * segment ends after the diacritic, so e.g. " \u0300 " becomes two segments.
111
+ * This function therefore runs the segmenter's .segment() method and then
112
+ * merges consecutive segments of whitespace into a single part.
113
+ */
114
+ export function segment(string, segmenter) {
115
+ const parts = [];
116
+ for (const segmentObj of Array.from(segmenter.segment(string))) {
117
+ const segment = segmentObj.segment;
118
+ if (parts.length && (/\s/).test(parts[parts.length - 1]) && (/\s/).test(segment)) {
119
+ parts[parts.length - 1] += segment;
120
+ }
121
+ else {
122
+ parts.push(segment);
123
+ }
124
+ }
125
+ return parts;
126
+ }
127
+ // The functions below take a `segmenter` argument so that, when called from
128
+ // diffWords when it is using a segmenter, they can use a notion of what
129
+ // constitutes "whitespace" that is consistent with the segmenter.
130
+ //
131
+ // USUALLY this will be identical to the result of the non-segmenter-based
132
+ // logic, but it differs in at least one case: when whitespace characters are
133
+ // modified by diacritics. A word segmenter considers these diacritics to be
134
+ // part of the whitespace, whereas our non-segmenter-based logic does not.
135
+ //
136
+ // Because the segmenter-based approach necessarily requires segmenting the
137
+ // entire string, we offer a leadingAndTrailingWs function to allow getting the
138
+ // whitespace prefix AND whitespace suffix with a single call to the segmenter,
139
+ // for efficiency's sake.
140
+ export function trailingWs(string, segmenter) {
141
+ if (segmenter) {
142
+ return leadingAndTrailingWs(string, segmenter)[1];
143
+ }
105
144
  // Yes, this looks overcomplicated and dumb - why not replace the whole function with
106
145
  // return string.match(/\s*$/)[0]
107
146
  // you ask? Because:
@@ -121,8 +160,25 @@ export function trailingWs(string) {
121
160
  }
122
161
  return string.substring(i + 1);
123
162
  }
124
- export function leadingWs(string) {
163
+ export function leadingWs(string, segmenter) {
164
+ if (segmenter) {
165
+ return leadingAndTrailingWs(string, segmenter)[0];
166
+ }
125
167
  // Thankfully the annoying considerations described in trailingWs don't apply here:
126
168
  const match = string.match(/^\s*/);
127
169
  return match ? match[0] : '';
128
170
  }
171
+ export function leadingAndTrailingWs(string, segmenter) {
172
+ if (!segmenter) {
173
+ return [leadingWs(string), trailingWs(string)];
174
+ }
175
+ if (segmenter.resolvedOptions().granularity != 'word') {
176
+ throw new Error('The segmenter passed must have a granularity of "word"');
177
+ }
178
+ const segments = segment(string, segmenter);
179
+ const firstSeg = segments[0];
180
+ const lastSeg = segments[segments.length - 1];
181
+ const head = (/\s/).test(firstSeg) ? firstSeg : '';
182
+ const tail = (/\s/).test(lastSeg) ? lastSeg : '';
183
+ return [head, tail];
184
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diff",
3
- "version": "8.0.3",
3
+ "version": "8.0.4",
4
4
  "description": "A JavaScript text diff implementation.",
5
5
  "keywords": [
6
6
  "diff",
@@ -83,35 +83,33 @@
83
83
  "run-mocha": "mocha --require ./runtime 'test/**/*.js'"
84
84
  },
85
85
  "devDependencies": {
86
- "@arethetypeswrong/cli": "^0.17.4",
87
- "@babel/core": "^7.26.9",
88
- "@babel/preset-env": "^7.26.9",
89
- "@babel/register": "^7.25.9",
86
+ "@arethetypeswrong/cli": "^0.18.2",
87
+ "@babel/core": "^7.29.0",
88
+ "@babel/preset-env": "^7.29.2",
89
+ "@babel/register": "^7.28.6",
90
90
  "@colors/colors": "^1.6.0",
91
- "@eslint/js": "^9.25.1",
92
- "babel-loader": "^10.0.0",
93
- "babel-plugin-istanbul": "^7.0.0",
94
- "chai": "^5.2.0",
95
- "cross-env": "^7.0.3",
96
- "eslint": "^9.25.1",
97
- "globals": "^16.0.0",
91
+ "@eslint/js": "^10.0.1",
92
+ "babel-loader": "^10.1.1",
93
+ "babel-plugin-istanbul": "^7.0.1",
94
+ "chai": "^6.2.2",
95
+ "cross-env": "^10.1.0",
96
+ "eslint": "^10.1.0",
97
+ "globals": "^17.4.0",
98
98
  "karma": "^6.4.4",
99
99
  "karma-mocha": "^2.0.1",
100
100
  "karma-mocha-reporter": "^2.2.5",
101
101
  "karma-sourcemap-loader": "^0.4.0",
102
102
  "karma-webpack": "^5.0.1",
103
- "mocha": "^11.1.0",
104
- "nyc": "^17.1.0",
105
- "rollup": "^4.40.1",
106
- "tsd": "^0.32.0",
107
- "typescript": "^5.8.3",
108
- "typescript-eslint": "^8.31.0",
103
+ "mocha": "^11.7.5",
104
+ "nyc": "^18.0.0",
105
+ "rollup": "^4.60.0",
106
+ "tsd": "^0.33.0",
107
+ "typescript": "^5.9.3",
108
+ "typescript-eslint": "^8.57.1",
109
109
  "uglify-js": "^3.19.3",
110
- "webpack": "^5.99.7",
111
- "webpack-dev-server": "^5.2.1"
110
+ "webpack": "^5.105.4",
111
+ "webpack-dev-server": "^5.2.3"
112
112
  },
113
- "optionalDependencies": {},
114
- "dependencies": {},
115
113
  "nyc": {
116
114
  "require": [
117
115
  "@babel/register"
@@ -128,5 +126,5 @@
128
126
  "functions": 100,
129
127
  "statements": 100
130
128
  },
131
- "packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
132
- }
129
+ "packageManager": "yarn@4.12.0"
130
+ }
@@ -1,5 +1,9 @@
1
1
  # Release Notes
2
2
 
3
+ ## 8.0.4
4
+
5
+ - [#667](https://github.com/kpdecker/jsdiff/pull/667) - **fix another bug in `diffWords` when used with an `Intl.Segmenter`**. If the text to be diffed included a combining mark after a whitespace character (i.e. roughly speaking, an accented space), `diffWords` would previously crash. Now this case is handled correctly.
6
+
3
7
  ## 8.0.3
4
8
 
5
9
  - [#631](https://github.com/kpdecker/jsdiff/pull/631) - **fix support for using an `Intl.Segmenter` with `diffWords`**. This has been almost completely broken since the feature was added in v6.0.0, since it would outright crash on any text that featured two consecutive newlines between a pair of words (a very common case).
@@ -87,6 +91,14 @@ This is a release containing many, *many* breaking changes. The objective of thi
87
91
  - [#535](https://github.com/kpdecker/jsdiff/pull/535) **Passing `newlineIsToken: true` to *patch*-generation functions is no longer allowed.** (Passing it to `diffLines` is still supported - it's only functions like `createPatch` where passing `newlineIsToken` is now an error.) Allowing it to be passed never really made sense, since in cases where the option had any effect on the output at all, the effect tended to be causing a garbled patch to be created that couldn't actually be applied to the source file.
88
92
  - [#539](https://github.com/kpdecker/jsdiff/pull/539) **`diffWords` now takes an optional `intlSegmenter` option** which should be an `Intl.Segmenter` with word-level granularity. This provides better tokenization of text into words than the default behaviour, even for English but especially for some other languages for which the default behaviour is poor.
89
93
 
94
+ ## v5.2.2 - January 2026
95
+
96
+ Only change from 5.2.0 is a backport of the fix to https://github.com/kpdecker/jsdiff/security/advisories/GHSA-73rr-hh4g-fpgx.
97
+
98
+ ## v5.2.1 (deprecated)
99
+
100
+ Accidental release - do not use.
101
+
90
102
  ## v5.2.0
91
103
 
92
104
  [Commits](https://github.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)
@@ -113,6 +125,18 @@ This is a release containing many, *many* breaking changes. The objective of thi
113
125
 
114
126
  [Commits](https://github.com/kpdecker/jsdiff/compare/v4.0.1...v5.0.0)
115
127
 
128
+ ## v4.0.4 - January 2026
129
+
130
+ Only change from 4.0.2 is a backport of the fix to https://github.com/kpdecker/jsdiff/security/advisories/GHSA-73rr-hh4g-fpgx.
131
+
132
+ ## v4.0.3 (deprecated)
133
+
134
+ Accidental release - do not use.
135
+
136
+ ## v4.0.2
137
+
138
+ No meaningful changes from v4.0.1 - just removed some cruft that shouldn't've been published.
139
+
116
140
  ## v4.0.1 - January 6th, 2019
117
141
 
118
142
  - Fix main reference path - b826104
@@ -138,6 +162,10 @@ Compatibility notes:
138
162
 
139
163
  [Commits](https://github.com/kpdecker/jsdiff/compare/v3.5.0...v4.0.0)
140
164
 
165
+ ## v3.5.1 - January 2026
166
+
167
+ Only change from 3.5.0 is a backport of the fix to https://github.com/kpdecker/jsdiff/security/advisories/GHSA-73rr-hh4g-fpgx.
168
+
141
169
  ## v3.5.0 - March 4th, 2018
142
170
 
143
171
  - Omit redundant slice in join method of diffArrays - 1023590
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@openclaw/diffs",
3
- "version": "2026.5.24-beta.2",
3
+ "version": "2026.5.26-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@openclaw/diffs",
9
- "version": "2026.5.24-beta.2",
9
+ "version": "2026.5.26-beta.1",
10
10
  "dependencies": {
11
- "@pierre/diffs": "1.2.1",
11
+ "@pierre/diffs": "1.2.2",
12
12
  "@pierre/theme": "1.0.3",
13
13
  "playwright-core": "1.60.0",
14
14
  "typebox": "1.1.38",
@@ -16,9 +16,9 @@
16
16
  }
17
17
  },
18
18
  "node_modules/@pierre/diffs": {
19
- "version": "1.2.1",
20
- "resolved": "https://registry.npmjs.org/@pierre/diffs/-/diffs-1.2.1.tgz",
21
- "integrity": "sha512-T9pYhh1KeaYLTwL1HMiAkeETj9CPjiKq6pqiUWRVJXvIkIvYutMrYyr3kN07cFWX2XPM8eqe6l2dknezs6K2AA==",
19
+ "version": "1.2.2",
20
+ "resolved": "https://registry.npmjs.org/@pierre/diffs/-/diffs-1.2.2.tgz",
21
+ "integrity": "sha512-MvWLv2oSOJOF8oYXWLdhicguHM11G/VNWu6OPR5ZETolp2NM2/KPQG3cZTnKpJ6ImqEHwvw6Gl6z2gmmy2FQmQ==",
22
22
  "license": "apache-2.0",
23
23
  "dependencies": {
24
24
  "@pierre/theme": "1.0.3",
@@ -212,9 +212,9 @@
212
212
  }
213
213
  },
214
214
  "node_modules/diff": {
215
- "version": "8.0.3",
216
- "resolved": "https://registry.npmjs.org/diff/-/diff-8.0.3.tgz",
217
- "integrity": "sha512-qejHi7bcSD4hQAZE0tNAawRK1ZtafHDmMTMkrrIGgSLl7hTnQHmKCeB45xAcbfTqK2zowkM3j3bHt/4b/ARbYQ==",
215
+ "version": "8.0.4",
216
+ "resolved": "https://registry.npmjs.org/diff/-/diff-8.0.4.tgz",
217
+ "integrity": "sha512-DPi0FmjiSU5EvQV0++GFDOJ9ASQUVFh5kD+OzOnYdi7n3Wpm9hWWGfB/O2blfHcMVTL5WkQXSnRiK9makhrcnw==",
218
218
  "license": "BSD-3-Clause",
219
219
  "engines": {
220
220
  "node": ">=0.3.1"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/diffs",
3
- "version": "2026.5.24-beta.2",
3
+ "version": "2026.5.26-beta.1",
4
4
  "description": "OpenClaw diff viewer plugin",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,7 +11,7 @@
11
11
  "build:viewer": "bun build src/viewer-client.ts --target browser --format esm --minify --outfile assets/viewer-runtime.js && node -e \"let fs=require('fs'),p='assets/viewer-runtime.js',s=fs.readFileSync(p,'utf8').replace(/[ \\\\t]+$/gm,'');fs.writeFileSync(p,s)\""
12
12
  },
13
13
  "dependencies": {
14
- "@pierre/diffs": "1.2.1",
14
+ "@pierre/diffs": "1.2.2",
15
15
  "@pierre/theme": "1.0.3",
16
16
  "playwright-core": "1.60.0",
17
17
  "typebox": "1.1.38",
@@ -28,10 +28,10 @@
28
28
  "minHostVersion": ">=2026.4.30"
29
29
  },
30
30
  "compat": {
31
- "pluginApi": ">=2026.5.24-beta.2"
31
+ "pluginApi": ">=2026.5.26-beta.1"
32
32
  },
33
33
  "build": {
34
- "openclawVersion": "2026.5.24-beta.2",
34
+ "openclawVersion": "2026.5.26-beta.1",
35
35
  "staticAssets": [
36
36
  {
37
37
  "source": "./assets/viewer-runtime.js",
@@ -55,7 +55,7 @@
55
55
  "skills/**"
56
56
  ],
57
57
  "peerDependencies": {
58
- "openclaw": ">=2026.5.24-beta.2"
58
+ "openclaw": ">=2026.5.26-beta.1"
59
59
  },
60
60
  "peerDependenciesMeta": {
61
61
  "openclaw": {