@miroshnik/elves 2026.1109.0 → 2026.1112.0

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.
@@ -332,6 +332,7 @@ var M = {
332
332
  RemoveBlockedBy: ["removeBlockedBy", "RemoveBlockedByInput", "issue { id }"],
333
333
  SetIssueField: ["setIssueFieldValue", "SetIssueFieldValueInput", "issue { id }"],
334
334
  CloseIssue: ["closeIssue", "CloseIssueInput", "issue { id state }"],
335
+ ReopenIssue: ["reopenIssue", "ReopenIssueInput", "issue { id state }"],
335
336
  UpdateIssue: ["updateIssue", "UpdateIssueInput", "issue { id }"],
336
337
  AddComment: ["addComment", "AddCommentInput", "subject { id }"],
337
338
  CreateRuleset: ["createRepositoryRuleset", "CreateRepositoryRulesetInput", "ruleset { id }"],
@@ -3646,7 +3647,19 @@ function cmdTaskFinish(io, slug, number, o) {
3646
3647
  const outOfTime = (what) => stop(5, `○ out of time (--timeout ${o.timeout}) — ${what}`, `${again} — it goes on from here`);
3647
3648
  const issue = loadIssue(io, slug, number);
3648
3649
  if (issue.state !== "OPEN") {
3649
- const closer = issue.stateReason === "COMPLETED" ? issue.prs.find((p) => p.merged && !isBatchBranch(p.base)) ?? null : null;
3650
+ const closer = issue.stateReason === "COMPLETED" ? lastMerged(issue.prs.filter((p) => !isBatchBranch(p.base))) ?? null : null;
3651
+ const work = workPastMerge(io, slug, number, issue, closer);
3652
+ if (work) {
3653
+ if (issue.stateReason !== "COMPLETED")
3654
+ return stop(1, `! #${number} is closed as ${issue.stateReason ?? "not planned"}, but ${work}`, `gh issue reopen ${number} --repo ${slug}, then ${again}`);
3655
+ mutate(io, { op: "ReopenIssue", input: { issueId: issue.id } });
3656
+ if (!inCloud(io)) {
3657
+ const ctx = taskContext(io, slug);
3658
+ setStatus(io, ctx, ensureItem(io, ctx, issue).id, N.status.inProgress);
3659
+ }
3660
+ io.out(`+ #${number} reopened, ${STATUS} ${q(N.status.inProgress)}: ${work} — the task's merged PR isn't its finish`);
3661
+ return cmdTaskFinish(io, slug, number, { ...o, timeout: Math.max(0, left()) });
3662
+ }
3650
3663
  if (!closer || tailOver(io, slug, number))
3651
3664
  return io.out(`= #${number} is closed — nothing to finish`), 0;
3652
3665
  io.out(`○ #${number} is closed by the merge of PR #${closer.number}, the tail isn't over (no ${q(N.status.done)} with the actual) — going on`);
@@ -3656,8 +3669,9 @@ function cmdTaskFinish(io, slug, number, o) {
3656
3669
  throw new GhError(`task finish runs from a checkout of ${slug}: the current directory is not one`);
3657
3670
  const found = unlinkedPrs(io, slug, number);
3658
3671
  const prs = [...issue.prs, ...found.prs, ...found.batched].filter((p, k, all) => all.findIndex((x) => x.number === p.number) === k);
3659
- const merged = prs.find((p) => p.merged);
3660
- if (merged)
3672
+ const merged = lastMerged(prs);
3673
+ const pending = prs.some((p) => p.state === "OPEN") || merged && unmergedBranch(io, number, merged.base, merged.head);
3674
+ if (merged && !pending)
3661
3675
  return finishMerged(io, slug, number, issue.parent?.number ?? null, merged, { left, again, stop, outOfTime });
3662
3676
  const branch = git(io, io.cwd, "branch", "--show-current").stdout.trim();
3663
3677
  const open = prs.find((p) => p.state === "OPEN");
@@ -3734,6 +3748,36 @@ function cmdTaskFinish(io, slug, number, o) {
3734
3748
  const yes = locale_default.autoProject(io.cwd ?? process.cwd()) ? "" : "the owner's «yes» (the project is without auto) — then ";
3735
3749
  return stop(4, `✅ PR #${pr} is ready to merge`, `${yes}gh pr merge ${pr} --rebase — a separate call, no cd or pipeline (the owner's permission rule matches it); then ${again}${isBatchBranch(base) ? "" : " — in the background: it waits for the deploy"}`);
3736
3750
  }
3751
+ function lastMerged(prs) {
3752
+ return prs.filter((p) => p.merged).sort((a, b) => b.number - a.number)[0];
3753
+ }
3754
+ function unmergedBranch(io, number, base, mergedHead) {
3755
+ const branch = git(io, io.cwd, "branch", "--show-current").stdout.trim();
3756
+ if (!isTaskBranch(branch, number))
3757
+ return null;
3758
+ if (branch === mergedHead) {
3759
+ git(io, io.cwd, "fetch", "-q", "origin", `+refs/heads/${branch}:refs/remotes/origin/${branch}`);
3760
+ const past = git(io, io.cwd, "rev-list", "--count", `refs/remotes/origin/${branch}..HEAD`);
3761
+ if (past.status === 0)
3762
+ return Number(past.stdout.trim()) > 0 ? branch : null;
3763
+ }
3764
+ if (git(io, io.cwd, "fetch", "-q", "origin", `+refs/heads/${base}:refs/remotes/origin/${base}`).status !== 0)
3765
+ return null;
3766
+ const cherry = git(io, io.cwd, "cherry", `origin/${base}`, "HEAD");
3767
+ return cherry.status === 0 && cherry.stdout.split(`
3768
+ `).some((l) => l.startsWith("+")) ? branch : null;
3769
+ }
3770
+ function workPastMerge(io, slug, number, issue, closer) {
3771
+ const open = issue.prs.find((p) => p.state === "OPEN");
3772
+ if (open)
3773
+ return `its PR #${open.number} is open`;
3774
+ const current = git(io, io.cwd, "branch", "--show-current").stdout.trim();
3775
+ if (!isTaskBranch(current, number) || !checkoutOfRepo(io, originUrl(io), slug))
3776
+ return null;
3777
+ const base = closer?.base ?? unlinkedPrs(io, slug, number).base;
3778
+ const branch = unmergedBranch(io, number, base, closer?.head);
3779
+ return branch ? `branch ${branch} has commits that aren't in origin/${base}` : null;
3780
+ }
3737
3781
  function finishBase(io, slug, number, found) {
3738
3782
  const batch = handedPastBatch(io, slug, number) ? null : batchOf(io, slug);
3739
3783
  if (!batch)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miroshnik/elves",
3
- "version": "2026.1109.0",
3
+ "version": "2026.1112.0",
4
4
  "type": "module",
5
5
  "description": "Elves — a development flow with AI agents: shared rules and skills for any agent; install — bunx @miroshnik/elves install -g; the installer and skill scripts — TypeScript under Bun, tests — bun test in tests/",
6
6
  "repository": {
@@ -72,5 +72,5 @@
72
72
  "eslint-plugin-boundaries": "^7.2.0",
73
73
  "knip": "^6.41.0"
74
74
  },
75
- "gitHead": "a09166687dccfad2f880d3f299812d5d9fd04de6"
75
+ "gitHead": "782e3e75f81a1b20f952a6fa001a44f5de6b4ed5"
76
76
  }
@@ -691,7 +691,12 @@ or 3. Then the merge command, code 4: the merge stays a separate `gh pr merge
691
691
  into a batch — code 0, nothing more (the release does it); otherwise
692
692
  `ci-wait merged`, the refresh's mechanics and its prompt (code 4 — the
693
693
  subagent), and `task close` once its report is on the epic (no epic or no
694
- other open tasks — right away). Code 5 — out of time: the same command
694
+ other open tasks — right away). A task reopened after its merge (#813): an
695
+ open PR of the task or the checkout's task branch with commits not in the
696
+ base (`git cherry`; the merged PR's own branch — commits past its pushed
697
+ head) is the tail, not the merged PR — the latest merged PR is the one
698
+ awaited after the merge; closed with such work — reopened and «In progress»
699
+ (not planned — code 1 with `gh issue reopen`). Code 5 — out of time: the same command
695
700
  again. A session runs it in the background — once before the merge and once
696
701
  after; a subagent — `--timeout 240` (540 with the hour cache,
697
702
  `docs/pr-checks.md`), again on code 5. The separate commands stay for manual
@@ -641,6 +641,7 @@ const M: Record<string, [field: string, inputType: string, select: string]> = {
641
641
  RemoveBlockedBy: ["removeBlockedBy", "RemoveBlockedByInput", "issue { id }"],
642
642
  SetIssueField: ["setIssueFieldValue", "SetIssueFieldValueInput", "issue { id }"],
643
643
  CloseIssue: ["closeIssue", "CloseIssueInput", "issue { id state }"],
644
+ ReopenIssue: ["reopenIssue", "ReopenIssueInput", "issue { id state }"],
644
645
  UpdateIssue: ["updateIssue", "UpdateIssueInput", "issue { id }"],
645
646
  AddComment: ["addComment", "AddCommentInput", "subject { id }"],
646
647
  CreateRuleset: ["createRepositoryRuleset", "CreateRepositoryRulesetInput", "ruleset { id }"],
@@ -5029,7 +5030,19 @@ export function cmdTaskFinish(io: Io, slug: string, number: number, o: { timeout
5029
5030
  const issue = loadIssue(io, slug, number);
5030
5031
  if (issue.state !== "OPEN") {
5031
5032
  // «Closes #N» of the PR closes the task at the merge (#761): a closed issue isn't a finished tail — task close's marks are
5032
- const closer = issue.stateReason === "COMPLETED" ? (issue.prs.find((p) => p.merged && !isBatchBranch(p.base)) ?? null) : null;
5033
+ const closer = issue.stateReason === "COMPLETED" ? (lastMerged(issue.prs.filter((p) => !isBatchBranch(p.base))) ?? null) : null;
5034
+ // a task reopened after its merge (#813): its open PR or its branch's unmerged work is the tail, not the merged PR
5035
+ const work = workPastMerge(io, slug, number, issue, closer);
5036
+ if (work) {
5037
+ if (issue.stateReason !== "COMPLETED") return stop(1, `! #${number} is closed as ${issue.stateReason ?? "not planned"}, but ${work}`, `gh issue reopen ${number} --repo ${slug}, then ${again}`);
5038
+ mutate(io, { op: "ReopenIssue", input: { issueId: issue.id } });
5039
+ if (!inCloud(io)) {
5040
+ const ctx = taskContext(io, slug);
5041
+ setStatus(io, ctx, ensureItem(io, ctx, issue).id, N.status.inProgress);
5042
+ }
5043
+ io.out(`+ #${number} reopened, ${STATUS} ${q(N.status.inProgress)}: ${work} — the task's merged PR isn't its finish`);
5044
+ return cmdTaskFinish(io, slug, number, { ...o, timeout: Math.max(0, left()) });
5045
+ }
5033
5046
  if (!closer || tailOver(io, slug, number)) return io.out(`= #${number} is closed — nothing to finish`), 0;
5034
5047
  io.out(`○ #${number} is closed by the merge of PR #${closer.number}, the tail isn't over (no ${q(N.status.done)} with the actual) — going on`);
5035
5048
  return finishMerged(io, slug, number, issue.parent?.number ?? null, closer, { left, again, stop, outOfTime });
@@ -5037,8 +5050,11 @@ export function cmdTaskFinish(io: Io, slug: string, number: number, o: { timeout
5037
5050
  if (!checkoutOfRepo(io, originUrl(io), slug)) throw new GhError(`task finish runs from a checkout of ${slug}: the current directory is not one`);
5038
5051
  const found = unlinkedPrs(io, slug, number);
5039
5052
  const prs = [...issue.prs, ...found.prs, ...found.batched].filter((p, k, all) => all.findIndex((x) => x.number === p.number) === k);
5040
- const merged = prs.find((p) => p.merged);
5041
- if (merged) return finishMerged(io, slug, number, issue.parent?.number ?? null, merged, { left, again, stop, outOfTime });
5053
+ // the latest merged PR is the task's finish only without an open PR and without unmerged work on its branch (#813):
5054
+ // a task reopened after the merge goes on with its new branch — its push, its PR, its merge
5055
+ const merged = lastMerged(prs);
5056
+ const pending = prs.some((p) => p.state === "OPEN") || (merged && unmergedBranch(io, number, merged.base, merged.head));
5057
+ if (merged && !pending) return finishMerged(io, slug, number, issue.parent?.number ?? null, merged, { left, again, stop, outOfTime });
5042
5058
 
5043
5059
  const branch = git(io, io.cwd, "branch", "--show-current").stdout.trim();
5044
5060
  const open = prs.find((p) => p.state === "OPEN");
@@ -5103,6 +5119,43 @@ export function cmdTaskFinish(io: Io, slug: string, number: number, o: { timeout
5103
5119
  return stop(4, `✅ PR #${pr} is ready to merge`, `${yes}gh pr merge ${pr} --rebase — a separate call, no cd or pipeline (the owner's permission rule matches it); then ${again}${isBatchBranch(base) ? "" : " — in the background: it waits for the deploy"}`);
5104
5120
  }
5105
5121
 
5122
+ /** The task's latest merged PR — the highest number: a task reopened after a merge has several (#813). */
5123
+ function lastMerged<T extends { number: number; merged: boolean }>(prs: T[]): T | undefined {
5124
+ return prs.filter((p) => p.merged).sort((a, b) => b.number - a.number)[0];
5125
+ }
5126
+
5127
+ /**
5128
+ * The checkout's branch of the task with commits that aren't in `origin/<base>` by their changes (`git cherry`: a
5129
+ * rebase merge gives other SHAs) — the work of a task reopened after its merge (#813); none — null. The merged PR's own
5130
+ * branch — by the commits past its pushed head while it is on origin: a squash merge has no commit-for-commit match.
5131
+ */
5132
+ function unmergedBranch(io: Io, number: number, base: string, mergedHead?: string): string | null {
5133
+ const branch = git(io, io.cwd, "branch", "--show-current").stdout.trim();
5134
+ if (!isTaskBranch(branch, number)) return null;
5135
+ if (branch === mergedHead) {
5136
+ git(io, io.cwd, "fetch", "-q", "origin", `+refs/heads/${branch}:refs/remotes/origin/${branch}`);
5137
+ const past = git(io, io.cwd, "rev-list", "--count", `refs/remotes/origin/${branch}..HEAD`);
5138
+ if (past.status === 0) return Number(past.stdout.trim()) > 0 ? branch : null;
5139
+ }
5140
+ if (git(io, io.cwd, "fetch", "-q", "origin", `+refs/heads/${base}:refs/remotes/origin/${base}`).status !== 0) return null;
5141
+ const cherry = git(io, io.cwd, "cherry", `origin/${base}`, "HEAD");
5142
+ return cherry.status === 0 && cherry.stdout.split("\n").some((l) => l.startsWith("+")) ? branch : null;
5143
+ }
5144
+
5145
+ /**
5146
+ * What a closed task still has after its merged PR (#813): an open PR of the task, or the checkout's task branch with
5147
+ * work its base hasn't got. Nothing — null; the checkout isn't the repository's — only the PR counts.
5148
+ */
5149
+ function workPastMerge(io: Io, slug: string, number: number, issue: Issue, closer: Issue["prs"][number] | null): string | null {
5150
+ const open = issue.prs.find((p) => p.state === "OPEN");
5151
+ if (open) return `its PR #${open.number} is open`;
5152
+ const current = git(io, io.cwd, "branch", "--show-current").stdout.trim();
5153
+ if (!isTaskBranch(current, number) || !checkoutOfRepo(io, originUrl(io), slug)) return null;
5154
+ const base = closer?.base ?? unlinkedPrs(io, slug, number).base;
5155
+ const branch = unmergedBranch(io, number, base, closer?.head);
5156
+ return branch ? `branch ${branch} has commits that aren't in origin/${base}` : null;
5157
+ }
5158
+
5106
5159
  /**
5107
5160
  * The base of the task's new PR: the dispatcher's batch branch (#648); a task past the batch (#697) — the default branch,
5108
5161
  * as outside a batch; the batch released (#768: its release PR merged, or its branch gone from origin) — the default