@eliya-oss/agent-diff 0.1.0-alpha.6 → 0.1.0-alpha.8

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 +14 -0
  2. package/dist/main.js +175 -43
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @eliya-oss/agent-diff
2
2
 
3
+ ## 0.1.0-alpha.8
4
+
5
+ ### Patch Changes
6
+
7
+ - The simulator seeds layers, so a demo run shows them.
8
+
9
+ - The worktree list says whether a branch already has a pull request.
10
+
11
+ ## 0.1.0-alpha.7
12
+
13
+ ### Patch Changes
14
+
15
+ - A layer's prose reads in the diff, above the code it introduces.
16
+
3
17
  ## 0.1.0-alpha.6
4
18
 
5
19
  ### Patch Changes
package/dist/main.js CHANGED
@@ -11261,6 +11261,33 @@ const withFullCoverage = (patches, layers) => {
11261
11261
  layers: [...layers.layers, remainder]
11262
11262
  };
11263
11263
  };
11264
+ const proseAnchors = (layer) => {
11265
+ const anchors = [];
11266
+ let pending = [];
11267
+ let last;
11268
+ for (const block of layer.blocks) {
11269
+ if (block.kind === "prose") {
11270
+ const markdown = block.markdown.trim();
11271
+ if (markdown.length > 0) pending.push(markdown);
11272
+ continue;
11273
+ }
11274
+ for (const markdown of pending) anchors.push({
11275
+ path: block.path,
11276
+ line: block.start,
11277
+ markdown,
11278
+ after: false
11279
+ });
11280
+ pending = [];
11281
+ last = block;
11282
+ }
11283
+ if (last === void 0) return anchors;
11284
+ return [...anchors, ...pending.map((markdown) => ({
11285
+ path: last.path,
11286
+ line: last.end,
11287
+ markdown,
11288
+ after: true
11289
+ }))];
11290
+ };
11264
11291
  //#endregion
11265
11292
  //#region src/domain/layers/version.ts
11266
11293
  const statusOf = (patches, layers, branchHead) => {
@@ -11360,7 +11387,8 @@ const reportedLayers = (patches, layers) => {
11360
11387
  title: layer.title,
11361
11388
  note: noteOf(layer),
11362
11389
  files: unique(spansOfLayer(layer).map((span) => span.path)).filter((path) => present.has(path)),
11363
- spans: spansOfLayer(layer)
11390
+ spans: spansOfLayer(layer),
11391
+ prose: proseAnchors(layer).filter((anchor) => present.has(anchor.path))
11364
11392
  }));
11365
11393
  };
11366
11394
  const reportOf = (patches, layers, branchHead) => {
@@ -11798,6 +11826,49 @@ const helpFor = (name) => {
11798
11826
  ].join("\n");
11799
11827
  };
11800
11828
  //#endregion
11829
+ //#region src/service/forge/service.ts
11830
+ var Forge = class extends Service()("Forge") {};
11831
+ const LIMIT = "200";
11832
+ const TIMEOUT_MS = 4e3;
11833
+ const stateOf = (row) => {
11834
+ if (row.isDraft === true && row.state === "OPEN") return "draft";
11835
+ if (row.state === "MERGED") return "merged";
11836
+ if (row.state === "CLOSED") return "closed";
11837
+ return "open";
11838
+ };
11839
+ const parse = (raw) => {
11840
+ const rows = JSON.parse(raw);
11841
+ if (!Array.isArray(rows)) return [];
11842
+ return rows.filter((row) => typeof row.headRefName === "string").map((row) => ({
11843
+ branch: String(row.headRefName),
11844
+ state: stateOf(row)
11845
+ }));
11846
+ };
11847
+ const ask = (repo) => new Promise((resolve) => {
11848
+ execFile("gh", [
11849
+ "pr",
11850
+ "list",
11851
+ "--state",
11852
+ "all",
11853
+ "--limit",
11854
+ LIMIT,
11855
+ "--json",
11856
+ "headRefName,state,isDraft"
11857
+ ], {
11858
+ cwd: repo,
11859
+ timeout: TIMEOUT_MS,
11860
+ encoding: "utf8"
11861
+ }, (error, stdout) => {
11862
+ if (error !== null) return resolve([]);
11863
+ try {
11864
+ resolve(parse(stdout));
11865
+ } catch {
11866
+ resolve([]);
11867
+ }
11868
+ });
11869
+ });
11870
+ const ForgeLive = succeed$1(Forge)({ pulls: (repo) => promise(() => ask(repo)) });
11871
+ //#endregion
11801
11872
  //#region src/tui/gaps.ts
