@eliya-oss/agent-diff 0.1.0-alpha.16 → 0.1.0-alpha.17

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,11 @@
1
1
  # @eliya-oss/agent-diff
2
2
 
3
+ ## 0.1.0-alpha.17
4
+
5
+ ### Patch Changes
6
+
7
+ - Say when an agent answers, settle a thread with d, and hold the comments still while the code pans.
8
+
3
9
  ## 0.1.0-alpha.16
4
10
 
5
11
  ### Patch Changes
package/dist/main.js CHANGED
@@ -5,7 +5,7 @@ import { dirname, join } from "node:path";
5
5
  import { execFile } from "node:child_process";
6
6
  import { promisify } from "node:util";
7
7
  import { homedir, hostname, platform } from "node:os";
8
- import { existsSync, readFileSync } from "node:fs";
8
+ import { existsSync, mkdirSync, readFileSync, watch } from "node:fs";
9
9
  import { fileURLToPath } from "node:url";
10
10
  import { ASCIIFontRenderable, BoxRenderable, CodeRenderable, LineNumberRenderable, RGBA, SelectRenderable, StyledText, SyntaxStyle, TextRenderable, bg, createCliRenderer, fg, getTreeSitterClient, pathToFiletype, t } from "@opentui/core";
11
11
  //#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/Pipeable.js
