@eliya-oss/agent-diff 0.1.0-alpha.56 → 0.1.0-alpha.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/main.js +209 -30
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @eliya-oss/agent-diff
2
2
 
3
+ ## 0.1.0-alpha.58
4
+
5
+ ### Patch Changes
6
+
7
+ - Syntax colour is read from the file now, not from the diff. The visible rows were handed to the parser as if they were a document, so a hunk starting inside a JSX block or an object literal gave it no opening to find, and the gap and comment rows between hunks were fed to it as code — which is why colour looked right in some files and wrong in others. Both sides of the file are parsed whole and the colours laid onto the rows that show them.
8
+
9
+ Three things around the diff were fixed with it. The pinned scope no longer keeps the previous file's line: the memo that skips redrawing an unchanged pin was reset without the pin being cleared, so an empty chain skipped the redraw and left the old scope on screen. Scrolling a deeply indented file no longer jumps, because the rows available to scroll through no longer shrink and grow with the pinned scope under the cursor. And `option` and `command` with backspace take back a word and a line while writing a comment, rather than one character like a bare backspace.
10
+
11
+ `}` and `{` walk changes rather than hunks. They jumped to the top of a hunk, which is its leading context, so the cursor landed three lines short of the thing it was jumping to — and with the whole file shown there was only ever one hunk, so they stopped working entirely. They now step from one run of changed lines to the next, which works at any width and lands on the change.
12
+
13
+ Opening a comment from the review panel brings the diff to it. The row was worked out from the diff before its gap and comment rows were counted in, so it landed somewhere else in the file — often the end. A comment whose line is not in the diff at all says so rather than moving you somewhere arbitrary.
14
+
15
+ The review screen also uses the two rows it was leaving empty above and below itself.
16
+
17
+ ## 0.1.0-alpha.57
18
+
19
+ ### Patch Changes
20
+
21
+ - Installing without naming a tag gets this version rather than one from weeks ago. The release moves the `latest` dist-tag itself now: the step used to throw away the credential the publish had just used successfully and go straight to an exchange that returns nothing, so the tag sat on `0.1.0-alpha.20` while releases ran on ahead, and moving it meant someone typing the command by hand every time. Opening the GitHub release retries too, so a refused API call no longer leaves a published version with no binaries and no Homebrew formula behind it.
22
+
3
23
  ## 0.1.0-alpha.56
4
24
 
5
25
  ### Patch Changes
package/dist/main.js CHANGED
@@ -8019,7 +8019,7 @@ var init_run = __esmMin((() => {
8019
8019
  }));
8020
8020
  //#endregion
8021
8021
  //#region src/service/git/service.ts