11802
11873
  const sourceLength = (source) => source.at(-1)?.trim() === "" ? source.length - 1 : source.length;
11803
11874
  const markerText = (hidden) => `⋯ ${hidden} lines hidden · press l`;
@@ -11904,7 +11975,7 @@ const compose = (build) => {
11904
11975
  };
11905
11976
  };
11906
11977
  const cache = /* @__PURE__ */ new WeakMap();
11907
- const keyOf = (total, full, reveals) => [
11978
+ const keyOf$1 = (total, full, reveals) => [
11908
11979
  total,
11909
11980
  full === void 0 ? 0 : full.rows.length,
11910
11981
  reveals.map((entry) => `${entry.gap}-${entry.lines}`).join(",")
@@ -11915,7 +11986,7 @@ const shownOf = (state) => {
11915
11986
  const full = state.full.find((patch) => patch.path === base.path);
11916
11987
  const total = sourceLength(state.source);
11917
11988
  const reveals = state.revealed.filter((entry) => entry.file === base.path);
11918
- const key = keyOf(total, full, reveals);
11989
+ const key = keyOf$1(total, full, reveals);
11919
11990
  const known = cache.get(base);
11920
11991
  const found = known?.get(key);
11921
11992
  if (found !== void 0) return found;
@@ -12090,11 +12161,19 @@ const initialState = (branches) => ({
12090
12161
  navOpen: true,
12091
12162
  layers: [],
12092
12163
  layersStale: false,
12164
+ pulls: {},
12093
12165
  layerIndex: 0,
12094
12166
  openLayers: [],
12095
12167
  rail: "tree"
12096
12168
  });
12097
12169
  const onLayers = (state) => state.rail === "layers" && state.layers.length > 0;
12170
+ const selectedLayer = (state) => state.layers[state.layerIndex];
12171
+ const proseFor = (state, path) => {
12172
+ if (!onLayers(state)) return [];
12173
+ const layer = selectedLayer(state);
12174
+ if (layer === void 0) return [];
12175
+ return layer.prose.filter((anchor) => anchor.path === path);
12176
+ };
12098
12177
  const layerFiles = (state, layerIndex) => {
12099
12178
  const layer = state.layers[layerIndex];
12100
12179
  if (layer === void 0) return [];
@@ -13028,6 +13107,10 @@ const withLayers = (state, told) => {
13028
13107
  top: 0
13029
13108
  };
13030
13109
  };
13110
+ const withPulls = (state, pulls) => ({
13111
+ ...state,
13112
+ pulls
13113
+ });
13031
13114
  const withBranches = (state, branches) => ({
13032
13115
  ...state,
13033
13116
  branches,
@@ -13235,6 +13318,7 @@ const syntaxTheme = {
13235
13318
  fg: "#9aa7c7",
13236
13319
  italic: true
13237
13320
  },
13321
+ prose: { fg: "#a9b4cc" },
13238
13322
  "note.sent": {
13239
13323
  fg: "#6d7893",
13240
13324
  italic: true
@@ -13381,20 +13465,25 @@ var DiffView = class {
13381
13465
  rows() {
13382
13466
  return this.fitted;
13383
13467
  }
13384
- show(patch, notes, gaps) {
13385
- const room = notes.length === 0 ? NOTE_MIN : this.noteRoom();
13386
- const key = [room, ...notes.map((note) => `${note.side}${note.line}:${note.body}`)].join("\0");
13468
+ show(patch, notes, gaps, prose = []) {
13469
+ const room = notes.length === 0 && prose.length === 0 ? NOTE_MIN : this.noteRoom();
13470
+ const key = keyOf(room, notes, prose);
13387
13471
  if (patch === this.shown && key === this.noted) return;
13388
13472
  this.pinnedText = "";
13389
13473
  this.shown = patch;
13390
13474
  this.noted = key;
13391
- this.display = layout(patch, notes, room, gaps);
13392
- this.starts = /* @__PURE__ */ new Map();
13393
- for (const [index, entry] of this.display.entries()) if (!entry.comment && !this.starts.has(entry.row)) this.starts.set(entry.row, index);
13475
+ this.display = layout({
13476
+ patch,
13477
+ notes,
13478
+ room,
13479
+ gaps,
13480
+ prose
13481
+ });
13482
+ this.starts = startsOf(this.display);
13394
13483
  this.code.filetype = pathToFiletype(patch.path) ?? "text";
13395
13484
  this.code.content = this.display.map((entry) => entry.text).join("\n");
13396
13485
  this.numbers.setLineNumbers(lineNumbers(patch, this.display));
13397
- this.numbers.setHideLineNumbers(new Set(this.display.flatMap((entry, index) => entry.comment || entry.gap ? [index] : [])));
13486
+ this.numbers.setHideLineNumbers(bareOf(this.display));
13398
13487
  this.numbers.setLineSigns(lineSigns(patch, this.display));
13399
13488
  this.numbers.setLineColors(/* @__PURE__ */ new Map());
13400
13489
  const spans = noteSpans(this.display);
@@ -13405,7 +13494,8 @@ var DiffView = class {
13405
13494
  return this.display[at]?.row ?? 0;
13406
13495
  }
13407
13496
  isComment(display) {
13408
- return this.display[display]?.comment === true;
13497
+ const entry = this.display[display];
13498
+ return entry?.comment === true || entry?.prose === true;
13409
13499
  }
13410
13500
  scrollTo(row, cursor) {
13411
13501
  const highest = Math.max(0, this.display.length - this.rows());
@@ -13422,7 +13512,7 @@ var DiffView = class {
13422
13512
  for (let index = Math.max(0, from - OVERSCAN); index < last; index++) {
13423
13513
  const entry = this.display[index];
13424
13514
  if (entry === void 0) continue;
13425
- const paint = entry.comment ? NOTE_PAINT : paintOf(entry.row);
13515
+ const paint = entry.comment || entry.prose ? NOTE_PAINT : paintOf(entry.row);
13426
13516
  if (paint !== void 0) colors.set(index, paint);
13427
13517
  }
13428
13518
  this.numbers.setLineColors(colors);
@@ -13431,7 +13521,19 @@ var DiffView = class {
13431
13521
  return WASH[kind];
13432
13522
  }
13433
13523
  };
13524
+ const startsOf = (display) => {
13525
+ const starts = /* @__PURE__ */ new Map();
13526
+ for (const [index, entry] of display.entries()) if (!entry.comment && !starts.has(entry.row)) starts.set(entry.row, index);
13527
+ return starts;
13528
+ };
13529
+ const bareOf = (display) => new Set(display.flatMap((entry, index) => entry.comment || entry.gap || entry.prose ? [index] : []));
13530
+ const keyOf = (room, notes, prose) => [
13531
+ room,
13532
+ ...notes.map((note) => `${note.side}${note.line}:${note.body}`),
13533
+ ...prose.map((entry) => `p${entry.line}${entry.after ? ">" : "<"}:${entry.markdown}`)
13534
+ ].join("\0");
13434
13535
  const groupOf = (entry) => {
13536
+ if (entry.prose) return "prose";
13435
13537
  if (entry.gap) return "gap";
13436
13538
  if (!entry.comment) return void 0;
13437
13539
  if (entry.label) return "note.label";
@@ -13473,45 +13575,66 @@ const noteRows = (note, row, room) => noteLines(note, room).map((line, index) =>
13473
13575
  comment: true,
13474
13576
  sent: note.sent,
13475
13577
  label: index === 0,
13476
- gap: false
13578
+ gap: false,
13579
+ prose: false
13477
13580
  }));
13478
- const layout = (patch, notes, room, gaps) => {
13479
- const display = [];
13480
- for (const row of patch.rows) {
13481
- display.push({
13482
- text: row.text,
13483
- row: row.index,
13484
- comment: false,
13485
- sent: false,
13486
- label: false,
13487
- gap: gaps.has(row.index)
13488
- });
13489
- for (const note of notes) if (sideLineOf(row, note.side) === note.line) display.push(...noteRows(note, row.index, room));
13490
- }
13491
- return display;
13492
- };
13581
+ const proseRows = (entry, row, room) => [...entry.markdown.split("\n").flatMap((line) => wrap(line, room - 2)), ""].map((line) => ({
13582
+ text: line.length === 0 ? "" : ` ${line}`,
13583
+ row,
13584
+ comment: false,
13585
+ sent: false,
13586
+ label: false,
13587
+ gap: false,
13588
+ prose: true
13589
+ }));
13590
+ const proseAt = (plan, row, after) => {
13591
+ const line = sideLineOf(row, "new");
13592
+ if (line === void 0) return [];
13593
+ return plan.prose.filter((entry) => entry.after === after && entry.line === line);
13594
+ };
13595
+ const notesAt = (plan, row) => plan.notes.filter((note) => sideLineOf(row, note.side) === note.line).flatMap((note) => noteRows(note, row.index, plan.room));
13596
+ const codeRow = (plan, row) => ({
13597
+ text: row.text,
13598
+ row: row.index,
13599
+ comment: false,
13600
+ sent: false,
13601
+ label: false,
13602
+ gap: plan.gaps.has(row.index),
13603
+ prose: false
13604
+ });
13605
+ const rowsFor = (plan, row) => [
13606
+ ...proseAt(plan, row, false).flatMap((entry) => proseRows(entry, row.index, plan.room)),
13607
+ codeRow(plan, row),
13608
+ ...notesAt(plan, row),
13609
+ ...proseAt(plan, row, true).flatMap((entry) => proseRows(entry, row.index, plan.room))
13610
+ ];
13611
+ const layout = (plan) => plan.patch.rows.flatMap((row) => rowsFor(plan, row));
13493
13612
  const lineNumbers = (patch, display) => {
13494
13613
  const numbers = /* @__PURE__ */ new Map();
13495
13614
  const rows = new Map(patch.rows.map((row) => [row.index, row]));
13496
13615
  for (const [index, entry] of display.entries()) {
13497
- const row = entry.comment ? void 0 : rows.get(entry.row);
13616
+ const row = entry.comment || entry.prose ? void 0 : rows.get(entry.row);
13498
13617
  const line = row === void 0 ? void 0 : numberFor(row);
13499
13618
  if (line !== void 0) numbers.set(index, line);
13500
13619
  }
13501
13620
  return numbers;
13502
13621
  };
13622
+ const BARE_SIGN = {
13623
+ after: " ",
13624
+ afterColor: palette.accent
13625
+ };
13626
+ const signFor = (entry, rows) => {
13627
+ if (entry.comment || entry.prose) return BARE_SIGN;
13628
+ const row = rows.get(entry.row);
13629
+ const sign = row === void 0 ? void 0 : SIGNS[row.kind];
13630
+ return sign === void 0 ? BARE_SIGN : {
13631
+ after: sign.text,
13632
+ afterColor: sign.color
13633
+ };
13634
+ };
13503
13635
  const lineSigns = (patch, display) => {
13504
- const signs = /* @__PURE__ */ new Map();
13505
13636
  const rows = new Map(patch.rows.map((row) => [row.index, row]));
13506
- for (const [index, entry] of display.entries()) {
13507
- const row = rows.get(entry.row);
13508
- const sign = entry.comment || row === void 0 ? void 0 : SIGNS[row.kind];
13509
- signs.set(index, {
13510
- after: sign?.text ?? " ",
13511
- afterColor: sign?.color ?? palette.accent
13512
- });
13513
- }
13514
- return signs;
13637
+ return new Map(display.map((entry, index) => [index, signFor(entry, rows)]));
13515
13638
  };
13516
13639
  const sideLineOf = (row, side) => getOrUndefined$1(lineOn(row, side));
13517
13640
  //#endregion
@@ -13850,6 +13973,7 @@ const layersCell = (branch) => {
13850
13973
  if (branch.layers === 0) return "";
13851
13974
  return branch.stale ? `${branch.layers} stale` : `${branch.layers} layers`;
13852
13975
  };
13976
+ const stateCell = (state, branch) => [state.pulls[branch.branch] ?? "", waitingLabel(branch).trim()].filter((part) => part.length > 0).join(" ");
13853
13977
  const branchCells = (branch, here, room) => ({
13854
13978
  lead: `${here ? marks().cursor : " "} `,
13855
13979
  name: clip(branch.branch, room).padEnd(room),
@@ -13857,7 +13981,7 @@ const branchCells = (branch, here, room) => ({
13857
13981
  added: `+${branch.added}`.padStart(8),
13858
13982
  gone: `-${branch.removed}`.padStart(8),
13859
13983
  layers: layersCell(branch),
13860
- state: waitingLabel(branch).trim()
13984
+ state: ""
13861
13985
  });
13862
13986
  const headerParts = (state, branch, path) => [
13863
13987
  branch,
@@ -14108,7 +14232,7 @@ var Screen = class {
14108
14232
  if (shown === void 0) return;
14109
14233
  const patch = shown.patch;
14110
14234
  this.paintSticky(state, state.top);
14111
- this.view.show(patch, notesFor(state, patch.path), gapRowSet(shown));
14235
+ this.view.show(patch, notesFor(state, patch.path), gapRowSet(shown), proseFor(state, patch.path));
14112
14236
  this.view.fit(this.diffScroll.height);
14113
14237
  const height = this.view.rows();
14114
14238
  const top = this.view.scrollTo(state.top, state.cursor);
@@ -14193,7 +14317,7 @@ var Screen = class {
14193
14317
  fg(palette.added)(cells.added),
14194
14318
  fg(palette.removed)(cells.gone),
14195
14319
  fg(palette.accent)(` ${cells.layers.padStart(8)}`),
14196
- fg(palette.attention)(` ${cells.state}\n`)
14320
+ fg(palette.attention)(` ${stateCell(state, branch)}\n`)
14197
14321
  ];
14198
14322
  });
14199
14323
  return new StyledText([...heading, ...rows]);
@@ -14402,6 +14526,7 @@ var App = class {
14402
14526
  renderer.on("frame", () => this.syncGeometry());
14403
14527
  renderer.setFrameCallback(async () => this.applyWheel());
14404
14528
  const resume = options.resume;
14529
+ this.dispatchTask(() => this.loadPulls());
14405
14530
  if (resume !== void 0) this.dispatchTask(() => this.resume(resume));
14406
14531
  }
14407
14532
  dispatchTask(task) {
@@ -14634,6 +14759,13 @@ var App = class {
14634
14759
  loadSent(branch) {
14635
14760
  return this.run(listSent(this.repo, branch));
14636
14761
  }
14762
+ async loadPulls() {
14763
+ const forge = await this.run(map(Forge, (service) => service));
14764
+ const pulls = await this.run(forge.pulls(this.repo));
14765
+ if (pulls.length === 0) return;
14766
+ const found = Object.fromEntries(pulls.map((pull) => [pull.branch, pull.state]));
14767
+ this.commit(withPulls(this.state, found));
14768
+ }
14637
14769
  async loadSource() {
14638
14770
  const branch = selectedBranch(this.state);
14639
14771
  const patch = selectedPatch(this.state);
@@ -14877,7 +15009,7 @@ if (said !== void 0) {
14877
15009
  process.stdout.write(`${said}\n`);
14878
15010
  process.exit(0);
14879
15011
  }
14880
- const layer = mergeAll(GitLive, storeAt(process.env["ADIFF_ROOT"] ?? defaultRoot()));
15012
+ const layer = mergeAll(GitLive, ForgeLive, storeAt(process.env["ADIFF_ROOT"] ?? defaultRoot()));
14881
15013
  const exit = await runPromiseExit(run(nameOf(argv), optionsFrom(argv)).pipe(provide(layer)));
14882
15014
  if (isFailure(exit)) {
14883
15015
  const reported = failure(squash(exit.cause));
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.6",
24
+ "version": "0.1.0-alpha.8",
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": {