@eliya-oss/agent-diff 0.1.0-alpha.123 → 0.1.0-alpha.124

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,13 @@
1
1
  # @eliya-oss/agent-diff
2
2
 
3
+ ## 0.1.0-alpha.124
4
+
5
+ ### Patch Changes
6
+
7
+ - `draft send` keeps the comments the forge did not take. A send the forge only partly accepted deleted every draft it had asked about and reported success, so comments the pull request never received were gone from disk. Only drafts the forge names back are cleared; the rest stay held, the answer says how many landed and how many are still waiting, and sending again sends only those. A reply adiff cannot read confirms nothing rather than everything.
8
+
9
+ Two sends at once post one review. They used to race, each read the whole set, and each post it, so the pull request got two identical reviews. A send now holds a lock across the whole cycle, and a second one finds nothing left to send.
10
+
3
11
  ## 0.1.0-alpha.123
4
12
 
5
13
  ### Patch Changes
package/dist/main.js CHANGED
@@ -8819,7 +8819,7 @@ var init_error$3 = __esmMin((() => {
8819
8819
  }));
8820
8820
  //#endregion
8821
8821
  //#region src/service/forge/service.ts
8822
- var Forge, LIMIT, TIMEOUT_MS$1, SEND_TIMEOUT_MS, MOST_OUTPUT, FIELDS$1, Row, decode$1, SAID, stateOf$1, ended, ask, show, read, pulls, openPull, NUMBER_FIELDS, Named, readNamed, gh, named, head, sideName, commentBody, bodyFor, Landed, readLanded, landedIn, review, ForgeLive;
8822
+ var Forge, LIMIT, TIMEOUT_MS$1, SEND_TIMEOUT_MS, MOST_OUTPUT, FIELDS$1, Row, decode$1, SAID, stateOf$1, ended, ask, show, read, pulls, openPull, NUMBER_FIELDS, Named, readNamed, gh, named, head, sideName, commentBody, bodyFor, Landed, readLanded, keyOf$2, counted, acknowledged, landedIn, review, ForgeLive;
8823
8823
  var init_service$2 = __esmMin((() => {
8824
8824
  init_dist();
8825
8825
  init_error$3();
@@ -8983,10 +8983,27 @@ var init_service$2 = __esmMin((() => {
8983
8983
  line: optionalKey(Int)
8984
8984
  }))) });
8985
8985
  readLanded = decodeUnknownEffect(Landed);
8986
+ keyOf$2 = (path, line) => `${path}:${line}`;
8987
+ counted = (back) => {
8988
+ const room = /* @__PURE__ */ new Map();
8989
+ back.forEach((one) => {
8990
+ const key = keyOf$2(one.path, one.line ?? 0);
8991
+ room.set(key, (room.get(key) ?? 0) + 1);
8992
+ });
8993
+ return room;
8994
+ };
8995
+ acknowledged = (said) => runSync(orElseSucceed(flatMap(try_(() => JSON.parse(said)), (value) => orElseSucceed(readLanded(value), () => ({ comments: void 0 }))), () => ({ comments: void 0 }))).comments;
8986
8996
  landedIn = (said, asked) => {
8987
- const back = runSync(orElseSucceed(flatMap(try_(() => JSON.parse(said)), (value) => orElseSucceed(readLanded(value), () => ({ comments: void 0 }))), () => ({ comments: void 0 }))).comments;
8988
- if (back === void 0) return asked.map((one) => `${one.path}:${one.line}`);
8989
- return back.map((one) => `${one.path}:${one.line ?? 0}`);
8997
+ const back = acknowledged(said);
8998
+ if (back === void 0) return [];
8999
+ const room = counted(back);
9000
+ return asked.flatMap((one, at) => {
9001
+ const key = keyOf$2(one.path, one.line);
9002
+ const left = room.get(key) ?? 0;
9003
+ if (left === 0) return [];
9004
+ room.set(key, left - 1);
9005
+ return [at];
9006
+ });
8990
9007
  };