8022
- var GREP_CONTEXT, DEFAULT_BRANCH_CANDIDATES, STAT, Git, parseStat, readEntries, baseNames, mergeBases, findDefaultBranch, defaultBranch, mergeBaseOf, toWorktree, branchTips, parents, parentOf, splitLines, absent, readText, settled, listWorktrees, readDiff, readStat, readSource, readGrep, shape, GitLive;
8022
+ var GREP_CONTEXT, DEFAULT_BRANCH_CANDIDATES, STAT, Git, parseStat, readEntries, baseNames, mergeBases, findDefaultBranch, defaultBranch, mergeBaseOf, toWorktree, branchTips, parents, parentOf, splitLines, absent, readText, settled, listWorktrees, readDiff, readStat, readSource, readBlob, readGrep, shape, GitLive;
8023
8023
  var init_service$2 = __esmMin((() => {
8024
8024
  init_dist();
8025
8025
  init_error$3();
@@ -8178,6 +8178,11 @@ var init_service$2 = __esmMin((() => {
8178
8178
  const text = yield* readText(join(worktree.path, path), path);
8179
8179
  return map$4(text, splitLines);
8180
8180
  });
8181
+ readBlob = fn("Git.blob")(function* (worktree, path) {
8182
+ const target = worktree.base.length > 0 ? worktree.base : "HEAD";
8183
+ const raw = yield* gitOrEmpty(worktree.path, ["show", `${target}:${path}`]);
8184
+ return raw.length === 0 ? none() : some(splitLines(raw));
8185
+ });
8181
8186
  readGrep = fn("Git.grep")(function* (worktree, term) {
8182
8187
  return yield* gitOrEmpty(worktree.path, [
8183
8188
  "grep",
@@ -8205,6 +8210,7 @@ var init_service$2 = __esmMin((() => {
8205
8210
  diff: readDiff,
8206
8211
  stat: readStat,
8207
8212
  source: readSource,
8213
+ blob: readBlob,
8208
8214
  grep: readGrep,
8209
8215
  defaultBranch,
8210
8216
  stackParent: (repo, branch) => defaultBranch(repo).pipe(flatMap((fallback) => parentOf(repo, branch, fallback))),
@@ -8741,7 +8747,7 @@ var init_error$1 = __esmMin((() => {
8741
8747
  }));
8742
8748
  //#endregion
8743
8749
  //#region src/cli/commands.ts
8744
- var CONTEXT, WHOLE_FILE$1, POLL, AUTO, askedFor, basedOn, worktreeNamed, findBranch, baseFor, patchesOf, findPatch, rowsCovering, waitingOn, listBranches, blobOf, toggleVouch, reviewProgress, anchorRequest, stageComment, editStaged, dropStaged, listPending, bodyOf, sentOf, listSent, submitReview, submitComment, listPatches, flatten, takeComments, repoOf$1, worktreeOf$1, branchAt, awaitComments, saveReport, fileSource, saveWrap, setBase, clearBase;
8750
+ var CONTEXT, WHOLE_FILE$1, POLL, AUTO, askedFor, basedOn, worktreeNamed, findBranch, baseFor, patchesOf, findPatch, rowsCovering, waitingOn, listBranches, blobOf, toggleVouch, reviewProgress, anchorRequest, stageComment, editStaged, dropStaged, listPending, bodyOf, sentOf, listSent, submitReview, submitComment, listPatches, flatten, takeComments, repoOf$1, worktreeOf$1, branchAt, awaitComments, saveReport, fileSource, fileBefore, saveWrap, setBase, clearBase;
8745
8751
  var init_commands = __esmMin((() => {
8746
8752
  init_dist();
8747
8753
  init_patch();
@@ -9119,6 +9125,12 @@ var init_commands = __esmMin((() => {
9119
9125
  const found = yield* git.source(worktree, file);
9120
9126
  return getOrElse(found, () => []);
9121
9127
  });
9128
+ fileBefore = fn("Cli.fileBefore")(function* (repo, branch, file) {
9129
+ const git = yield* Git;
9130
+ const worktree = yield* findBranch(repo, branch);
9131
+ const found = yield* git.blob(worktree, file);
9132
+ return getOrElse(found, () => []);
9133
+ });
9122
9134
  saveWrap = fn("Cli.saveWrap")(function* (wrap) {
9123
9135
  const store = yield* Store;
9124
9136
  const current = yield* store.settings;
@@ -9411,7 +9423,7 @@ var init_pane = __esmMin((() => {
9411
9423
  init_commands();
9412
9424
  init_init();
9413
9425
  init_pane();
9414
- var version$1 = "0.1.0-alpha.56";
9426
+ var version$1 = "0.1.0-alpha.58";
9415
9427
  //#endregion
9416
9428
  //#region src/cli/upgrade.ts
9417
9429
  var PACKAGE, TAG, RELEASES, REGISTRY, ASK_MS, RUN_MS, CELLAR, COMPILED, INSTALLED, BUN_GLOBAL, routeOf, ROUTES, asRoute, checkoutOf, assetOf, commandFor, NOTES, RUNNABLE, NUMBERS, numbersIn, compare$1, partsOf, newer, tagIn, fetched, askLatest, here, findUpgrade, willUpgrade, runUpgrade, statusOf$1, sayFound, sayDone, attempted, REFRESH_MS, refreshSkills, updatedIn, sayRefreshed, upgradeReport;
@@ -11183,7 +11195,7 @@ var init_tree = __esmMin((() => {
11183
11195
  return node.children.reduce((total, child) => total + filesUnder(tree, child), 0);
11184
11196
  };
11185
11197
  crowdedDirectories = (tree, limit) => tree.nodes.filter((node) => node.kind === "directory" && directFiles(tree, node.id) > limit).map((node) => node.path);
11186
- })), nothingReviewed, initialState, TREE_MAX, TREE_MIN, TREE_SHARE, DIFF_MIN, DIFF_ROOMY, bodyRoom, treeWidth, reviewWidth, panelFits, panelShown, onLayers, selectedLayer, proseFor, layerFiles, layerHolding, layerOpen, chunked, packed, shortened, wordWrapped, wrapped, NO_NOTE, noteRows$1, proseRow, proseRows$1, titleRows, clipEnd, FILE_LEAD, fileRows, layerRows, railWindow, selectedBranch, selectedPatch, pullHere, knownToHaveNoPull, treeOf, treeRows, crowdedOf, foldersOfFile, isReviewed, treeWindow, commentsOn, hiddenLines, markedRows, carriesLine, selectedRows, snippetOf, selectedLineCount, lineOf, caretAt, drafted, WORD, wordLeft, wordRight, caretByWord, lineStart, lineEnd, caretToEdge, editedComment, composeTarget, selectedLines, KEYWORDS, NAME, longestName$1, searchTerm, matchHere, selectionReadout, WHOLE_FILE, CONTEXT_STEPS, wholeFileOff, contextToggled, layerContext, newLineAt, sourceLineAt, rowAtSourceLine, lineOnSide, commentRowsIn, threadsAtRow, stopsAtRow, threadAtStop, threadAtRow, openCommentRows, filesWithComments, answerCount, answersIn, newerOf, sectionOf, sentEntry, panelEntries, panelEntry, threadChosen, spokenSince, hunkStarts, changeAround, nextUnreviewed, reviewedCount, fileOrder, layerFile, selectionRange;
11198
+ })), nothingReviewed, initialState, TREE_MAX, TREE_MIN, TREE_SHARE, DIFF_MIN, DIFF_ROOMY, bodyRoom, treeWidth, reviewWidth, panelFits, panelShown, onLayers, selectedLayer, proseFor, layerFiles, layerHolding, layerOpen, chunked, packed, shortened, wordWrapped, wrapped, NO_NOTE, noteRows$1, proseRow, proseRows$1, titleRows, clipEnd, FILE_LEAD, fileRows, layerRows, railWindow, selectedBranch, selectedPatch, pullHere, knownToHaveNoPull, treeOf, treeRows, crowdedOf, foldersOfFile, isReviewed, treeWindow, commentsOn, hiddenLines, markedRows, carriesLine, selectedRows, snippetOf, selectedLineCount, lineOf, caretAt, drafted, WORD, wordLeft, wordRight, caretByWord, lineStart, lineEnd, caretToEdge, editedComment, composeTarget, selectedLines, KEYWORDS, NAME, longestName$1, searchTerm, matchHere, selectionReadout, WHOLE_FILE, CONTEXT_STEPS, wholeFileOff, contextToggled, layerContext, newLineAt, sourceLineAt, rowAtSourceLine, rowShowing, lineOnSide, commentRowsIn, threadsAtRow, stopsAtRow, threadAtStop, threadAtRow, openCommentRows, filesWithComments, answerCount, answersIn, newerOf, sectionOf, sentEntry, panelEntries, panelEntry, threadChosen, spokenSince, hunkStarts, changeAround, nextUnreviewed, reviewedCount, fileOrder, layerFile, selectionRange;
11187
11199
  var init_model = __esmMin((() => {
11188
11200
  init_dist();
11189
11201
  init_patch();
@@ -11570,6 +11582,10 @@ var init_model = __esmMin((() => {
11570
11582
  onSome: (value) => value >= line
11571
11583
  }))?.index ?? 0;
11572
11584
  };
11585
+ rowShowing = (patch, line) => patch.rows.find((row) => match$3(row.newLine, {
11586
+ onNone: () => false,
11587
+ onSome: (value) => value === line
11588
+ }))?.index;
11573
11589
  lineOnSide = (row, side) => getOrUndefined$1(side === "old" ? row.oldLine : row.newLine);
11574
11590
  commentRowsIn = (state, fileIndex) => {
11575
11591
  const patch = fileIndex === state.patchIndex ? selectedPatch(state) : state.patches[fileIndex];
@@ -11636,8 +11652,15 @@ var init_model = __esmMin((() => {
11636
11652
  };
11637
11653
  spokenSince = (seen, now) => Math.max(0, answerCount(now) - answerCount(seen));
11638
11654
  hunkStarts = (state) => {
11639
- const patch = selectedPatch(state);
11640
- return patch === void 0 ? [] : patch.hunks.map((hunk) => hunk.startRow);
11655
+ const rows = selectedPatch(state)?.rows ?? [];
11656
+ const starts = [];
11657
+ let running = false;
11658
+ for (const [index, row] of rows.entries()) {
11659
+ const changed = row.kind !== "context";
11660
+ if (changed && !running) starts.push(index);
11661
+ running = changed;
11662
+ }
11663
+ return starts;
11641
11664
  };
11642
11665
  changeAround = (state) => {
11643
11666
  const rows = selectedPatch(state)?.rows ?? [];
@@ -12335,7 +12358,7 @@ var init_match = __esmMin((() => {
12335
12358
  }));
12336
12359
  //#endregion
12337
12360
  //#region src/tui/reduce.ts
12338
- var clamp, lastRow, rowsIn, withCursorVisible, moveCursor, stepStop, scrolled, draggedTo, atRow, noneLeft, layerHunk, nextFileWithComments, atComment, nothingOpen, layerComment, PAN_STEP, panned, movePending, moveLayer, inRail, movePanel, layerDown, PANES, panesShown, focusStepped, togglePanel, packedAway, zoom, toggleRail, foldDirectory, foldLayer, foldThread, fold, moveBranch, moveFile, selectHunk, swapEnds, atBranch, startSelection, openCompose, goBack, walkMatches, openPalette, openKeys, movePalette, paletteMatches, offered, paletteChoice, transitions, reduce, atFile, withContext, withFull, revealsAfter, gapOpened, withPending, panBy, withSent, withArrived, withColumns, withLayers, withPulls, withSilentForge, withBranches, withSource, withVouched, restoredTo, withPatches, inserted, typed, TAB_WIDTH, SPACE_CODE, ERASED_FROM, ERASED_TO, readable, legible, pasted, backspaced, deleted, caretMoved, caretJumped, caretHomed, withDraft, paletteMoved, paletteClosed, withWaiting, withMatches, withNoticeHere, withNotice;
12361
+ var clamp, lastRow, rowsIn, withCursorVisible, moveCursor, stepStop, scrolled, draggedTo, atRow, noneLeft, layerHunk, nextFileWithComments, atComment, nothingOpen, layerComment, PAN_STEP, panned, movePending, moveLayer, inRail, movePanel, layerDown, PANES, panesShown, focusStepped, togglePanel, packedAway, zoom, toggleRail, foldDirectory, foldLayer, foldThread, fold, moveBranch, moveFile, selectHunk, swapEnds, atBranch, startSelection, openCompose, goBack, walkMatches, openPalette, openKeys, movePalette, paletteMatches, offered, paletteChoice, transitions, reduce, atFile, withContext, withFull, revealsAfter, gapOpened, withPending, panBy, withSent, withArrived, withColumns, withLayers, withPulls, withSilentForge, withBranches, withSource, withVouched, restoredTo, openedAt, withPatches, inserted, typed, TAB_WIDTH, SPACE_CODE, ERASED_FROM, ERASED_TO, readable, legible, pasted, backspaced, cutBackTo, wordBackspaced, lineBackspaced, deleted, caretMoved, caretJumped, caretHomed, withDraft, paletteMoved, paletteClosed, withWaiting, withMatches, withNoticeHere, withNotice;
12339
12362
  var init_reduce = __esmMin((() => {
12340
12363
  init_dist();
12341
12364
  init_patch();
@@ -12401,8 +12424,8 @@ var init_reduce = __esmMin((() => {
12401
12424
  cursor: clamp(row, 0, lastRow(selectedPatch(state)))
12402
12425
  });
12403
12426
  noneLeft = (state, delta) => {
12404
- const only = hunkStarts(state).length <= 1;
12405
- return withNotice(state, only ? "this file reads as one change · press - for less context to split it" : `no change ${delta > 0 ? "after" : "before"} this one`);
12427
+ const none = hunkStarts(state).length === 0;
12428
+ return withNotice(state, none ? "nothing changed in this file" : `no change ${delta > 0 ? "after" : "before"} this one`);
12406
12429
  };
12407
12430
  layerHunk = (state, delta) => {
12408
12431
  const starts = hunkStarts(state);
@@ -12877,6 +12900,29 @@ var init_reduce = __esmMin((() => {
12877
12900
  top
12878
12901
  });
12879
12902
  };
12903
+ openedAt = (state, patchIndex, line) => {
12904
+ const landed = {
12905
+ ...state,
12906
+ patchIndex,
12907
+ stop: 0,
12908
+ anchorRow: 0,
12909
+ selecting: false
12910
+ };
12911
+ const shown = selectedPatch(landed);
12912
+ if (shown === void 0) return {
12913
+ ...landed,
12914
+ cursor: 0,
12915
+ top: 0
12916
+ };
12917
+ const cursor = rowShowing(shown, line) ?? rowAtSourceLine(shown, line);
12918
+ const height = Math.max(1, landed.viewport);
12919
+ const room = Math.max(0, shown.rows.length - height);
12920
+ return withCursorVisible({
12921
+ ...landed,
12922
+ cursor,
12923
+ top: clamp(cursor - Math.floor(height / 2), 0, room)
12924
+ });
12925
+ };
12880
12926
  withPatches = (state, patches) => ({
12881
12927
  ...state,
12882
12928
  screen: "review",
@@ -12935,6 +12981,17 @@ var init_reduce = __esmMin((() => {
12935
12981
  caret: at - 1
12936
12982
  };
12937
12983
  };
12984
+ cutBackTo = (state, to) => {
12985
+ const at = caretAt(state);
12986
+ if (to >= at) return state;
12987
+ return {
12988
+ ...state,
12989
+ draft: `${state.draft.slice(0, to)}${state.draft.slice(at)}`,
12990
+ caret: to
12991
+ };
12992
+ };
12993
+ wordBackspaced = (state) => state.screen === "palette" ? backspaced(state) : cutBackTo(state, caretByWord(state, -1));
12994
+ lineBackspaced = (state) => state.screen === "palette" ? backspaced(state) : cutBackTo(state, caretToEdge(state, "start"));
12938
12995
  deleted = (state) => {
12939
12996
  const at = caretAt(state);
12940
12997
  if (at >= state.draft.length) return state;
@@ -13154,7 +13211,7 @@ var init_theme = __esmMin((() => {
13154
13211
  }));
13155
13212
  //#endregion
13156
13213
  //#region src/tui/diffview.ts
13157
- var WASH, NOTE_MIN, ANSWER_MARK, OVERSCAN, SIGN_WIDTH, SCROLL_ROWS, PAN_COLUMNS, WAYS, notchesIn, wheelTo, SIGNS, numberFor, DiffView, startsOf, bareOf, keyOf, groupOf, isChrome, heldAt, textAt, noteSpans, NOTE_PAINT, wrap, headOf, spokenLines, answerLines, noteLines, noteRows, proseRows, proseAt, notesAt, codeRow, rowsFor, layout, lineNumbers, BARE_SIGN, signFor, lineSigns, sideLineOf;
13214
+ var WASH, NOTE_MIN, ANSWER_MARK, OVERSCAN, SIGN_WIDTH, SCROLL_ROWS, PAN_COLUMNS, WAYS, notchesIn, wheelTo, SIGNS, numberFor, DiffView, startsOf, bareOf, keyOf, groupOf, isChrome, heldAt, NO_SPANS, lineStarts, overLine, shifted, acrossLines, spansByLine, textAt, noteSpans, NOTE_PAINT, wrap, headOf, spokenLines, answerLines, noteLines, noteRows, proseRows, proseAt, notesAt, codeRow, rowsFor, layout, lineNumbers, BARE_SIGN, signFor, lineSigns, sideLineOf;
13158
13215
  var init_diffview = __esmMin((() => {
13159
13216
  init_dist();
13160
13217
  init_patch();
@@ -13223,6 +13280,9 @@ var init_diffview = __esmMin((() => {
13223
13280
  pinned;
13224
13281
  pinBox;
13225
13282
  pinnedText = "";
13283
+ newLit = [];
13284
+ oldLit = [];
13285
+ litFor = "";
13226
13286
  shown;
13227
13287
  noted = "";
13228
13288
  display = [];
@@ -13287,6 +13347,12 @@ var init_diffview = __esmMin((() => {
13287
13347
  gutterWidth() {
13288
13348
  return Math.max(0, this.code.x - this.numbers.x) + SIGN_WIDTH;
13289
13349
  }
13350
+ unpin() {
13351
+ this.pinnedText = "";
13352
+ this.pinned.content = "";
13353
+ this.pinned.height = 0;
13354
+ this.pinBox.height = 0;
13355
+ }
13290
13356
  pin(lines) {
13291
13357
  const indent = this.gutterWidth();
13292
13358
  if (this.pinBox.paddingLeft !== indent) this.pinBox.paddingLeft = indent;
@@ -13332,7 +13398,7 @@ var init_diffview = __esmMin((() => {
13332
13398
  const room = notes.length === 0 && prose.length === 0 ? NOTE_MIN : this.noteRoom();
13333
13399
  const key = keyOf(room, notes, prose);
13334
13400
  if (patch === this.shown && key === this.noted) return;
13335
- this.pinnedText = "";
13401
+ this.unpin();
13336
13402
  this.shown = patch;
13337
13403
  this.noted = key;
13338
13404
  this.display = layout({
@@ -13350,10 +13416,41 @@ var init_diffview = __esmMin((() => {
13350
13416
  this.numbers.setLineSigns(lineSigns(patch, this.display));
13351
13417
  this.numbers.setLineColors(/* @__PURE__ */ new Map());
13352
13418
  }
13419
+ lit(path, side, lines, found) {
13420
+ const held = spansByLine(lines, found);
13421
+ if (side === "new") this.newLit = held;
13422
+ else this.oldLit = held;
13423
+ this.litFor = path;
13424
+ this.feed();
13425
+ this.code.requestRender();
13426
+ }
13427
+ litRow(entry) {
13428
+ if (this.shown === void 0 || this.shown.path !== this.litFor) return NO_SPANS;
13429
+ const row = this.shown.rows[entry.row];
13430
+ if (row === void 0) return NO_SPANS;
13431
+ const fresh = getOrUndefined$1(row.newLine);
13432
+ if (fresh !== void 0) return this.newLit[fresh - 1] ?? NO_SPANS;
13433
+ const gone = getOrUndefined$1(row.oldLine);
13434
+ return gone === void 0 ? NO_SPANS : this.oldLit[gone - 1] ?? NO_SPANS;
13435
+ }
13436
+ ownSpans() {
13437
+ if (this.shown === void 0 || this.shown.path !== this.litFor) return void 0;
13438
+ const spans = [];
13439
+ let at = 0;
13440
+ for (const entry of this.display) {
13441
+ const width = heldAt(entry, this.held).length;
13442
+ const here = isChrome(entry) ? NO_SPANS : this.litRow(entry);
13443
+ spans.push(...shifted(here, at, width));
13444
+ at += width + 1;
13445
+ }
13446
+ return spans;
13447
+ }
13353
13448
  feed() {
13354
13449
  const spans = noteSpans(this.display, this.held);
13355
13450
  this.code.content = textAt(this.display, this.held);
13356
- this.code.onHighlight = (highlights) => [...highlights.filter((highlight) => !spans.some(([from, to]) => highlight[0] < to && highlight[1] > from)), ...spans];
13451
+ this.code.onHighlight = (highlights) => {
13452
+ return [...(this.ownSpans() ?? highlights).filter((highlight) => !spans.some(([from, to]) => highlight[0] < to && highlight[1] > from)), ...spans];
13453
+ };
13357
13454
  }
13358
13455
  setWrap(on) {
13359
13456
  if (on !== this.wrapped) {
@@ -13488,6 +13585,58 @@ var init_diffview = __esmMin((() => {
13488
13585
  };
13489
13586
  isChrome = (entry) => entry.comment || entry.gap || entry.prose;
13490
13587
  heldAt = (entry, pan) => isChrome(entry) && pan > 0 ? `${" ".repeat(pan)}${entry.text}` : entry.text;
13588
+ NO_SPANS = [];
13589
+ lineStarts = (lines) => {
13590
+ const starts = [];
13591
+ let at = 0;
13592
+ for (const line of lines) {
13593
+ starts.push(at);
13594
+ at += line.length + 1;
13595
+ }
13596
+ return starts;
13597
+ };
13598
+ overLine = (start, starts) => {
13599
+ let low = 0;
13600
+ let high = starts.length - 1;
13601
+ while (low < high) {
13602
+ const mid = Math.ceil((low + high) / 2);
13603
+ if ((starts[mid] ?? 0) <= start) low = mid;
13604
+ else high = mid - 1;
13605
+ }
13606
+ return low;
13607
+ };
13608
+ shifted = (spans, at, width) => spans.filter(([from]) => from < width).map(([from, to, group]) => [
13609
+ at + from,
13610
+ at + Math.min(to, width),
13611
+ group
13612
+ ]);
13613
+ acrossLines = (lines, starts, held, span) => {
13614
+ const [from, to, group] = span;
13615
+ let at = from;
13616
+ let line = overLine(at, starts);
13617
+ while (at < to && line < lines.length) {
13618
+ const start = starts[line] ?? 0;
13619
+ const width = lines[line]?.length ?? 0;
13620
+ const stop = Math.min(to, start + width);
13621
+ if (stop > at) held[line]?.push([
13622
+ at - start,
13623
+ stop - start,
13624
+ group
13625
+ ]);
13626
+ at = start + width + 1;
13627
+ line += 1;
13628
+ }
13629
+ };
13630
+ spansByLine = (lines, found) => {
13631
+ const starts = lineStarts(lines);
13632
+ const held = lines.map(() => []);
13633
+ for (const [from, to, group] of found) acrossLines(lines, starts, held, [
13634
+ from,
13635
+ to,
13636
+ group
13637
+ ]);
13638
+ return held;
13639
+ };
13491
13640
  textAt = (display, pan) => display.map((entry) => heldAt(entry, pan)).join("\n");
13492
13641
  noteSpans = (display, pan) => {
13493
13642
  const spans = [];
@@ -14263,8 +14412,8 @@ var init_render = __esmMin((() => {
14263
14412
  renderer.root.flexDirection = "column";
14264
14413
  renderer.root.paddingLeft = FRAME_PAD;
14265
14414
  renderer.root.paddingRight = FRAME_PAD;
14266
- renderer.root.paddingTop = FRAME_PAD;
14267
- renderer.root.paddingBottom = FRAME_PAD;
14415
+ renderer.root.paddingTop = 0;
14416
+ renderer.root.paddingBottom = 0;
14268
14417
  this.header = bar(renderer, "header", palette.ink);
14269
14418
  this.footer = bar(renderer, "footer", palette.faint);
14270
14419
  this.body = makeBody(renderer);
@@ -14338,7 +14487,12 @@ var init_render = __esmMin((() => {
14338
14487
  return this.view.rowAt(Math.max(0, y - this.view.screenTop() + this.lastTop));
14339
14488
  }
14340
14489
  viewportRows() {
14341
- return this.diffRows();
14490
+ const edges = this.diffPane.border === true ? PANE_EDGES : 0;
14491
+ const pane = this.diffPane.height - edges - STICKY_MAX;
14492
+ return Math.max(1, pane > 0 ? pane : this.diffRows());
14493
+ }
14494
+ lit(path, side, lines, found) {
14495
+ this.view.lit(path, side, lines, found);
14342
14496
  }
14343
14497
  noteRoom() {
14344
14498
  return this.view.room();
@@ -14494,10 +14648,10 @@ var init_render = __esmMin((() => {
14494
14648
  const shown = shownOf(state);
14495
14649
  if (shown === void 0) return;
14496
14650
  const patch = shown.patch;
14497
- this.paintSticky(state, state.top);
14498
14651
  this.view.setWrap(state.wrap);
14499
14652
  this.view.setPan(state.pan);
14500
14653
  this.view.show(patch, notesFor(state, patch.path), gapRowSet(shown), proseFor(state, patch.path));
14654
+ this.paintSticky(state, state.top);
14501
14655
  this.view.fit(this.diffRows());
14502
14656
  const height = this.view.rows();
14503
14657
  const top = this.view.scrollTo(state.top, state.cursor);
@@ -14779,7 +14933,7 @@ var init_render = __esmMin((() => {
14779
14933
  }));
14780
14934
  //#endregion
14781
14935
  //#region src/tui/display.ts
14782
- var Display, paintWith, listenWith, shapeOf, displayOn;
14936
+ var Display, paintWith, listenWith, lightWith, shapeOf, displayOn;
14783
14937
  var init_display = __esmMin((() => {
14784
14938
  init_dist();
14785
14939
  init_render();
@@ -14790,12 +14944,19 @@ var init_display = __esmMin((() => {
14790
14944
  listenWith = (screen) => fn("Tui.listen")(function* (mouse) {
14791
14945
  yield* sync(() => screen.listen(mouse));
14792
14946
  });
14947
+ lightWith = (screen, path, side, lines) => gen(function* () {
14948
+ const filetype = pathToFiletype(path) ?? "text";
14949
+ if (filetype === "text" || lines.length === 0) return;
14950
+ const found = (yield* promise(() => getTreeSitterClient().highlightOnce(lines.join("\n"), filetype))).highlights;
14951
+ if (found !== void 0) screen.lit(path, side, lines, found);
14952
+ });
14793
14953
  shapeOf = (screen) => ({
14794
14954
  paint: paintWith(screen),
14795
14955
  rows: sync(() => screen.viewportRows()),
14796
14956
  room: sync(() => screen.noteRoom()),
14797
14957
  columns: sync(() => screen.columns()),
14798
- listen: listenWith(screen)
14958
+ listen: listenWith(screen),
14959
+ light: (path, side, lines) => lightWith(screen, path, side, lines)
14799
14960
  });
14800
14961
  displayOn = (renderer, repo) => sync$1(Display)(() => shapeOf(new Screen(renderer, repo)));
14801
14962
  }));
@@ -14874,7 +15035,7 @@ var init_upgrade = __esmMin((() => {
14874
15035
  return due ? `adiff ${latest} is out · adiff upgrade` : "";
14875
15036
  }).pipe(withSpan("Tui.upgradeHint"));
14876
15037
  upgradeHint = worded.pipe(orElseSucceed(() => ""));
14877
- })), PRINTABLE, KEY_HISTORY, copyToClipboard, asKey, openedPull, byWord, WORD_STEP, caretSideways, caretFor, LISTENS, listens, keyName, App, settledPath, openingOn, launch, told, untilDestroyed, runOn, runTui;
15038
+ })), PRINTABLE, KEY_HISTORY, copyToClipboard, asKey, openedPull, byWord, WORD_STEP, caretSideways, caretFor, erasedBy, LISTENS, listens, keyName, App, settledPath, openingOn, launch, told, untilDestroyed, runOn, runTui;
14878
15039
  var init_app = __esmMin((() => {
14879
15040
  init_dist();
14880
15041
  init_report();
@@ -14931,6 +15092,10 @@ var init_app = __esmMin((() => {
14931
15092
  if (key.name === "end") return caretHomed(state, "end");
14932
15093
  return key.name === "delete" ? deleted(state) : void 0;
14933
15094
  };
15095
+ erasedBy = (state, key) => {
15096
+ if (key.meta || key.ctrl) return lineBackspaced(state);
15097
+ return key.option ? wordBackspaced(state) : backspaced(state);
15098
+ };
14934
15099
  LISTENS = /* @__PURE__ */ new Set(["keys", "palette"]);
14935
15100
  listens = (screen) => LISTENS.has(screen);
14936
15101
  keyName = (key) => {
@@ -15253,7 +15418,7 @@ var init_app = __esmMin((() => {
15253
15418
  onText(key) {
15254
15419
  if (!takesText(this.state.screen)) return;
15255
15420
  if (key.name === "backspace") {
15256
- this.commit(backspaced(this.state));
15421
+ this.commit(erasedBy(this.state, key));
15257
15422
  return;
15258
15423
  }
15259
15424
  if (key.name === "down") {
@@ -15380,17 +15545,20 @@ var init_app = __esmMin((() => {
15380
15545
  return;
15381
15546
  }
15382
15547
  const at = this.state.patches.findIndex((patch) => patch.path === entry.comment.file);
15383
- const patch = this.state.patches[at];
15384
- if (patch === void 0) {
15548
+ if (this.state.patches[at] === void 0) {
15385
15549
  this.commit(withNoticeHere(this.state, `${entry.comment.file} is not on this branch`));
15386
15550
  return;
15387
15551
  }
15388
- const landed = atFile(this.state, at);
15389
- this.commit({
15390
- ...landed,
15391
- cursor: rowAtSourceLine(patch, entry.comment.end)
15552
+ const shown = selectedPatch({
15553
+ ...this.measured(),
15554
+ patchIndex: at
15392
15555
  });
15393
- yield* this.loadSource();
15556
+ if (shown !== void 0 && rowShowing(shown, entry.comment.end) === void 0) {
15557
+ this.commit(withNoticeHere(this.state, "that comment is outside this diff"));
15558
+ return;
15559
+ }
15560
+ this.commit(openedAt(this.measured(), at, entry.comment.end));
15561
+ yield* this.turnedTo();
15394
15562
  });
15395
15563
  }
15396
15564
  settleHere() {
@@ -15466,14 +15634,14 @@ var init_app = __esmMin((() => {
15466
15634
  return gen({ self: this }, function* () {
15467
15635
  const was = this.state.patchIndex;
15468
15636
  this.commit(reduce(this.measured(), delta > 0 ? "comment.next" : "comment.prev"));
15469
- if (this.state.patchIndex !== was) yield* this.loadSource();
15637
+ if (this.state.patchIndex !== was) yield* this.turnedTo();
15470
15638
  });
15471
15639
  }
15472
15640
  commitSynced(action) {
15473
15641
  return gen({ self: this }, function* () {
15474
15642
  const was = this.state.patchIndex;
15475
15643
  this.commit(reduce(this.measured(), action));
15476
- if (this.state.patchIndex !== was) yield* this.loadSource();
15644
+ if (this.state.patchIndex !== was) yield* this.turnedTo();
15477
15645
  });
15478
15646
  }
15479
15647
  moveFile(delta) {
@@ -15585,13 +15753,24 @@ var init_app = __esmMin((() => {
15585
15753
  }));
15586
15754
  });
15587
15755
  }
15756
+ turnedTo() {
15757
+ return gen({ self: this }, function* () {
15758
+ this.commit(withSource(this.state, []));
15759
+ yield* this.loadSource();
15760
+ });
15761
+ }
15588
15762
  loadSource() {
15589
15763
  return gen({ self: this }, function* () {
15590
15764
  const branch = selectedBranch(this.state);
15591
15765
  const patch = selectedPatch(this.state);
15592
15766
  if (branch === void 0 || patch === void 0) return;
15593
- const source = yield* fileSource(this.repo, branch.branch, patch.path);
15767
+ const asked = patch.path;
15768
+ const source = yield* fileSource(this.repo, branch.branch, asked);
15769
+ if (selectedPatch(this.state)?.path !== asked) return;
15594
15770
  this.commit(withSource(this.state, source));
15771
+ yield* this.display.light(asked, "new", source);
15772
+ const before = yield* fileBefore(this.repo, branch.branch, asked);
15773
+ if (before.length > 0) yield* this.display.light(asked, "old", before);
15595
15774
  });
15596
15775
  }
15597
15776
  expand(delta) {
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.56",
26
+ "version": "0.1.0-alpha.58",
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": {