@@ -11201,6 +11201,7 @@ const bodyOf = (entry) => entry.body;
11201
11201
  const sentOf = (comment, spoken, settled, head) => {
11202
11202
  const mine = spoken.filter((entry) => entry.comment === comment.id);
11203
11203
  return {
11204
+ id: comment.id,
11204
11205
  file: comment.file,
11205
11206
  side: comment.side,
11206
11207
  start: comment.start,
@@ -12432,6 +12433,7 @@ const initialState = (branches) => ({
12432
12433
  selecting: false,
12433
12434
  draft: "",
12434
12435
  notice: "",
12436
+ waiting: "",
12435
12437
  query: "",
12436
12438
  paletteIndex: 0,
12437
12439
  returnTo: "branches",
@@ -12677,7 +12679,21 @@ const commentRowsIn = (state, fileIndex) => {
12677
12679
  const notes = [...state.pending, ...state.sent].filter((entry) => entry.file === patch.path);
12678
12680
  return patch.rows.filter((row) => notes.some((note) => lineOnSide(row, note.side) === note.end)).map((row) => row.index).toSorted((left, right) => left - right);
12679
12681
  };
12682
+ const threadAtRow = (state, row) => {
12683
+ const patch = selectedPatch(state);
12684
+ const here = patch?.rows[row];
12685
+ if (patch === void 0 || here === void 0) return void 0;
12686
+ return state.sent.find((entry) => entry.file === patch.path && entry.id !== void 0 && lineOnSide(here, entry.side) === entry.end);
12687
+ };
12688
+ const openCommentRows = (state) => {
12689
+ const patch = selectedPatch(state);
12690
+ if (patch === void 0) return [];
12691
+ const open = [...state.pending, ...state.sent].filter((entry) => entry.file === patch.path && entry.settled !== true);
12692
+ return patch.rows.filter((row) => open.some((note) => lineOnSide(row, note.side) === note.end)).map((row) => row.index);
12693
+ };
12680
12694
  const filesWithComments = (state) => state.patches.flatMap((patch, index) => [...state.pending, ...state.sent].some((entry) => entry.file === patch.path) ? [index] : []);
12695
+ const answerCount = (comments) => comments.reduce((total, entry) => total + (entry.answers?.length ?? 0), 0);
12696
+ const spokenSince = (seen, now) => Math.max(0, answerCount(now) - answerCount(seen));
12681
12697
  const hunkStarts = (state) => {
12682
12698
  const patch = selectedPatch(state);
12683
12699
  return patch === void 0 ? [] : patch.hunks.map((hunk) => hunk.startRow);
@@ -12767,6 +12783,31 @@ const buildReport = (state, around) => {
12767
12783
  ].join("\n");
12768
12784
  };
12769
12785
  //#endregion
12786
+ //#region src/tui/watch.ts
12787
+ const OUTBOX = "outbox.jsonl";
12788
+ const SETTLE_MS = 120;
12789
+ const answered = (name) => name !== null && name.endsWith(OUTBOX);
12790
+ const watchAnswers = (root, arrived) => {
12791
+ const branches = join(root, "branches");
12792
+ let timer;
12793
+ let watcher;
12794
+ try {
12795
+ mkdirSync(branches, { recursive: true });
12796
+ watcher = watch(branches, { recursive: true }, (_event, name) => {
12797
+ if (!answered(name)) return;
12798
+ if (timer !== void 0) clearTimeout(timer);
12799
+ timer = setTimeout(arrived, SETTLE_MS);
12800
+ });
12801
+ watcher.on("error", () => void 0);
12802
+ } catch {
12803
+ watcher = void 0;
12804
+ }
12805
+ return { stop: () => {
12806
+ if (timer !== void 0) clearTimeout(timer);
12807
+ watcher?.close();
12808
+ } };
12809
+ };
12810
+ //#endregion
12770
12811
  //#region src/tui/command.ts
12771
12812
  const command = (input) => ({
12772
12813
  category: "Review",
@@ -12959,6 +13000,14 @@ const commands = [
12959
13000
  screens: ["branches", "review"],
12960
13001
  hint: "reload"
12961
13002
  }),
13003
+ command({
13004
+ action: "thread.settle",
13005
+ title: "Settle the thread here",
13006
+ category: "Review",
13007
+ keys: ["d"],
13008
+ screens: ["review"],
13009
+ hint: "settle"
13010
+ }),
12962
13011
  command({
12963
13012
  action: "rail.toggle",
12964
13013
  title: "Switch between layers and files",
@@ -13248,13 +13297,17 @@ const atComment = (state, file, delta) => {
13248
13297
  const landing = delta > 0 ? rows[0] : rows.at(-1);
13249
13298
  return landing === void 0 ? moved : atRow(moved, landing);
13250
13299
  };
13300
+ const nothingOpen = (state) => {
13301
+ const any = commentRowsIn(state, state.patchIndex).length > 0;
13302
+ return withNotice(state, any ? "no open comment" : "no comments yet");
13303
+ };
13251
13304
  const layerComment = (state, delta) => {
13252
- const here = commentRowsIn(state, state.patchIndex);
13305
+ const here = openCommentRows(state);
13253
13306
  const target = delta > 0 ? here.find((row) => row > state.cursor) : here.findLast((row) => row < state.cursor);
13254
13307
  if (target !== void 0) return atRow(state, target);
13255
13308
  const file = nextFileWithComments(state, delta);
13256
13309
  if (file !== void 0) return atComment(state, file, delta);
13257
- return here.length > 0 ? state : withNotice(state, "no comments yet");
13310
+ return here.length > 0 ? state : nothingOpen(state);
13258
13311
  };
13259
13312
  const PAN_STEP = 8;
13260
13313
  const panned = (state, delta) => {
@@ -13455,6 +13508,7 @@ const transitions = {
13455
13508
  "pan.right": (state) => panned(state, PAN_STEP),
13456
13509
  "pan.left": (state) => panned(state, -8),
13457
13510
  "review.reload": (state) => state,
13511
+ "thread.settle": (state) => state,
13458
13512
  "rail.toggle": toggleRail,
13459
13513
  "file.vouch": (state) => state,
13460
13514
  "file.vouch.next": (state) => state,
@@ -13616,6 +13670,10 @@ const paletteClosed = (state) => ({
13616
13670
  screen: state.returnTo,
13617
13671
  query: ""
13618
13672
  });
13673
+ const withWaiting = (state, waiting) => ({
13674
+ ...state,
13675
+ waiting
13676
+ });
13619
13677
  const withNoticeHere = (state, notice) => ({
13620
13678
  ...state,
13621
13679
  notice
@@ -13855,6 +13913,7 @@ var DiffView = class {
13855
13913
  starts = /* @__PURE__ */ new Map();
13856
13914
  fitted = 1;
13857
13915
  wrapped = false;
13916
+ held = 0;
13858
13917
  constructor(renderer) {
13859
13918
  this.code = new CodeRenderable(renderer, {
13860
13919
  id: "diff-code",
@@ -13963,12 +14022,15 @@ var DiffView = class {
13963
14022
  });
13964
14023
  this.starts = startsOf(this.display);
13965
14024
  this.code.filetype = pathToFiletype(patch.path) ?? "text";
13966
- this.code.content = this.display.map((entry) => entry.text).join("\n");
14025
+ this.feed();
13967
14026
  this.numbers.setLineNumbers(lineNumbers(patch, this.display));
13968
14027
  this.numbers.setHideLineNumbers(bareOf(this.display));
13969
14028
  this.numbers.setLineSigns(lineSigns(patch, this.display));
13970
14029
  this.numbers.setLineColors(/* @__PURE__ */ new Map());
13971
- const spans = noteSpans(this.display);
14030
+ }
14031
+ feed() {
14032
+ const spans = noteSpans(this.display, this.held);
14033
+ this.code.content = textAt(this.display, this.held);
13972
14034
  this.code.onHighlight = (highlights) => [...highlights.filter((highlight) => !spans.some(([from, to]) => highlight[0] < to && highlight[1] > from)), ...spans];
13973
14035
  }
13974
14036
  setWrap(on) {
@@ -13982,6 +14044,10 @@ var DiffView = class {
13982
14044
  }
13983
14045
  setPan(columns) {
13984
14046
  const wanted = this.wrapped ? 0 : Math.max(0, Math.min(this.code.maxScrollX, columns));
14047
+ if (wanted !== this.held) {
14048
+ this.held = wanted;
14049
+ this.feed();
14050
+ }
13985
14051
  if (this.code.scrollX !== wanted) this.code.scrollX = wanted;
13986
14052
  if (this.pinned.scrollX !== wanted) this.pinned.scrollX = wanted;
13987
14053
  }
@@ -14078,17 +14144,21 @@ const groupOf = (entry) => {
14078
14144
  if (entry.label) return "note.label";
14079
14145
  return entry.sent ? "note.sent" : "note";
14080
14146
  };
14081
- const noteSpans = (display) => {
14147
+ const isChrome = (entry) => entry.comment || entry.gap || entry.prose;
14148
+ const heldAt = (entry, pan) => isChrome(entry) && pan > 0 ? `${" ".repeat(pan)}${entry.text}` : entry.text;
14149
+ const textAt = (display, pan) => display.map((entry) => heldAt(entry, pan)).join("\n");
14150
+ const noteSpans = (display, pan) => {
14082
14151
  const spans = [];
14083
14152
  let at = 0;
14084
14153
  for (const entry of display) {
14085
14154
  const group = groupOf(entry);
14155
+ const width = heldAt(entry, pan).length;
14086
14156
  if (group !== void 0) spans.push([
14087
14157
  at,
14088
- at + entry.text.length,
14158
+ at + width,
14089
14159
  group
14090
14160
  ]);
14091
- at += entry.text.length + 1;
14161
+ at += width + 1;
14092
14162
  }
14093
14163
  return spans;
14094
14164
  };
@@ -14499,17 +14569,23 @@ const notesOf = (comments, path, sent) => comments.filter((entry) => entry.file
14499
14569
  answers: entry.answers ?? []
14500
14570
  }));
14501
14571
  const notesFor = (state, path) => [...notesOf(state.sent, path, true), ...notesOf(state.pending, path, false)];
14572
+ const paired = (chunks) => {
14573
+ const chips = [];
14574
+ for (let at = 0; at < chunks.length; at += CHIP_CHUNKS) chips.push(chunks.slice(at, at + CHIP_CHUNKS));
14575
+ return chips;
14576
+ };
14502
14577
  const keptWithin = (chunks, room) => {
14503
14578
  const kept = [];
14504
14579
  let used = 0;
14505
- for (const chunk of chunks.toReversed()) {
14506
- const width = chunk.text.length;
14580
+ for (const chip of paired(chunks).toReversed()) {
14581
+ const width = chip.reduce((total, chunk) => total + chunk.text.length, 0);
14507
14582
  if (used + width > room) break;
14508
- kept.unshift(chunk);
14583
+ kept.unshift(chip);
14509
14584
  used += width;
14510
14585
  }
14511
- return kept;
14586
+ return kept.flat();
14512
14587
  };
14588
+ const CHIP_CHUNKS = 3;
14513
14589
  const shortPath = (path) => {
14514
14590
  const home = process.env["HOME"] ?? "";
14515
14591
  return home.length > 0 && path.startsWith(home) ? `~${path.slice(home.length)}` : path;
@@ -14766,11 +14842,13 @@ var Screen = class {
14766
14842
  const readout = selectionReadout(state);
14767
14843
  this.lead = readout.length === 0 ? 0 : readout.length + 3;
14768
14844
  const lead = readout.length === 0 ? [] : [fg(palette.muted)(`${readout} `)];
14769
- const tail = state.notice.length === 0 ? "" : ` ${state.notice}`;
14845
+ const said = state.notice.length === 0 ? state.waiting : state.notice;
14846
+ const tail = said.length === 0 ? "" : ` ${said}`;
14770
14847
  const width = this.footer.width > 0 ? this.footer.width : this.renderer.width;
14771
14848
  const room = Math.max(0, width - this.lead - tail.length);
14772
14849
  const chips = keptWithin(this.chipRow().chunks, room);
14773
- const notice = tail.length === 0 ? [] : [fg(palette.attention)(tail)];
14850
+ const colour = state.notice.length === 0 ? palette.accent : palette.attention;
14851
+ const notice = tail.length === 0 ? [] : [fg(colour)(tail)];
14774
14852
  return new StyledText([
14775
14853
  ...lead,
14776
14854
  ...chips,
@@ -14915,8 +14993,10 @@ var Screen = class {
14915
14993
  }
14916
14994
  homeKeys(state) {
14917
14995
  const chips = this.chipRow().chunks;
14918
- if (state.notice.length === 0) return new StyledText(chips);
14919
- return new StyledText([...chips, fg(palette.attention)(` ${state.notice}`)]);
14996
+ const said = state.notice.length === 0 ? state.waiting : state.notice;
14997
+ if (said.length === 0) return new StyledText(chips);
14998
+ const colour = state.notice.length === 0 ? palette.accent : palette.attention;
14999
+ return new StyledText([...chips, fg(colour)(` ${said}`)]);
14920
15000
  }
14921
15001
  chipRow() {
14922
15002
  return new StyledText(this.chips.flatMap((chip, index) => {
@@ -15093,6 +15173,7 @@ var App = class {
15093
15173
  fading;
15094
15174
  wheel = 0;
15095
15175
  sideways = 0;
15176
+ watching;
15096
15177
  constructor(options) {
15097
15178
  this.renderer = options.renderer;
15098
15179
  this.repo = options.repo;
@@ -15114,13 +15195,34 @@ var App = class {
15114
15195
  onChip: (key) => this.dispatchTask(() => this.onKey(asKey(key)))
15115
15196
  });
15116
15197
  renderer.keyInput.on("keypress", (key) => this.dispatch(key));
15198
+ renderer.on("destroy", () => this.stopWatching());
15117
15199
  renderer.on("destroy", () => this.stopFading());
15118
15200
  renderer.on("frame", () => this.syncGeometry());
15119
15201
  renderer.setFrameCallback(async () => this.applyWheel());
15120
15202
  const resume = options.resume;
15203
+ this.startWatching(options.storeRoot);
15121
15204
  this.dispatchTask(() => this.loadPulls());
15122
15205
  if (resume !== void 0) this.dispatchTask(() => this.resume(resume));
15123
15206
  }
15207
+ startWatching(root) {
15208
+ if (root === void 0) return;
15209
+ this.watching = watchAnswers(root, () => this.dispatchTask(() => this.noticeAnswers()));
15210
+ }
15211
+ stopWatching() {
15212
+ this.watching?.stop();
15213
+ this.watching = void 0;
15214
+ }
15215
+ async noticeAnswers() {
15216
+ const branch = selectedBranch(this.state);
15217
+ if (branch === void 0) return this.noticeOnList();
15218
+ const sent = await this.loadSent(branch.branch);
15219
+ const said = spokenSince(this.state.sent, sent);
15220
+ if (said === 0) return;
15221
+ this.commit(withWaiting(this.state, `${said} answered · press r`));
15222
+ }
15223
+ async noticeOnList() {
15224
+ this.commit(withWaiting(this.state, "the agent answered · press r"));
15225
+ }
15124
15226
  dispatchTask(task) {
15125
15227
  this.pending = this.pending.then(task).catch((cause) => this.fail(cause));
15126
15228
  }
@@ -15236,6 +15338,7 @@ var App = class {
15236
15338
  "rail.toggle": () => this.commitSynced("rail.toggle"),
15237
15339
  "file.vouch": () => this.vouch(false),
15238
15340
  "file.vouch.next": () => this.vouch(true),
15341
+ "thread.settle": () => this.settleHere(),
15239
15342
  "review.reload": () => this.state.screen === "branches" ? this.reloadList() : this.reloadBranch(),
15240
15343
  "pending.open": () => this.openPending(),
15241
15344
  "pending.edit": () => this.editStagedComment(),
@@ -15304,6 +15407,14 @@ var App = class {
15304
15407
  this.commit(await this.readBranch(branch.branch));
15305
15408
  await this.loadSource();
15306
15409
  }
15410
+ async settleHere() {
15411
+ const branch = selectedBranch(this.state);
15412
+ const id = threadAtRow(this.state, this.state.cursor)?.id;
15413
+ if (branch === void 0 || id === void 0) return this.commit(withNotice(this.state, "no thread here"));
15414
+ await this.run(settleThread(this.repo, branch.branch, id, (/* @__PURE__ */ new Date()).toISOString()));
15415
+ const sent = await this.loadSent(branch.branch);
15416
+ this.commit(withNotice(withSent(this.state, sent), "settled"));
15417
+ }
15307
15418
  async reloadList() {
15308
15419
  const here = selectedBranch(this.state)?.branch;
15309
15420
  const branches = await this.run(listBranches(this.repo));
@@ -15313,7 +15424,7 @@ var App = class {
15313
15424
  ...read,
15314
15425
  branchIndex: at
15315
15426
  };
15316
- this.commit(withNoticeHere(kept, "read the list again"));
15427
+ this.commit(withWaiting(withNoticeHere(kept, "read the list again"), ""));
15317
15428
  this.dispatchTask(() => this.loadPulls());
15318
15429
  }
15319
15430
  async reloadBranch() {
@@ -15322,7 +15433,7 @@ var App = class {
15322
15433
  const path = selectedPatch(this.state)?.path;
15323
15434
  const line = sourceLineAt(this.state, this.state.cursor);
15324
15435
  const read = await this.readBranch(branch.branch);
15325
- this.commit(withNotice(restoredTo(read, path, line), "read the branch again"));
15436
+ this.commit(withWaiting(withNotice(restoredTo(read, path, line), "read the branch again"), ""));
15326
15437
  await this.loadSource();
15327
15438
  }
15328
15439
  async goBack() {
@@ -15523,7 +15634,8 @@ const launch = fn("Tui.launch")(function* (repo, renderer, noticeMs, sessionPath
15523
15634
  const context$2 = yield* context();
15524
15635
  const branches = yield* listBranches(repo);
15525
15636
  const resume = sessionPath === void 0 ? void 0 : yield* promise(() => readSession(sessionPath));
15526
- const settings = yield* (yield* Store).settings();
15637
+ const store = yield* Store;
15638
+ const settings = yield* store.settings();
15527
15639
  return new App({
15528
15640
  renderer,
15529
15641
  repo,
@@ -15532,7 +15644,8 @@ const launch = fn("Tui.launch")(function* (repo, renderer, noticeMs, sessionPath
15532
15644
  noticeMs,
15533
15645
  sessionPath,
15534
15646
  resume,
15535
- wrap: settings.wrap === true
15647
+ wrap: settings.wrap === true,
15648
+ storeRoot: store.root
15536
15649
  });
15537
15650
  });
15538
15651
  const untilDestroyed = (renderer) => callback((resume) => {
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.16",
24
+ "version": "0.1.0-alpha.17",
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": {