@the-vibe-company/armada 0.2.28 → 0.2.30

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 (2) hide show
  1. package/dist/armada.js +63 -14
  2. package/package.json +1 -1
package/dist/armada.js CHANGED
@@ -3685,6 +3685,12 @@ var MIN2 = 60000;
3685
3685
  var REWRITTEN = ["hand-back", "plan"];
3686
3686
  var digest = (text) => createHash("sha256").update(text).digest("base64url").slice(0, 12);
3687
3687
  var entryKey = (e) => e.id !== null ? REWRITTEN.includes(e.kind) ? `#${e.id}@${digest(e.body)}` : `#${e.id}` : e.version ? `version:${e.version}` : e.kind === "not-started" && e.body.startsWith("not started (token expired)") ? `not-started:${e.ticket}:expired@${digest(e.body)}` : `${e.kind}:${e.ticket}`;
3688
+ function handBackPr(body) {
3689
+ const match = body.split(`
3690
+ `, 1)[0]?.match(/\bPR #(\d+)\b/i);
3691
+ const number = match ? Number(match[1]) : 0;
3692
+ return Number.isSafeInteger(number) && number > 0 ? number : null;
3693
+ }
3688
3694
  var hhmm = (iso) => `${iso.slice(11, 16)} UTC`;
3689
3695
  function notStartedBody(l, now) {
3690
3696
  const minutes = Math.floor((now.getTime() - Date.parse(l.launchedAt)) / MIN2);
@@ -4184,8 +4190,8 @@ async function answerItem(ctx, input) {
4184
4190
  throw new Refusal(warnings.length ? `inbox item #${itemId} cannot be read (${warnings.join("; ")})` : `inbox item #${itemId} does not exist in project ${project}`, warnings.length ? 'armada answer <ticket> "<answer>", to answer by ticket instead' : "armada inbox");
4185
4191
  if (item.resolvedAt)
4186
4192
  throw new Refusal(`inbox item #${itemId} was already resolved at ${item.resolvedAt}`, "armada inbox");
4187
- if (item.kind === "hand-back")
4188
- throw new Refusal(`inbox item #${itemId} is a hand-back: armada merge resolves it once the pull request is merged`, `armada merge <pr>${item.ticket ? ` --ticket ${item.ticket}` : ""} --dry-run`);
4193
+ if (item.kind === "hand-back" && item.recipient === "coordinator")
4194
+ return answerHandBack(ctx, item, text, warnings);
4189
4195
  if (item.recipient !== "coordinator" || !ANSWERABLE.includes(item.kind))
4190
4196
  throw new Refusal(`inbox item #${itemId} is a ${item.kind} for the ${item.recipient}, not something to answer`, "armada inbox");
4191
4197
  ticketId = item.ticket;
@@ -4237,6 +4243,26 @@ async function declineLaunch(ctx, item, reason, warnings) {
4237
4243
  ];
4238
4244
  return { ticket: item.ticket ?? `#${item.id}`, url: "", lines, warnings: [...new Set(warnings)], inbox: null };
4239
4245
  }
4246
+ async function answerHandBack(ctx, item, text, warnings) {
4247
+ const ticket = item.ticket ? await ctx.linear.readTicket(item.ticket) : null;
4248
+ const number = handBackPr(item.body);
4249
+ let stale = ticket?.statusType === "completed" || ticket?.statusType === "canceled";
4250
+ if (!stale && number !== null && ctx.readPull) {
4251
+ const pull = await ctx.readPull(number);
4252
+ stale = pull?.number === number && pull.repo.toLowerCase() === ctx.config.github.repository.toLowerCase() && (pull.state === "merged" || pull.state === "closed");
4253
+ }
4254
+ if (!stale)
4255
+ throw new Refusal(`inbox item #${item.id} is a hand-back: armada merge resolves it once the pull request is merged`, `armada merge ${number ?? "<pr>"}${item.ticket ? ` --ticket ${item.ticket}` : ""} --dry-run`);
4256
+ warnings.push(...ticket?.warnings ?? []);
4257
+ const recorded = await live(ctx, warnings, "resolve the stale hand-back", (fleet) => fleet.answer({ text, note: false, ticket: item.ticket, item: item.id }));
4258
+ return {
4259
+ ticket: item.ticket ?? `#${item.id}`,
4260
+ url: ticket?.url ?? "",
4261
+ lines: recorded ? [recorded] : [],
4262
+ warnings: [...new Set(warnings)],
4263
+ inbox: null
4264
+ };
4265
+ }
4240
4266
 
4241
4267
  // ../core/src/labels.ts
4242
4268
  function requiredLabels(config) {
@@ -4854,6 +4880,7 @@ var LEASE_POLL_MS = 5000;
4854
4880
  var MERGE_BACKOFF_MS = [2000, 4000, 8000];
4855
4881
  var CONFIRM_BACKOFF_MS = [1000, 2000, 4000, 8000];
4856
4882
  var UNKNOWN_BACKOFF_MS = [2000, 4000];
4883
+ var CLEANUP_BACKOFF_MS = [2000, 4000];
4857
4884
  var MERGE_WAIT_DEFAULT_MS = 30 * 60000;
4858
4885
  var MERGE_WAIT_POLL_MS = 30000;
4859
4886
  var UPDATE_STALL_MS = 3 * 60000;
@@ -5519,6 +5546,8 @@ async function locked(ctx, input, run) {
5519
5546
  const owner = await ownerDecision(ctx, input, c, false);
5520
5547
  c.lines.push(...owner.lines);
5521
5548
  c.decided = owner.decided;
5549
+ const handBacks = c.ticket ? await live(ctx, c.warnings, "read the hand-back for merge recovery", (fleet) => fleet.ticketItems(c.ticket?.id ?? "")) : null;
5550
+ const handBackId = handBacks?.find((item) => item.kind === "hand-back")?.id ?? null;
5522
5551
  await recheck(ctx, input, run, c);
5523
5552
  if (!await renew())
5524
5553
  throw new Refusal("the merge lock could not be renewed (it expired and another coordinator took it, or Armada did not answer); nothing was merged", `armada merge ${input.pr} again`);
@@ -5536,7 +5565,7 @@ async function locked(ctx, input, run) {
5536
5565
  }
5537
5566
  else
5538
5567
  lines.push("No ticket: nothing was written to Linear.");
5539
- return after(ctx, c, merged, lines);
5568
+ return after(ctx, c, merged, lines, handBackId);
5540
5569
  };
5541
5570
  if (input.noLock) {
5542
5571
  early.push(`merged without the merge lock (--no-lock): make sure no other coordinator merges in ${slug} now`);
@@ -5558,16 +5587,35 @@ async function locked(ctx, input, run) {
5558
5587
  onWait: (held) => say(ctx, `Waiting for the merge lock held by ${held?.holder ?? "another coordinator"} (until ${held?.expiresAt ?? "?"})…`)
5559
5588
  }, body);
5560
5589
  }
5561
- async function after(ctx, c, merged, lines) {
5590
+ async function after(ctx, c, merged, lines, handBackId) {
5562
5591
  const ticket = c.ticket;
5563
- const live$ = ticket ? await live(ctx, c.warnings, "record the merge", (fleet) => fleet.merge({
5564
- ticket: ticket.id,
5565
- number: merged.number,
5566
- url: merged.url,
5567
- mergeCommit: merged.mergeCommit,
5568
- headSha: merged.headSha,
5569
- decision: c.decided ?? null
5570
- })) : null;
5592
+ let live$ = null;
5593
+ if (ticket) {
5594
+ for (let attempt = 0;; attempt++) {
5595
+ live$ = await live(ctx, c.warnings, "record the merge", (fleet) => fleet.merge({
5596
+ ticket: ticket.id,
5597
+ number: merged.number,
5598
+ url: merged.url,
5599
+ mergeCommit: merged.mergeCommit,
5600
+ headSha: merged.headSha,
5601
+ decision: c.decided ?? null
5602
+ }));
5603
+ if (live$)
5604
+ break;
5605
+ if (!(await ctx.fleet()).fleet) {
5606
+ if (ctx.lockRequired)
5607
+ lines.push(`Next: armada answer ${handBackId ?? "<hand-back id>"} "resolved: PR merged"`);
5608
+ break;
5609
+ }
5610
+ const wait = CLEANUP_BACKOFF_MS[attempt];
5611
+ if (wait === undefined) {
5612
+ lines.push(`Next: armada answer ${handBackId ?? "<hand-back id>"} "resolved: PR merged"`);
5613
+ break;
5614
+ }
5615
+ say(ctx, `#${merged.number} is merged; retrying Armada clean-up in ${wait / 1000} s…`);
5616
+ await ctx.sleep(wait);
5617
+ }
5618
+ }
5571
5619
  if (live$?.resolved)
5572
5620
  lines.push(`Hand-back resolved in the coordinator's inbox.`);
5573
5621
  let workers = [];
@@ -6526,7 +6574,7 @@ ${attachments.join(`
6526
6574
  };
6527
6575
  }
6528
6576
  // package.json
6529
- var version = "0.2.28";
6577
+ var version = "0.2.30";
6530
6578
 
6531
6579
  // src/attach.ts
6532
6580
  import { resolve } from "node:path";
@@ -9266,7 +9314,8 @@ var COMMAND_HELP = {
9266
9314
  answer: ` answer <item|ticket> "<answer>"
9267
9315
  Coordinator: record an answer already delivered in the worker's
9268
9316
  session (runtime guide): resolves the question or plan and posts it on
9269
- the ticket. A ticket id answers its open questions and plans. Never calls a runtime
9317
+ the ticket. A ticket id answers its open questions and plans. A hand-back id can
9318
+ clear a merged/closed PR or a Done/Canceled ticket. Never calls a runtime
9270
9319
  answer --note <ticket|plan item> "<message>"
9271
9320
  Coordinator: record a delivered note; an open plan is resolved
9272
9321
  `,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-vibe-company/armada",
3
- "version": "0.2.28",
3
+ "version": "0.2.30",
4
4
  "type": "module",
5
5
  "description": "Run a fleet of coding agents on one project: the armada command line.",
6
6
  "license": "MIT",