@eliya-oss/agent-diff 0.1.0-alpha.13 → 0.1.0-alpha.14

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,13 @@
1
1
  # @eliya-oss/agent-diff
2
2
 
3
+ ## 0.1.0-alpha.14
4
+
5
+ ### Patch Changes
6
+
7
+ - V selects the change under the cursor, o grows a selection from its other end, and g and G reach the ends of the worktree list.
8
+
9
+ - w wraps long lines in the diff, and the cursor gutter stops at the last line.
10
+
3
11
  ## 0.1.0-alpha.13
4
12
 
5
13
  ### Patch Changes
package/dist/main.js CHANGED
@@ -12414,6 +12414,7 @@ const initialState = (branches) => ({
12414
12414
  revealed: [],
12415
12415
  focus: "diff",
12416
12416
  navOpen: true,
12417
+ wrap: false,
12417
12418
  layers: [],
12418
12419
  layersStale: false,
12419
12420
  pulls: {},
@@ -12644,6 +12645,19 @@ const hunkStarts = (state) => {
12644
12645
  const patch = selectedPatch(state);
12645
12646
  return patch === void 0 ? [] : patch.hunks.map((hunk) => hunk.startRow);
12646
12647
  };
12648
+ const changeAround = (state) => {
12649
+ const rows = selectedPatch(state)?.rows ?? [];
12650
+ const changed = (at) => {
12651
+ const row = rows[at];
12652
+ return row !== void 0 && row.kind !== "context";
12653
+ };
12654
+ if (!changed(state.cursor)) return void 0;
12655
+ let first = state.cursor;
12656
+ let last = state.cursor;
12657
+ while (changed(first - 1)) first -= 1;
12658
+ while (changed(last + 1)) last += 1;
12659
+ return [first, last];
12660
+ };
12647
12661
  const nextUnreviewed = (state, from) => {
12648
12662
  const order = fileOrder(state);
12649
12663
  const start = Math.max(0, order.indexOf(from));
@@ -12854,6 +12868,40 @@ const commands = [
12854
12868
  screens: ["review"],
12855
12869
  hint: "zoom"
12856
12870
  }),
12871
+ command({
12872
+ action: "branch.first",
12873
+ title: "Go to the first worktree",
12874
+ category: "Branches",
12875
+ keys: ["g"],
12876
+ screens: ["branches"]
12877
+ }),
12878
+ command({
12879
+ action: "branch.last",
12880
+ title: "Go to the last worktree",
12881
+ category: "Branches",
12882
+ keys: ["G"],
12883
+ screens: ["branches"]
12884
+ }),
12885
+ command({
12886
+ action: "select.hunk",
12887
+ title: "Select the change under the cursor",
12888
+ keys: ["V"],
12889
+ screens: ["review"]
12890
+ }),
12891
+ command({
12892
+ action: "select.swap",
12893
+ title: "Grow the selection from its other end",
12894
+ keys: ["o"],
12895
+ screens: ["review"]
12896
+ }),
12897
+ command({
12898
+ action: "wrap.toggle",
12899
+ title: "Wrap long lines",
12900
+ category: "General",
12901
+ keys: ["w"],
12902
+ screens: ["review"],
12903
+ hint: "wrap"
12904
+ }),
12857
12905
  command({
12858
12906
  action: "review.reload",
12859
12907
  title: "Read the branch again",
@@ -13222,6 +13270,25 @@ const moveFile = (state, delta) => ({
13222
13270
  anchorRow: 0,
13223
13271
  selecting: false
13224
13272
  });
13273
+ const selectHunk = (state) => {
13274
+ const found = changeAround(state);
13275
+ if (found === void 0) return withNotice(state, "no change under the cursor");
13276
+ return withCursorVisible({
13277
+ ...state,
13278
+ selecting: true,
13279
+ anchorRow: found[0],
13280
+ cursor: found[1]
13281
+ });
13282
+ };
13283
+ const swapEnds = (state) => state.selecting ? withCursorVisible({
13284
+ ...state,
13285
+ anchorRow: state.cursor,
13286
+ cursor: state.anchorRow
13287
+ }) : state;
13288
+ const atBranch = (state, at) => ({
13289
+ ...state,
13290
+ branchIndex: clamp(at, 0, Math.max(0, state.branches.length - 1))
13291
+ });
13225
13292
  const startSelection = (state) => ({
13226
13293
  ...state,
13227
13294
  selecting: true,
@@ -13278,6 +13345,8 @@ const movePalette = (state, delta) => ({
13278
13345
  const paletteMatches = (state) => searchCommands(state.returnTo, state.query);
13279
13346
  const paletteChoice = (state) => paletteMatches(state)[state.paletteIndex]?.action;
13280
13347
  const transitions = {
13348
+ "branch.first": (state) => atBranch(state, 0),
13349
+ "branch.last": (state) => atBranch(state, state.branches.length - 1),
13281
13350
  "branch.next": (state) => moveBranch(state, 1),
13282
13351
  "branch.prev": (state) => moveBranch(state, -1),
13283
13352
  "branch.open": (state) => state,
@@ -13296,6 +13365,8 @@ const transitions = {
13296
13365
  "file.next": (state) => moveFile(state, 1),
13297
13366
  "file.prev": (state) => moveFile(state, -1),
13298
13367
  "select.start": startSelection,
13368
+ "select.hunk": selectHunk,
13369
+ "select.swap": swapEnds,
13299
13370
  "compose.open": openCompose,
13300
13371
  "compose.submit": (state) => state,
13301
13372
  "compose.stage": (state) => state,
@@ -13319,6 +13390,10 @@ const transitions = {
13319
13390
  navOpen: !state.navOpen,
13320
13391
  focus: "diff"
13321
13392
  }),
13393
+ "wrap.toggle": (state) => ({
13394
+ ...state,
13395
+ wrap: !state.wrap
13396
+ }),
13322
13397
  "review.reload": (state) => state,
13323
13398
  "rail.toggle": toggleRail,
13324
13399
  "file.vouch": (state) => state,
@@ -13688,6 +13763,7 @@ var DiffView = class {
13688
13763
  display = [];
13689
13764
  starts = /* @__PURE__ */ new Map();
13690
13765
  fitted = 1;
13766
+ wrapped = false;
13691
13767
  constructor(renderer) {
13692
13768
  this.code = new CodeRenderable(renderer, {
13693
13769
  id: "diff-code",
@@ -13809,18 +13885,59 @@ var DiffView = class {
13809
13885
  const spans = noteSpans(this.display);
13810
13886
  this.code.onHighlight = (highlights) => [...highlights.filter((highlight) => !spans.some(([from, to]) => highlight[0] < to && highlight[1] > from)), ...spans];
13811
13887
  }
13812
- rowAt(display) {
13813
- const at = Math.max(0, Math.min(this.display.length - 1, display));
13888
+ setWrap(on) {
13889
+ if (on === this.wrapped) return;
13890
+ this.wrapped = on;
13891
+ this.code.wrapMode = on ? "word" : "none";
13892
+ this.code.requestRender();
13893
+ this.numbers.requestRender();
13894
+ }
13895
+ sources() {
13896
+ const reported = this.code.lineInfo?.lineSources;
13897
+ return this.wrapped && reported !== void 0 && reported.length > 0 ? reported : [];
13898
+ }
13899
+ lineAt(visual) {
13900
+ const sources = this.sources();
13901
+ if (sources.length === 0) return visual;
13902
+ return sources[Math.max(0, Math.min(sources.length - 1, visual))] ?? visual;
13903
+ }
13904
+ visualOf(line) {
13905
+ const sources = this.sources();
13906
+ if (sources.length === 0) return line;
13907
+ let low = 0;
13908
+ let high = sources.length;
13909
+ while (low < high) {
13910
+ const mid = low + high >> 1;
13911
+ if ((sources[mid] ?? 0) < line) low = mid + 1;
13912
+ else high = mid;
13913
+ }
13914
+ return low;
13915
+ }
13916
+ tallest() {
13917
+ return this.sources().length === 0 ? this.display.length : this.sources().length;
13918
+ }
13919
+ drawn() {
13920
+ return this.tallest();
13921
+ }
13922
+ rowAt(visual) {
13923
+ const line = this.lineAt(visual);
13924
+ const at = Math.max(0, Math.min(this.display.length - 1, line));
13814
13925
  return this.display[at]?.row ?? 0;
13815
13926
  }
13816
- isComment(display) {
13817
- const entry = this.display[display];
13927
+ isComment(visual) {
13928
+ const entry = this.display[this.lineAt(visual)];
13818
13929
  return entry?.comment === true || entry?.prose === true;
13819
13930
  }
13931
+ isRunOn(visual) {
13932
+ const sources = this.sources();
13933
+ if (sources.length === 0) return false;
13934
+ return visual > 0 && sources[visual] === sources[visual - 1];
13935
+ }
13820
13936
  scrollTo(row, cursor) {
13821
- const highest = Math.max(0, this.display.length - this.rows());
13822
- const wanted = this.starts.get(row) ?? row;
13823
- const at = this.starts.get(cursor);
13937
+ const highest = Math.max(0, this.tallest() - this.rows());
13938
+ const wanted = this.visualOf(this.starts.get(row) ?? row);
13939
+ const line = this.starts.get(cursor);
13940
+ const at = line === void 0 ? void 0 : this.visualOf(line);
13824
13941
  const kept = cursor >= row && cursor < row + this.rows() && at !== void 0 ? Math.max(wanted, at - this.rows() + 1) : wanted;
13825
13942
  const clamped = Math.max(0, Math.min(highest, kept));
13826
13943
  if (this.code.scrollY !== clamped) this.code.scrollY = clamped;
@@ -13828,8 +13945,9 @@ var DiffView = class {
13828
13945
  }
13829
13946
  paint(paintOf, from, rows) {
13830
13947
  const colors = /* @__PURE__ */ new Map();
13831
- const last = Math.min(this.display.length, from + rows + OVERSCAN);
13832
- for (let index = Math.max(0, from - OVERSCAN); index < last; index++) {
13948
+ const first = this.lineAt(Math.max(0, from - OVERSCAN));
13949
+ const last = Math.min(this.display.length, this.lineAt(from + rows + OVERSCAN) + 1);
13950
+ for (let index = first; index < last; index++) {
13833
13951
  const entry = this.display[index];
13834
13952
  if (entry === void 0) continue;
13835
13953
  const paint = entry.comment || entry.prose ? NOTE_PAINT : paintOf(entry.row);
@@ -14587,6 +14705,7 @@ var Screen = class {
14587
14705
  if (shown === void 0) return;
14588
14706
  const patch = shown.patch;
14589
14707
  this.paintSticky(state, state.top);
14708
+ this.view.setWrap(state.wrap);
14590
14709
  this.view.show(patch, notesFor(state, patch.path), gapRowSet(shown), proseFor(state, patch.path));
14591
14710
  this.view.fit(this.diffScroll.height);
14592
14711
  const height = this.view.rows();
@@ -14750,8 +14869,10 @@ var Screen = class {
14750
14869
  paintGutter(state, top, height) {
14751
14870
  const [from, to] = selectionRange(state);
14752
14871
  const marked = markedRows(state);
14872
+ const drawn = this.view.drawn();
14873
+ const bare = (visual) => visual >= drawn || this.view.isComment(visual) || this.view.isRunOn(visual);
14753
14874
  const rows = Array.from({ length: height }, (_, index) => {
14754
- if (this.view.isComment(top + index)) return ` `;
14875
+ if (bare(top + index)) return ` `;
14755
14876
  const row = this.view.rowAt(top + index);
14756
14877
  return `${row === state.cursor || state.selecting && row >= from && row <= to ? marks().cursor : " "}${marked.has(row) ? marks().comment : " "}`;
14757
14878
  });
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "bin": {
22
22
  "adiff": "./bin/adiff.js"
23
23
  },
24
- "version": "0.1.0-alpha.13",
24
+ "version": "0.1.0-alpha.14",
25
25
  "description": "Review agent work across git worktrees like a PR, and hand the comments back to the agent.",
26
26
  "license": "MIT",
27
27
  "repository": {