@miroshnik/elves 2026.1112.0 → 2026.1112.1

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.
@@ -2879,6 +2879,45 @@ function pruneAgentWorktrees(io, slug, kept, closed = () => false) {
2879
2879
  `).filter((l) => l.startsWith("+")).length;
2880
2880
  return n ? `${plural(n, "commit", "commits")} not in ${upstream}` : null;
2881
2881
  };
2882
+ const releases = new Map;
2883
+ const releasedBy = (batch) => {
2884
+ if (!releases.has(batch)) {
2885
+ let pr = null;
2886
+ try {
2887
+ const release = releasePrOf(batchPrs(io, slug, batch), batch);
2888
+ pr = release?.merged ? release.number : null;
2889
+ } catch (e) {
2890
+ if (!(e instanceof GhError))
2891
+ throw e;
2892
+ }
2893
+ releases.set(batch, pr);
2894
+ }
2895
+ return releases.get(batch);
2896
+ };
2897
+ const mergedByPr = (sha) => {
2898
+ let pulls;
2899
+ try {
2900
+ pulls = rest(io, `repos/${slug}/commits/${sha}/pulls`) ?? [];
2901
+ } catch (e) {
2902
+ if (!(e instanceof GhError))
2903
+ throw e;
2904
+ return null;
2905
+ }
2906
+ for (const p of pulls) {
2907
+ const r = prRef(p);
2908
+ const tasks = prTasks(p);
2909
+ if (!r.merged || !r.sha || !tasks.length || !tasks.every(closed))
2910
+ continue;
2911
+ if (r.sha !== sha && git(io, io.cwd, "merge-base", "--is-ancestor", sha, r.sha).status !== 0)
2912
+ continue;
2913
+ const release = isBatchBranch(r.base) ? releasedBy(r.base) : null;
2914
+ if (r.base !== base && release === null)
2915
+ continue;
2916
+ const into = release === null ? r.base : `${r.base} (released by PR #${release})`;
2917
+ return `its HEAD is in PR #${r.number} merged into ${into}, ${tasks.map((n) => `#${n}`).join(", ")} closed`;
2918
+ }
2919
+ return null;
2920
+ };
2882
2921
  const deleteBranch = (branch) => {
2883
2922
  const d = git(io, io.cwd, "branch", "-D", branch);
2884
2923
  if (d.status !== 0)
@@ -2904,7 +2943,9 @@ function pruneAgentWorktrees(io, slug, kept, closed = () => false) {
2904
2943
  }
2905
2944
  const dirty = status.stdout.split(`
2906
2945
  `).filter((l) => l.trim()).length;
2907
- const reasons = [dirty ? `${plural(dirty, "uncommitted file", "uncommitted files")}` : null, unmerged(w.head)].filter((r) => r !== null);
2946
+ const cherry = unmerged(w.head);
2947
+ const byPr = !dirty && cherry !== null ? mergedByPr(w.head) : null;
2948
+ const reasons = [dirty ? `${plural(dirty, "uncommitted file", "uncommitted files")}` : null, byPr ? null : cherry].filter((r) => r !== null);
2908
2949
  if (reasons.length) {
2909
2950
  io.out(`○ worktree ${w.path} left: ${reasons.join(", ")}`);
2910
2951
  continue;
@@ -2917,7 +2958,7 @@ function pruneAgentWorktrees(io, slug, kept, closed = () => false) {
2917
2958
  continue;
2918
2959
  }
2919
2960
  const withBranch = w.branch !== null && deleteBranch(w.branch) ? ` with branch ${w.branch}` : "";
2920
- io.out(`+ worktree ${w.path} removed${withBranch}: clean, nothing outside ${upstream}`);
2961
+ io.out(`+ worktree ${w.path} removed${withBranch}: clean, ${byPr ?? `nothing outside ${upstream}`}`);
2921
2962
  }
2922
2963
  const checkedOut = new Set(all.map((w) => w.branch).filter(Boolean));
2923
2964
  const loose = git(io, io.cwd, "for-each-ref", "--format=%(refname:short)", "refs/heads/worktree-agent-*").stdout.split(`
@@ -4873,7 +4914,7 @@ label's — from the latest «External blocker: …» comment). Marks the sessio
4873
4914
  with the session's id; a session with a pinned task keeps it. Before the queue, in the repository's checkout —
4874
4915
  finished agents' worktrees (.claude/worktrees/agent-*, detached or on worktree-agent-*, not locked by a live process,
4875
4916
  not an executor's whose handed-out task is open; on a task branch — when its task is closed): clean and merged (git
4876
- cherry) — removed with the branch (+),
4917
+ cherry, or its HEAD in a merged PR of its closed task into the default branch or a released batch) — removed with the branch (+),
4877
4918
  otherwise left (○ with the reason), and so is one a subagent works in without a worktree of its own (its transcript
4878
4919
  written in the last ${QUIET_MINUTES} min); loose worktree-agent-* branches — the same. --type and --priority — in an
4879
4920
  organization. --assignment N (the executor's first call; read-only on GitHub) — its whole assignment; in a session
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miroshnik/elves",
3
- "version": "2026.1112.0",
3
+ "version": "2026.1112.1",
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": "782e3e75f81a1b20f952a6fa001a44f5de6b4ed5"
75
+ "gitHead": "0dab46d135df7aac0fa7c5155a47ed19ab185740"
76
76
  }
@@ -941,9 +941,21 @@ it removes what finished executors left (#515): an agent's worktree
941
941
  (`.claude/worktrees/agent-*`) detached or on a `worktree-agent-*` branch, not
942
942
  locked by a live process (Claude Code locks a running agent's worktree; a lock
943
943
  whose pid is gone doesn't hold), clean and without commits outside
944
- `origin/<base>` by `git cherry` — removed with its branch, a `+` line;
945
- uncommitted changes or unmerged commits — left, an `○` line with the reason; a
946
- `worktree-agent-*` branch without a worktree — the same by its commits. A
944
+ `origin/<base>` by `git cherry`, or clean with its HEAD in a merged PR of its
945
+ closed task — removed with its branch, a `+` line; uncommitted changes or
946
+ unmerged commits — left, an `○` line with the reason; a `worktree-agent-*`
947
+ branch without a worktree — the same by its commits (`git cherry`). "Merged by
948
+ the PR" (#816): a batch's release rebases the batch onto a fresh
949
+ `origin/<base>`, a task's commit reaches it rewritten twice and differs there by
950
+ context — `git cherry` counts it unmerged, and the executors' worktrees piled
951
+ up with each batch. For a clean worktree `git cherry` counts unmerged, the
952
+ queue asks GitHub for the PRs of its HEAD (`commits/<sha>/pulls`): one counts
953
+ when it is merged, its head is the HEAD or a descendant of it (a commit a
954
+ force-push dropped from the PR doesn't count), its tasks are closed and its
955
+ base is the default branch or a batch branch its merged release PR shipped; a
956
+ commit on top of the PR's head, no such PR, or GitHub not read — `git cherry`
957
+ decides, as before. The `+` line names the PR (`its HEAD is in PR #77 merged
958
+ into batch/… (released by PR #80), #47 closed`). A
947
959
  session's worktree, an agent's on an open task's branch and an executor's whose
948
960
  handed-out task is open or awaits `task close` after its merge — untouched,
949
961
  no line (#533, #769); an agent's on a closed
@@ -1044,8 +1056,18 @@ machine's executors in subagents and 5 cloud sessions at once, the owner's
1044
1056
  number replaces either (subagents share the machine: `Next:` names the
1045
1057
  executors of its capacity — `slot --capacity`, `machine.json` or the cores and
1046
1058
  memory, without the slot skill — 3; a cloud session has its own container); a task in work (`=`) isn't launched again.
1047
- Before each launch — `get_usage`: the 5-hour limit at 85% and more — no new
1048
- executors, the running ones finish, then `Remaining: N tasks, the limit`. An
1059
+ Before each launch — `get_usage` (#815): a window of `plan.windows` at 85% and
1060
+ more — any but the window of a model the executors don't run on (`Weekly ·
1061
+ <model>`; theirs — the dispatcher's own unless the launch names another) — no
1062
+ new executors, the running ones finish, then `Remaining: N tasks, the limit:
1063
+ <its label> <percent>%, extra usage <percent>% of <monthly limit>` (or `extra
1064
+ usage off`). Extra usage doesn't lift the stop: money past the plan is the
1065
+ owner's decision; after the owner's «yes» to it — launches until
1066
+ `plan.extraUsage.percentUsed` is at 85%, then `Remaining: N tasks, the limit:
1067
+ extra usage <percent>%`. `not_applicable` (an API key, Bedrock, Vertex, a
1068
+ gateway) — no plan limits: executors by the machine's capacity; `unavailable`
1069
+ — asked again if its note says that helps, otherwise no new executors, the
1070
+ running ones finish, `Remaining: N tasks, limits unavailable`. An
1049
1071
  answer arrives as the subagent's notification; after each — `task queue`
1050
1072
  again. A question — to the owner in text; the answer — ✅ in the task's
1051
1073
  questions section and to the same executor with `SendMessage` (its context is
@@ -3930,8 +3930,9 @@ function openOf(io: Io, slug: string): (n: number) => boolean {
3930
3930
  * Executors' worktrees go away with the dispatcher's next queue (#515): an executor can't remove its own — it works in it,
3931
3931
  * and `task close` leaves it detached on origin/<base>; its subagents leave theirs on `worktree-agent-*` branches.
3932
3932
  * Only agents' worktrees (`AGENT_WORKTREE`), detached or on a `worktree-agent-*` branch, not locked by a live process
3933
- * (a running agent): clean and without commits outside origin/<base> (`git cherry` — a rebase merge gives new SHAs) —
3934
- * removed with their branch, a `+` line each; uncommitted changes or unmerged commits — left, a `○` line with the
3933
+ * (a running agent): clean and without commits outside origin/<base> (`git cherry` — a rebase merge gives new SHAs), or
3934
+ * clean with its HEAD in a merged PR of its closed task (`mergedByPr`, #816: a batch's release rewrites the commits
3935
+ * past `git cherry`) — removed with their branch, a `+` line each; uncommitted changes or unmerged commits — left, a `○` line with the
3935
3936
  * reason. A `worktree-agent-*` branch without a worktree — the same by its commits. A session's worktree, an agent's on
3936
3937
  * a task branch of an open task (`closed` — #698: a closed one's goes with its branch, as above), an executor's whose handed-out task is open (`kept`, #533: Claude Code unlocks
3937
3938
  * an agent's worktree when it ends its answer — a question too — and doesn't lock it again when the agent is continued
@@ -3954,6 +3955,48 @@ function pruneAgentWorktrees(io: Io, slug: string, kept: (dir: string) => boolea
3954
3955
  const n = r.stdout.split("\n").filter((l) => l.startsWith("+")).length;
3955
3956
  return n ? `${plural(n, "commit", "commits")} not in ${upstream}` : null;
3956
3957
  };
3958
+ /** A batch branch's merged release PR (`releasePrOf`), read once per batch; not released or not read — null. */
3959
+ const releases = new Map<string, number | null>();
3960
+ const releasedBy = (batch: string): number | null => {
3961
+ if (!releases.has(batch)) {
3962
+ let pr: number | null = null;
3963
+ try {
3964
+ const release = releasePrOf(batchPrs(io, slug, batch), batch);
3965
+ pr = release?.merged ? release.number : null;
3966
+ } catch (e) {
3967
+ if (!(e instanceof GhError)) throw e;
3968
+ }
3969
+ releases.set(batch, pr);
3970
+ }
3971
+ return releases.get(batch)!;
3972
+ };
3973
+ /**
3974
+ * Merged by its PR (#816): a batch's release rebases the batch onto a fresh origin/<base>, and a task's commit reaches
3975
+ * the default branch rewritten twice — its patch differs there by context, and `git cherry` counts it unmerged. GitHub
3976
+ * names the PRs of a commit (`commits/<sha>/pulls`); one counts when it is merged, its head is the HEAD or a descendant
3977
+ * of it, its tasks are closed (`closed`), and its base is the default branch or a batch branch its merged release PR
3978
+ * shipped. The reason for the `+` line; none, or not read — null: `git cherry` decides.
3979
+ */
3980
+ const mergedByPr = (sha: string): string | null => {
3981
+ let pulls: Any[];
3982
+ try {
3983
+ pulls = rest(io, `repos/${slug}/commits/${sha}/pulls`) ?? [];
3984
+ } catch (e) {
3985
+ if (!(e instanceof GhError)) throw e;
3986
+ return null;
3987
+ }
3988
+ for (const p of pulls) {
3989
+ const r = prRef(p);
3990
+ const tasks = prTasks(p);
3991
+ if (!r.merged || !r.sha || !tasks.length || !tasks.every(closed)) continue;
3992
+ if (r.sha !== sha && git(io, io.cwd, "merge-base", "--is-ancestor", sha, r.sha).status !== 0) continue;
3993
+ const release = isBatchBranch(r.base) ? releasedBy(r.base) : null;
3994
+ if (r.base !== base && release === null) continue;
3995
+ const into = release === null ? r.base : `${r.base} (released by PR #${release})`;
3996
+ return `its HEAD is in PR #${r.number} merged into ${into}, ${tasks.map((n) => `#${n}`).join(", ")} closed`;
3997
+ }
3998
+ return null;
3999
+ };
3957
4000
  const deleteBranch = (branch: string) => {
3958
4001
  const d = git(io, io.cwd, "branch", "-D", branch);
3959
4002
  if (d.status !== 0) io.out(`! git branch -D ${branch}: ${why(d)}`);
@@ -3982,7 +4025,10 @@ function pruneAgentWorktrees(io: Io, slug: string, kept: (dir: string) => boolea
3982
4025
  continue;
3983
4026
  }
3984
4027
  const dirty = status.stdout.split("\n").filter((l) => l.trim()).length;
3985
- const reasons = [dirty ? `${plural(dirty, "uncommitted file", "uncommitted files")}` : null, unmerged(w.head)].filter((r): r is string => r !== null);
4028
+ const cherry = unmerged(w.head);
4029
+ // git cherry first — local; the PR only for a clean worktree it counts unmerged: the API call is for the doubt alone
4030
+ const byPr = !dirty && cherry !== null ? mergedByPr(w.head) : null;
4031
+ const reasons = [dirty ? `${plural(dirty, "uncommitted file", "uncommitted files")}` : null, byPr ? null : cherry].filter((r): r is string => r !== null);
3986
4032
  if (reasons.length) {
3987
4033
  io.out(`○ worktree ${w.path} left: ${reasons.join(", ")}`);
3988
4034
  continue;
@@ -3995,7 +4041,7 @@ function pruneAgentWorktrees(io: Io, slug: string, kept: (dir: string) => boolea
3995
4041
  continue;
3996
4042
  }
3997
4043
  const withBranch = w.branch !== null && deleteBranch(w.branch) ? ` with branch ${w.branch}` : "";
3998
- io.out(`+ worktree ${w.path} removed${withBranch}: clean, nothing outside ${upstream}`);
4044
+ io.out(`+ worktree ${w.path} removed${withBranch}: clean, ${byPr ?? `nothing outside ${upstream}`}`);
3999
4045
  }
4000
4046
  // a branch checked out anywhere — a locked worktree's included — isn't loose
4001
4047
  const checkedOut = new Set(all.map((w) => w.branch).filter(Boolean));
@@ -6589,7 +6635,7 @@ label's — from the latest «External blocker: …» comment). Marks the sessio
6589
6635
  with the session's id; a session with a pinned task keeps it. Before the queue, in the repository's checkout —
6590
6636
  finished agents' worktrees (.claude/worktrees/agent-*, detached or on worktree-agent-*, not locked by a live process,
6591
6637
  not an executor's whose handed-out task is open; on a task branch — when its task is closed): clean and merged (git
6592
- cherry) — removed with the branch (+),
6638
+ cherry, or its HEAD in a merged PR of its closed task into the default branch or a released batch) — removed with the branch (+),
6593
6639
  otherwise left (○ with the reason), and so is one a subagent works in without a worktree of its own (its transcript
6594
6640
  written in the last ${QUIET_MINUTES} min); loose worktree-agent-* branches — the same. --type and --priority — in an
6595
6641
  organization. --assignment N (the executor's first call; read-only on GitHub) — its whole assignment; in a session