@eliya-oss/agent-diff 0.1.0-alpha.194 → 0.1.0-alpha.196

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,32 @@
1
1
  # @eliya-oss/agent-diff
2
2
 
3
+ ## 0.1.0-alpha.196
4
+
5
+ ### Patch Changes
6
+
7
+ - feat(CLI): `comment take --new` hands over only comments the review has not handed over before, so a `--wait` ends on a new comment, a reply, or a thread reopened or restored rather than on one the agent is already working on.
8
+
9
+ <details><summary>What was wrong</summary>
10
+
11
+ A wait returned at once whenever any comment was still owed an answer, so an agent listening in the background was woken again and again by the comment it was already working on.
12
+
13
+ </details>
14
+
15
+ ## 0.1.0-alpha.195
16
+
17
+ ### Patch Changes
18
+
19
+ - fix(comment delivery): a comment whose lines were changed or deleted stays where the change is and is marked outdated, instead of landing on a look-alike line elsewhere in the file.
20
+
21
+ <details><summary>What was wrong</summary>
22
+
23
+ A comment on two lines that a later commit deleted showed up on a near-identical line in another
24
+ method of the same file, as if it were about that code. Comments now follow their lines through
25
+ git's diff from the version they were written on, and `comment list` reports `outdated: true` with
26
+ the original snippet when the commented lines changed.
27
+
28
+ </details>
29
+
3
30
  ## 0.1.0-alpha.194
4
31
 
5
32
  ### Patch Changes
