@eliya-oss/agent-diff 0.1.0-alpha.190 → 0.1.0-alpha.191

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,19 @@
1
1
  # @eliya-oss/agent-diff
2
2
 
3
+ ## 0.1.0-alpha.191
4
+
5
+ ### Patch Changes
6
+
7
+ - perf(layers): layers show on a branch of 3,185 changed files takes 1.0s, down from 3.3s.
8
+
9
+ <details><summary>What was slow</summary>
10
+
11
+ Working out which changed lines a layer covers looked through every span of every layer for each
12
+ line, so a branch with thousands of files spent most of the command there. The answer is the same,
13
+ byte for byte.
14
+
15
+ </details>
16
+
3
17
  ## 0.1.0-alpha.190
4
18
 
5
19
  ### Patch Changes
package/dist/main.js CHANGED
@@ -10044,7 +10044,7 @@ var init_config = __esmMin((() => {
10044
10044
  //#region package.json
10045
10045
  init_pane();
10046
10046
  init_config();
10047
- var version$1 = "0.1.0-alpha.190";
10047
+ var version$1 = "0.1.0-alpha.191";
10048
10048
  //#endregion
10049
10049
  //#region src/cli/error.ts
10050
10050
  var UnknownCommand, MissingOption, UnknownField, UnknownOption, BadOption, RegistryUnanswered, NotServed, BadRequest;
@@ -13294,7 +13294,7 @@ var init_model$3 = __esmMin((() => {
13294
13294
  }));
13295
13295
  //#endregion
13296
13296
  //#region src/domain/layers/coverage.ts
13297
- var codeBlockOf$1, codeBlocks, noteOf, spansOf$1, changedLines, holds, claimsHunk, runsOf, tallyOf, coverage, sharedHunks, runsSaid, filesSaid, leftSaid, unordered, withFullCoverage, proseAnchors;
13297
+ var codeBlockOf$1, codeBlocks, noteOf, spansOf$1, changedLines, NOTHING, reachesOf, claimsOf, reaching, claimedBy, runsOf, tallyOf, changedHunks, coverage, sharedIn, sharedHunks, runsSaid, filesSaid, leftSaid, unordered, withFullCoverage, proseAnchors;
13298
13298
  var init_coverage = __esmMin((() => {
13299
13299
  init_dist();
13300
13300
  init_model$3();
@@ -13315,8 +13315,42 @@ var init_coverage = __esmMin((() => {
13315
13315
  onNone: () => [],
13316
13316
  onSome: (line) => [line]
13317
13317
  }));
13318
- holds = (span, path, line) => span.path === path && span.start <= line && span.end >= line;
13319
- claimsHunk = (spans, path, hunk) => changedLines(hunk).some((line) => spans.some((span) => holds(span, path, line)));
13318
+ NOTHING = [];
13319
+ reachesOf = (spans) => {
13320
+ const reaches = [];
13321
+ const ordered = spans.filter((span) => span.start <= span.end).toSorted((a, b) => a.start - b.start);
13322
+ for (const span of ordered) {
13323
+ const open = reaches.at(-1);
13324
+ if (open !== void 0 && span.start <= open.end) open.end = Math.max(open.end, span.end);
13325
+ else reaches.push({
13326
+ start: span.start,
13327
+ end: span.end
13328
+ });
13329
+ }
13330
+ return reaches;
13331
+ };
13332
+ claimsOf = (spans) => {
13333
+ const byPath = /* @__PURE__ */ new Map();
13334
+ for (const span of spans) {
13335
+ const held = byPath.get(span.path);
13336
+ if (held === void 0) byPath.set(span.path, [span]);
13337
+ else held.push(span);
13338
+ }
13339
+ return new Map([...byPath].map(([path, held]) => [path, reachesOf(held)]));
13340
+ };
13341
+ reaching = (reaches, line) => {
13342
+ let low = 0;
13343
+ let high = reaches.length;
13344
+ while (low < high) {
13345
+ const middle = low + high >>> 1;
13346
+ const reach = reaches[middle];
13347
+ if (reach === void 0 || reach.start > line) high = middle;
13348
+ else low = middle + 1;
13349
+ }
13350
+ const last = reaches[low - 1];
13351
+ return last !== void 0 && last.end >= line;
13352
+ };
13353
+ claimedBy = (reaches, changed) => changed.some((line) => reaching(reaches, line));
13320
13354
  runsOf = (path, lines) => {
13321
13355
  const runs = [];
13322
13356
  for (const line of lines.toSorted((a, b) => a - b)) {
@@ -13330,20 +13364,23 @@ var init_coverage = __esmMin((() => {
13330
13364
  }
13331
13365
  return runs;
13332
13366
  };
13333
- tallyOf = (patch, hunk, claimed) => {
13334
- const changed = changedLines(hunk);
13335
- const loose = changed.filter((line) => !claimed.some((span) => holds(span, patch.path, line)));
13367
+ tallyOf = (path, changed, reaches) => {
13368
+ const loose = changed.filter((line) => !reaching(reaches, line));
13336
13369
  const whole = changed.length > 0 && loose.length === 0;
13337
13370
  const some = loose.length > 0 && loose.length < changed.length;
13338
13371
  return {
13339
13372
  covered: whole ? 1 : 0,
13340
13373
  partial: some ? 1 : 0,
13341
- missing: runsOf(patch.path, loose)
13374
+ missing: runsOf(path, loose)
13342
13375
  };
13343
13376
  };
13377
+ changedHunks = (patch) => patch.hunks.map(changedLines).filter((changed) => changed.length > 0);
13344
13378
  coverage = (patches, layers) => {
13345
- const claimed = spansOf$1(layers);
13346
- const tallies = patches.flatMap((patch) => patch.hunks.filter((hunk) => changedLines(hunk).length > 0).map((hunk) => tallyOf(patch, hunk, claimed)));
13379
+ const claims = claimsOf(spansOf$1(layers));
13380
+ const tallies = patches.flatMap((patch) => {
13381
+ const reaches = claims.get(patch.path) ?? NOTHING;
13382
+ return changedHunks(patch).map((changed) => tallyOf(patch.path, changed, reaches));
13383
+ });
13347
13384
  return {
13348
13385
  total: tallies.length,
13349
13386
  covered: tallies.reduce((sum, tally) => sum + tally.covered, 0),
@@ -13351,9 +13388,17 @@ var init_coverage = __esmMin((() => {
13351
13388
  missing: tallies.flatMap((tally) => tally.missing)
13352
13389
  };
13353
13390
  };
13391
+ sharedIn = (patch, claims) => {
13392
+ const held = claims.flatMap((claim) => {
13393
+ const reaches = claim.get(patch.path);
13394
+ return reaches === void 0 ? [] : [reaches];
13395
+ });
13396
+ if (held.length < 2) return 0;
13397
+ return changedHunks(patch).filter((changed) => held.filter((reaches) => claimedBy(reaches, changed)).length > 1).length;
13398
+ };
13354
13399
  sharedHunks = (patches, layers) => {
13355
- const claiming = (patch, hunk) => layers.filter((layer) => claimsHunk(spansOf$1([layer]), patch.path, hunk)).length;
13356
- return patches.reduce((sum, patch) => sum + patch.hunks.filter((hunk) => changedLines(hunk).length > 0 && claiming(patch, hunk) > 1).length, 0);
13400
+ const claims = layers.map((layer) => claimsOf(spansOf$1([layer])));
13401
+ return patches.reduce((sum, patch) => sum + sharedIn(patch, claims), 0);
13357
13402
  };
13358
13403
  runsSaid = (count) => count === 1 ? "One run of changed lines the layers do not account for." : `${count} runs of changed lines the layers do not account for.`;
13359
13404
  filesSaid = (count) => count === 1 ? "One file the layers had no lines to order." : `${count} files the layers had no lines to order.`;
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.190",
26
+ "version": "0.1.0-alpha.191",
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": {