@futurelastic/colab-handbook 1.14.1-rc.8 → 1.14.1-rc.9

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/package.json CHANGED
@@ -33,5 +33,5 @@
33
33
  "engines": {
34
34
  "node": ">=18"
35
35
  },
36
- "version": "1.14.1-rc.8"
36
+ "version": "1.14.1-rc.9"
37
37
  }
package/tools/colab CHANGED
@@ -10556,7 +10556,7 @@ function branchCommits(mainRoot, trunk, branchName) {
10556
10556
  const base = mb.ok && mb.stdout ? mb.stdout : trunk;
10557
10557
  const logShas = git.git(['log', '--first-parent', `${base}..${branch}`, '--no-merges', '--format=%H'], mainRoot);
10558
10558
  const shas = logShas.ok ? logShas.stdout.split('\n').filter(Boolean) : [];
10559
- return shas.map((sha) => {
10559
+ const commits = shas.map((sha) => {
10560
10560
  const full = git.git(['log', '-1', '--format=%B', sha], mainRoot).stdout;
10561
10561
  const nl = full.indexOf('\n');
10562
10562
  return {
@@ -10565,6 +10565,56 @@ function branchCommits(mainRoot, trunk, branchName) {
10565
10565
  body: (nl === -1 ? '' : full.slice(nl + 1)).replace(/^\n+/, '').replace(/\s+$/, ''),
10566
10566
  };
10567
10567
  });
10568
+ markFollowUps(mainRoot, base, commits);
10569
+ return commits;
10570
+ }
10571
+
10572
+ /**
10573
+ * #621: flag each commit that only rewrites lines an EARLIER commit on this branch added — lines
10574
+ * absent from the merge base — as `followUp: true`, which lib/squash.js ranks below every named type.
10575
+ * Measured, never inferred from the subject: a one-word `fix:` to a `refactor:`'s brand-new text once
10576
+ * titled a 148-file unit, because `fix` outweighs `refactor`.
10577
+ *
10578
+ * Only a commit that could actually steal the subject is measured — one weighing MORE than every
10579
+ * older commit (a tie already goes to the oldest), so the cost is a diff plus a blame per hunk of a
10580
+ * handful of commits, not of the branch. Every uncertainty reads as "not a follow-up", leaving the
10581
+ * pre-#621 ranking in place. Per changed file of the candidate commit:
10582
+ * - a file this commit creates → not contained (new content, not a repair);
10583
+ * - a file absent at the base but present in the parent → wholly branch-added, contained;
10584
+ * - a file present at the base → every hunk must REPLACE or DELETE lines (a pure insertion adds
10585
+ * behaviour beside trunk's lines, so it is not contained) and `git blame base..<sha>^` must
10586
+ * attribute every replaced line to a commit of this branch (a boundary line is trunk's);
10587
+ * - binary, quoted-path or unparseable diffs, and any failed git read → not contained.
10588
+ */
10589
+ function markFollowUps(mainRoot, base, commits) {
10590
+ if (!base || commits.length < 2) return;
10591
+ const own = new Set(commits.map((c) => c.sha));
10592
+ for (let i = commits.length - 2; i >= 0; i--) { // newest-first list; the oldest can never be one
10593
+ const c = commits[i];
10594
+ if (squash.isSyncNoise(c.subject)) continue;
10595
+ const older = commits.slice(i + 1).filter((o) => !squash.isSyncNoise(o.subject));
10596
+ if (!older.length || squash.commitWeight(c) <= Math.max(...older.map((o) => squash.commitWeight(o)))) continue;
10597
+ if (commitIsFollowUp(mainRoot, base, c.sha, own)) c.followUp = true;
10598
+ }
10599
+ }
10600
+
10601
+ function commitIsFollowUp(mainRoot, base, sha, own) {
10602
+ const d = git.git(['-c', 'core.quotePath=true', 'diff', '-U0', '--no-renames', '--no-ext-diff', '--no-color', `${sha}^`, sha], mainRoot);
10603
+ if (!d.ok) return false;
10604
+ const files = squash.parseZeroContextDiff(d.stdout);
10605
+ if (!files.length) return false;
10606
+ for (const f of files) {
10607
+ if (f.binary || f.unparsed || f.created || !f.path || !f.hunks.length) return false;
10608
+ if (!git.git(['cat-file', '-e', `${base}:${f.path}`], mainRoot).ok) continue; // the branch made this file
10609
+ for (const h of f.hunks) {
10610
+ if (h.oldCount === 0) return false;
10611
+ const b = git.git(['blame', '--porcelain', '-L', `${h.oldStart},+${h.oldCount}`, `${base}..${sha}^`, '--', f.path], mainRoot);
10612
+ if (!b.ok) return false;
10613
+ const authors = b.stdout.split('\n').map((l) => /^([0-9a-f]{40}) \d+ \d+/.exec(l)).filter(Boolean).map((m) => m[1]);
10614
+ if (!authors.length || authors.some((a) => !own.has(a))) return false;
10615
+ }
10616
+ }
10617
+ return true;
10568
10618
  }
10569
10619
 
10570
10620
  /** Files one commit touched (#88's narrow-subject signal). [] when the read fails — never a guess. */
@@ -66,6 +66,19 @@ const TYPE_WEIGHT = {
66
66
  */
67
67
  const UNRECOGNISED_WEIGHT = 5;
68
68
 
69
+ /**
70
+ * Weight of a FOLLOW-UP (#621): a commit whose every changed line was added by an EARLIER commit on
71
+ * the same branch and is absent from the merge base. It repairs the branch's own unshipped work, so
72
+ * whatever its type says, it means nothing to a consumer — no shipped behaviour was broken. Measured
73
+ * at v1.14.0: a 148-file `refactor:` shipped titled by a one-word `fix:` to text that refactor had
74
+ * just added, because `fix` (60) outweighs `refactor` (40). Ranked below every named type AND below
75
+ * `UNRECOGNISED_WEIGHT`, so it never titles a unit that has any other shaped commit; above 0 only so
76
+ * a branch of nothing but follow-ups and shapeless commits still reads as "weighed". The flag itself
77
+ * (`commit.followUp`) is measured by the CLI against git (`tools/colab` `markFollowUps`) — this
78
+ * module stays pure and only reads it.
79
+ */
80
+ const FOLLOW_UP_WEIGHT = 3;
81
+
69
82
  /** A breaking change outranks every non-breaking one, whatever its type. */
70
83
  const BREAKING_BONUS = 1000;
71
84
 
@@ -105,6 +118,9 @@ function commitWeight(commit) {
105
118
  if (!parsed) return 0;
106
119
  const base = TYPE_WEIGHT[parsed.type];
107
120
  const breaking = parsed.breaking || /^BREAKING[ -]CHANGE:/m.test(String((commit && commit.body) || ''));
121
+ // #621: a follow-up keeps its breaking bonus — declaring a break is a consumer-facing claim, not a
122
+ // repair — but loses its type's rank.
123
+ if (commit && commit.followUp) return FOLLOW_UP_WEIGHT + (breaking ? BREAKING_BONUS : 0);
108
124
  if (base === undefined) return UNRECOGNISED_WEIGHT + (breaking ? BREAKING_BONUS : 0); // shaped, unnamed type (#261)
109
125
  return base + (breaking ? BREAKING_BONUS : 0);
110
126
  }
@@ -153,7 +169,8 @@ function unweightedCommits(commits) {
153
169
  * Rules, in order:
154
170
  * 1. sync-merge noise never titles a squash (unless it is all there is);
155
171
  * 2. highest weight wins — an unrecognised-but-shaped type (#261, weight `UNRECOGNISED_WEIGHT`)
156
- * beats a truly shapeless commit here, so it is no longer a coin-flip against rule 4;
172
+ * beats a truly shapeless commit here, so it is no longer a coin-flip against rule 4; a
173
+ * follow-up to the branch's own unshipped lines (#621, `FOLLOW_UP_WEIGHT`) ranks below both;
157
174
  * 3. ties go to the OLDEST of the tied commits — on a branch of three `feat`s, the first one
158
175
  * names the branch's purpose and the rest extend it;
159
176
  * 4. if NOTHING on the branch carries any Conventional Commit shape at all (weight 0, the one
@@ -507,8 +524,47 @@ function spliceCloses(message, closes = [], refs = [], conflicts) {
507
524
  return rest ? `${head}\n\n${refLine}\n\n${rest}` : `${head}\n\n${refLine}`;
508
525
  }
509
526
 
527
+ /**
528
+ * Parse `git diff -U0 --no-renames` output into per-file records for the #621 follow-up measurement:
529
+ * `{ path, created, deleted, binary, unparsed, hunks: [{ oldStart, oldCount }] }`. `created` means
530
+ * the old side is /dev/null — the commit added the file. `unparsed` is set when a path is quoted
531
+ * (git's C-style escaping) — the caller must then refuse to call the commit a follow-up rather than
532
+ * guess at the name. Pure, so the hunk arithmetic is testable without a repository.
533
+ */
534
+ function parseZeroContextDiff(diffText) {
535
+ const files = [];
536
+ let cur = null;
537
+ const strip = (p) => p.replace(/\t$/, '');
538
+ for (const line of String(diffText || '').split('\n')) {
539
+ if (line.startsWith('diff --git ')) {
540
+ cur = { path: null, created: false, deleted: false, binary: false, unparsed: false, hunks: [] };
541
+ files.push(cur);
542
+ continue;
543
+ }
544
+ if (!cur) continue;
545
+ if (line.startsWith('--- ')) {
546
+ const p = strip(line.slice(4));
547
+ if (p === '/dev/null') cur.created = true;
548
+ else if (p.startsWith('"')) cur.unparsed = true;
549
+ else if (p.startsWith('a/')) cur.path = p.slice(2);
550
+ else cur.unparsed = true;
551
+ } else if (line.startsWith('+++ ')) {
552
+ const p = strip(line.slice(4));
553
+ if (p === '/dev/null') cur.deleted = true;
554
+ else if (p.startsWith('"')) cur.unparsed = true;
555
+ } else if (line.startsWith('Binary files ') || line === 'GIT binary patch') {
556
+ cur.binary = true;
557
+ } else if (line.startsWith('@@ ')) {
558
+ const m = /^@@ -(\d+)(?:,(\d+))? \+\d+(?:,\d+)? @@/.exec(line);
559
+ if (!m) { cur.unparsed = true; continue; }
560
+ cur.hunks.push({ oldStart: Number(m[1]), oldCount: m[2] === undefined ? 1 : Number(m[2]) });
561
+ }
562
+ }
563
+ return files;
564
+ }
565
+
510
566
  module.exports = {
511
- TYPE_WEIGHT, UNRECOGNISED_WEIGHT, BREAKING_BONUS, TRAILER_RE,
567
+ TYPE_WEIGHT, UNRECOGNISED_WEIGHT, FOLLOW_UP_WEIGHT, BREAKING_BONUS, TRAILER_RE, parseZeroContextDiff,
512
568
  isSyncNoise, parseSubject, commitWeight, hasRecognisedType, unweightedCommits, pickSubjectIndex,
513
569
  harvestTrailers, composeSquashMessage, spliceCloses, reconcileClosesRefsConflict,
514
570
  closedIssueNumbers, inheritedClosingKeywordConflicts,