package/dist/main.js CHANGED
@@ -10083,7 +10083,7 @@ var init_config = __esmMin((() => {
10083
10083
  //#region package.json
10084
10084
  init_pane();
10085
10085
  init_config();
10086
- var version$1 = "0.1.0-alpha.194";
10086
+ var version$1 = "0.1.0-alpha.196";
10087
10087
  //#endregion
10088
10088
  //#region src/cli/error.ts
10089
10089
  var UnknownCommand, MissingOption, UnknownField, UnknownOption, BadOption, RegistryUnanswered, NotServed, BadRequest;
@@ -10291,7 +10291,7 @@ var init_upgrade$1 = __esmMin((() => {
10291
10291
  }));
10292
10292
  //#endregion
10293
10293
  //#region src/cli/catalog.ts
10294
- var WAIT_MOST, worktreeOf$1, repoOf$1, branchOf, fieldsOption, addressing, baseOf, based, repo, opening$2, file, range, READ_A_BRANCH, WRITE_COMMENTS, ANSWER_COMMENTS, FOLLOW_UP, DRAFTS, SET_UP, withFields, commands$1, catalog, commandNames, findCommand, VALUED_ANYWHERE, KNOWN_ANYWHERE, valuedIn, knownIn, verbsUnder, groups, MIN_EDITS, distance, CHARS_PER_EDIT, nearestCommand;
10294
+ var WAIT_MOST, worktreeOf$1, repoOf$1, branchOf, fieldsOption, addressing, baseOf$1, based, repo, opening$2, file, range, READ_A_BRANCH, WRITE_COMMENTS, ANSWER_COMMENTS, FOLLOW_UP, DRAFTS, SET_UP, withFields, commands$1, catalog, commandNames, findCommand, VALUED_ANYWHERE, KNOWN_ANYWHERE, valuedIn, knownIn, verbsUnder, groups, MIN_EDITS, distance, CHARS_PER_EDIT, nearestCommand;
10295
10295
  var init_catalog = __esmMin((() => {
10296
10296
  WAIT_MOST = 86400;
10297
10297
  worktreeOf$1 = {
@@ -10323,13 +10323,13 @@ var init_catalog = __esmMin((() => {
10323
10323
  repoOf$1,
10324
10324
  branchOf
10325
10325
  ];
10326
- baseOf = {
10326
+ baseOf$1 = {
10327
10327
  name: "base",
10328
10328
  required: false,
10329
10329
  value: "ref",
10330
10330
  about: "Ref to diff against, instead of the one this branch is stacked on. `auto` asks for the stacked parent explicitly"
10331
10331
  };
10332
- based = [...addressing, baseOf];
10332
+ based = [...addressing, baseOf$1];
10333
10333
  repo = {
10334
10334
  name: "repo",
10335
10335
  required: true,
@@ -10392,7 +10392,7 @@ var init_catalog = __esmMin((() => {
10392
10392
  group: READ_A_BRANCH,
10393
10393
  addresses: "repo",
10394
10394
  safety: "read",
10395
- options: [repo, baseOf],
10395
+ options: [repo, baseOf$1],
10396
10396
  dataKey: "branches",
10397
10397
  example: "adiff branch list --repo . --fields branch,files"
10398
10398
  },
@@ -10405,7 +10405,7 @@ var init_catalog = __esmMin((() => {
10405
10405
  options: [
10406
10406
  repo,
10407
10407
  opening$2,
10408
- baseOf
10408
+ baseOf$1
10409
10409
  ],
10410
10410
  dataKey: "",
10411
10411
  example: "adiff review open --repo . --branch add-invitations"
@@ -10419,7 +10419,7 @@ var init_catalog = __esmMin((() => {
10419
10419
  options: [
10420
10420
  repo,
10421
10421
  opening$2,
10422
- baseOf
10422
+ baseOf$1
10423
10423
  ],
10424
10424
  dataKey: "pane",
10425
10425
  example: "adiff review pane --repo ."
@@ -10602,14 +10602,23 @@ var init_catalog = __esmMin((() => {
10602
10602
  group: ANSWER_COMMENTS,
10603
10603
  addresses: "review",
10604
10604
  safety: "read",
10605
- options: [...addressing, {
10606
- name: "wait",
10607
- required: false,
10608
- value: "seconds",
10609
- about: `Block until a comment arrives or the timeout elapses. A whole number of seconds from 1 to ${WAIT_MOST}; anything else is refused`
10610
- }],
10605
+ options: [
10606
+ ...addressing,
10607
+ {
10608
+ name: "wait",
10609
+ required: false,
10610
+ value: "seconds",
10611
+ about: `Block until a comment arrives or the timeout elapses. A whole number of seconds from 1 to ${WAIT_MOST}; anything else is refused`
10612
+ },
10613
+ {
10614
+ name: "new",
10615
+ required: false,
10616
+ value: "flag",
10617
+ about: "Hand over only comments this review has not handed over before, so a wait ends on something new"
10618
+ }
10619
+ ],
10611
10620
  dataKey: "comments",
10612
- example: "adiff comment take --worktree . --wait 300"
10621
+ example: "adiff comment take --worktree . --new --wait 6900"
10613
10622
  },
10614
10623
  {
10615
10624
  name: "comment answer",
@@ -11628,11 +11637,69 @@ var init_model$5 = __esmMin((() => {
11628
11637
  lineOn = (row, side) => side === "new" ? row.newLine : row.oldLine;
11629
11638
  }));
11630
11639
  //#endregion
11640
+ //#region src/domain/patch/sticky.ts
11641
+ var CLOSER, COMMENT, LOOKAHEAD, indentOf, pinnable, limitFrom, enclosing, read$3, enclosedBy, scopeLines, stickyChain, kept;
11642
+ var init_sticky = __esmMin((() => {
11643
+ CLOSER = /^[)\]}>;,]/;
11644
+ COMMENT = /^(\/\/|\/\*|\*|#|<!--)/;
11645
+ LOOKAHEAD = 5;
11646
+ indentOf = (text) => text.length - text.trimStart().length;
11647
+ pinnable = (text) => {
11648
+ const trimmed = text.trim();
11649
+ if (trimmed.length === 0) return false;
11650
+ return !CLOSER.test(trimmed) && !COMMENT.test(trimmed);
11651
+ };
11652
+ limitFrom = (source, index) => {
11653
+ const here = source[index] ?? "";
11654
+ if (here.trim().length > 0) return indentOf(here);
11655
+ const ahead = source.slice(index, index + LOOKAHEAD).find((line) => line.trim().length > 0);
11656
+ return ahead === void 0 ? 0 : indentOf(ahead);
11657
+ };
11658
+ enclosing = (source) => {
11659
+ const open = [];
11660
+ const found = [];
11661
+ source.forEach((text, index) => {
11662
+ const limit = limitFrom(source, index);
11663
+ const outer = open.findLast((at) => indentOf(source[at] ?? "") < limit);
11664
+ found.push(outer === void 0 ? 0 : outer + 1);
11665
+ if (!pinnable(text)) return;
11666
+ const indent = indentOf(text);
11667
+ while (open.length > 0 && indentOf(source[open.at(-1) ?? 0] ?? "") >= indent) open.pop();
11668
+ open.push(index);
11669
+ });
11670
+ return found;
11671
+ };
11672
+ read$3 = /* @__PURE__ */ new WeakMap();
11673
+ enclosedBy = (source) => {
11674
+ const known = read$3.get(source);
11675
+ if (known !== void 0) return known;
11676
+ const found = enclosing(source);
11677
+ read$3.set(source, found);
11678
+ return found;
11679
+ };
11680
+ scopeLines = (source) => [...new Set(enclosedBy(source).filter((line) => line > 0))].toSorted((left, right) => left - right);
11681
+ stickyChain = (source, line, max) => {
11682
+ const index = line - 1;
11683
+ if (index <= 0 || index >= source.length) return [];
11684
+ const outer = enclosedBy(source);
11685
+ const chain = [];
11686
+ for (let at = outer[index] ?? 0; at > 0; at = outer[at - 1] ?? 0) chain.push(source[at - 1] ?? "");
11687
+ return kept(chain.toReversed(), max);
11688
+ };
11689
+ kept = (chain, max) => {
11690
+ if (chain.length <= max || max < 2) return chain.slice(0, max);
11691
+ const outer = chain[0] ?? "";
11692
+ const inner = chain.slice(chain.length - (max - 1));
11693
+ return [`${outer} ⋯`, ...inner];
11694
+ };
11695
+ }));
11696
+ //#endregion
11631
11697
  //#region src/domain/patch/anchor.ts
11632
- var sideOf$1, linesOn, anchorFor, rowsForRange, sideLines, runsAt, nearestRun, SHORTEST_NEAR, PER_EDIT, edits, isNear, nearestLike, foundExactly, foundAlike, foundAgain;
11698
+ var sideOf$1, linesOn, anchorFor, rowsForRange, sideLines, runsAt, nearestRun, SHORTEST_NEAR, PER_EDIT, edits, isNear, nearestLike, exactlyIn, alikeIn, againIn, foundExactly, sourceLines, foundInScope;
11633
11699
  var init_anchor = __esmMin((() => {
11634
11700
  init_dist();
11635
11701
  init_model$5();
11702
+ init_sticky();
11636
11703
  sideOf$1 = (rows) => rows.some((row) => isSome(row.newLine)) ? "new" : "old";
11637
11704
  linesOn = (rows, side) => rows.flatMap((row) => match$3(lineOn(row, side), {
11638
11705
  onNone: () => [],
@@ -11696,10 +11763,9 @@ var init_anchor = __esmMin((() => {
11696
11763
  return room >= SHORTEST_NEAR && edits(one, other) <= Math.floor(room / PER_EDIT);
11697
11764
  };
11698
11765
  nearestLike = (lines, said, near) => lines.filter((here) => isNear(here.text, said)).toSorted((one, other) => Math.abs(one.line - near) - Math.abs(other.line - near))[0]?.line;
11699
- foundExactly = (patch, wanted) => {
11766
+ exactlyIn = (lines, wanted) => {
11700
11767
  const said = wanted.snippet.split("\n");
11701
11768
  if (said.every((text) => text.trim().length === 0)) return none();
11702
- const lines = sideLines(patch, wanted.side);
11703
11769
  const whole = nearestRun(lines, said, wanted.start);
11704
11770
  if (whole !== void 0) return some({
11705
11771
  side: wanted.side,
@@ -11715,17 +11781,78 @@ var init_anchor = __esmMin((() => {
11715
11781
  end: opening
11716
11782
  });
11717
11783
  };
11718
- foundAlike = (patch, wanted) => {
11784
+ alikeIn = (lines, wanted) => {
11719
11785
  const first = wanted.snippet.split("\n")[0] ?? "";
11720
11786
  if (first.trim().length === 0) return none();
11721
- const alike = nearestLike(sideLines(patch, wanted.side), first, wanted.start);
11787
+ const alike = nearestLike(lines, first, wanted.start);
11722
11788
  return alike === void 0 ? none() : some({
11723
11789
  side: wanted.side,
11724
11790
  start: alike,
11725
11791
  end: alike
11726
11792
  });
11727
11793
  };
11728
- foundAgain = (patch, wanted) => orElse(foundExactly(patch, wanted), () => foundAlike(patch, wanted));
11794
+ againIn = (lines, wanted) => orElse(exactlyIn(lines, wanted), () => alikeIn(lines, wanted));
11795
+ foundExactly = (patch, wanted) => exactlyIn(sideLines(patch, wanted.side), wanted);
11796
+ sourceLines = (source) => source.map((text, at) => ({
11797
+ line: at + 1,
11798
+ text
11799
+ }));
11800
+ foundInScope = (source, wanted) => {
11801
+ const outer = enclosedBy(source);
11802
+ const scope = outer[Math.max(1, Math.min(wanted.start, source.length)) - 1] ?? 0;
11803
+ const inScope = sourceLines(source).filter((here) => (outer[here.line - 1] ?? 0) === scope);
11804
+ return againIn(inScope, wanted);
11805
+ };
11806
+ }));
11807
+ //#endregion
11808
+ //#region src/domain/patch/follow.ts
11809
+ var MARKER, countOf$1, spansOf$2, changedAt, isBefore, isInside, landing, insertedWithin, within, followed;
11810
+ var init_follow = __esmMin((() => {
11811
+ MARKER = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
11812
+ countOf$1 = (said) => said === void 0 ? 1 : Number(said);
11813
+ spansOf$2 = (diff) => diff.hunks.flatMap((hunk) => {
11814
+ const found = MARKER.exec(hunk.marker);
11815
+ if (found === null) return [];
11816
+ return [{
11817
+ oldStart: Number(found[1]),
11818
+ oldCount: countOf$1(found[2]),
11819
+ newStart: Number(found[3]),
11820
+ newCount: countOf$1(found[4])
11821
+ }];
11822
+ });
11823
+ changedAt = (span) => span.newCount > 0 ? span.newStart : span.newStart + 1;
11824
+ isBefore = (span, line) => span.oldCount > 0 ? line < span.oldStart : line <= span.oldStart;
11825
+ isInside = (span, line) => span.oldCount > 0 && line >= span.oldStart && line < span.oldStart + span.oldCount;
11826
+ landing = (spans, line) => {
11827
+ let shift = 0;
11828
+ for (const span of spans) {
11829
+ if (isBefore(span, line)) return {
11830
+ line: line + shift,
11831
+ touched: false
11832
+ };
11833
+ if (isInside(span, line)) return {
11834
+ line: changedAt(span),
11835
+ touched: true
11836
+ };
11837
+ shift += span.newCount - span.oldCount;
11838
+ }
11839
+ return {
11840
+ line: line + shift,
11841
+ touched: false
11842
+ };
11843
+ };
11844
+ insertedWithin = (spans, start, end) => spans.some((span) => span.oldCount === 0 && span.oldStart >= start && span.oldStart < end);
11845
+ within = (line, length) => Math.max(1, Math.min(line, Math.max(1, length)));
11846
+ followed = (diff, range, length) => {
11847
+ const spans = spansOf$2(diff);
11848
+ const first = landing(spans, range.start);
11849
+ const last = landing(spans, range.end);
11850
+ return {
11851
+ start: within(first.line, length),
11852
+ end: within(Math.max(first.line, last.line), length),
11853
+ outdated: first.touched || last.touched || insertedWithin(spans, range.start, range.end) || spans.some((span) => span.oldCount > 0 && span.oldStart > range.start && span.oldStart < range.end)
11854
+ };
11855
+ };
11729
11856
  }));
11730
11857
  //#endregion
11731
11858
  //#region src/domain/patch/reindent.ts
@@ -12032,66 +12159,10 @@ var init_parse = __esmMin((() => {
12032
12159
  };
12033
12160
  }));
12034
12161
  //#endregion
12035
- //#region src/domain/patch/sticky.ts
12036
- var CLOSER, COMMENT, LOOKAHEAD, indentOf, pinnable, limitFrom, enclosing, read$3, enclosedBy, scopeLines, stickyChain, kept;
12037
- var init_sticky = __esmMin((() => {
12038
- CLOSER = /^[)\]}>;,]/;
12039
- COMMENT = /^(\/\/|\/\*|\*|#|<!--)/;
12040
- LOOKAHEAD = 5;
12041
- indentOf = (text) => text.length - text.trimStart().length;
12042
- pinnable = (text) => {
12043
- const trimmed = text.trim();
12044
- if (trimmed.length === 0) return false;
12045
- return !CLOSER.test(trimmed) && !COMMENT.test(trimmed);
12046
- };
12047
- limitFrom = (source, index) => {
12048
- const here = source[index] ?? "";
12049
- if (here.trim().length > 0) return indentOf(here);
12050
- const ahead = source.slice(index, index + LOOKAHEAD).find((line) => line.trim().length > 0);
12051
- return ahead === void 0 ? 0 : indentOf(ahead);
12052
- };
12053
- enclosing = (source) => {
12054
- const open = [];
12055
- const found = [];
12056
- source.forEach((text, index) => {
12057
- const limit = limitFrom(source, index);
12058
- const outer = open.findLast((at) => indentOf(source[at] ?? "") < limit);
12059
- found.push(outer === void 0 ? 0 : outer + 1);
12060
- if (!pinnable(text)) return;
12061
- const indent = indentOf(text);
12062
- while (open.length > 0 && indentOf(source[open.at(-1) ?? 0] ?? "") >= indent) open.pop();
12063
- open.push(index);
12064
- });
12065
- return found;
12066
- };
12067
- read$3 = /* @__PURE__ */ new WeakMap();
12068
- enclosedBy = (source) => {
12069
- const known = read$3.get(source);
12070
- if (known !== void 0) return known;
12071
- const found = enclosing(source);
12072
- read$3.set(source, found);
12073
- return found;
12074
- };
12075
- scopeLines = (source) => [...new Set(enclosedBy(source).filter((line) => line > 0))].toSorted((left, right) => left - right);
12076
- stickyChain = (source, line, max) => {
12077
- const index = line - 1;
12078
- if (index <= 0 || index >= source.length) return [];
12079
- const outer = enclosedBy(source);
12080
- const chain = [];
12081
- for (let at = outer[index] ?? 0; at > 0; at = outer[at - 1] ?? 0) chain.push(source[at - 1] ?? "");
12082
- return kept(chain.toReversed(), max);
12083
- };
12084
- kept = (chain, max) => {
12085
- if (chain.length <= max || max < 2) return chain.slice(0, max);
12086
- const outer = chain[0] ?? "";
12087
- const inner = chain.slice(chain.length - (max - 1));
12088
- return [`${outer} ⋯`, ...inner];
12089
- };
12090
- }));
12091
- //#endregion
12092
12162
  //#region src/domain/patch/index.ts
12093
12163
  var init_patch = __esmMin((() => {
12094
12164
  init_anchor();
12165
+ init_follow();
12095
12166
  init_parse();
12096
12167
  init_sticky();
12097
12168
  init_model$5();
@@ -12297,11 +12368,12 @@ var init_service$2 = __esmMin((() => {
12297
12368
  });
12298
12369
  findKept = fn("Git.kept")(function* (worktree, blob) {
12299
12370
  if (blob.length === 0) return none();
12371
+ const named = blob.includes(":") ? blob : `${blob}^{blob}`;
12300
12372
  const found = (yield* gitOrEmpty(worktree.path, [
12301
12373
  "rev-parse",
12302
12374
  "--verify",
12303
12375
  "--quiet",
12304
- `${blob}^{blob}`
12376
+ named
12305
12377
  ])).trim();
12306
12378
  return found.length === 0 ? none() : some(found);
12307
12379
  });
@@ -12523,7 +12595,8 @@ var init_schema = __esmMin((() => {
12523
12595
  snippet: String$1,
12524
12596
  side: Side,
12525
12597
  start: Int,
12526
- end: Int
12598
+ end: Int,
12599
+ version: optionalKey(String$1)
12527
12600
  });
12528
12601
  StoredComment = Struct({
12529
12602
  id: String$1,
@@ -12788,11 +12861,12 @@ var init_service$1 = __esmMin((() => {
12788
12861
  }
12789
12862
  });
12790
12863
  cursorOps = (state, inbox, spoken, changeState) => {
12791
- const owedIn = fn("Store.owedIn")(function* (worktreePath) {
12864
+ const handedIn = fn("Store.handedIn")(function* (worktreePath, handing) {
12792
12865
  const batches = yield* inbox(worktreePath);
12793
12866
  const current = yield* state(worktreePath);
12794
12867
  const answered = new Set((yield* spoken(worktreePath)).map((entry) => entry.comment));
12795
- const owed = (comment) => !answered.has(comment.id) && !Object.hasOwn(current.settled, comment.id) && !Object.hasOwn(current.removed, comment.id);
12868
+ const taken = current.taken ?? {};
12869
+ const owed = (comment) => !answered.has(comment.id) && !Object.hasOwn(current.settled, comment.id) && !Object.hasOwn(current.removed, comment.id) && (handing === "owed" || !Object.hasOwn(taken, comment.id));
12796
12870
  return batches.flatMap((batch) => {
12797
12871
  const comments = batch.comments.filter(owed);
12798
12872
  return comments.length === 0 ? [] : [{
@@ -12803,9 +12877,10 @@ var init_service$1 = __esmMin((() => {
12803
12877
  }];
12804
12878
  });
12805
12879
  });
12880
+ const owedIn = (worktreePath) => handedIn(worktreePath, "owed");
12806
12881
  return {
12807
- take: fn("Store.take")(function* (worktreePath, at) {
12808
- const batches = yield* owedIn(worktreePath);
12882
+ take: fn("Store.take")(function* (worktreePath, at, handing = "owed") {
12883
+ const batches = yield* handedIn(worktreePath, handing);
12809
12884
  const ids = idsIn$1(batches);
12810
12885
  if (ids.length > 0) yield* changeState(worktreePath, takes(ids, at));
12811
12886
  return batches;
@@ -13378,7 +13453,7 @@ var init_branches$1 = __esmMin((() => {
13378
13453
  }));
13379
13454
  //#endregion
13380
13455
  //#region src/review/patches.ts
13381
- var findPatch, blobOf, anchor, list$4, source, before, linesAround, GENERATED_NAME, lineOf$2, isNote$1, shownRow, shownHunk, scopesOf, shownFile, sourceShown, fileShown$1, shownAs, onDisk$1, show$3;
13456
+ var findPatch, blobOf, anchorWith, anchor, list$4, source, before, linesAround, GENERATED_NAME, lineOf$2, isNote$1, shownRow, shownHunk, scopesOf, shownFile, sourceShown, fileShown$1, shownAs, onDisk$1, show$3;
13382
13457
  var init_patches = __esmMin((() => {
13383
13458
  init_dist();
13384
13459
  init_patch();
@@ -13387,7 +13462,7 @@ var init_patches = __esmMin((() => {
13387
13462
  init_branches$1();
13388
13463
  findPatch = (patches, file) => fromNullishOr(patches.find((patch) => patch.path === file));
13389
13464
  blobOf = (patches, file) => map$5(findPatch(patches, file), (patch) => patch.blob);
13390
- anchor = fn("Review.Diff.anchor")(function* (worktree, request) {
13465
+ anchorWith = fn("Review.Diff.anchorWith")(function* (worktree, request) {
13391
13466
  const only = yield* patches(worktree, WHOLE_FILE, request.file);
13392
13467
  const found = only.length > 0 ? only : yield* patches(worktree, WHOLE_FILE);
13393
13468
  const patch = findPatch(found, request.file);
@@ -13405,9 +13480,13 @@ var init_patches = __esmMin((() => {
13405
13480
  start: request.start,
13406
13481
  end: request.end
13407
13482
  }),
13408
- onSome: succeed$1
13483
+ onSome: (made) => succeed$1({
13484
+ anchor: made,
13485
+ patch: resolved
13486
+ })
13409
13487
  });
13410
13488
  });
13489
+ anchor = (worktree, request) => map$1(anchorWith(worktree, request), (found) => found.anchor);
13411
13490
  list$4 = patches;
13412
13491
  source = fn("Review.Diff.source")(function* (worktree, file) {
13413
13492
  const found = yield* (yield* Git).source(worktree, file);
@@ -13686,8 +13765,150 @@ var init_layers$1 = __esmMin((() => {
13686
13765
  init_model$3();
13687
13766
  }));
13688
13767
  //#endregion
13768
+ //#region src/review/placing.ts
13769
+ var keptOf, baseOf, nowOnNew, nowOnOld, writtenName, unplaced, rewordedAt, standing, searched, keyOf$3, pairOf, unique$1, nowFor, placedWithout, placedThrough, placedFrom, placeOne, nowsOf, writtenOf, pairsOf, diffsOf, placedAll, versionOf;
13770
+ var init_placing = __esmMin((() => {
13771
+ init_dist();
13772
+ init_patch();
13773
+ init_git();
13774
+ keptOf = (found) => getOrElse(found, () => []);
13775
+ baseOf = (worktree) => worktree.base.length > 0 ? worktree.base : "HEAD";
13776
+ nowOnNew = fn("Review.Placing.nowOnNew")(function* (worktree, patch) {
13777
+ const git = yield* Git;
13778
+ if (patch.status === "deleted") return {
13779
+ version: none(),
13780
+ lines: []
13781
+ };
13782
+ const lines = keptOf(yield* git.source(worktree, patch.path));
13783
+ const [version] = yield* git.keep(worktree, [patch.path]);
13784
+ return {
13785
+ version: fromNullishOr(version),
13786
+ lines
13787
+ };
13788
+ });
13789
+ nowOnOld = fn("Review.Placing.nowOnOld")(function* (worktree, patch) {
13790
+ const git = yield* Git;
13791
+ if (patch.status === "added") return {
13792
+ version: none(),
13793
+ lines: []
13794
+ };
13795
+ const named = `${baseOf(worktree)}:${patch.previousPath}`;
13796
+ const version = yield* git.kept(worktree, named);
13797
+ return {
13798
+ version,
13799
+ lines: isNone(version) ? [] : keptOf(yield* git.blob(worktree, patch.previousPath))
13800
+ };
13801
+ });
13802
+ writtenName = (anchor) => anchor.version ?? (anchor.side === "new" ? anchor.blob : "");
13803
+ unplaced = (anchor) => ({
13804
+ start: anchor.start,
13805
+ end: anchor.end,
13806
+ placed: false,
13807
+ outdated: false,
13808
+ reworded: false
13809
+ });
13810
+ rewordedAt = (anchor, lines, start, end) => {
13811
+ const first = anchor.snippet.split("\n")[0] ?? "";
13812
+ if (first.trim().length === 0) return false;
13813
+ return lines.slice(start - 1, end).some((line) => line === first || isNear(line, first));
13814
+ };
13815
+ standing = (anchor) => ({
13816
+ ...unplaced(anchor),
13817
+ placed: true
13818
+ });
13819
+ searched = (anchor, now) => match$3(foundInScope(now.lines, anchor), {
13820
+ onNone: () => unplaced(anchor),
13821
+ onSome: (range) => ({
13822
+ start: range.start,
13823
+ end: range.end,
13824
+ placed: true,
13825
+ outdated: true,
13826
+ reworded: rewordedAt(anchor, now.lines, range.start, range.end)
13827
+ })
13828
+ });
13829
+ keyOf$3 = (anchor) => `${anchor.side}\u0000${anchor.path}`;
13830
+ pairOf = (from, to) => `${from}..${to}`;
13831
+ unique$1 = (keys) => [...new Set(keys)];
13832
+ nowFor = (anchor, read) => {
13833
+ const now = read.nows.get(keyOf$3(anchor));
13834
+ return now === void 0 || isNone(now.version) ? none() : some(now);
13835
+ };
13836
+ placedWithout = (anchor, now) => anchor.snippet.trim().length === 0 ? standing(anchor) : searched(anchor, now);
13837
+ placedThrough = (anchor, now, diff) => {
13838
+ const moved = followed(diff, anchor, now.lines.length);
13839
+ return {
13840
+ ...moved,
13841
+ placed: true,
13842
+ reworded: moved.outdated && rewordedAt(anchor, now.lines, moved.start, moved.end)
13843
+ };
13844
+ };
13845
+ placedFrom = (anchor, now, was, read) => {
13846
+ const version = getOrElse(now.version, () => was);
13847
+ if (was === version) return standing(anchor);
13848
+ const diff = read.diffs.get(pairOf(was, version));
13849
+ return diff === void 0 ? standing(anchor) : placedThrough(anchor, now, diff);
13850
+ };
13851
+ placeOne = (anchor, read) => {
13852
+ if (anchor.start === 1e5) return unplaced(anchor);
13853
+ return match$3(nowFor(anchor, read), {
13854
+ onNone: () => unplaced(anchor),
13855
+ onSome: (now) => match$3(read.written.get(writtenName(anchor)) ?? none(), {
13856
+ onNone: () => placedWithout(anchor, now),
13857
+ onSome: (was) => placedFrom(anchor, now, was, read)
13858
+ })
13859
+ });
13860
+ };
13861
+ nowsOf = (worktree, byPath, shown) => {
13862
+ const nowOf = (anchor, patch) => {
13863
+ const reading = anchor.side === "new" ? nowOnNew(worktree, patch) : nowOnOld(worktree, patch);
13864
+ return map$1(reading, (now) => [keyOf$3(anchor), now]);
13865
+ };
13866
+ const reads = [...new Map(shown.map((anchor) => [keyOf$3(anchor), anchor])).values()].flatMap((anchor) => {
13867
+ const patch = byPath.get(anchor.path);
13868
+ return patch === void 0 ? [] : [nowOf(anchor, patch)];
13869
+ });
13870
+ return map$1(all(reads, { concurrency: 8 }), (found) => new Map(found));
13871
+ };
13872
+ writtenOf = fn("Review.Placing.writtenOf")(function* (worktree, shown) {
13873
+ const git = yield* Git;
13874
+ const names = unique$1(shown.map(writtenName).filter((name) => name.length > 0));
13875
+ const keptOne = (name) => map$1(git.kept(worktree, name), (found) => [name, found]);
13876
+ return new Map(yield* forEach(names, keptOne, { concurrency: 8 }));
13877
+ });
13878
+ pairsOf = (shown, read) => shown.flatMap((anchor) => {
13879
+ const was = read.written.get(writtenName(anchor)) ?? none();
13880
+ const now = read.nows.get(keyOf$3(anchor))?.version ?? none();
13881
+ if (isNone(was) || isNone(now) || was.value === now.value) return [];
13882
+ return [[was.value, now.value]];
13883
+ });
13884
+ diffsOf = fn("Review.Placing.diffsOf")(function* (worktree, pairs) {
13885
+ const git = yield* Git;
13886
+ const between = ([from, to]) => map$1(git.between(worktree, from, to, 0), (raw) => [pairOf(from, to), parsePatches(raw)[0]]);
13887
+ const wanted = [...new Map(pairs.map((pair) => [pairOf(pair[0], pair[1]), pair])).values()];
13888
+ return new Map(yield* forEach(wanted, between, { concurrency: 8 }));
13889
+ });
13890
+ placedAll = fn("Review.Placing.placedAll")(function* (worktree, patches, anchors) {
13891
+ const byPath = new Map(patches.map((patch) => [patch.path, patch]));
13892
+ const shown = anchors.filter((anchor) => byPath.has(anchor.path) && anchor.start !== 1e5);
13893
+ const nows = yield* nowsOf(worktree, byPath, shown);
13894
+ const written = yield* writtenOf(worktree, shown);
13895
+ const read = {
13896
+ nows,
13897
+ written,
13898
+ diffs: yield* diffsOf(worktree, pairsOf(shown, {
13899
+ nows,
13900
+ written
13901
+ }))
13902
+ };
13903
+ return anchors.map((anchor) => byPath.has(anchor.path) ? placeOne(anchor, read) : unplaced(anchor));
13904
+ });
13905
+ versionOf = fn("Review.Placing.versionOf")(function* (worktree, patch, side) {
13906
+ return (side === "new" ? yield* nowOnNew(worktree, patch) : yield* nowOnOld(worktree, patch)).version;
13907
+ });
13908
+ }));
13909
+ //#endregion
13689
13910
  //#region src/review/comments.ts
13690
- var POLL, bodyOf, saidTo, spunOf, sentOf, placedNow$2, linesIn, trimmedLines, NAMES_SOMETHING, worthMatching, blockAt, wholeSnippetIn, stillInFile, foundOutsideTheHunks, flatten, listSent, submitMany, submit, without$2, reply, threadBefore, layerOver, layersOn, take, awaitTaken, markRead;
13911
+ var POLL, bodyOf, saidTo, spunOf, sentOf, placedNow$1, linesIn, trimmedLines, NAMES_SOMETHING, worthMatching, blockAt, wholeSnippetIn, stillInFile, foundOutsideTheHunks, flatten, listSent, submitMany, submit, without$2, reply, threadBefore, layerOver, layersOn, take, awaitTaken, markRead;
13691
13912
  var init_comments$1 = __esmMin((() => {
13692
13913
  init_dist();
13693
13914
  init_patch();
@@ -13697,6 +13918,7 @@ var init_comments$1 = __esmMin((() => {
13697
13918
  init_error$2();
13698
13919
  init_branches$1();
13699
13920
  init_patches();
13921
+ init_placing();
13700
13922
  POLL = "500 millis";
13701
13923
  bodyOf = (entry) => entry.body;
13702
13924
  saidTo = (spoken, id) => spoken.filter((entry) => entry.comment === id).length;
@@ -13731,6 +13953,8 @@ var init_comments$1 = __esmMin((() => {
13731
13953
  settled: Object.hasOwn(settled, comment.id),
13732
13954
  removed: Object.hasOwn(removed, comment.id),
13733
13955
  stale: comment.head !== head,
13956
+ outdated: comment.placed !== false && comment.outdated === true,
13957
+ reworded: comment.placed !== false && comment.reworded === true,
13734
13958
  outside: !shown.has(comment.file) || comment.placed === false,
13735
13959
  unread: Math.max(0, said.length - seen),
13736
13960
  asks: last?.voice === "agent" && last.asks,
@@ -13743,33 +13967,33 @@ var init_comments$1 = __esmMin((() => {
13743
13967
  }))
13744
13968
  };
13745
13969
  };
13746
- placedNow$2 = (patches, comment) => {
13747
- const patch = patches.find((candidate) => candidate.path === comment.file);
13748
- if (patch === void 0) return {
13749
- ...comment,
13750
- placed: false
13751
- };
13752
- if (comment.start === 1e5) return {
13753
- ...comment,
13754
- placed: false
13755
- };
13756
- if (comment.snippet.trim().length === 0) return {
13757
- ...comment,
13758
- placed: true
13759
- };
13760
- return match$3(foundAgain(patch, comment), {
13761
- onNone: () => ({
13970
+ placedNow$1 = fn("Review.Comment.placedNow")(function* (reading, held) {
13971
+ const anchors = held.map((comment) => ({
13972
+ path: comment.file,
13973
+ side: comment.side,
13974
+ start: comment.start,
13975
+ end: comment.end,
13976
+ snippet: comment.snippet,
13977
+ blob: comment.blob ?? "",
13978
+ version: comment.version
13979
+ }));
13980
+ const placed = yield* placedAll(reading.worktree, reading.patches, anchors);
13981
+ return held.map((comment, at) => {
13982
+ const sits = placed[at];
13983
+ if (sits === void 0) return {
13762
13984
  ...comment,
13763
13985
  placed: false
13764
- }),
13765
- onSome: (range) => ({
13986
+ };
13987
+ return {
13766
13988
  ...comment,
13767
- start: range.start,
13768
- end: range.end,
13769
- placed: true
13770
- })
13989
+ start: sits.start,
13990
+ end: sits.end,
13991
+ placed: sits.placed,
13992
+ outdated: sits.outdated,
13993
+ reworded: sits.reworded
13994
+ };
13771
13995
  });
13772
- };
13996
+ });
13773
13997
  linesIn = (found) => getOrElse(found, () => []);
13774
13998
  trimmedLines = (snippet) => snippet.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
13775
13999
  NAMES_SOMETHING = /[A-Za-z0-9_$]{3}/;
@@ -13813,6 +14037,8 @@ var init_comments$1 = __esmMin((() => {
13813
14037
  start: comment.anchor.start,
13814
14038
  end: comment.anchor.end,
13815
14039
  snippet: comment.anchor.snippet,
14040
+ blob: comment.anchor.blob,
14041
+ version: comment.anchor.version,
13816
14042
  body: comment.body,
13817
14043
  replyTo: comment.replyTo,
13818
14044
  ...comment.theirs === true ? { theirs: true } : {},
@@ -13824,7 +14050,7 @@ var init_comments$1 = __esmMin((() => {
13824
14050
  const spoken = yield* store.answers(worktree.path);
13825
14051
  const current = yield* store.state(worktree.path);
13826
14052
  const shown = new Set(reading.patches.map((patch) => patch.path));
13827
- const placed = flatten(yield* store.inbox(worktree.path)).map((comment) => placedNow$2(reading.patches, comment));
14053
+ const placed = yield* placedNow$1(reading, flatten(yield* store.inbox(worktree.path)));
13828
14054
  const held = yield* foundOutsideTheHunks(worktree, placed, shown);
13829
14055
  const replies = held.filter((comment) => comment.replyTo !== void 0);
13830
14056
  const conversation = {
@@ -13842,10 +14068,17 @@ var init_comments$1 = __esmMin((() => {
13842
14068
  submitMany = fn("Review.Comment.submitMany")(function* (worktree, requests) {
13843
14069
  const store = yield* Store;
13844
14070
  const anchoring = fn("Review.Comment.anchoring")(function* (request) {
13845
- const anchored = yield* anchor(worktree, request);
14071
+ const { patch, anchor: anchored } = yield* anchorWith(worktree, request);
14072
+ const version = yield* versionOf(worktree, patch, anchored.side);
13846
14073
  return {
13847
14074
  id: request.id,
13848
- anchor: anchored,
14075
+ anchor: match$3(version, {
14076
+ onNone: () => anchored,
14077
+ onSome: (kept) => ({
14078
+ ...anchored,
14079
+ version: kept
14080
+ })
14081
+ }),
13849
14082
  body: request.body,
13850
14083
  ...request.remark === void 0 ? {} : { remark: request.remark },
13851
14084
  ...request.theirs === true ? { theirs: true } : {},
@@ -13913,12 +14146,12 @@ var init_comments$1 = __esmMin((() => {
13913
14146
  onSome: (held) => held.layers
13914
14147
  });
13915
14148
  });
13916
- take = fn("Review.Comment.take")(function* (worktreePath) {
14149
+ take = fn("Review.Comment.take")(function* (worktreePath, handing = "owed") {
13917
14150
  const store = yield* Store;
13918
14151
  const resolved = yield* realOf(worktreePath);
13919
14152
  const at = (/* @__PURE__ */ new Date()).toISOString();
13920
14153
  yield* ignore(store.noteWatching(resolved, at));
13921
- const owed = flatten(yield* store.take(resolved, at));
14154
+ const owed = flatten(yield* store.take(resolved, at, handing));
13922
14155
  if (owed.length === 0) return owed;
13923
14156
  const layers = yield* layersOn(resolved);
13924
14157
  const under = (one) => {
@@ -13931,7 +14164,7 @@ var init_comments$1 = __esmMin((() => {
13931
14164
  const carried = (one) => one.replyTo === void 0 ? one : Object.assign({}, one, { thread: threadBefore(one, held, spoken) });
13932
14165
  return owed.map(carried).map(under);
13933
14166
  });
13934
- awaitTaken = (worktreePath, deadline) => take(worktreePath).pipe(flatMap((comments) => comments.length > 0 || Date.now() >= deadline ? succeed$1(comments) : sleep(POLL).pipe(flatMap(() => awaitTaken(worktreePath, deadline)))));
14167
+ awaitTaken = (worktreePath, deadline, handing = "owed") => take(worktreePath, handing).pipe(flatMap((comments) => comments.length > 0 || Date.now() >= deadline ? succeed$1(comments) : sleep(POLL).pipe(flatMap(() => awaitTaken(worktreePath, deadline, handing)))));
13935
14168
  markRead = fn("Review.Comment.markRead")(function* (worktree, id) {
13936
14169
  const store = yield* Store;
13937
14170
  const spoken = yield* store.answers(worktree.path);
@@ -13959,12 +14192,12 @@ var init_comments$1 = __esmMin((() => {
13959
14192
  }));
13960
14193
  //#endregion
13961
14194
  //#region src/review/threads.ts
13962
- var stateOf$2, placedNow$1, choicesOf, answerOf, turnsOf, threadOf, threadsIn$1, idsIn, rootIn, rootOf, isKnown, known, list$3, clearDoing, doing, answer$3, repliesTo, settle, without$1, unsettle, remove, restore$1, settleRead;
14195
+ var stateOf$2, choicesOf, answerOf, turnsOf, threadOf, threadsIn$1, idsIn, rootIn, rootOf, isKnown, known, list$3, clearDoing, doing, answer$3, repliesTo, settle, without$1, unsettle, remove, restore$1, settleRead;
13963
14196
  var init_threads$1 = __esmMin((() => {
13964
14197
  init_dist();
13965
- init_patch();
13966
14198
  init_store();
13967
14199
  init_error$2();
14200
+ init_placing();
13968
14201
  stateOf$2 = (turns, asked, isSettled, isRemoved) => {
13969
14202
  if (isRemoved) return "removed";
13970
14203
  if (isSettled) return "done";
@@ -13972,27 +14205,6 @@ var init_threads$1 = __esmMin((() => {
13972
14205
  if (last === void 0 || last.voice === "reviewer") return "sent";
13973
14206
  return asked ? "question" : "answered";
13974
14207
  };
13975
- placedNow$1 = (patches, anchor) => {
13976
- const patch = patches.find((candidate) => candidate.path === anchor.path);
13977
- if (patch === void 0) return {
13978
- ...anchor,
13979
- placed: false
13980
- };
13981
- if (anchor.snippet.trim().length === 0) return {
13982
- ...anchor,
13983
- placed: true
13984
- };
13985
- return match$3(foundAgain(patch, anchor), {
13986
- onNone: () => ({
13987
- ...anchor,
13988
- placed: false
13989
- }),
13990
- onSome: (range) => ({
13991
- ...range,
13992
- placed: true
13993
- })
13994
- });
13995
- };
13996
14208
  choicesOf = (entry) => entry.choices === void 0 ? {} : { choices: entry.choices };
13997
14209
  answerOf = (entry) => ({
13998
14210
  body: entry.body,
@@ -14017,7 +14229,12 @@ var init_threads$1 = __esmMin((() => {
14017
14229
  const seen = [...ids].reduce((total, id) => total + (conversation.read[id] ?? 0), 0);
14018
14230
  const turns = turnsOf(replies, mine);
14019
14231
  const settled = Object.hasOwn(conversation.settled, comment.id);
14020
- const sits = placedNow$1(conversation.patches, comment.anchor);
14232
+ const sits = conversation.places.get(comment.id) ?? {
14233
+ ...comment.anchor,
14234
+ placed: false,
14235
+ outdated: false,
14236
+ reworded: false
14237
+ };
14021
14238
  const doing = conversation.doing[comment.id];
14022
14239
  return {
14023
14240
  id: comment.id,
@@ -14030,6 +14247,7 @@ var init_threads$1 = __esmMin((() => {
14030
14247
  at: batch.at,
14031
14248
  state: stateOf$2(turns, mine.at(-1)?.asks === true, settled, Object.hasOwn(conversation.removed, comment.id)),
14032
14249
  stale: batch.head !== conversation.head,
14250
+ outdated: sits.placed && sits.outdated,
14033
14251
  outside: !conversation.shown.has(comment.anchor.path) || !sits.placed,
14034
14252
  unread: Math.max(0, mine.length - seen),
14035
14253
  taken: [...ids].some((id) => Object.hasOwn(conversation.taken, id)),
@@ -14067,13 +14285,22 @@ var init_threads$1 = __esmMin((() => {
14067
14285
  const store = yield* Store;
14068
14286
  const { worktree, patches } = reading;
14069
14287
  const current = yield* store.state(worktree.path);
14070
- return threadsIn$1(yield* store.inbox(worktree.path), {
14288
+ const batches = yield* store.inbox(worktree.path);
14289
+ const roots = batches.flatMap((batch) => batch.comments).filter((comment) => comment.replyTo === void 0);
14290
+ const placed = yield* placedAll(worktree, patches, roots.map((comment) => comment.anchor));
14291
+ const places = new Map(roots.map((comment, at) => [comment.id, placed[at] ?? {
14292
+ ...comment.anchor,
14293
+ placed: false,
14294
+ outdated: false,
14295
+ reworded: false
14296
+ }]));
14297
+ return threadsIn$1(batches, {
14071
14298
  answers: yield* store.answers(worktree.path),
14072
14299
  settled: current.settled,
14073
14300
  removed: current.removed,
14074
14301
  head: worktree.head,
14075
14302
  shown: new Set(patches.map((patch) => patch.path)),
14076
- patches,
14303
+ places,
14077
14304
  read: current.read,
14078
14305
  taken: current.taken ?? {},
14079
14306
  doing: current.doing
@@ -14154,7 +14381,8 @@ var init_threads$1 = __esmMin((() => {
14154
14381
  yield* store.changeState(worktree.path, (was) => ({
14155
14382
  ...was,
14156
14383
  settled: without$1(was.settled, id),
14157
- read: without$1(was.read, id)
14384
+ read: without$1(was.read, id),
14385
+ taken: without$1(was.taken ?? {}, id)
14158
14386
  }));
14159
14387
  return { unsettled: id };
14160
14388
  });
@@ -14181,7 +14409,8 @@ var init_threads$1 = __esmMin((() => {
14181
14409
  yield* known(worktree, id);
14182
14410
  yield* store.changeState(worktree.path, (was) => ({
14183
14411
  ...was,
14184
- removed: without$1(was.removed, id)
14412
+ removed: without$1(was.removed, id),
14413
+ taken: without$1(was.taken ?? {}, id)
14185
14414
  }));
14186
14415
  return { restored: id };
14187
14416
  });
@@ -16010,7 +16239,8 @@ const banner = () => [
16010
16239
  "",
16011
16240
  "An agent working in that worktree answers them:",
16012
16241
  "",
16013
- " adiff comment take --worktree . --wait 300 block until a comment arrives",
16242
+ " adiff comment take --worktree . collect every comment owed an answer",
16243
+ " adiff comment take --worktree . --new --wait 6900 block until a new comment arrives",
16014
16244
  " adiff comment answer --worktree . --id <id> --body '…'",
16015
16245
  " adiff layers set --worktree . --json - publish a reading order, when asked",
16016
16246
  "",
@@ -17531,7 +17761,7 @@ var init_match = __esmMin((() => {
17531
17761
  }));
17532
17762
  //#endregion
17533
17763
  //#region src/tui/state.ts
17534
- var HOLDS$1, chosenNow, withChosen, EDITOR_ROW, editorRow, preferenceRows, nothingReviewed, nothingFound, initialState, selectedBranch, selectedPatch, pullHere, authorHere, theirPull, heldWhere, noteEditing, hasNoPull, onLayers, selectedLayer;
17764
+ var HOLDS$1, chosenNow, withChosen, EDITOR_ROW, editorRow, preferenceRows, nothingReviewed, nothingFound, initialState, selectedBranch, selectedPatch, pullHere, authorHere, theirPull, heldWhere, noteEditing, hasNoPull, onLayers, selectedLayer, movedPast;
17535
17765
  var init_state = __esmMin((() => {
17536
17766
  init_preferences$1();
17537
17767
  init_gaps();
@@ -17679,6 +17909,7 @@ var init_state = __esmMin((() => {
17679
17909
  hasNoPull = (state) => state.forge === "answered" && pullHere(state).length === 0;
17680
17910
  onLayers = (state) => state.rail === "layers" && state.layers.length > 0;
17681
17911
  selectedLayer = (state) => state.layers[state.layerIndex];
17912
+ movedPast = (comment) => comment.outside === true || comment.outdated === true && comment.reworded !== true;
17682
17913
  }));
17683
17914
  //#endregion
17684
17915
  //#region src/tui/cursor.ts
@@ -18315,6 +18546,7 @@ var init_layerview = __esmMin((() => {
18315
18546
  //#region src/tui/panel.ts
18316
18547
  var PANEL_SECTIONS, answersIn, newerOf, lastVoice, SECTION_OF, outsideOpen, sectionOf, sentEntry, remarkRows, panelHolds, panelEntries, panelEntry, threadChosen, MINUTE, HOUR, DAY, agoText, threadStand, STAND_WEIGHT, louderOf;
18317
18548
  var init_panel = __esmMin((() => {
18549
+ init_state();
18318
18550
  PANEL_SECTIONS = [
18319
18551
  "remarks",
18320
18552
  "held",
@@ -18343,7 +18575,7 @@ var init_panel = __esmMin((() => {
18343
18575
  answered: "answered",
18344
18576
  waiting: "with"
18345
18577
  };
18346
- outsideOpen = (comment) => comment.outside === true && comment.settled !== true && comment.removed !== true;
18578
+ outsideOpen = (comment) => movedPast(comment) && comment.settled !== true && comment.removed !== true;
18347
18579
  sectionOf = (comment) => outsideOpen(comment) ? "movedOn" : SECTION_OF[threadStand(comment)];
18348
18580
  sentEntry = (state, comment) => {
18349
18581
  const newer = newerOf(state, comment);
@@ -18478,7 +18710,7 @@ var init_notes = __esmMin((() => {
18478
18710
  return asking.threads.flatMap((id) => {
18479
18711
  const thread = state.sent.find((entry) => entry.id === id);
18480
18712
  if (thread === void 0) return [];
18481
- const where = thread.outside === true ? "not in the diff" : `line ${thread.end}`;
18713
+ const where = movedPast(thread) ? "not in the diff" : `line ${thread.end}`;
18482
18714
  return [`${firstLineOf(thread.body)} · ${where}`];
18483
18715
  });
18484
18716
  };
@@ -18500,7 +18732,7 @@ var init_notes = __esmMin((() => {
18500
18732
  const patch = selectedPatch(state);
18501
18733
  const found = /* @__PURE__ */ new Map();
18502
18734
  if (patch === void 0) return found;
18503
- const here = [...state.sent, ...state.held].filter((entry) => entry.file === patch.path && entry.removed !== true && entry.outside !== true);
18735
+ const here = [...state.sent, ...state.held].filter((entry) => entry.file === patch.path && entry.removed !== true && !movedPast(entry));
18504
18736
  for (const entry of here) {
18505
18737
  const stand = threadStand(entry);
18506
18738
  for (const row of rowsUnder(patch, entry)) found.set(row, louderOf(stand, found.get(row) ?? "gone"));
@@ -18558,7 +18790,7 @@ var init_notes = __esmMin((() => {
18558
18790
  commentRowsIn = (state, fileIndex) => {
18559
18791
  const patch = fileIndex === state.patchIndex ? selectedPatch(state) : state.patches[fileIndex];
18560
18792
  if (patch === void 0) return [];
18561
- const notes = [...state.sent, ...state.held].filter((entry) => entry.file === patch.path && entry.outside !== true);
18793
+ const notes = [...state.sent, ...state.held].filter((entry) => entry.file === patch.path && !movedPast(entry));
18562
18794
  return patch.rows.filter((row) => notes.some((note) => lineOnSide(row, note.side) === note.end)).map((row) => row.index).toSorted((left, right) => left - right);
18563
18795
  };
18564
18796
  draftPlace = (state) => {
@@ -18580,7 +18812,7 @@ var init_notes = __esmMin((() => {
18580
18812
  stop: drawn.filter((one) => one.side === note.side && one.end === note.end && drawn.indexOf(one) <= at).length
18581
18813
  };
18582
18814
  };
18583
- notesShown = (state, path) => [...state.sent.filter((one) => one.file === path && one.removed !== true && one.outside !== true).map((one) => ({
18815
+ notesShown = (state, path) => [...state.sent.filter((one) => one.file === path && one.removed !== true && !movedPast(one)).map((one) => ({
18584
18816
  id: one.id,
18585
18817
  side: one.side,
18586
18818
  end: one.end
@@ -18593,7 +18825,7 @@ var init_notes = __esmMin((() => {
18593
18825
  const patch = selectedPatch(state);
18594
18826
  const here = patch?.rows[row];
18595
18827
  if (patch === void 0 || here === void 0) return [];
18596
- return state.sent.filter((entry) => entry.file === patch.path && entry.id !== void 0 && entry.removed !== true && entry.outside !== true && lineOnSide(here, entry.side) === entry.end);
18828
+ return state.sent.filter((entry) => entry.file === patch.path && entry.id !== void 0 && entry.removed !== true && !movedPast(entry) && lineOnSide(here, entry.side) === entry.end);
18597
18829
  };
18598
18830
  remarkShown = (remark) => remark.state === "waiting" && remark.placed;
18599
18831
  remarksAtRow = (state, row) => {
@@ -18665,12 +18897,12 @@ var init_notes = __esmMin((() => {
18665
18897
  const patch = selectedPatch(state);
18666
18898
  const here = patch?.rows[row];
18667
18899
  if (patch === void 0 || here === void 0) return void 0;
18668
- return state.sent.find((entry) => entry.file === patch.path && entry.id !== void 0 && entry.removed !== true && entry.outside !== true && lineOnSide(here, entry.side) === entry.end);
18900
+ return state.sent.find((entry) => entry.file === patch.path && entry.id !== void 0 && entry.removed !== true && !movedPast(entry) && lineOnSide(here, entry.side) === entry.end);
18669
18901
  };
18670
18902
  openCommentRows = (state) => {
18671
18903
  const patch = selectedPatch(state);
18672
18904
  if (patch === void 0) return [];
18673
- const open = state.sent.filter((entry) => entry.file === patch.path && entry.settled !== true && entry.removed !== true && entry.outside !== true);
18905
+ const open = state.sent.filter((entry) => entry.file === patch.path && entry.settled !== true && entry.removed !== true && !movedPast(entry));
18674
18906
  return patch.rows.filter((row) => open.some((note) => lineOnSide(row, note.side) === note.end) || state.remarks.some((one) => one.file === patch.path && remarkShown(one) && lineOnSide(row, one.side) === one.end)).map((row) => row.index);
18675
18907
  };
18676
18908
  filesWithComments = (state) => state.patches.flatMap((patch, index) => state.sent.some((entry) => entry.file === patch.path) || state.remarks.some((one) => one.file === patch.path && remarkShown(one)) ? [index] : []);
@@ -20503,7 +20735,7 @@ var init_diffview = __esmMin((() => {
20503
20735
  return note.takenAt === void 0 ? `${marks().sent} sent` : `${marks().waiting} picked up ${agoText(note.takenAt, note.now)}`;
20504
20736
  };
20505
20737
  commentHead = (note) => {
20506
- const moved = note.stale ? ", the branch moved on" : "";
20738
+ const moved = `${note.outdated === true ? " · outdated" : ""}${note.stale ? ", the branch moved on" : ""}`;
20507
20739
  if (note.settled) return `${marks().done} settled${moved}`;
20508
20740
  if (note.asks) return `${marks().asked} asked back${moved}`;
20509
20741
  if (note.turns.at(-1)?.voice === "reviewer") return `${marks().waiting} replied${moved}`;
@@ -20729,7 +20961,7 @@ var init_notespane = __esmMin((() => {
20729
20961
  notesOf = (comments, path, sent, shown = {
20730
20962
  opened: [],
20731
20963
  now: Date.now()
20732
- }) => comments.filter((entry) => entry.file === path && entry.outside !== true).toSorted((left, right) => (left.at ?? "").localeCompare(right.at ?? "")).map((entry) => ({
20964
+ }) => comments.filter((entry) => entry.file === path && !movedPast(entry)).toSorted((left, right) => (left.at ?? "").localeCompare(right.at ?? "")).map((entry) => ({
20733
20965
  id: entry.id ?? "",
20734
20966
  folded: entry.settled === true && !(entry.id !== void 0 && shown.opened.includes(entry.id)),
20735
20967
  side: entry.side,
@@ -20738,6 +20970,7 @@ var init_notespane = __esmMin((() => {
20738
20970
  sent,
20739
20971
  settled: entry.settled === true,
20740
20972
  stale: entry.stale === true,
20973
+ outdated: entry.outdated === true,
20741
20974
  asks: entry.asks === true,
20742
20975
  answers: entry.answers ?? [],
20743
20976
  turns: entry.turns ?? [],
@@ -20817,7 +21050,9 @@ var init_panelpane = __esmMin((() => {
20817
21050
  return remarkWhere(entry.remark, known);
20818
21051
  }
20819
21052
  const tail = entry.comment.rewritten === true ? " · rewritten by the agent" : entry.comment.draft === void 0 ? "" : " · asks to redraft";
20820
- return entry.comment.outside === true ? " · not in the diff" : `:${entry.comment.end}${tail}`;
21053
+ if (movedPast(entry.comment)) return " · not in the diff";
21054
+ const changed = entry.comment.outdated === true ? " · outdated" : "";
21055
+ return `:${entry.comment.end}${changed}${tail}`;
20821
21056
  };
20822
21057
  panelFile = (entry) => {
20823
21058
  if (entry.kind === "fold") return "";
@@ -20839,7 +21074,7 @@ var init_panelpane = __esmMin((() => {
20839
21074
  if (entry.kind === "fold") return [];
20840
21075
  return (entry.kind === "remark" ? entry.remark.code : (entry.comment.snippet ?? "").split("\n")).filter((line) => line.trim().length > 0);
20841
21076
  };
20842
- lostEntry = (state, entry) => entry.kind === "fold" ? false : entry.kind === "remark" ? !entry.remark.placed && state.patches.some((patch) => patch.path === entry.remark.file) : entry.comment.outside === true;
21077
+ lostEntry = (state, entry) => entry.kind === "fold" ? false : entry.kind === "remark" ? !entry.remark.placed && state.patches.some((patch) => patch.path === entry.remark.file) : movedPast(entry.comment) || entry.comment.outdated === true;
20843
21078
  writtenOn = (state, placed, room) => {
20844
21079
  const { entry } = placed;
20845
21080
  if (placed.at !== state.panelIndex || !lostEntry(state, entry)) return [];
@@ -23721,7 +23956,7 @@ var init_comments = __esmMin((() => {
23721
23956
  }
23722
23957
  yield* readRewrite(app, entry);
23723
23958
  const at = app.state.patches.findIndex((patch) => patch.path === entry.comment.file);
23724
- if (at === -1 || entry.comment.outside === true) {
23959
+ if (at === -1 || movedPast(entry.comment)) {
23725
23960
  yield* openAway(app, entry, at);
23726
23961
  return;
23727
23962
  }
@@ -25817,11 +26052,12 @@ const commentReply = fn("Main.commentReply")(function* (options) {
25817
26052
  });
25818
26053
  yield* answer(options, { batch });
25819
26054
  });
25820
- const NOTHING_WAITING = "No comment is waiting. Pass --wait <seconds> to block until one arrives, and answer what you collect with `adiff comment answer --worktree . --id <id> --body '…'`.";
26055
+ const NOTHING_WAITING = "No comment is waiting. Pass --new --wait <seconds> to block until a new one arrives, and answer what you collect with `adiff comment answer --worktree . --id <id> --body '…'`.";
25821
26056
  const commentTake = fn("Main.commentTake")(function* (options) {
25822
26057
  const worktree = yield* required(options, "worktree");
25823
26058
  const wait = yield* seconds(options, "wait");
25824
- const comments = wait > 0 ? yield* awaitTaken(worktree, Date.now() + wait * WAIT_UNIT) : yield* take(worktree);
26059
+ const handing = options["new"] === void 0 ? "owed" : "new";
26060
+ const comments = wait > 0 ? yield* awaitTaken(worktree, Date.now() + wait * WAIT_UNIT, handing) : yield* take(worktree, handing);
25825
26061
  const hint = comments.length === 0 ? { hint: NOTHING_WAITING } : {};
25826
26062
  yield* answer(options, {
25827
26063
  comments,
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.194",
26
+ "version": "0.1.0-alpha.196",
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": {
@@ -29,8 +29,8 @@ revision has it. The code the layer describes is about to change under your hand
29
29
  stale the moment you act on the comment: write a new revision with `adiff layers set` before you
30
30
  answer, and say in the answer that you did.
31
31
 
32
- A comment keeps coming back until it is answered. A second `take` returns it again, so answer what
33
- you take. Settling or removing it also retires it: those are the reviewer saying they no longer
32
+ A comment keeps coming back until it is answered. A second plain `take` returns it again, so answer
33
+ what you take. Settling or removing it also retires it: those are the reviewer saying they no longer
34
34
  need one.
35
35
 
36
36
  ## A remark is context, a comment is work
@@ -43,12 +43,35 @@ one. Never act on a remark that has not been accepted, and never accept one your
43
43
 
44
44
  ## Wait for the next one
45
45
 
46
+ Start a session with a plain take, which collects everything still owed an answer:
47
+
46
48
  ```bash
47
- adiff comment take --worktree . --wait 300
49
+ adiff comment take --worktree .
48
50
  ```
49
51
 
50
- Blocks until a comment arrives or the timeout in seconds elapses, then returns the same envelope.
51
- An empty `comments` array means the wait expired with nothing new — that is not an error.
52
+ Then listen for what comes next:
53
+
54
+ ```bash
55
+ adiff comment take --worktree . --new --wait 6900
56
+ ```
57
+
58
+ `--new` hands back only comments this review has not handed you before: a new comment, a reply to
59
+ one of your answers, or a comment the reviewer reopened or restored. Comments you already took
60
+ and are still working on never end the wait, so it wakes you only for something new. It blocks until
61
+ such a comment arrives or the timeout in seconds elapses, then returns the same envelope.
62
+
63
+ An empty `comments` array means only that the wait ran out. It is not an error and not news: run the
64
+ same wait again and say nothing to the user about it.
65
+
66
+ Run it in the background, never in the foreground. In Claude Code that is the Bash tool with
67
+ `run_in_background` and a `timeout` of 7200000. 6900 seconds keeps the wait under the harness's
68
+ two-hour limit on a background command, so it ends with an empty answer rather than being killed. A
69
+ foreground wait holds the turn, so you cannot do anything else and the person you are working with
70
+ cannot talk to you. Backgrounded, the harness brings you back the moment a comment lands.
71
+
72
+ Do not run it under a Monitor, do not re-arm a short wait on a timer, and do not schedule wakeups to
73
+ check on it. Each of those wakes you for nothing; the background wait already brings you back when a
74
+ comment arrives.
52
75
 
53
76
  `--wait` takes a whole number of seconds from 1 to 86400. A value outside that is refused on
54
77
  stderr with exit 2, because an instant empty answer would read exactly like a wait that expired:
@@ -58,21 +81,17 @@ Arm the wait as the first thing you do in a turn, before the work. A turn that i
58
81
  half-way then still leaves a listener running, and a wait armed at the end of a turn is a wait that
59
82
  often never gets armed.
60
83
 
61
- Run the wait in the background, not in the foreground. A foreground wait holds the turn, so you
62
- cannot do anything else and the person you are working with cannot talk to you. Backgrounded, the
63
- harness brings you back the moment a comment lands.
84
+ Keep one wait per worktree. Two waits running at once hand the same comment to both, which is two of
85
+ you answering one comment. Before starting one, check whether one is already running.
64
86
 
65
- Keep one wait per worktree. A second wait returns the same comments as the first, so two of them
66
- running at once is two of you answering the same comment. Before starting one, check whether one is
67
- already running.
68
-
69
- Re-arm it after each comment you handle, and keep it running while you work. A reviewer reads at
70
- their own pace, so comments arrive minutes apart, and the whole point is that they reach you as
71
- events rather than by you asking. When you finish a piece of work, say you are still listening.
87
+ Re-arm it as soon as it returns, before you handle what it returned, and keep it running while you
88
+ work. A reviewer reads at their own pace, so comments arrive minutes apart, and the whole point is
89
+ that they reach you as events rather than by you asking. When you finish a piece of work, say you are
90
+ still listening.
72
91
 
73
92
  A backgrounded wait that is killed rather than expiring is not the reviewer going quiet, and not a
74
- reason to stop listening. A kill loses whatever the wait would have handed you, so take once
75
- without `--wait` to collect what landed, then arm a new wait.
93
+ reason to stop listening. A kill loses nothing: taking is what records a comment as handed over, so a
94
+ comment that arrived after the kill is still new to the next `--new` wait. Arm a new one.
76
95
 
77
96
  ## Answering a comment
78
97
 
@@ -149,7 +168,8 @@ answer as many comments as it addresses. When a comment is a question rather tha
149
168
  it with `adiff comment answer` too; an answer written into a commit message never reaches the
150
169
  reviewer's screen.
151
170
 
152
- Handle every comment in the batch before taking again.
171
+ Handle every comment in the batch. The `--new` wait you re-armed does not hand them back, so a
172
+ comment you skip waits for your next plain take.
153
173
 
154
174
  ## Failure
155
175
 
@@ -168,8 +188,9 @@ about, because the reviewer has not opened it; report that rather than looping.
168
188
  ## Handing work over
169
189
 
170
190
  Finishing is not a reason to publish anything. Say the work is ready, put the review in front of
171
- them if they asked for one, and say how to read it. That is the whole handover. A reading order is
172
- extra work you do on request, and it has its own section further down.
191
+ them if they asked for one, and say how to read it. That is the whole handover. A first reading order
192
+ is extra work you do on request, and it has its own section further down. A reading order that
193
+ already exists is different: keep it current before you say the work is ready, without being asked.
173
194
 
174
195
  ## Put the review in front of them
175
196
 
@@ -209,13 +230,15 @@ the branch in a list. `--branch` takes the name `branch list` reports; without i
209
230
  on the worktree list.
210
231
 
211
232
  Say what you want looked at hardest, and where you are unsure. A reviewer who knows which part you
212
- doubt spends their attention there. Offer a reading order rather than writing one: if the change is
213
- long enough that the order matters, say you can publish one and let them decide.
233
+ doubt spends their attention there. When the branch has no reading order, offer one rather than
234
+ writing one: if the change is long enough that the order matters, say you can publish one and let
235
+ them decide.
214
236
 
215
237
  ## Publishing a reading order, when you are asked for one
216
238
 
217
- Only when the reviewer asks. A reading order is a real piece of work, it can be wrong, and one
218
- nobody wanted spends their attention on your summary rather than on the code.
239
+ Write a first reading order only when the reviewer asks. A reading order is a real piece of work, it
240
+ can be wrong, and one nobody wanted spends their attention on your summary rather than on the code.
241
+ Once one exists, keeping it current is not a new ask: see the next section.
219
242
 
220
243
  The ask often arrives as a comment. Pressing `L` in the review sends you one of these:
221
244
 
@@ -319,13 +342,31 @@ each claim their own run. Done means `uncovered` is empty **and** `shared` is ze
319
342
 
320
343
  Setting layers again supersedes the previous set and bumps `version`; the set records the commit it
321
344
  was written for, and adiff reports it as `stale` once the branch moves past that commit. Once a
322
- reviewer has a reading order, keep it true: write it again after you address their comments.
345
+ reviewer has a reading order, keep it true, as the next section says.
323
346
 
324
347
  When you have published one, tell them the sidebar now holds it: `s` swaps between the layers and
325
348
  the files, each layer shows the files it covers with the ones already reviewed ticked off, and `]`
326
349
  and `[` walk those files in the order you put them in — from the last file of one layer into the
327
350
  first of the next.
328
351
 
352
+ ## Keep an existing reading order current, unasked
353
+
354
+ Once a branch has layers, check them after each change you make (a commit, an answered comment, a
355
+ rebase) and before you say the work is ready:
356
+
357
+ ```bash
358
+ adiff layers show --worktree . --fields stale,uncovered,shared,vanished
359
+ ```
360
+
361
+ If `uncovered` is not empty, `stale` is true or `vanished` names a path, write a new revision with
362
+ `adiff layers set` right away. Put new runs into the layer whose claim they serve, and add a final
363
+ layer only for lines that serve none. When the base moved, read the diff again rather than patching
364
+ line numbers. Done means `uncovered` is empty and `shared` is zero.
365
+
366
+ Do it silently: it is upkeep, not news, so do not ask first and do not report it unless the reviewer
367
+ asks. `NoLayers` (exit 3) means the branch has no reading order, and then you write one only when
368
+ asked.
369
+
329
370
  ## Helping draft a review of somebody else's pull request
330
371
 
331
372
  Sometimes the reviewer is not reading your work — they are reading a stranger's pull request,