@eliya-oss/agent-diff 0.1.0-alpha.11 → 0.1.0-alpha.12

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.12
4
+
5
+ ### Patch Changes
6
+
7
+ - An agent can answer a comment, and a reviewer can settle the thread.
8
+
3
9
  ## 0.1.0-alpha.11
4
10
 
5
11
  ### Patch Changes
package/dist/main.js CHANGED
@@ -10795,7 +10795,8 @@ var StoreUnreadable = class extends TaggedError("StoreUnreadable") {};
10795
10795
  const emptyBranchState = {
10796
10796
  vouches: {},
10797
10797
  consumed: 0,
10798
- pending: []
10798
+ pending: [],
10799
+ settled: {}
10799
10800
  };
10800
10801
  //#endregion
10801
10802
  //#region src/service/store/paths.ts
@@ -10804,6 +10805,7 @@ const slugOf = (worktreePath) => worktreePath.replace(NON_SLUG, "-");
10804
10805
  const defaultRoot = () => join(homedir(), ".adiff");
10805
10806
  const branchDir = (root, worktreePath) => join(root, "branches", slugOf(worktreePath));
10806
10807
  const inboxPath = (root, worktreePath) => join(branchDir(root, worktreePath), "inbox.jsonl");
10808
+ const outboxPath = (root, worktreePath) => join(branchDir(root, worktreePath), "outbox.jsonl");
10807
10809
  const statePath = (root, worktreePath) => join(branchDir(root, worktreePath), "state.json");
10808
10810
  const layersPath = (root, worktreePath) => join(branchDir(root, worktreePath), "layers.json");
10809
10811
  const reportsDir = (root) => join(root, "reports");
@@ -10831,6 +10833,7 @@ const readOptional = fn("Store.readOptional")(function* (path) {
10831
10833
  });
10832
10834
  const missing = succeed(none());
10833
10835
  const parseBatches = (raw) => raw.split("\n").filter((line) => line.trim().length > 0).map((line) => JSON.parse(line));
10836
+ const parseAnswers = (raw) => raw.split("\n").filter((line) => line.trim().length > 0).map((line) => JSON.parse(line));
10834
10837
  const parseState = (raw) => ({
10835
10838
  ...emptyBranchState,
10836
10839
  ...JSON.parse(raw)
@@ -10858,6 +10861,40 @@ const cursorOps = (state, saveState, inbox) => {
10858
10861
  })
10859
10862
  };
10860
10863
  };
10864
+ const reportOps = (root) => fn("Store.saveReport")(function* (stamp, text) {
10865
+ const path = reportPath(root, stamp);
10866
+ yield* ensureDir(reportsDir(root));
10867
+ yield* tryPromise({
10868
+ try: () => writeFile(path, text, "utf8"),
10869
+ catch: (cause) => new StoreUnwritable({
10870
+ path,
10871
+ reason: String(cause)
10872
+ })
10873
+ });
10874
+ return path;
10875
+ });
10876
+ const answerOps = (root) => {
10877
+ return {
10878
+ answer: fn("Store.answer")(function* (worktreePath, entry) {
10879
+ const path = outboxPath(root, worktreePath);
10880
+ yield* ensureDir(branchDir(root, worktreePath));
10881
+ yield* tryPromise({
10882
+ try: () => appendFile(path, `${JSON.stringify(entry)}\n`, "utf8"),
10883
+ catch: (cause) => new StoreUnwritable({
10884
+ path,
10885
+ reason: String(cause)
10886
+ })
10887
+ });
10888
+ }),
10889
+ answers: fn("Store.answers")(function* (worktreePath) {
10890
+ const raw = yield* readOptional(outboxPath(root, worktreePath));
10891
+ return match$2(raw, {
10892
+ onNone: () => [],
10893
+ onSome: parseAnswers
10894
+ });
10895
+ })
10896
+ };
10897
+ };
10861
10898
  const layersOps = (root) => {
10862
10899
  return {
10863
10900
  layers: fn("Store.layers")(function* (worktreePath) {
@@ -10914,18 +10951,6 @@ const makeStore = (root) => {
10914
10951
  })
10915
10952
  });
10916
10953
  });