8991
9008
  review = fn("Forge.review")(function* (repo, branch, comments) {
8992
9009
  const pull = yield* named(repo, branch);
@@ -9159,7 +9176,7 @@ var init_paths = __esmMin((() => {
9159
9176
  }));
9160
9177
  //#endregion
9161
9178
  //#region src/service/store/service.ts
9162
- var Store, ensureDir, readOptional, missing$1, damaged, jsonOf$1, decoded, unwritable, wrote, added, INDENT, DRAFTS_VERSION, encoded, writes, appends, writeSettings, writeUpgradeCheck, writeState, writeLayers, writeDrafts, writeBatch, writeAnswer, asSettings, asUpgradeCheck, asBatch, asAnswer, asState, asLayers, asDrafts, linesOf, readLines, parseSettings, parseUpgradeCheck, parseState, parseLayers, cursorOps, settingsOps, upgradeOps, reportOps, HEAD_REF, gitDirOf, headOf$1, repoOf$2, branchKeyOf, wasKeyOf, there, moved, adopt, SPLIT$1, ADOPT_SIZE, adopting, keyIn, answerOps, draftsOps, layersOps, inboxOps, LOCK_TRIES, LOCK_WAIT_MS, LOCK_STALE_MS, held$1, stale$1, stolen, taken, freed, stateOps, makeStore, madeStore, storeAt;
9179
+ var Store, ensureDir, readOptional, missing$1, damaged, jsonOf$1, decoded, unwritable, wrote, added, INDENT, DRAFTS_VERSION, encoded, writes, appends, writeSettings, writeUpgradeCheck, writeState, writeLayers, writeDrafts, writeBatch, writeAnswer, asSettings, asUpgradeCheck, asBatch, asAnswer, asState, asLayers, asDrafts, linesOf, readLines, parseSettings, parseUpgradeCheck, parseState, parseLayers, cursorOps, settingsOps, upgradeOps, reportOps, HEAD_REF, gitDirOf, headOf$1, repoOf$2, branchKeyOf, wasKeyOf, there, moved, adopt, SPLIT$1, ADOPT_SIZE, adopting, keyIn, answerOps, layersOps, inboxOps, STATE_LOCK, DRAFTS_LOCK, held$1, stale$1, stolen, taken, freed, alone, draftsOps, stateOps, makeStore, madeStore, storeAt;
9163
9180
  var init_service$1 = __esmMin((() => {
9164
9181
  init_dist();
9165
9182
  init_error$2();
@@ -9360,27 +9377,6 @@ var init_service$1 = __esmMin((() => {
9360
9377
  })
9361
9378
  };
9362
9379
  };
9363
- draftsOps = (root, adopted) => {
9364
- return {
9365
- drafts: fn("Store.drafts")(function* (worktreePath) {
9366
- const key = yield* keyIn(adopted, worktreePath);
9367
- const path = draftsPath(root, key);
9368
- const raw = yield* readOptional(path);
9369
- if (isNone(raw)) return [];
9370
- const value = yield* jsonOf$1(path, raw.value);
9371
- return (yield* asDrafts(path, value)).drafts;
9372
- }),
9373
- saveDrafts: fn("Store.saveDrafts")(function* (worktreePath, next) {
9374
- const key = yield* keyIn(adopted, worktreePath);
9375
- const path = draftsPath(root, key);
9376
- yield* ensureDir(branchDir(root, key));
9377
- yield* writeDrafts(path, {
9378
- version: DRAFTS_VERSION,
9379
- drafts: next
9380
- });
9381
- })
9382
- };
9383
- };
9384
9380
  layersOps = (root, adopted) => {
9385
9381
  return {
9386
9382
  layers: fn("Store.layers")(function* (worktreePath) {
@@ -9417,9 +9413,16 @@ var init_service$1 = __esmMin((() => {
9417
9413
  })
9418
9414
  };
9419
9415
  };
9420
- LOCK_TRIES = 240;
9421
- LOCK_WAIT_MS = 25;
9422
- LOCK_STALE_MS = 15e3;
9416
+ STATE_LOCK = {
9417
+ tries: 240,
9418
+ waitMs: 25,
9419
+ staleMs: 15e3
9420
+ };
9421
+ DRAFTS_LOCK = {
9422
+ tries: 600,
9423
+ waitMs: 50,
9424
+ staleMs: 3e4
9425
+ };
9423
9426
  held$1 = (path) => tryPromise({
9424
9427
  try: () => writeFile(path, `${process.pid}`, { flag: "wx" }),
9425
9428
  catch: (cause) => new StoreUnwritable({
@@ -9427,13 +9430,43 @@ var init_service$1 = __esmMin((() => {
9427
9430
  reason: String(cause)
9428
9431
  })
9429
9432
  });
9430
- stale$1 = (path) => promise(() => stat(path).then((found) => Date.now() - found.mtimeMs > LOCK_STALE_MS, () => false));
9431
- stolen = (path, cause) => flatMap(stale$1(path), (old) => old ? flatMap(promise(() => rm(path, { force: true })), () => held$1(path)) : fail(cause));
9432
- taken = (path) => retry(held$1(path).pipe(catchTag("StoreUnwritable", (cause) => stolen(path, cause))), {
9433
- times: LOCK_TRIES,
9434
- schedule: spaced(LOCK_WAIT_MS)
9433
+ stale$1 = (path, waiting) => promise(() => stat(path).then((found) => Date.now() - found.mtimeMs > waiting.staleMs, () => false));
9434
+ stolen = (path, waiting, cause) => flatMap(stale$1(path, waiting), (old) => old ? flatMap(promise(() => rm(path, { force: true })), () => held$1(path)) : fail(cause));
9435
+ taken = (path, waiting) => retry(held$1(path).pipe(catchTag("StoreUnwritable", (cause) => stolen(path, waiting, cause))), {
9436
+ times: waiting.tries,
9437
+ schedule: spaced(waiting.waitMs)
9435
9438
  });
9436
9439
  freed = (path) => promise(() => rm(path, { force: true }));
9440
+ alone = (path, waiting, work) => acquireUseRelease(taken(path, waiting), () => work, () => freed(path));
9441
+ draftsOps = (root, adopted) => {
9442
+ const drafts = fn("Store.drafts")(function* (worktreePath) {
9443
+ const key = yield* keyIn(adopted, worktreePath);
9444
+ const path = draftsPath(root, key);
9445
+ const raw = yield* readOptional(path);
9446
+ if (isNone(raw)) return [];
9447
+ const value = yield* jsonOf$1(path, raw.value);
9448
+ return (yield* asDrafts(path, value)).drafts;
9449
+ });
9450
+ const saveDrafts = fn("Store.saveDrafts")(function* (worktreePath, next) {
9451
+ const key = yield* keyIn(adopted, worktreePath);
9452
+ const path = draftsPath(root, key);
9453
+ yield* ensureDir(branchDir(root, key));
9454
+ yield* writeDrafts(path, {
9455
+ version: DRAFTS_VERSION,
9456
+ drafts: next
9457
+ });
9458
+ });
9459
+ const whileHoldingDrafts = (worktreePath, work) => gen(function* () {
9460
+ const key = yield* keyIn(adopted, worktreePath);
9461
+ yield* ensureDir(branchDir(root, key));
9462
+ return yield* alone(`${draftsPath(root, key)}.lock`, DRAFTS_LOCK, work);
9463
+ }).pipe(withSpan("Store.whileHoldingDrafts"));
9464
+ return {
9465
+ drafts,
9466
+ saveDrafts,
9467
+ whileHoldingDrafts
9468
+ };
9469
+ };
9437
9470
  stateOps = (root, adopted) => {
9438
9471
  const state = fn("Store.state")(function* (worktreePath) {
9439
9472
  const key = yield* keyIn(adopted, worktreePath);
@@ -9453,8 +9486,7 @@ var init_service$1 = __esmMin((() => {
9453
9486
  const changeState = fn("Store.changeState")(function* (worktreePath, change) {
9454
9487
  const key = yield* keyIn(adopted, worktreePath);
9455
9488
  yield* ensureDir(branchDir(root, key));
9456
- const lock = `${statePath(root, key)}.lock`;
9457
- yield* acquireUseRelease(taken(lock), () => under(worktreePath, change), () => freed(lock));
9489
+ yield* alone(`${statePath(root, key)}.lock`, STATE_LOCK, under(worktreePath, change));
9458
9490
  });
9459
9491
  const under = fn("Store.under")(function* (worktreePath, change) {
9460
9492
  yield* saveState(worktreePath, change(yield* state(worktreePath)));
@@ -10062,7 +10094,7 @@ var init_preferences = __esmMin((() => {
10062
10094
  }));
10063
10095
  //#endregion
10064
10096
  //#region src/cli/error.ts
10065
- var UnknownBranch, UnknownBase, UnknownFile, UnknownComment, UnknownPreference, UnknownPreferenceValue, UnselectableRange, UnknownCommand, MissingOption, UnknownWorktree, MalformedLayers, UnknownField, UnknownOption, BadOption, UnknownDraft, NothingDrafted, PullMoved, NoLayers, InitUnwritable;
10097
+ var UnknownBranch, UnknownBase, UnknownFile, UnknownComment, UnknownPreference, UnknownPreferenceValue, UnselectableRange, UnknownCommand, MissingOption, UnknownWorktree, MalformedLayers, UnknownField, UnknownOption, BadOption, UnknownDraft, NothingDrafted, PartlySent, PullMoved, NoLayers, InitUnwritable;
10066
10098
  var init_error = __esmMin((() => {
10067
10099
  init_dist();
10068
10100
  UnknownBranch = class extends TaggedError("UnknownBranch") {};
@@ -10081,6 +10113,7 @@ var init_error = __esmMin((() => {
10081
10113
  BadOption = class extends TaggedError("BadOption") {};
10082
10114
  UnknownDraft = class extends TaggedError("UnknownDraft") {};
10083
10115
  NothingDrafted = class extends TaggedError("NothingDrafted") {};
10116
+ PartlySent = class extends TaggedError("PartlySent") {};
10084
10117
  PullMoved = class extends TaggedError("PullMoved") {};
10085
10118
  NoLayers = class extends TaggedError("NoLayers") {};
10086
10119
  InitUnwritable = class extends TaggedError("InitUnwritable") {};
@@ -10580,7 +10613,7 @@ var init_commands = __esmMin((() => {
10580
10613
  }));
10581
10614
  //#endregion
10582
10615
  //#region src/cli/drafts.ts
10583
- var reported, listDrafts, addDraft, editDraft, dropDraft, sameCommit, commentOf, dispatchDrafts;
10616
+ var reported, listDrafts, addDraft, editDraft, dropDraft, sameCommit, commentOf, sending, dispatchDrafts;
10584
10617
  var init_drafts = __esmMin((() => {
10585
10618
  init_dist();
10586
10619
  init_forge();
@@ -10651,10 +10684,9 @@ var init_drafts = __esmMin((() => {
10651
10684
  side: draft.anchor.side,
10652
10685
  body: draft.body
10653
10686
  });
10654
- dispatchDrafts = fn("Cli.dispatchDrafts")(function* (repo, branch) {
10687
+ sending = fn("Cli.sending")(function* (repo, branch, worktree) {
10655
10688
  const store = yield* Store;
10656
10689
  const forge = yield* Forge;
10657
- const worktree = yield* findBranch(repo, branch);
10658
10690
  const held = yield* store.drafts(worktree.path);
10659
10691
  if (held.length === 0) return yield* new NothingDrafted({ branch });
10660
10692
  const head = yield* forge.head(repo, branch);
@@ -10664,15 +10696,31 @@ var init_drafts = __esmMin((() => {
10664
10696
  now: head
10665
10697
  });
10666
10698
  const sent = yield* forge.review(repo, branch, held.map(commentOf));
10667
- const gone = new Set(held.map((one) => one.id));
10668
- const waiting = (yield* store.drafts(worktree.path)).filter((one) => !gone.has(one.id));
10699
+ const gone = new Set(sent.landed.map((at) => held[at]?.id));
10700
+ const kept = held.filter((one) => !gone.has(one.id));
10701
+ const asked = new Set(held.map((one) => one.id));
10702
+ const since = (yield* store.drafts(worktree.path)).filter((one) => !asked.has(one.id));
10703
+ const waiting = [...kept, ...since];
10669
10704
  yield* store.saveDrafts(worktree.path, waiting);
10705
+ if (kept.length > 0) return yield* new PartlySent({
10706
+ branch,
10707
+ url: sent.url,
10708
+ sent: held.length - kept.length,
10709
+ held: waiting.length,
10710
+ landed: held.filter((one) => gone.has(one.id)).map((one) => one.id),
10711
+ kept: kept.map((one) => one.id)
10712
+ });
10670
10713
  return {
10671
- sent: sent.landed.length,
10714
+ sent: held.length,
10672
10715
  url: sent.url,
10673
- held: waiting.length
10716
+ held: since.length
10674
10717
  };
10675
10718
  });
10719
+ dispatchDrafts = fn("Cli.dispatchDrafts")(function* (repo, branch) {
10720
+ const store = yield* Store;
10721
+ const worktree = yield* findBranch(repo, branch);
10722
+ return yield* store.whileHoldingDrafts(worktree.path, sending(repo, branch, worktree));
10723
+ });
10676
10724
  }));
10677
10725
  //#endregion
10678
10726
  //#region src/cli/init.ts
@@ -10929,7 +10977,7 @@ var init_pane = __esmMin((() => {
10929
10977
  init_drafts();
10930
10978
  init_init();
10931
10979
  init_pane();
10932
- var version$1 = "0.1.0-alpha.123";
10980
+ var version$1 = "0.1.0-alpha.124";
10933
10981
  //#endregion
10934
10982
  //#region src/cli/upgrade.ts
10935
10983
  var PACKAGE, TAG, RELEASES, REGISTRY, ASK_MS, RUN_MS, CELLAR, COMPILED, INSTALLED, BUN_GLOBAL, routeOf, ROUTES, asRoute, checkoutOf, assetOf, commandFor, NOTES, RUNNABLE, NUMBERS, numbersIn, compare$1, partsOf, newer, tagIn, fetched, askLatest, here, findUpgrade, willUpgrade, ranChild, runUpgrade, statusOf$1, sayFound, sayDone, attempted, REFRESH_MS, refreshSkills, updatedIn, sayRefreshed, upgradeReport;
@@ -12480,6 +12528,11 @@ var init_report$1 = __esmMin((() => {
12480
12528
  suggestion: "Nothing is being held for this review. Write a comment on the pull request first; `adiff draft list` reports what is waiting.",
12481
12529
  retriable: false
12482
12530
  },
12531
+ PartlySent: {
12532
+ exit: 1,
12533
+ suggestion: "The forge confirmed some of the comments and said nothing about the rest. What it confirmed is on the pull request; what it did not is still held, listed under kept. Run the same send again to send only those.",
12534
+ retriable: true
12535
+ },
12483
12536
  PullMoved: {
12484
12537
  exit: 1,
12485
12538
  suggestion: "The pull request has moved since these comments were written, so they name lines that may no longer be there. Nothing was sent and nothing was lost. Read the diff again and check each draft still says what you mean.",
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.123",
26
+ "version": "0.1.0-alpha.124",
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": {