@miroshnik/elves 2026.1027.1 → 2026.1028.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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bun
2
2
  import {
3
3
  locale_default
4
- } from "../../spec/scripts/harness-91h1qpb5.js";
4
+ } from "../../spec/scripts/harness-yh09fn5z.js";
5
5
 
6
6
  // skills/github/scripts/github.ts
7
7
  import { spawnSync } from "node:child_process";
@@ -1726,16 +1726,6 @@ function projectChecked(io, slug) {
1726
1726
  }
1727
1727
  return true;
1728
1728
  }
1729
- function scenarioItems(body, heading) {
1730
- const lines = body.replace(/\r\n/g, `
1731
- `).split(`
1732
- `);
1733
- const start = lines.findIndex((l) => l.trim().toLowerCase() === heading.toLowerCase());
1734
- if (start < 0)
1735
- return null;
1736
- const end = lines.findIndex((l, k) => k > start && /^#{1,2}\s/.test(l));
1737
- return lines.slice(start + 1, end < 0 ? undefined : end).map((l) => /^\s*\d+[.)]\s+(.+)$/.exec(l)?.[1]?.trim()).filter((x) => Boolean(x));
1738
- }
1739
1729
  function cmdTaskStart(io, slug, number, branch, resume = false) {
1740
1730
  if (resume && branch !== undefined)
1741
1731
  throw new GhError(`--resume continues the task's existing branch — without --branch`);
@@ -1773,7 +1763,7 @@ function cmdTaskStart(io, slug, number, branch, resume = false) {
1773
1763
  if (!t.estimate && type)
1774
1764
  runEstimate(io, slug, number, type);
1775
1765
  const now = git(io, io.cwd, "branch", "--show-current").stdout.trim();
1776
- const scenarios = scenarioItems(t.body, N.sections.scenarios);
1766
+ const scenarios = locale_default.scenarioItems(t.body);
1777
1767
  io.out(`Next: the session name — «#${number} ${t.title}»`);
1778
1768
  if (resume && !here)
1779
1769
  io.out(`Branch: continue ${parallel.join(", ")} — checked out in another worktree (git worktree list): work in that one; in none — git switch it here`);
@@ -2224,6 +2214,7 @@ function cmdTaskQueue(io, slug, o) {
2224
2214
  if (o.epic !== undefined && o.tasks !== undefined)
2225
2215
  throw new GhError("--epic or --tasks, not both: the group is the epic's open tasks or the ones named");
2226
2216
  let numbers;
2217
+ let subs = null;
2227
2218
  if (o.tasks !== undefined) {
2228
2219
  if (!o.tasks.length)
2229
2220
  throw new GhError("--tasks: the group's task numbers, comma-separated — --tasks 47,49");
@@ -2235,12 +2226,18 @@ function cmdTaskQueue(io, slug, o) {
2235
2226
  if (epic.state !== "OPEN")
2236
2227
  throw new GhError(`epic #${o.epic} is closed`);
2237
2228
  numbers = epic.subIssues.filter((x) => x.state === "OPEN").map((x) => x.number);
2229
+ subs = new Set(epic.subIssues.map((x) => x.number));
2238
2230
  } else {
2239
2231
  const found = graphql(io, Q.IssueSearch, { q: `repo:${slug} is:issue is:open` }).search.nodes;
2240
2232
  if (found.length >= 100)
2241
2233
  io.out("○ the search gave 100 open tasks — the queue sees only them: narrow it with --epic");
2242
2234
  numbers = found.filter((x) => x?.state === "OPEN").map((x) => x.number);
2243
2235
  }
2236
+ const handed = handedOut(io, slug);
2237
+ if (o.tasks === undefined) {
2238
+ numbers = [...new Set([...numbers, ...handed.filter((h) => subs === null || subs.has(h.number)).map((h) => h.number)])];
2239
+ }
2240
+ const awaiting = awaitingCloseOf(io, slug, handed);
2244
2241
  const recent = recentPrs(io, slug);
2245
2242
  const openPr = openPrOf(io, slug, recent);
2246
2243
  const args = [o.epic !== undefined && `--epic ${o.epic}`, o.tasks !== undefined && `--tasks ${numbers.join(",")}`, o.type !== undefined && `--type ${o.type}`, o.priority?.length && `--priority ${o.priority.join(",")}`].filter(Boolean).join(" ");
@@ -2256,7 +2253,6 @@ function cmdTaskQueue(io, slug, o) {
2256
2253
  const pastBatch = (i) => prsOf(i).some((p) => (p.state === "OPEN" || p.merged) && p.base !== batch);
2257
2254
  const release = batch === null ? undefined : releasePrOf(recent, batch);
2258
2255
  const releasing = release?.state === "OPEN" ? release.number : null;
2259
- const handed = handedOut(io, slug);
2260
2256
  const states = new Map;
2261
2257
  const read = openOf(io, slug);
2262
2258
  const isOpen = (n) => states.has(n) ? states.get(n) === "OPEN" : read(n);
@@ -2269,7 +2265,8 @@ function cmdTaskQueue(io, slug, o) {
2269
2265
  for (const n of numbers.sort((a, b) => a - b)) {
2270
2266
  const i = loadIssue(io, slug, n);
2271
2267
  states.set(i.number, i.state);
2272
- if (i.state !== "OPEN")
2268
+ const closer = i.state === "OPEN" ? null : awaiting(i.number, i);
2269
+ if (i.state !== "OPEN" && closer === null)
2273
2270
  continue;
2274
2271
  const label = `#${i.number} ${q(i.title)}`;
2275
2272
  if (isEpic(i, org)) {
@@ -2284,7 +2281,8 @@ function cmdTaskQueue(io, slug, o) {
2284
2281
  const pr = openPr(i);
2285
2282
  const merged = inBatch?.(i.number, i.prs);
2286
2283
  const work = [
2287
- status === N.status.inProgress ? q(N.status.inProgress) : "",
2284
+ closer === null ? "" : `PR #${closer} merged and closed the issue — waits for the deploy and task close`,
2285
+ closer === null && status === N.status.inProgress ? q(N.status.inProgress) : "",
2288
2286
  pr === undefined ? "" : `open PR #${pr} https://github.com/${slug}/pull/${pr}`,
2289
2287
  merged === undefined ? "" : `PR #${merged} merged into ${batch} — the task closes with the batch's release`
2290
2288
  ].filter(Boolean);
@@ -2310,7 +2308,11 @@ function cmdTaskQueue(io, slug, o) {
2310
2308
  continue;
2311
2309
  }
2312
2310
  const batched = (b) => inBatch !== null && b.repo.toLowerCase() === slug.toLowerCase() && inBatch(b.number) !== undefined;
2313
- const blockers = i.blockers.filter((b) => b.state === "OPEN" && !batched(b)).map((b) => blockerRef(slug, b));
2311
+ const unclosed = (b) => b.state !== "OPEN" && b.repo.toLowerCase() === slug.toLowerCase() && awaiting(b.number) !== null;
2312
+ const blockers = [
2313
+ ...i.blockers.filter((b) => b.state === "OPEN" && !batched(b)).map((b) => blockerRef(slug, b)),
2314
+ ...i.blockers.filter(unclosed).map((b) => `#${b.number} (merged, not closed by task close)`)
2315
+ ];
2314
2316
  const external = i.labels.find((l) => locale_default.every((n) => n.labels.externalBlocker).includes(l));
2315
2317
  if (status === N.status.done)
2316
2318
  waiting.push(`○ ${label} — ${STATUS} ${q(status)}, but the task is open`);
@@ -2341,7 +2343,7 @@ ${batches.map((b) => `batch ${b.repo} ${b.branch}
2341
2343
  } else
2342
2344
  io.out("○ session not recognized (no CLAUDE_CODE_SESSION_ID) — not marked as a dispatcher: task status in the executors would pin their tasks");
2343
2345
  appWorktreeWarning(io);
2344
- pruneExecutors(io, slug, handed, isOpen);
2346
+ pruneExecutors(io, slug, handed, isOpen, awaiting);
2345
2347
  if (settled.length && checkoutOfRepo(io, originUrl(io), slug))
2346
2348
  for (const n of settled)
2347
2349
  takeDownStacks(io, n, true);
@@ -2421,14 +2423,15 @@ function releaseChecks(io, slug, release) {
2421
2423
  }
2422
2424
  var TEST_FILE = /((?:[\w.@-]+\/)*[\w.@-]+\.(?:test|spec|e2e)\.[cm]?[jt]sx?)\b/;
2423
2425
  var isTestFile = (p) => new RegExp(`^${TEST_FILE.source}$`).test(p);
2426
+ var ANSI = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-?]*[ -/]*[@-~]|\u001b[@-Z\\-_]/g;
2424
2427
  function failedFilesIn(log) {
2425
2428
  const out = [];
2426
2429
  const rel = (p) => p.replace(/^.*?\/work\/[^/]+\/[^/]+\//, "").replace(/^\.\//, "");
2427
2430
  const header = new RegExp(`^\\s*/?${TEST_FILE.source}:$`);
2428
2431
  let current = null;
2429
- for (const raw of asTsc(log).split(`
2432
+ for (const raw of asTsc(log.replace(ANSI, "")).split(`
2430
2433
  `)) {
2431
- const line = raw.replace(/\u001b\[[\d;]*m/g, "").replace(/^\d{4}-\d\d-\d\dT[\d:.]+Z ?/, "").trimEnd();
2434
+ const line = raw.replace(/^\d{4}-\d\d-\d\dT[\d:.]+Z ?/, "").trimEnd();
2432
2435
  const file = header.exec(line);
2433
2436
  if (file) {
2434
2437
  current = rel(file[1]);
@@ -2447,7 +2450,7 @@ function failedFilesOf(io, slug, failed) {
2447
2450
  for (const r of failed) {
2448
2451
  let log;
2449
2452
  try {
2450
- log = io.gh(["api", `repos/${slug}/actions/jobs/${r.id}/logs`]);
2453
+ log = io.gh(["api", `repos/${slug}/actions/jobs/${r.id}/logs`, "--allow-escape-sequences"]);
2451
2454
  } catch (e) {
2452
2455
  if (!(e instanceof GhError))
2453
2456
  throw e;
@@ -2776,9 +2779,31 @@ function lockHolds(reason) {
2776
2779
  }
2777
2780
  }
2778
2781
  var plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
2779
- function pruneExecutors(io, slug, handed, isOpen) {
2782
+ function pruneExecutors(io, slug, handed, isOpen, awaiting = awaitingCloseOf(io, slug, handed)) {
2780
2783
  const executors = handed.flatMap((h) => h.worktree === null ? [] : [{ number: h.number, worktree: realPath(h.worktree) }]);
2781
- pruneAgentWorktrees(io, slug, (dir) => executors.some((h) => h.worktree === realPath(dir) && isOpen(h.number)), (n) => !isOpen(n));
2784
+ const live = (n) => isOpen(n) || awaiting(n) !== null;
2785
+ pruneAgentWorktrees(io, slug, (dir) => executors.some((h) => h.worktree === realPath(dir) && live(h.number)), (n) => !live(n));
2786
+ }
2787
+ function awaitingCloseOf(io, slug, handed) {
2788
+ const memo = new Map;
2789
+ return (n, issue) => {
2790
+ if (!handed.some((h) => h.number === n))
2791
+ return null;
2792
+ if (!memo.has(n)) {
2793
+ let pr = null;
2794
+ try {
2795
+ const i = issue ?? loadIssue(io, slug, n);
2796
+ const closer = i.state === "CLOSED" && i.stateReason === "COMPLETED" ? i.prs.find((p) => p.merged && !isBatchBranch(p.base) && !isBatchBranch(p.head)) : undefined;
2797
+ if (closer && !tailOver(io, slug, n))
2798
+ pr = closer.number;
2799
+ } catch (e) {
2800
+ if (!(e instanceof GhError))
2801
+ throw e;
2802
+ }
2803
+ memo.set(n, pr);
2804
+ }
2805
+ return memo.get(n);
2806
+ };
2782
2807
  }
2783
2808
  function openOf(io, slug) {
2784
2809
  const states = new Map;
@@ -3604,7 +3629,7 @@ function cmdTaskFinish(io, slug, number, o) {
3604
3629
  const dirty = git(io, io.cwd, "status", "--porcelain", "--untracked-files=no").stdout.trim();
3605
3630
  if (dirty)
3606
3631
  return stop(1, `! uncommitted changes in the checkout — the PR would go without them`, `the checks before a commit, git commit, then ${again}`);
3607
- const base = open?.base ?? (handedPastBatch(io, slug, number) ? null : batchOf(io, slug)) ?? found.base;
3632
+ const base = open?.base ?? finishBase(io, slug, number, found);
3608
3633
  const fetched = git(io, io.cwd, "fetch", "-q", "origin", `+refs/heads/${base}:refs/remotes/origin/${base}`);
3609
3634
  if (fetched.status !== 0)
3610
3635
  throw new GhError(`git fetch origin ${base}: ${why(fetched)}`);
@@ -3612,6 +3637,11 @@ function cmdTaskFinish(io, slug, number, o) {
3612
3637
  `).filter((l) => l.trim());
3613
3638
  if (!commits.length)
3614
3639
  return stop(1, `! no commits on ${branch} past origin/${base} — nothing to put into a PR`, `commit the task's work, then ${again}`);
3640
+ const applied = git(io, io.cwd, "cherry", `origin/${base}`, "HEAD").stdout.split(`
3641
+ `).filter((l) => l.startsWith("-")).length;
3642
+ if (applied) {
3643
+ return stop(1, `! ${applied} ${applied > 1 ? "commits" : "commit"} of ${branch} ${applied > 1 ? "are" : "is"} in origin/${base} already by the changes (a released batch's, a merged PR's) — the PR would take its title and decision labels from them`, `git rebase origin/${base} (it drops them), then ${again} (it pushes the rebased branch with --force-with-lease)`);
3644
+ }
3615
3645
  const refused = pushTaskBranch(io, branch);
3616
3646
  if (refused)
3617
3647
  return stop(1, `! ${refused}`, `then ${again}`);
@@ -3665,6 +3695,18 @@ function cmdTaskFinish(io, slug, number, o) {
3665
3695
  const yes = locale_default.autoProject(io.cwd ?? process.cwd()) ? "" : "the owner's «yes» (the project is without auto) — then ";
3666
3696
  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"}`);
3667
3697
  }
3698
+ function finishBase(io, slug, number, found) {
3699
+ const batch = handedPastBatch(io, slug, number) ? null : batchOf(io, slug);
3700
+ if (!batch)
3701
+ return found.base;
3702
+ const release = releasePrOf(found.recent, batch);
3703
+ if (release?.merged)
3704
+ return io.out(`○ ${batch} is released by PR #${release.number} — the PR goes into ${found.base}`), found.base;
3705
+ const listed = git(io, io.cwd, "ls-remote", "--heads", "origin", `refs/heads/${batch}`);
3706
+ if (listed.status === 0 && !listed.stdout.trim())
3707
+ return io.out(`○ ${batch} is gone from origin (released) — the PR goes into ${found.base}`), found.base;
3708
+ return batch;
3709
+ }
3668
3710
  function tailOver(io, slug, number) {
3669
3711
  if (inCloud(io))
3670
3712
  return true;
@@ -3793,7 +3835,8 @@ function renameBranch(io, slug, target) {
3793
3835
  return false;
3794
3836
  }
3795
3837
  function unlinkedPrs(io, slug, number) {
3796
- const { base, nodes } = recentPrs(io, slug);
3838
+ const recent = recentPrs(io, slug);
3839
+ const { base, nodes } = recent;
3797
3840
  const prs = [];
3798
3841
  const batched = [];
3799
3842
  for (const p of nodes) {
@@ -3805,7 +3848,7 @@ function unlinkedPrs(io, slug, number) {
3805
3848
  if (why)
3806
3849
  (into === base ? prs : batched).push({ number: p.number, state: p.state ?? "", merged: Boolean(p.merged), head, base: into, why });
3807
3850
  }
3808
- return { base, prs, batched };
3851
+ return { base, prs, batched, recent };
3809
3852
  }
3810
3853
  var estScript = (io) => io.env["ELVES_EST"] ?? path.resolve(import.meta.dir, "../../est/scripts/est.ts");
3811
3854
  function originUrl(io) {
@@ -4676,7 +4719,8 @@ Examples:
4676
4719
  The tail of a task from its committed branch to its close, resumable: each call does what is ready within --timeout
4677
4720
  (default ${FINISH_TIMEOUT} s), prints the state and the Next line, a repeat goes on from there. Before the merge: the task
4678
4721
  branch pushed (a rebased one — --force-with-lease), the PR into the dispatcher's batch branch or the default branch
4679
- (the title — --title, otherwise the branch type's first commit; the body — spec-diff and Closes #N; an existing PR —
4722
+ (a released batch — the default branch; commits of the branch already in the base by their changes — a stop: git
4723
+ rebase drops them; the title — --title, otherwise the branch type's first commit; the body — spec-diff and Closes #N; an existing PR —
4680
4724
  its body updated), pr labels, the CI wait (ci-wait pr; none into a batch), pr premerge, then the merge command — a
4681
4725
  separate gh pr merge <PR> --rebase. After the merge: the deploy wait on the merge SHA (ci-wait merged), the epic
4682
4726
  refresh's mechanics and its subagent's prompt (once), task close once the report is on the epic; merged into a batch —
@@ -5149,7 +5193,6 @@ export {
5149
5193
  questionItems,
5150
5194
  realGh,
5151
5195
  realRun,
5152
- scenarioItems,
5153
5196
  sectionNames,
5154
5197
  sectionTopics,
5155
5198
  sessionPin,
@@ -2,10 +2,10 @@ import {
2
2
  invariant2,
3
3
  codeOnly2,
4
4
  envNamesInCode2
5
- } from "./harness-whad9qej.js";
5
+ } from "./harness-wcyv20e3.js";
6
6
  import {
7
7
  locale_default
8
- } from "./harness-91h1qpb5.js";
8
+ } from "./harness-yh09fn5z.js";
9
9
 
10
10
  // skills/spec/scripts/architecture.ts
11
11
  import { readdirSync, readFileSync } from "node:fs";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  locale_default
3
- } from "./harness-91h1qpb5.js";
3
+ } from "./harness-yh09fn5z.js";
4
4
  var __create = Object.create;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __defProp = Object.defineProperty;
@@ -1027,6 +1027,30 @@ function count(language, forms, n) {
1027
1027
  function escapeRe(text) {
1028
1028
  return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1029
1029
  }
1030
- var locale_default = { LANGUAGE_CODE, DEFAULT_LANGUAGE, projectRoot, manifestOf, projectLanguage, missingManifest, batchProject, autoProject, names, languages, everyNames, every, fill, plural, count, escapeRe };
1030
+ function scenarioItems(md) {
1031
+ let fence = null;
1032
+ const lines = md.split(/\r?\n/).map((l) => {
1033
+ const f = /^\s*(`{3,}|~{3,})/.exec(l)?.[1];
1034
+ if (f && (fence === null || f[0] === fence[0] && f.length >= fence.length)) {
1035
+ fence = fence === null ? f : null;
1036
+ return "";
1037
+ }
1038
+ return fence === null ? l : "";
1039
+ });
1040
+ const heads = every((n) => n.sections.scenarios).map((h) => new RegExp(`^${escapeRe(h).replace(/ +/g, "\\s+")}\\s*$`));
1041
+ const start = lines.findIndex((l) => heads.some((h) => h.test(l.trim())));
1042
+ if (start < 0)
1043
+ return null;
1044
+ const out = [];
1045
+ for (const l of lines.slice(start + 1)) {
1046
+ if (/^#{1,2}\s/.test(l))
1047
+ break;
1048
+ const m = /^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?(.+?)\s*$/.exec(l);
1049
+ if (m)
1050
+ out.push(m[1]);
1051
+ }
1052
+ return out;
1053
+ }
1054
+ var locale_default = { LANGUAGE_CODE, DEFAULT_LANGUAGE, projectRoot, manifestOf, projectLanguage, missingManifest, batchProject, autoProject, names, languages, everyNames, every, fill, plural, count, escapeRe, scenarioItems };
1031
1055
 
1032
1056
  export { locale_default };
@@ -23,7 +23,7 @@ import {
23
23
  envNamesInCode2,
24
24
  dotenvNames2,
25
25
  envVars2
26
- } from "./harness-whad9qej.js";
26
+ } from "./harness-wcyv20e3.js";
27
27
  export {
28
28
  ENV_SERVICE2 as ENV_SERVICE,
29
29
  codeFiles2 as codeFiles,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miroshnik/elves",
3
- "version": "2026.1027.1",
3
+ "version": "2026.1028.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": "af1dc04656248295ddbc09910f726dafcb145cec"
75
+ "gitHead": "4dda0139a91991ebff3648aafbc228ecdeb29e37"
76
76
  }
@@ -672,7 +672,11 @@ subagent). Before the merge: uncommitted changes or no commits past
672
672
  `origin/<base>` — code 1; the task branch pushed (origin has the same
673
673
  commits rebased — `--force-with-lease` on its head; commits that aren't
674
674
  here — code 1), no `-u`; the PR into the dispatcher's batch branch, otherwise
675
- the default branch: the title — `--title`, otherwise the first commit of the
675
+ — and when that batch is released (its release PR merged, its branch gone
676
+ from origin, #768) — the default branch; commits of the branch already in
677
+ the base by their changes (a released batch's, rebased with other SHAs) —
678
+ code 1 before the PR: `git rebase origin/<base>` drops them, otherwise the
679
+ PR's title and decision labels would be theirs; the title — `--title`, otherwise the first commit of the
676
680
  branch type, a conventional commit; the body — `spec-diff` and `Closes #N`
677
681
  (an existing PR — the body updated); `pr labels`; `ci-wait pr` (none into a
678
682
  batch): FAIL, a conflict — code 1 with the step; `pr premerge` — its code 1
@@ -916,8 +920,12 @@ work, no open blockers — another repository's named `owner/repo#N` —, no
916
920
  line — its executor's prompt, «Task #N …» in the project language (`est` links
917
921
  the subagent's work by it); then `=` lines — in work: In progress, an open PR
918
922
  (linked, or by the task branch and "Closes #N" among recent PRs) with its link,
919
- handed out to an executor of this session; `○` lines — not ready
920
- with the reason, and `Next:`. Before the queue, in the repository's checkout,
923
+ handed out to an executor of this session, a hand-out's task closed by its PR's
924
+ merge («Closes #N») before `task close` — «waits for the deploy and task close»
925
+ (#769: its work lives till `task close` leaves Status Done and the actual; a
926
+ release PR's merge isn't one); `○` lines — not ready with the reason (such a
927
+ task holds its dependents: `blocked by #N (merged, not closed by task close)`),
928
+ and `Next:`. Before the queue, in the repository's checkout,
921
929
  it removes what finished executors left (#515): an agent's worktree
922
930
  (`.claude/worktrees/agent-*`) detached or on a `worktree-agent-*` branch, not
923
931
  locked by a live process (Claude Code locks a running agent's worktree; a lock
@@ -926,7 +934,8 @@ whose pid is gone doesn't hold), clean and without commits outside
926
934
  uncommitted changes or unmerged commits — left, an `○` line with the reason; a
927
935
  `worktree-agent-*` branch without a worktree — the same by its commits. A
928
936
  session's worktree, an agent's on an open task's branch and an executor's whose
929
- handed-out task is open — untouched, no line (#533); an agent's on a closed
937
+ handed-out task is open or awaits `task close` after its merge — untouched,
938
+ no line (#533, #769); an agent's on a closed
930
939
  task's branch — as a detached one (#698: a batch executor ends on its task
931
940
  branch, the release closes the task): Claude Code unlocks the
932
941
  worktree when the agent ends its answer, a question too, and doesn't lock it
@@ -2392,18 +2392,6 @@ function projectChecked(io: Io, slug: string): boolean {
2392
2392
  return true;
2393
2393
  }
2394
2394
 
2395
- /** The numbered items of the description's scenarios section — the future `it` names; no section — null. */
2396
- export function scenarioItems(body: string, heading: string): string[] | null {
2397
- const lines = body.replace(/\r\n/g, "\n").split("\n");
2398
- const start = lines.findIndex((l) => l.trim().toLowerCase() === heading.toLowerCase());
2399
- if (start < 0) return null;
2400
- const end = lines.findIndex((l, k) => k > start && /^#{1,2}\s/.test(l));
2401
- return lines
2402
- .slice(start + 1, end < 0 ? undefined : end)
2403
- .map((l) => /^\s*\d+[.)]\s+(.+)$/.exec(l)?.[1]?.trim())
2404
- .filter((x): x is string => Boolean(x));
2405
- }
2406
-
2407
2395
  /**
2408
2396
  * Taking a task in one call (#666) instead of ~11 flow turns: `project check` (once per session), the task as `task
2409
2397
  * show` prints it, then the stops before any change — open questions of the task or its epic (they are asked first,
@@ -2445,7 +2433,7 @@ export function cmdTaskStart(io: Io, slug: string, number: number, branch?: stri
2445
2433
  const type = taskBranch(branch ?? (here ? current : (others[0] ?? "")))?.type;
2446
2434
  if (!t.estimate && type) runEstimate(io, slug, number, type);
2447
2435
  const now = git(io, io.cwd, "branch", "--show-current").stdout.trim();
2448
- const scenarios = scenarioItems(t.body, N.sections.scenarios);
2436
+ const scenarios = locale.scenarioItems(t.body);
2449
2437
  io.out(`Next: the session name — «#${number} ${t.title}»`);
2450
2438
  if (resume && !here) io.out(`Branch: continue ${parallel.join(", ")} — checked out in another worktree (git worktree list): work in that one; in none — git switch it here`);
2451
2439
  else io.out(now ? `Branch: ${now}` : `Branch: none — the task branch from a fresh origin/<base>${branch ? `: ${branch}` : ""}`);
@@ -3077,7 +3065,8 @@ function batchPrOf(recent: Recent, batch: string): (number: number, linked?: Iss
3077
3065
  * the owner's "yes" to an epic's dispatcher becomes work at once, without a new session) — its pin stays, its task is
3078
3066
  * in work. Ready — open, not an epic, not in work, no open blockers (other repositories' too), no external blocker
3079
3067
  * label; order — Priority, then the number. In work (`=`) — "In progress", an open PR (linked, or by the task branch and
3080
- * "Closes #N" among recent PRs) named with its link, or handed out to an executor of this session (`handedOutFile`).
3068
+ * "Closes #N" among recent PRs) named with its link, or handed out to an executor of this session (`handedOutFile`);
3069
+ * a hand-out's task closed by its PR's merge stays in work and holds its dependents till `task close` (`awaitingCloseOf`, #769).
3081
3070
  * Marks the session as a dispatcher (`dispatcherFile`). A batch project (#648) — the batch branch first
3082
3071
  * (`dispatcherBatch`), its line in the marker: a task merged into it is `=` till the release, a blocker merged into it
3083
3072
  * doesn't hold. The batch's release (#649): nothing ready and every task of the batch merged into it — `Next:` names
@@ -3098,6 +3087,8 @@ export function cmdTaskQueue(io: Io, slug: string, o: QueueFilter): number {
3098
3087
  if (!org && (o.type !== undefined || o.priority?.length)) throw new GhError("--type and --priority — only in an organization: a personal account has no issue types and no Priority");
3099
3088
  if (o.epic !== undefined && o.tasks !== undefined) throw new GhError("--epic or --tasks, not both: the group is the epic's open tasks or the ones named");
3100
3089
  let numbers: number[];
3090
+ /** The epic's sub-issues, closed ones included — a hand-out's task closed by a merge is among them (#769). */
3091
+ let subs: Set<number> | null = null;
3101
3092
  if (o.tasks !== undefined) {
3102
3093
  if (!o.tasks.length) throw new GhError("--tasks: the group's task numbers, comma-separated — --tasks 47,49");
3103
3094
  numbers = [...new Set(o.tasks)];
@@ -3106,11 +3097,18 @@ export function cmdTaskQueue(io: Io, slug: string, o: QueueFilter): number {
3106
3097
  if (!isEpic(epic, org)) throw new GhError(`#${o.epic} is not an epic — --epic takes an epic`);
3107
3098
  if (epic.state !== "OPEN") throw new GhError(`epic #${o.epic} is closed`);
3108
3099
  numbers = epic.subIssues.filter((x) => x.state === "OPEN").map((x) => x.number);
3100
+ subs = new Set(epic.subIssues.map((x) => x.number));
3109
3101
  } else {
3110
3102
  const found = graphql(io, Q.IssueSearch, { q: `repo:${slug} is:issue is:open` }).search.nodes as Any[];
3111
3103
  if (found.length >= 100) io.out("○ the search gave 100 open tasks — the queue sees only them: narrow it with --epic");
3112
3104
  numbers = found.filter((x) => x?.state === "OPEN").map((x) => x.number);
3113
3105
  }
3106
+ const handed = handedOut(io, slug);
3107
+ // a hand-out's task closed by its PR's merge is in work till task close (#769): the open tasks don't name it
3108
+ if (o.tasks === undefined) {
3109
+ numbers = [...new Set([...numbers, ...handed.filter((h) => subs === null || subs.has(h.number)).map((h) => h.number)])];
3110
+ }
3111
+ const awaiting = awaitingCloseOf(io, slug, handed);
3114
3112
  const recent = recentPrs(io, slug);
3115
3113
  const openPr = openPrOf(io, slug, recent);
3116
3114
  const args = [o.epic !== undefined && `--epic ${o.epic}`, o.tasks !== undefined && `--tasks ${numbers.join(",")}`, o.type !== undefined && `--type ${o.type}`, o.priority?.length && `--priority ${o.priority.join(",")}`].filter(Boolean).join(" ");
@@ -3132,7 +3130,6 @@ export function cmdTaskQueue(io: Io, slug: string, o: QueueFilter): number {
3132
3130
  // the release its CI checked
3133
3131
  const release = batch === null ? undefined : releasePrOf(recent, batch);
3134
3132
  const releasing = release?.state === "OPEN" ? (release.number as number) : null;
3135
- const handed = handedOut(io, slug);
3136
3133
  /** Issue states the queue has read; a hand-out's task outside the queue is read when its worktree is up for removal. */
3137
3134
  const states = new Map<number, string>();
3138
3135
  const read = openOf(io, slug);
@@ -3154,7 +3151,8 @@ export function cmdTaskQueue(io: Io, slug: string, o: QueueFilter): number {
3154
3151
  for (const n of numbers.sort((a, b) => a - b)) {
3155
3152
  const i = loadIssue(io, slug, n);
3156
3153
  states.set(i.number, i.state);
3157
- if (i.state !== "OPEN") continue;
3154
+ const closer = i.state === "OPEN" ? null : awaiting(i.number, i);
3155
+ if (i.state !== "OPEN" && closer === null) continue;
3158
3156
  const label = `#${i.number} ${q(i.title)}`;
3159
3157
  if (isEpic(i, org)) {
3160
3158
  waiting.push(`○ ${label} — an epic: its tasks — task queue --epic ${i.number}`);
@@ -3169,7 +3167,8 @@ export function cmdTaskQueue(io: Io, slug: string, o: QueueFilter): number {
3169
3167
  // merged into the batch branch (question 1 of epic #645): open and In progress till the release — not given out again
3170
3168
  const merged = inBatch?.(i.number, i.prs);
3171
3169
  const work = [
3172
- status === N.status.inProgress ? q(N.status.inProgress) : "",
3170
+ closer === null ? "" : `PR #${closer} merged and closed the issue — waits for the deploy and task close`,
3171
+ closer === null && status === N.status.inProgress ? q(N.status.inProgress) : "",
3173
3172
  pr === undefined ? "" : `open PR #${pr} https://github.com/${slug}/pull/${pr}`,
3174
3173
  merged === undefined ? "" : `PR #${merged} merged into ${batch} — the task closes with the batch's release`,
3175
3174
  ].filter(Boolean);
@@ -3193,7 +3192,12 @@ export function cmdTaskQueue(io: Io, slug: string, o: QueueFilter): number {
3193
3192
  // a blocker merged into this batch's branch doesn't hold its task: the executor branches from the batch (#648); a
3194
3193
  // blocker outside it — merged into another batch or not merged — holds, as without batches
3195
3194
  const batched = (b: Blocker) => inBatch !== null && b.repo.toLowerCase() === slug.toLowerCase() && inBatch(b.number) !== undefined;
3196
- const blockers = i.blockers.filter((b) => b.state === "OPEN" && !batched(b)).map((b) => blockerRef(slug, b));
3195
+ // a blocker closed by its PR's merge holds till its task close (#769): the deploy it waits for may not have happened
3196
+ const unclosed = (b: Blocker) => b.state !== "OPEN" && b.repo.toLowerCase() === slug.toLowerCase() && awaiting(b.number) !== null;
3197
+ const blockers = [
3198
+ ...i.blockers.filter((b) => b.state === "OPEN" && !batched(b)).map((b) => blockerRef(slug, b)),
3199
+ ...i.blockers.filter(unclosed).map((b) => `#${b.number} (merged, not closed by task close)`),
3200
+ ];
3197
3201
  const external = i.labels.find((l) => locale.every((n) => n.labels.externalBlocker).includes(l));
3198
3202
  if (status === N.status.done) waiting.push(`○ ${label} — ${STATUS} ${q(status)}, but the task is open`);
3199
3203
  else if (blockers.length) waiting.push(`○ ${label} — blocked by ${blockers.join(", ")}`);
@@ -3216,7 +3220,7 @@ export function cmdTaskQueue(io: Io, slug: string, o: QueueFilter): number {
3216
3220
  } else io.out("○ session not recognized (no CLAUDE_CODE_SESSION_ID) — not marked as a dispatcher: task status in the executors would pin their tasks");
3217
3221
  appWorktreeWarning(io);
3218
3222
  // the executor the dispatcher continues with SendMessage — an answered question, a restart — has no lock (#533)
3219
- pruneExecutors(io, slug, handed, isOpen);
3223
+ pruneExecutors(io, slug, handed, isOpen, awaiting);
3220
3224
  // a task merged into the batch waits for the release, its stack doesn't (#765): the executor didn't take it down — the queue does
3221
3225
  if (settled.length && checkoutOfRepo(io, originUrl(io), slug)) for (const n of settled) takeDownStacks(io, n, true);
3222
3226
  const group = o.tasks !== undefined ? `tasks ${numbers.map((n) => `#${n}`).join(", ")}` : null;
@@ -3345,20 +3349,23 @@ function releaseChecks(io: Io, slug: string, release: PrRef): ReleaseChecks {
3345
3349
  const TEST_FILE = /((?:[\w.@-]+\/)*[\w.@-]+\.(?:test|spec|e2e)\.[cm]?[jt]sx?)\b/;
3346
3350
  const isTestFile = (p: string) => new RegExp(`^${TEST_FILE.source}$`).test(p);
3347
3351
 
3352
+ /** Terminal escape sequences: OSC (`ESC ] … BEL|ESC \\`, links), CSI (`ESC [ … letter`, colors, erasing), two-byte ones. */
3353
+ const ANSI = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-?]*[ -/]*[@-~]|\u001b[@-Z\\-_]/g;
3354
+
3348
3355
  /**
3349
3356
  * The files a failed job's log names (#650): a failed test's file — in its failure line (Vitest, Jest, Playwright) or in
3350
3357
  * the file header above it (Bun: `tests/…/x.test.ts:`), a compiler error's file — `a.ts(3,5): error TS…` (a `bun check`
3351
3358
  * block too, `asTsc`); failure lines — `FAILED_LINE`, as on the merge. Paths — the checkout's: the runner's workspace
3352
- * prefix (`…/work/<repo>/<repo>/`), the log's timestamps and colors are cut.
3359
+ * prefix (`…/work/<repo>/<repo>/`), the log's timestamps and terminal escape sequences (`ANSI`: colors, erasing, OSC
3360
+ * links — #774) are cut.
3353
3361
  */
3354
3362
  function failedFilesIn(log: string): string[] {
3355
3363
  const out: string[] = [];
3356
3364
  const rel = (p: string) => p.replace(/^.*?\/work\/[^/]+\/[^/]+\//, "").replace(/^\.\//, "");
3357
3365
  const header = new RegExp(`^\\s*/?${TEST_FILE.source}:$`);
3358
3366
  let current: string | null = null;
3359
- for (const raw of asTsc(log).split("\n")) {
3367
+ for (const raw of asTsc(log.replace(ANSI, "")).split("\n")) {
3360
3368
  const line = raw
3361
- .replace(/\u001b\[[\d;]*m/g, "")
3362
3369
  .replace(/^\d{4}-\d\d-\d\dT[\d:.]+Z ?/, "")
3363
3370
  .trimEnd();
3364
3371
  const file = header.exec(line);
@@ -3379,7 +3386,8 @@ function failedFilesOf(io: Io, slug: string, failed: Any[]): string[] {
3379
3386
  for (const r of failed) {
3380
3387
  let log: string;
3381
3388
  try {
3382
- log = io.gh(["api", `repos/${slug}/actions/jobs/${r.id}/logs`]);
3389
+ // a runner's log has the terminal's escape sequences (colors, line erasing, links): gh prints it only with the flag (#774)
3390
+ log = io.gh(["api", `repos/${slug}/actions/jobs/${r.id}/logs`, "--allow-escape-sequences"]);
3383
3391
  } catch (e) {
3384
3392
  if (!(e instanceof GhError)) throw e;
3385
3393
  io.out(`○ the log of ${r.name} not read: ${e.message}`);
@@ -3795,16 +3803,45 @@ const plural = (n: number, one: string, many: string) => `${n} ${n === 1 ? one :
3795
3803
  * (#698): an executor's whose handed-out task is open is kept (#533); an agent's on the task branch of a closed task goes
3796
3804
  * too — a batch executor ends on its task branch, and the release closes the task (GitHub, by its «Closes»).
3797
3805
  */
3798
- function pruneExecutors(io: Io, slug: string, handed: HandOut[], isOpen: (n: number) => boolean): void {
3806
+ function pruneExecutors(io: Io, slug: string, handed: HandOut[], isOpen: (n: number) => boolean, awaiting = awaitingCloseOf(io, slug, handed)): void {
3799
3807
  const executors = handed.flatMap((h) => (h.worktree === null ? [] : [{ number: h.number, worktree: realPath(h.worktree) }]));
3808
+ // a task closed by its PR's merge, task close not run yet (#769): its executor waits for the deploy in that worktree
3809
+ const live = (n: number) => isOpen(n) || awaiting(n) !== null;
3800
3810
  pruneAgentWorktrees(
3801
3811
  io,
3802
3812
  slug,
3803
- (dir) => executors.some((h) => h.worktree === realPath(dir) && isOpen(h.number)),
3804
- (n) => !isOpen(n),
3813
+ (dir) => executors.some((h) => h.worktree === realPath(dir) && live(h.number)),
3814
+ (n) => !live(n),
3805
3815
  );
3806
3816
  }
3807
3817
 
3818
+ /**
3819
+ * A handed-out task closed by its PR's merge, the tail not over (#769): «Closes #N» closes the issue at the merge into the
3820
+ * default branch, while its executor still waits for the deploy, runs the epic refresh and `task close`. The task's work
3821
+ * lives till `task close` — what it leaves (`tailOver`: Status Done and the actual), not the issue's state: till then the
3822
+ * queue keeps the executor's worktree, shows the task `=` and holds its dependents. A release PR's merge (its head — a
3823
+ * batch branch) isn't one: the batch's executors are done, the dispatcher closes their tasks. The closing PR's number;
3824
+ * otherwise — null. Read once per number; an issue not read — null.
3825
+ */
3826
+ function awaitingCloseOf(io: Io, slug: string, handed: HandOut[]): (n: number, issue?: Issue) => number | null {
3827
+ const memo = new Map<number, number | null>();
3828
+ return (n, issue) => {
3829
+ if (!handed.some((h) => h.number === n)) return null;
3830
+ if (!memo.has(n)) {
3831
+ let pr: number | null = null;
3832
+ try {
3833
+ const i = issue ?? loadIssue(io, slug, n);
3834
+ const closer = i.state === "CLOSED" && i.stateReason === "COMPLETED" ? i.prs.find((p) => p.merged && !isBatchBranch(p.base) && !isBatchBranch(p.head)) : undefined;
3835
+ if (closer && !tailOver(io, slug, n)) pr = closer.number;
3836
+ } catch (e) {
3837
+ if (!(e instanceof GhError)) throw e;
3838
+ }
3839
+ memo.set(n, pr);
3840
+ }
3841
+ return memo.get(n)!;
3842
+ };
3843
+ }
3844
+
3808
3845
  /** The issue's state, read once per command: open — true; not read (no such issue) — open, nothing is removed for it. */
3809
3846
  function openOf(io: Io, slug: string): (n: number) => boolean {
3810
3847
  const states = new Map<number, boolean>();
@@ -4943,12 +4980,21 @@ export function cmdTaskFinish(io: Io, slug: string, number: number, o: { timeout
4943
4980
  if (!isTaskBranch(branch, number)) throw new GhError(`the checkout is on ${q(branch || "a detached HEAD")}, not on a branch of #${number} — task start ${number} --branch <type>/${number}-<slug>`);
4944
4981
  const dirty = git(io, io.cwd, "status", "--porcelain", "--untracked-files=no").stdout.trim();
4945
4982
  if (dirty) return stop(1, `! uncommitted changes in the checkout — the PR would go without them`, `the checks before a commit, git commit, then ${again}`);
4946
- // a task past the batch (#697) — into the default branch, as outside a batch
4947
- const base = open?.base ?? (handedPastBatch(io, slug, number) ? null : batchOf(io, slug)) ?? found.base;
4983
+ const base = open?.base ?? finishBase(io, slug, number, found);
4948
4984
  const fetched = git(io, io.cwd, "fetch", "-q", "origin", `+refs/heads/${base}:refs/remotes/origin/${base}`);
4949
4985
  if (fetched.status !== 0) throw new GhError(`git fetch origin ${base}: ${why(fetched)}`);
4950
4986
  const commits = git(io, io.cwd, "log", "--reverse", "--format=%s", `origin/${base}..HEAD`).stdout.split("\n").filter((l) => l.trim());
4951
4987
  if (!commits.length) return stop(1, `! no commits on ${branch} past origin/${base} — nothing to put into a PR`, `commit the task's work, then ${again}`);
4988
+ // commits already in the base by their changes (#768) — a released batch's, rebased into the default branch with other
4989
+ // SHAs: the PR would take its title from them and its decision labels from their diff; a rebase drops them
4990
+ const applied = git(io, io.cwd, "cherry", `origin/${base}`, "HEAD").stdout.split("\n").filter((l) => l.startsWith("-")).length;
4991
+ if (applied) {
4992
+ return stop(
4993
+ 1,
4994
+ `! ${applied} ${applied > 1 ? "commits" : "commit"} of ${branch} ${applied > 1 ? "are" : "is"} in origin/${base} already by the changes (a released batch's, a merged PR's) — the PR would take its title and decision labels from them`,
4995
+ `git rebase origin/${base} (it drops them), then ${again} (it pushes the rebased branch with --force-with-lease)`,
4996
+ );
4997
+ }
4952
4998
  const refused = pushTaskBranch(io, branch);
4953
4999
  if (refused) return stop(1, `! ${refused}`, `then ${again}`);
4954
5000
 
@@ -4991,6 +5037,22 @@ export function cmdTaskFinish(io: Io, slug: string, number: number, o: { timeout
4991
5037
  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"}`);
4992
5038
  }
4993
5039
 
5040
+ /**
5041
+ * The base of the task's new PR: the dispatcher's batch branch (#648); a task past the batch (#697) — the default branch,
5042
+ * as outside a batch; the batch released (#768: its release PR merged, or its branch gone from origin) — the default
5043
+ * branch too: a released batch takes no more PRs, and the queue starts the next one only with a task to hand out (its
5044
+ * marker names it then).
5045
+ */
5046
+ function finishBase(io: Io, slug: string, number: number, found: ReturnType<typeof unlinkedPrs>): string {
5047
+ const batch = handedPastBatch(io, slug, number) ? null : batchOf(io, slug);
5048
+ if (!batch) return found.base;
5049
+ const release = releasePrOf(found.recent, batch);
5050
+ if (release?.merged) return io.out(`○ ${batch} is released by PR #${release.number} — the PR goes into ${found.base}`), found.base;
5051
+ const listed = git(io, io.cwd, "ls-remote", "--heads", "origin", `refs/heads/${batch}`);
5052
+ if (listed.status === 0 && !listed.stdout.trim()) return io.out(`○ ${batch} is gone from origin (released) — the PR goes into ${found.base}`), found.base;
5053
+ return batch;
5054
+ }
5055
+
4994
5056
  /**
4995
5057
  * The tail is over — what `task close` leaves (#761, question 1): Status Done and the actual written, not the issue's
4996
5058
  * state, which «Closes #N» sets at the merge. In the cloud there is no project to read — over, as before.
@@ -5175,8 +5237,9 @@ function renameBranch(io: Io, slug: string, target: string): boolean {
5175
5237
  * `batched` — the same into a batch branch (#648): GitHub never links those, and they don't close the task — the
5176
5238
  * batch's release does.
5177
5239
  */
5178
- function unlinkedPrs(io: Io, slug: string, number: number): { base: string; prs: UnlinkedPr[]; batched: UnlinkedPr[] } {
5179
- const { base, nodes } = recentPrs(io, slug);
5240
+ function unlinkedPrs(io: Io, slug: string, number: number): { base: string; prs: UnlinkedPr[]; batched: UnlinkedPr[]; recent: Recent } {
5241
+ const recent = recentPrs(io, slug);
5242
+ const { base, nodes } = recent;
5180
5243
  const prs: UnlinkedPr[] = [];
5181
5244
  const batched: UnlinkedPr[] = [];
5182
5245
  for (const p of nodes) {
@@ -5186,7 +5249,7 @@ function unlinkedPrs(io: Io, slug: string, number: number): { base: string; prs:
5186
5249
  const why = taskLinks(p).find((x) => x.number === number)?.why;
5187
5250
  if (why) (into === base ? prs : batched).push({ number: p.number, state: p.state ?? "", merged: Boolean(p.merged), head, base: into, why });
5188
5251
  }
5189
- return { base, prs, batched };
5252
+ return { base, prs, batched, recent };
5190
5253
  }
5191
5254
 
5192
5255
  type UnlinkedPr = Issue["prs"][number] & { why: string };
@@ -6336,7 +6399,8 @@ Examples:
6336
6399
  The tail of a task from its committed branch to its close, resumable: each call does what is ready within --timeout
6337
6400
  (default ${FINISH_TIMEOUT} s), prints the state and the Next line, a repeat goes on from there. Before the merge: the task
6338
6401
  branch pushed (a rebased one — --force-with-lease), the PR into the dispatcher's batch branch or the default branch
6339
- (the title — --title, otherwise the branch type's first commit; the body — spec-diff and Closes #N; an existing PR —
6402
+ (a released batch — the default branch; commits of the branch already in the base by their changes — a stop: git
6403
+ rebase drops them; the title — --title, otherwise the branch type's first commit; the body — spec-diff and Closes #N; an existing PR —
6340
6404
  its body updated), pr labels, the CI wait (ci-wait pr; none into a batch), pr premerge, then the merge command — a
6341
6405
  separate gh pr merge <PR> --rebase. After the merge: the deploy wait on the merge SHA (ci-wait merged), the epic
6342
6406
  refresh's mechanics and its subagent's prompt (once), task close once the report is on the epic; merged into a batch —
@@ -586,4 +586,33 @@ function escapeRe(text: string): string {
586
586
  return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
587
587
  }
588
588
 
589
- export default { LANGUAGE_CODE, DEFAULT_LANGUAGE, projectRoot, manifestOf, projectLanguage, missingManifest, batchProject, autoProject, names, languages, everyNames, every, fill, plural, count, escapeRe };
589
+ /**
590
+ * A task's scenarios — the list items (`-`, `*`, `+` or numbered) of the description's scenarios section up to the next
591
+ * heading, checkboxes stripped; no section — null. The heading is in any dictionary language (`## Scenarios` or its
592
+ * translation): the task could have been written before the project language changed. One parser for `task start`
593
+ * and `spec-diff` (#767: `task start` read only numbered items and missed `- «…»`).
594
+ */
595
+ function scenarioItems(md: string): string[] | null {
596
+ // a fenced code block is an example in the task text, not its sections: its lines are blanked out
597
+ let fence: string | null = null;
598
+ const lines = md.split(/\r?\n/).map((l) => {
599
+ const f = /^\s*(`{3,}|~{3,})/.exec(l)?.[1];
600
+ if (f && (fence === null || (f[0] === fence[0] && f.length >= fence.length))) {
601
+ fence = fence === null ? f : null;
602
+ return "";
603
+ }
604
+ return fence === null ? l : "";
605
+ });
606
+ const heads = every((n) => n.sections.scenarios).map((h) => new RegExp(`^${escapeRe(h).replace(/ +/g, "\\s+")}\\s*$`));
607
+ const start = lines.findIndex((l) => heads.some((h) => h.test(l.trim())));
608
+ if (start < 0) return null;
609
+ const out: string[] = [];
610
+ for (const l of lines.slice(start + 1)) {
611
+ if (/^#{1,2}\s/.test(l)) break;
612
+ const m = /^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?(.+?)\s*$/.exec(l);
613
+ if (m) out.push(m[1]!);
614
+ }
615
+ return out;
616
+ }
617
+
618
+ export default { LANGUAGE_CODE, DEFAULT_LANGUAGE, projectRoot, manifestOf, projectLanguage, missingManifest, batchProject, autoProject, names, languages, everyNames, every, fill, plural, count, escapeRe, scenarioItems };
@@ -832,38 +832,20 @@ function asJson(
832
832
  );
833
833
  }
834
834
 
835
- /**
836
- * Task scenarios — the list items of the scenarios section (up to the next heading); checkboxes stripped; no section —
837
- * null. The heading is in any dictionary language (`## Scenarios` or its translation): the task could have been written
838
- * before the project language changed.
839
- */
840
- export function parseScenarios(md: string): string[] | null {
841
- // a fenced code block is an example in the task text, not its sections: its lines are blanked out
842
- let fence: string | null = null;
843
- const lines = md.split(/\r?\n/).map((l) => {
844
- const f = /^\s*(`{3,}|~{3,})/.exec(l)?.[1];
845
- if (f && (fence === null || (f[0] === fence[0] && f.length >= fence.length))) {
846
- fence = fence === null ? f : null;
847
- return "";
848
- }
849
- return fence === null ? l : "";
850
- });
851
- const heads = locale.every((n) => n.sections.scenarios).map((h) => new RegExp(`^${locale.escapeRe(h).replace(/ +/g, "\\s+")}\\s*$`));
852
- const start = lines.findIndex((l) => heads.some((h) => h.test(l.trim())));
853
- if (start < 0) return null;
854
- const out: string[] = [];
855
- for (const l of lines.slice(start + 1)) {
856
- if (/^#{1,2}\s/.test(l)) break;
857
- const m = /^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?(.+?)\s*$/.exec(l);
858
- if (m) out.push(m[1]!);
859
- }
860
- return out;
861
- }
862
-
863
835
  /** Quotes that quote a scenario whole: `«…»;` in a task is the same name as the test's. */
864
836
  const QUOTES: [string, string][] = [["«", "»"], ['"', '"'], ["“", "”"], ["`", "`"]];
865
837
  const TAIL = /[.。;,]+$/;
866
838
 
839
+ /** Paired quotes are balanced in the text: no close before its open, every open closed. */
840
+ const balanced = (text: string, open: string, close: string): boolean => {
841
+ let depth = 0;
842
+ for (const c of text) {
843
+ if (c === open) depth++;
844
+ else if (c === close && --depth < 0) return false;
845
+ }
846
+ return depth === 0;
847
+ };
848
+
867
849
  /**
868
850
  * A name for matching: whitespace collapsed, case-insensitive, without outer quotes and a trailing mark — both before
869
851
  * and after the quotes.
@@ -872,8 +854,9 @@ const norm = (s: string): string => {
872
854
  let t = s.replace(/\s+/g, " ").trim().replace(TAIL, "");
873
855
  for (const [open, close] of QUOTES) {
874
856
  const inner = t.slice(open.length, -close.length);
875
- // "a" and "b" isn't a whole quote: its own closing quote is inside
876
- if (t.length > open.length + close.length && t.startsWith(open) && t.endsWith(close) && !inner.includes(close)) t = inner.trim().replace(TAIL, "");
857
+ // "a" and "b" isn't a whole quote: its own closing quote is inside; paired quotes nest — «a «b»» is whole
858
+ // when every inner close has its inner open before it (#767)
859
+ if (t.length > open.length + close.length && t.startsWith(open) && t.endsWith(close) && (open === close ? !inner.includes(close) : balanced(inner, open, close))) t = inner.trim().replace(TAIL, "");
877
860
  }
878
861
  return t.toLowerCase();
879
862
  };
@@ -1150,7 +1133,7 @@ export async function main(argv: string[]): Promise<number> {
1150
1133
  let scenarios: string[] | null = null;
1151
1134
  if (v.scenarios !== undefined) {
1152
1135
  try {
1153
- scenarios = parseScenarios(readFileSync(v.scenarios === "-" ? 0 : v.scenarios, "utf8"));
1136
+ scenarios = locale.scenarioItems(readFileSync(v.scenarios === "-" ? 0 : v.scenarios, "utf8"));
1154
1137
  } catch (e) {
1155
1138
  console.error(`spec-diff: --scenarios: ${(e as Error).message}`);
1156
1139
  return 2;