@eliya-oss/agent-diff 0.1.0-alpha.177 → 0.1.0-alpha.179

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @eliya-oss/agent-diff
2
2
 
3
+ ## 0.1.0-alpha.179
4
+
5
+ ### Patch Changes
6
+
7
+ - feat(diff): a line that only changed its indentation is shown once, as unchanged, so a block wrapped in a new function is two added lines and not a rewrite of every line inside it.
8
+
9
+ <details><summary>What was wrong</summary>
10
+
11
+ Wrapping twenty-five lines in `startTransition(() => { … })` drew twenty-five removed lines and
12
+ twenty-seven added ones, and the reviewer had to read both blocks to find the two that mattered.
13
+
14
+ </details>
15
+
16
+ ## 0.1.0-alpha.178
17
+
18
+ ### Patch Changes
19
+
20
+ - feat(diff): a removed line and an added line that differ only in their indentation are washed dimmer than a change, so a block wrapped in a new function reads as one wrapper and not as a rewrite of every line inside it.
21
+
3
22
  ## 0.1.0-alpha.177
4
23
 
5
24
  ### Patch Changes
package/dist/main.js CHANGED
@@ -10027,7 +10027,7 @@ var init_config = __esmMin((() => {
10027
10027
  //#region package.json
10028
10028
  init_pane();
10029
10029
  init_config();
10030
- var version$1 = "0.1.0-alpha.177";
10030
+ var version$1 = "0.1.0-alpha.179";
10031
10031
  //#endregion
10032
10032
  //#region src/cli/error.ts
10033
10033
  var UnknownCommand, MissingOption, UnknownField, UnknownOption, BadOption, RegistryUnanswered;
@@ -11215,11 +11215,11 @@ var init_model$5 = __esmMin((() => {
11215
11215
  }));
11216
11216
  //#endregion
11217
11217
  //#region src/domain/patch/anchor.ts
11218
- var sideOf, linesOn, anchorFor, rowsForRange, sideLines, runsAt, nearestRun, SHORTEST_NEAR, PER_EDIT, edits, isNear, nearestLike, foundExactly, foundAlike, foundAgain;
11218
+ var sideOf$1, linesOn, anchorFor, rowsForRange, sideLines, runsAt, nearestRun, SHORTEST_NEAR, PER_EDIT, edits, isNear, nearestLike, foundExactly, foundAlike, foundAgain;
11219
11219
  var init_anchor = __esmMin((() => {
11220
11220
  init_dist();
11221
11221
  init_model$5();
11222
- sideOf = (rows) => rows.some((row) => isSome(row.newLine)) ? "new" : "old";
11222
+ sideOf$1 = (rows) => rows.some((row) => isSome(row.newLine)) ? "new" : "old";
11223
11223
  linesOn = (rows, side) => rows.flatMap((row) => match$3(lineOn(row, side), {
11224
11224
  onNone: () => [],
11225
11225
  onSome: (n) => [n]
@@ -11228,7 +11228,7 @@ var init_anchor = __esmMin((() => {
11228
11228
  const [low, high] = from <= to ? [from, to] : [to, from];
11229
11229
  const rows = patch.rows.slice(low, high + 1);
11230
11230
  if (rows.length === 0) return none();
11231
- const side = wanted ?? sideOf(rows);
11231
+ const side = wanted ?? sideOf$1(rows);
11232
11232
  const onSide = rows.filter((row) => isSome(lineOn(row, side)));
11233
11233
  const lines = linesOn(onSide, side);
11234
11234
  if (lines.length === 0) return none();
@@ -11314,10 +11314,120 @@ var init_anchor = __esmMin((() => {
11314
11314
  foundAgain = (patch, wanted) => orElse(foundExactly(patch, wanted), () => foundAlike(patch, wanted));
11315
11315
  }));
11316
11316
  //#endregion
11317
+ //#region src/domain/patch/reindent.ts
11318
+ var LCS_ROOM, body, isBlock, openBlock, sideOf, blocksOf$1, at, fillRow, lcsTable, joined, stepAt, walked, canFold, folded, rowsOf, reindexed, foldReindents;
11319
+ var init_reindent = __esmMin((() => {
11320
+ LCS_ROOM = 1e6;
11321
+ body = (row) => row.text.trimStart();
11322
+ isBlock = (entry) => !("kind" in entry);
11323
+ openBlock = () => ({
11324
+ removed: [],
11325
+ added: []
11326
+ });
11327
+ sideOf = (block, row) => row.kind === "removed" ? block.removed : block.added;
11328
+ blocksOf$1 = (rows) => {
11329
+ const out = [];
11330
+ for (const row of rows) {
11331
+ if (row.kind === "context") {
11332
+ out.push(row);
11333
+ continue;
11334
+ }
11335
+ const last = out.at(-1);
11336
+ const block = last !== void 0 && isBlock(last) ? last : openBlock();
11337
+ if (block !== last) out.push(block);
11338
+ sideOf(block, row).push(row);
11339
+ }
11340
+ return out;
11341
+ };
11342
+ at = (table, i, j) => table[i]?.[j] ?? 0;
11343
+ fillRow = (table, old, now, i) => {
11344
+ const row = table[i];
11345
+ if (row === void 0) return;
11346
+ for (let j = now.length - 1; j >= 0; j--) row[j] = old === now[j] ? at(table, i + 1, j + 1) + 1 : Math.max(at(table, i + 1, j), at(table, i, j + 1));
11347
+ };
11348
+ lcsTable = (old, now) => {
11349
+ const table = Array.from({ length: old.length + 1 }, () => new Uint32Array(now.length + 1));
11350
+ for (let i = old.length - 1; i >= 0; i--) fillRow(table, old[i] ?? "", now, i);
11351
+ return table;
11352
+ };
11353
+ joined = (removed, added) => ({
11354
+ index: 0,
11355
+ kind: "context",
11356
+ oldLine: removed.oldLine,
11357
+ newLine: added.newLine,
11358
+ text: added.text
11359
+ });
11360
+ stepAt = (block, table, i, j) => {
11361
+ const removed = block.removed[i];
11362
+ const added = block.added[j];
11363
+ if (removed === void 0 || added === void 0) return void 0;
11364
+ if (body(removed) === body(added)) return {
11365
+ row: joined(removed, added),
11366
+ old: 1,
11367
+ now: 1
11368
+ };
11369
+ if (at(table, i + 1, j) >= at(table, i, j + 1)) return {
11370
+ row: removed,
11371
+ old: 1,
11372
+ now: 0
11373
+ };
11374
+ return {
11375
+ row: added,
11376
+ old: 0,
11377
+ now: 1
11378
+ };
11379
+ };
11380
+ walked = (block, table) => {
11381
+ const out = [];
11382
+ let i = 0;
11383
+ let j = 0;
11384
+ for (let step = stepAt(block, table, i, j); step !== void 0; step = stepAt(block, table, i, j)) {
11385
+ out.push(step.row);
11386
+ i += step.old;
11387
+ j += step.now;
11388
+ }
11389
+ return [
11390
+ ...out,
11391
+ ...block.removed.slice(i),
11392
+ ...block.added.slice(j)
11393
+ ];
11394
+ };
11395
+ canFold = (block) => block.removed.length > 0 && block.added.length > 0 && block.removed.length * block.added.length <= LCS_ROOM;
11396
+ folded = (block) => {
11397
+ if (!canFold(block)) return [...block.removed, ...block.added];
11398
+ const table = lcsTable(block.removed.map(body), block.added.map(body));
11399
+ if (at(table, 0, 0) === 0) return [...block.removed, ...block.added];
11400
+ return walked(block, table);
11401
+ };
11402
+ rowsOf = (hunk) => blocksOf$1(hunk.rows).flatMap((entry) => isBlock(entry) ? folded(entry) : [entry]);
11403
+ reindexed = (rows, startRow) => rows.map((row, offset) => Object.assign({}, row, { index: startRow + offset }));
11404
+ foldReindents = (hunks) => {
11405
+ const rows = [];
11406
+ const kept = [];
11407
+ for (const hunk of hunks) {
11408
+ const startRow = rows.length;
11409
+ const own = reindexed(rowsOf(hunk), startRow);
11410
+ rows.push(...own);
11411
+ kept.push({
11412
+ ...hunk,
11413
+ startRow,
11414
+ rows: own
11415
+ });
11416
+ }
11417
+ return {
11418
+ hunks: kept,
11419
+ rows,
11420
+ added: rows.filter((row) => row.kind === "added").length,
11421
+ removed: rows.filter((row) => row.kind === "removed").length
11422
+ };
11423
+ };
11424
+ }));
11425
+ //#endregion
11317
11426
  //#region src/domain/patch/parse.ts
11318
11427
  var FILE_MARKER, HUNK_MARKER, BINARY_MARKER, NO_NEWLINE_MARKER, NO_NEWLINE_SAID, BINARY_SAID, MODE_OLD_MARKER, MODE_NEW_MARKER, FILE_ADDED_MARKER, FILE_GONE_MARKER, EMPTY_ADDED_SAID, EMPTY_GONE_SAID, NOTHING_SAID, BLOB_MARKER, OLD_PATH_MARKER, NEW_PATH_MARKER, HUNK_HEADER, FILE_HEADER, SIGNS$1, MADE_SAID, FROM_MARKERS, draftFrom, openHunk, appendRow, appendMarker, readBody, openPlain, told, notesOf$1, readMode, readMeta, readBinary, readHeader, readLine, parsePatches;
11319
11428
  var init_parse = __esmMin((() => {
11320
11429
  init_dist();
11430
+ init_reindent();
11321
11431
  FILE_MARKER = "diff --git ";
11322
11432
  HUNK_MARKER = "@@";
11323
11433
  BINARY_MARKER = "Binary files ";
@@ -11497,7 +11607,7 @@ var init_parse = __esmMin((() => {
11497
11607
  if (draft !== void 0) readLine(draft, line);
11498
11608
  }
11499
11609
  for (const draft of drafts) told(draft, notesOf$1(draft));
11500
- return drafts;
11610
+ return drafts.map((draft) => Object.assign(draft, foldReindents(draft.hunks)));
11501
11611
  };
11502
11612
  }));
11503
11613
  //#endregion
package/package.json CHANGED
@@ -23,7 +23,7 @@
23
23
  "bin": {
24
24
  "adiff": "./bin/adiff.js"
25
25
  },
26
- "version": "0.1.0-alpha.177",
26
+ "version": "0.1.0-alpha.179",
27
27
  "description": "Review the work an agent left you without losing the thread: comments live on the lines, the agent answers them, and each point stays open until you settle it.",
28
28
  "license": "MIT",
29
29
  "repository": {