10917
- const saveReport = fn("Store.saveReport")(function* (stamp, text) {
10918
- const path = reportPath(root, stamp);
10919
- yield* ensureDir(reportsDir(root));
10920
- yield* tryPromise({
10921
- try: () => writeFile(path, text, "utf8"),
10922
- catch: (cause) => new StoreUnwritable({
10923
- path,
10924
- reason: String(cause)
10925
- })
10926
- });
10927
- return path;
10928
- });
10929
10954
  const cursors = cursorOps(state, saveState, inbox);
10930
10955
  return {
10931
10956
  root,
@@ -10933,7 +10958,8 @@ const makeStore = (root) => {
10933
10958
  inbox,
10934
10959
  state,
10935
10960
  saveState,
10936
- saveReport,
10961
+ saveReport: reportOps(root),
10962
+ ...answerOps(root),
10937
10963
  ...layersOps(root),
10938
10964
  ...cursors
10939
10965
  };
@@ -10944,6 +10970,7 @@ storeAt(defaultRoot());
10944
10970
  //#region src/cli/error.ts
10945
10971
  var UnknownBranch = class extends TaggedError("UnknownBranch") {};
10946
10972
  var UnknownFile = class extends TaggedError("UnknownFile") {};
10973
+ var UnknownComment = class extends TaggedError("UnknownComment") {};
10947
10974
  var UnselectableRange = class extends TaggedError("UnselectableRange") {};
10948
10975
  var UnknownCommand = class extends TaggedError("UnknownCommand") {};
10949
10976
  var MissingOption = class extends TaggedError("MissingOption") {};
@@ -11095,6 +11122,7 @@ const listPending = fn("Cli.listPending")(function* (repo, branch) {
11095
11122
  const store = yield* Store;
11096
11123
  const worktree = yield* findBranch(repo, branch);
11097
11124
  return (yield* store.state(worktree.path)).pending.map((entry) => ({
11125
+ id: entry.id,
11098
11126
  file: entry.anchor.path,
11099
11127
  side: entry.anchor.side,
11100
11128
  start: entry.anchor.start,
@@ -11102,16 +11130,26 @@ const listPending = fn("Cli.listPending")(function* (repo, branch) {
11102
11130
  body: entry.body
11103
11131
  }));
11104
11132
  });
11105
- const listSent = fn("Cli.listSent")(function* (repo, branch) {
11106
- const store = yield* Store;
11107
- const worktree = yield* findBranch(repo, branch);
11108
- return flatten(yield* store.inbox(worktree.path)).map((comment) => ({
11133
+ const bodyOf = (entry) => entry.body;
11134
+ const sentOf = (comment, spoken, settled) => {
11135
+ const mine = spoken.filter((entry) => entry.comment === comment.id);
11136
+ return {
11109
11137
  file: comment.file,
11110
11138
  side: comment.side,
11111
11139
  start: comment.start,
11112
11140
  end: comment.end,
11113
- body: comment.body
11114
- }));
11141
+ body: comment.body,
11142
+ settled: Object.hasOwn(settled, comment.id),
11143
+ asks: mine.at(-1)?.asks === true,
11144
+ answers: mine.map(bodyOf)
11145
+ };
11146
+ };
11147
+ const listSent = fn("Cli.listSent")(function* (repo, branch) {
11148
+ const store = yield* Store;
11149
+ const worktree = yield* findBranch(repo, branch);
11150
+ const spoken = yield* store.answers(worktree.path);
11151
+ const current = yield* store.state(worktree.path);
11152
+ return flatten(yield* store.inbox(worktree.path)).map((comment) => sentOf(comment, spoken, current.settled));
11115
11153
  });
11116
11154
  const submitReview = fn("Cli.submitReview")(function* (repo, branch, id, at) {
11117
11155
  const store = yield* Store;
@@ -11179,6 +11217,7 @@ const listPatches = fn("Cli.listPatches")(function* (repo, branch, context = CON
11179
11217
  return parsePatches(yield* git.diff(worktree, context));
11180
11218
  });
11181
11219
  const flatten = (batches) => batches.flatMap((batch) => batch.comments.map((comment) => ({
11220
+ id: comment.id,
11182
11221
  at: batch.at,
11183
11222
  head: batch.head,
11184
11223
  file: comment.anchor.path,
@@ -11472,6 +11511,76 @@ const listLayers = fn("Cli.listLayers")(function* (repo, branch) {
11472
11511
  };
11473
11512
  });
11474
11513
  //#endregion
11514
+ //#region src/cli/threads.ts
11515
+ const stateOf$1 = (answers, isSettled) => {
11516
+ if (isSettled) return "done";
11517
+ const last = answers.at(-1);
11518
+ if (last === void 0) return "submitted";
11519
+ return last.asks ? "question" : "answered";
11520
+ };
11521
+ const spoken$1 = (entry) => ({
11522
+ body: entry.body,
11523
+ at: entry.at,
11524
+ asks: entry.asks
11525
+ });
11526
+ const threadOf = (comment, batch, reading) => {
11527
+ const mine = reading.answers.filter((entry) => entry.comment === comment.id);
11528
+ return {
11529
+ id: comment.id,
11530
+ file: comment.anchor.path,
11531
+ side: comment.anchor.side,
11532
+ start: comment.anchor.start,
11533
+ end: comment.anchor.end,
11534
+ body: comment.body,
11535
+ state: stateOf$1(mine, Object.hasOwn(reading.settled, comment.id)),
11536
+ stale: batch.head !== reading.head,
11537
+ answers: mine.map(spoken$1)
11538
+ };
11539
+ };
11540
+ const threadsIn = (batches, reading) => batches.flatMap((batch) => batch.comments.map((comment) => threadOf(comment, batch, reading)));
11541
+ const idsIn = (batches) => batches.flatMap((batch) => batch.comments.map((comment) => comment.id));
11542
+ const isKnown = fn("Cli.isKnown")(function* (worktreePath, id) {
11543
+ const store = yield* Store;
11544
+ return idsIn(yield* store.inbox(worktreePath)).includes(id);
11545
+ });
11546
+ const listThreads = fn("Cli.listThreads")(function* (repo, branch) {
11547
+ const store = yield* Store;
11548
+ const worktree = yield* findBranch(repo, branch);
11549
+ const current = yield* store.state(worktree.path);
11550
+ return threadsIn(yield* store.inbox(worktree.path), {
11551
+ answers: yield* store.answers(worktree.path),
11552
+ settled: current.settled,
11553
+ head: worktree.head
11554
+ });
11555
+ });
11556
+ const answerComment = fn("Cli.answerComment")(function* (request) {
11557
+ const store = yield* Store;
11558
+ const worktree = yield* worktreeAt(request.worktree);
11559
+ if (!(yield* isKnown(worktree.path, request.id))) return yield* new UnknownComment({ id: request.id });
11560
+ yield* store.answer(worktree.path, {
11561
+ comment: request.id,
11562
+ body: request.body,
11563
+ head: worktree.head,
11564
+ asks: request.asks,
11565
+ at: request.at
11566
+ });
11567
+ return { answered: (yield* store.answers(worktree.path)).filter((entry) => entry.comment === request.id).length };
11568
+ });
11569
+ const settleThread = fn("Cli.settleThread")(function* (repo, branch, id, at) {
11570
+ const store = yield* Store;
11571
+ const worktree = yield* findBranch(repo, branch);
11572
+ if (!(yield* isKnown(worktree.path, id))) return yield* new UnknownComment({ id });
11573
+ const current = yield* store.state(worktree.path);
11574
+ yield* store.saveState(worktree.path, {
11575
+ ...current,
11576
+ settled: {
11577
+ ...current.settled,
11578
+ [id]: at
11579
+ }
11580
+ });
11581
+ return { settled: id };
11582
+ });
11583
+ //#endregion
11475
11584
  //#region src/cli/parse.ts
11476
11585
  const optionsFrom = (argv) => {
11477
11586
  const options = {};
@@ -11614,6 +11723,64 @@ const catalog = [
11614
11723
  dataKey: "comments",
11615
11724
  example: "adiff comment take --worktree . --wait 300"
11616
11725
  },
11726
+ {
11727
+ name: "comment answer",
11728
+ about: "Say what was done about a comment, or ask the reviewer something back",
11729
+ safety: "write",
11730
+ options: [
11731
+ {
11732
+ name: "worktree",
11733
+ required: true,
11734
+ value: "path",
11735
+ about: "The worktree the comment was written against"
11736
+ },
11737
+ {
11738
+ name: "id",
11739
+ required: true,
11740
+ value: "id",
11741
+ about: "The comment being answered, as `comment take` reported it"
11742
+ },
11743
+ {
11744
+ name: "body",
11745
+ required: true,
11746
+ value: "text",
11747
+ about: "What was done, or what is being asked"
11748
+ },
11749
+ {
11750
+ name: "asks",
11751
+ required: false,
11752
+ value: "flag",
11753
+ about: "The answer needs a reply before the work continues"
11754
+ }
11755
+ ],
11756
+ dataKey: "answered",
11757
+ example: "adiff comment answer --worktree . --id c1 --body \"dropped it, and the import with it\""
11758
+ },
11759
+ {
11760
+ name: "comment threads",
11761
+ about: "Every comment on a branch with its answers and whether it is settled",
11762
+ safety: "read",
11763
+ options: [repo, branch],
11764
+ dataKey: "threads",
11765
+ example: "adiff comment threads --repo . --branch add-teammate-invitations"
11766
+ },
11767
+ {
11768
+ name: "comment resolve",
11769
+ about: "Mark a comment settled. Only the reviewer who raised it can",
11770
+ safety: "write",
11771
+ options: [
11772
+ repo,
11773
+ branch,
11774
+ {
11775
+ name: "id",
11776
+ required: true,
11777
+ value: "id",
11778
+ about: "The comment to settle"
11779
+ }
11780
+ ],
11781
+ dataKey: "settled",
11782
+ example: "adiff comment resolve --repo . --branch add-teammate-invitations --id c1"
11783
+ },
11617
11784
  {
11618
11785
  name: "file vouch",
11619
11786
  about: "Toggle a file as reviewed. Lapses on its own when the file changes",
@@ -11738,6 +11905,11 @@ const ADVICE = {
11738
11905
  suggestion: "No layers has been written for this worktree. Write one with `adiff layers set`.",
11739
11906
  retriable: false
11740
11907
  },
11908
+ UnknownComment: {
11909
+ exit: 3,
11910
+ suggestion: "No comment carries that id. Ids come from `adiff comment take`; answer a comment it handed you.",
11911
+ retriable: false
11912
+ },
11741
11913
  UnselectableRange: {
11742
11914
  exit: 2,
11743
11915
  suggestion: "Those lines are not in the diff. Check --side: new is the working tree, old is the version being replaced.",
@@ -13377,6 +13549,7 @@ const WASH = {
13377
13549
  }
13378
13550
  };
13379
13551
  const NOTE_MIN = 24;
13552
+ const ANSWER_MARK = "↳";
13380
13553
  const OVERSCAN = 2;
13381
13554
  const SIGN_WIDTH = 2;
13382
13555
  const SCROLL_ROWS = 3;
@@ -13606,7 +13779,21 @@ const wrap = (text, room) => {
13606
13779
  }
13607
13780
  return lines;
13608
13781
  };
13609
- const noteLines = (note, room) => [note.sent ? `${marks().sent} sent` : `${marks().staged} staged`, ...note.body.split("\n").flatMap((line) => wrap(line, room))];
13782
+ const headOf = (note) => {
13783
+ if (note.settled) return `${marks().sent} settled`;
13784
+ if (note.asks) return `${marks().staged} asked back`;
13785
+ if (note.answers.length > 0) return `${marks().sent} answered`;
13786
+ return note.sent ? `${marks().sent} sent` : `${marks().staged} staged`;
13787
+ };
13788
+ const spokenLines = (body, room) => {
13789
+ return wrap(body.replaceAll("\n", " "), Math.max(NOTE_MIN, room - 2)).map((text, at) => at === 0 ? `${ANSWER_MARK} ${text}` : ` ${text}`);
13790
+ };
13791
+ const answerLines = (note, room) => note.answers.flatMap((body) => spokenLines(body, room));
13792
+ const noteLines = (note, room) => [
13793
+ headOf(note),
13794
+ ...note.body.split("\n").flatMap((line) => wrap(line, room)),
13795
+ ...answerLines(note, room)
13796
+ ];
13610
13797
  const noteRows = (note, row, room) => noteLines(note, room).map((line, index) => ({
13611
13798
  text: `${marks().rule} ${line}`,
13612
13799
  row,
@@ -13975,7 +14162,10 @@ const notesOf = (comments, path, sent) => comments.filter((entry) => entry.file
13975
14162
  side: entry.side,
13976
14163
  line: entry.end,
13977
14164
  body: entry.body,
13978
- sent
14165
+ sent,
14166
+ settled: entry.settled === true,
14167
+ asks: entry.asks === true,
14168
+ answers: entry.answers ?? []
13979
14169
  }));
13980
14170
  const notesFor = (state, path) => [...notesOf(state.sent, path, true), ...notesOf(state.pending, path, false)];
13981
14171
  const keptWithin = (chunks, room) => {
@@ -14970,6 +15160,24 @@ const commentTake = fn("Main.commentTake")(function* (options) {
14970
15160
  const comments = wait > 0 ? yield* awaitComments(worktree, Date.now() + wait * WAIT_UNIT) : yield* takeComments(worktree);
14971
15161
  yield* answer(options, { comments });
14972
15162
  });
15163
+ const commentAnswer = fn("Main.commentAnswer")(function* (options) {
15164
+ const report = yield* answerComment({
15165
+ worktree: yield* required(options, "worktree"),
15166
+ id: yield* required(options, "id"),
15167
+ body: yield* required(options, "body"),
15168
+ asks: options["asks"] !== void 0,
15169
+ at: options["at"] ?? (/* @__PURE__ */ new Date()).toISOString()
15170
+ });
15171
+ yield* answer(options, { answered: report.answered });
15172
+ });
15173
+ const commentThreads = fn("Main.commentThreads")(function* (options) {
15174
+ const threads = yield* listThreads(yield* required(options, "repo"), yield* required(options, "branch"));
15175
+ yield* answer(options, { threads });
15176
+ });
15177
+ const commentResolve = fn("Main.commentResolve")(function* (options) {
15178
+ const report = yield* settleThread(yield* required(options, "repo"), yield* required(options, "branch"), yield* required(options, "id"), options["at"] ?? (/* @__PURE__ */ new Date()).toISOString());
15179
+ yield* answer(options, { settled: report.settled });
15180
+ });
14973
15181
  const commentStage = fn("Main.commentStage")(function* (options) {
14974
15182
  const report = yield* stageComment({
14975
15183
  repo: yield* required(options, "repo"),
@@ -15018,6 +15226,9 @@ const routes = {
15018
15226
  "comment add": commentAdd,
15019
15227
  "comment stage": commentStage,
15020
15228
  "comment take": commentTake,
15229
+ "comment answer": commentAnswer,
15230
+ "comment threads": commentThreads,
15231
+ "comment resolve": commentResolve,
15021
15232
  "review submit": reviewSubmit,
15022
15233
  "review progress": reviewStatus,
15023
15234
  "layers set": fn("Main.layersSet")(function* (options) {
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.11",
24
+ "version": "0.1.0-alpha.12",
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": {
@@ -43,6 +43,33 @@ Re-arm it after each comment you handle, and keep it running while you work. A r
43
43
  their own pace, so comments arrive minutes apart, and the whole point is that they reach you as
44
44
  events rather than by you asking. When you finish a piece of work, say you are still listening.
45
45
 
46
+ ## Answering a comment
47
+
48
+ Say what you did, against the comment you were handed:
49
+
50
+ ```bash
51
+ adiff comment answer --worktree . --id <id> --body "Dropped it, and the import with it."
52
+ ```
53
+
54
+ The id comes from `comment take`. The reviewer sees the answer under their own words the next time
55
+ they read the branch, so this is how they learn a point was addressed rather than ignored.
56
+
57
+ Answer when the change alone does not carry the reasoning: what you did instead of what was asked,
58
+ what you found while doing it, or why the comment does not apply. A comment that asked a question
59
+ deserves an answer even when nothing changed.
60
+
61
+ Add `--asks` when you need the reviewer to decide before you continue:
62
+
63
+ ```bash
64
+ adiff comment answer --worktree . --id <id> --asks --body "Drop it, or keep it and map the error?"
65
+ ```
66
+
67
+ That marks the thread as waiting on them rather than on you. Do not use it to check in; use it when
68
+ the work genuinely stops without an answer.
69
+
70
+ Settling a thread is the reviewer's to do, not yours. They raised the point, so they decide it is
71
+ closed.
72
+
46
73
  ## Acting on a comment
47
74
 
48
75
  Read `snippet` before opening the file: the reviewer commented on the diff, and the file may have