@futurelastic/colab-handbook 1.14.0-rc.3 → 1.14.0-rc.5

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/audit/audit.mjs CHANGED
@@ -41,6 +41,19 @@
41
41
  // # (colab batch-stats --json) — see "Batch history" below
42
42
  // node audit.mjs --base <rev> # the instruction-file ratchet's base for LOCAL repos
43
43
  // # (default origin/<trunk>) — see checkInstructionFileShape
44
+ // node audit.mjs --offline # local checks only: no GitHub read at all — see "Remote cache"
45
+ // node audit.mjs --fresh # ignore the cache TTL: re-ask GitHub (still conditional)
46
+ // node audit.mjs --cache-ttl <secs> # how long a cached GitHub read is served unasked
47
+ // # (default 600; env COLAB_AUDIT_CACHE_TTL; 0 = always ask)
48
+ //
49
+ // Remote cache (#593): the GitHub reads (repository metadata, labels, and a slug target's files,
50
+ // branches and tags) are cached across runs, one file per repo under COLAB_AUDIT_CACHE_DIR, else
51
+ // ${COLAB_HOME:-~/.colab}/cache/audit when that home already exists (the audit never creates it).
52
+ // Within the TTL a read costs no request; past it each page is re-asked with If-None-Match, and a
53
+ // 304 costs no quota. A rate limit or no response serves the cached copy, marked stale. --json
54
+ // states per repo where its remote facts came from (`remote`). --offline is the cheap frequent
55
+ // pass: local checks only, remote-only (slug) entries skipped, and it refuses --identity,
56
+ // --batch-history and --fresh, which all need the network.
44
57
  //
45
58
  // Identity (--identity): metadata never passes through git, so the pre-commit identity scan
46
59
  // (templates/pre-commit-identity) structurally cannot see it, and it is the first thing a
@@ -112,6 +125,8 @@ const shipBatch = require("../tools/lib/ship-batch.js");
112
125
  const ciProfile = require("../tools/lib/ci-profile.js"); // #559
113
126
  const thresholdsLib = require("../tools/lib/thresholds.js"); // #560
114
127
  const batchHistory = require("../tools/lib/batch-history.js"); // #556
128
+ // #593: every GitHub REST read goes through one on-disk, per-repo cache (ETag + TTL) — see the module.
129
+ const auditCache = require("../tools/lib/audit-cache.js");
115
130
  // #383: where migrations live — the one rule `colab ship`'s gate and `release cut` read; the audit
116
131
  // validates the `migrations:` declaration against it and reports a `*/migrations/` dir it misses.
117
132
  const migrationPaths = require("../tools/lib/migration-paths.js");
@@ -155,13 +170,20 @@ const COLAB_HOME = process.env.COLAB_HOME || join(homedir(), ".colab");
155
170
 
156
171
  function parseArgs(argv) {
157
172
  // config === null means "resolve from the precedence chain"; a string means explicit.
158
- const opts = { config: null, locals: [], slugs: [], json: false, quiet: false, help: false, identity: false, batchHistory: false };
173
+ const opts = { config: null, locals: [], slugs: [], json: false, quiet: false, help: false, identity: false, batchHistory: false, offline: false, fresh: false, cacheTtl: null };
159
174
  for (let i = 0; i < argv.length; i++) {
160
175
  const a = argv[i];
161
176
  if (a === "--json") opts.json = true;
162
177
  else if (a === "--quiet" || a === "-q") opts.quiet = true;
163
178
  else if (a === "--identity") opts.identity = true;
164
179
  else if (a === "--batch-history") opts.batchHistory = true;
180
+ else if (a === "--offline" || a === "--no-remote") opts.offline = true;
181
+ else if (a === "--fresh") opts.fresh = true;
182
+ else if (a === "--cache-ttl") {
183
+ const p = argv[++i];
184
+ if (p === undefined) die("--cache-ttl needs a number of seconds");
185
+ opts.cacheTtl = p;
186
+ }
165
187
  else if (a === "--base") {
166
188
  const p = argv[++i];
167
189
  if (!p) die("--base needs a rev");
@@ -515,31 +537,30 @@ function runGh(args) {
515
537
  }
516
538
 
517
539
  // A slug is fetched read-only through the API — nothing is cloned, nothing is written
518
- // into anyone's working tree.
540
+ // into anyone's working tree. Every REST read below goes through `remoteCache` (#593), set up
541
+ // once per run in runAudit; the `--jq` filters these used to pass are applied here in JS,
542
+ // because a cached page is the raw API body.
543
+ let remoteCache = auditCache.create({ dir: null, ttlSeconds: 0 });
544
+
519
545
  function readRemoteFile(slug, path) {
520
- try {
521
- return runGh(["api", `repos/${slug}/contents/${path}`, "-H", "Accept: application/vnd.github.raw"]);
522
- } catch {
523
- return null;
524
- }
546
+ const r = remoteCache.get(slug, `repos/${slug}/contents/${path}`, { accept: "application/vnd.github.raw" });
547
+ return r.status === "ok" ? r.text : null;
525
548
  }
526
549
 
527
550
  function listRemoteDir(slug, path) {
551
+ const r = remoteCache.get(slug, `repos/${slug}/contents/${path}`);
552
+ if (r.status !== "ok") return [];
528
553
  try {
529
- const out = runGh(["api", `repos/${slug}/contents/${path}`, "--jq", ".[].name"]);
530
- return out.split("\n").map((s) => s.trim()).filter(Boolean);
554
+ const arr = JSON.parse(r.text);
555
+ return Array.isArray(arr) ? arr.map((e) => String(e.name || "").trim()).filter(Boolean) : [];
531
556
  } catch {
532
557
  return [];
533
558
  }
534
559
  }
535
560
 
536
561
  function listRemoteBranches(slug) {
537
- try {
538
- const out = runGh(["api", `repos/${slug}/branches`, "--paginate", "--jq", ".[].name"]);
539
- return out.split("\n").map((s) => s.trim()).filter(Boolean);
540
- } catch {
541
- return null; // null = could not determine, distinct from "no branches"
542
- }
562
+ const r = remoteCache.get(slug, `repos/${slug}/branches`, { paginate: true });
563
+ return r.status === "ok" ? r.items.map((b) => String(b.name)) : null; // null = could not determine, distinct from "no branches"
543
564
  }
544
565
 
545
566
  // Same null/[] contract as listRemoteBranches: null = could not determine (no remote, no
@@ -547,33 +568,22 @@ function listRemoteBranches(slug) {
547
568
  // falsifiers (#137) — a version-shaped tag is evidence against a declared "nothing consumes
548
569
  // this" claim, whether the source is local or remote.
549
570
  function listRemoteTags(slug) {
550
- try {
551
- const out = runGh(["api", `repos/${slug}/tags`, "--paginate", "--jq", ".[].name"]);
552
- return out.split("\n").map((s) => s.trim()).filter(Boolean);
553
- } catch {
554
- return null;
555
- }
571
+ const r = remoteCache.get(slug, `repos/${slug}/tags`, { paginate: true });
572
+ return r.status === "ok" ? r.items.map((t) => String(t.name)) : null;
556
573
  }
557
574
 
558
575
  // Labels live on GitHub, not in the working tree, so this is the audit's one check that
559
576
  // needs the tracker. `null` means "could not determine" — no remote, no auth, gh absent,
560
- // API error — and the caller stays SILENT on it rather than warning: unlike branches
577
+ // API error, --offline — and the caller stays SILENT on it rather than warning: unlike branches
561
578
  // (every git repo has them), labels are a GitHub-only concept and a remote-less or
562
579
  // offline audit legitimately cannot see them. A warn per offline repo would be noise,
563
580
  // and we cannot assert a label is missing when we could not read the set at all.
564
- // Each entry is { name, description } (#364) — one JSON object per line from `--jq`, so a
565
- // paginated read never has to splice arrays. A line that does not parse makes the whole read
566
- // null: a half-read set would report the unread half as "missing".
581
+ // Each entry is { name, description } (#364). Any page that does not parse makes the whole
582
+ // read null: a half-read set would report the unread half as "missing".
567
583
  function listRemoteLabels(slug) {
568
- try {
569
- const out = runGh(["api", `repos/${slug}/labels`, "--paginate", "--jq", ".[] | {name, description}"]);
570
- return out.split("\n").map((s) => s.trim()).filter(Boolean).map((line) => {
571
- const l = JSON.parse(line);
572
- return { name: String(l.name), description: typeof l.description === "string" ? l.description : "" };
573
- });
574
- } catch {
575
- return null;
576
- }
584
+ const r = remoteCache.get(slug, `repos/${slug}/labels`, { paginate: true });
585
+ if (r.status !== "ok") return null;
586
+ return r.items.map((l) => ({ name: String(l.name), description: typeof l.description === "string" ? l.description : "" }));
577
587
  }
578
588
 
579
589
  // The repository's own METADATA — name, description, homepage, topics, visibility — which
@@ -596,6 +606,7 @@ function listRemoteLabels(slug) {
596
606
  // One issue's state, labels and comments (#441 — a release.final-grant's decision issue), or null
597
607
  // when it could not be read. null is never "no decision": the caller fails closed on it.
598
608
  function readRemoteIssue(slug, num) {
609
+ if (remoteCache.offline) return null; // --offline: no tracker read (the caller skips the check)
599
610
  try {
600
611
  return JSON.parse(runGh(["issue", "view", String(num), "--repo", slug, "--json", "state,labels,comments"]));
601
612
  } catch {
@@ -609,11 +620,11 @@ const remoteMetadataCache = new Map();
609
620
  function readRemoteMetadata(slug) {
610
621
  if (remoteMetadataCache.has(slug)) return remoteMetadataCache.get(slug);
611
622
  let r;
612
- try {
613
- const out = runGh(["api", `repos/${slug}`]);
614
- r = { status: "ok", data: JSON.parse(out) };
615
- } catch {
616
- r = { status: "unreadable" };
623
+ const got = remoteCache.get(slug, `repos/${slug}`);
624
+ if (got.status === "offline") r = { status: "offline" };
625
+ else if (got.status !== "ok") r = { status: "unreadable" };
626
+ else {
627
+ try { r = { status: "ok", data: JSON.parse(got.text) }; } catch { r = { status: "unreadable" }; }
617
628
  }
618
629
  remoteMetadataCache.set(slug, r);
619
630
  return r;
@@ -1123,6 +1134,16 @@ function renderDuration(age, minDays = DURATION_MIN_DAYS) {
1123
1134
  }
1124
1135
 
1125
1136
  function auditRepo(target, ctx) {
1137
+ remoteCache.begin();
1138
+ const info = auditRepoInner(target, ctx);
1139
+ // #593: where this repo's remote facts came from — cache, revalidated (304), fetched, stale —
1140
+ // and how old the oldest is. Absent when the repo made no GitHub read at all.
1141
+ const remote = remoteCache.summary();
1142
+ if (remote) info.remote = remote;
1143
+ return info;
1144
+ }
1145
+
1146
+ function auditRepoInner(target, ctx) {
1126
1147
  const src = makeSource(target);
1127
1148
  // #522: the branch list is read by the single-trunk rule (tier B / exposure none|released) AND the
1128
1149
  // trunk-exists check below — one read, so a remote target costs one API listing, not three.
@@ -1572,7 +1593,11 @@ function auditRepo(target, ctx) {
1572
1593
  // not been reopened. Unreadable fails closed: an automatic production deploy nobody can
1573
1594
  // trace to a human's choice is exactly what the grant exists to rule out.
1574
1595
  const grant = rel.effective.finalGrant;
1575
- if (grant) {
1596
+ if (grant && ctx.offline) {
1597
+ // #593: --offline reads no tracker. Recorded, not judged — the run header says once that
1598
+ // remote facts were not read, so this row is never mistaken for a verified grant.
1599
+ info.releaseFinalGrant = { issue: grant.issue, ok: null, checked: false, reason: "--offline" };
1600
+ } else if (grant) {
1576
1601
  const v = releasePolicy.finalGrantVerdict(src.issue ? src.issue(grant.issue) : null, { issue: grant.issue, trust: trustHumansLib.parseTrustHumans(cfg) });
1577
1602
  info.releaseFinalGrant = { issue: grant.issue, ok: v.ok, ruledBy: v.ruledBy };
1578
1603
  if (!v.ok) {
@@ -2900,6 +2925,9 @@ function checkPrivateNpm(src, workflows, fail, warn) {
2900
2925
  const assetSurface = npmGuard.releaseAssetUploads(workflows, reader.readFile).length > 0;
2901
2926
  if (!npmSurface && !assetSurface) return;
2902
2927
  const meta = src.metadata ? src.metadata() : { status: "unreadable" };
2928
+ // #593: --offline reads no visibility by request; the run header already says so once, and a
2929
+ // "could not be read" advisory on every offline pass would mark every such repo non-clean.
2930
+ if (meta.status === "offline") return;
2903
2931
  let visibility = null;
2904
2932
  if (meta.status === "ok" && meta.data) {
2905
2933
  visibility = meta.data.visibility || (meta.data.private === true ? "private" : meta.data.private === false ? "public" : null);
@@ -3251,6 +3279,10 @@ function report(results, opts, ctx) {
3251
3279
  ? { scanned: true, vocabulary: ctx.identity.path, source: ctx.identity.source, terms: ctx.identity.count }
3252
3280
  : { scanned: false, reason: "not requested (--identity)" },
3253
3281
  batchHistory: ctx.batchHistory ? { read: true } : { read: false, reason: "not requested (--batch-history)" },
3282
+ // #593: whether GitHub was read at all this run, and the cache it was read through.
3283
+ remote: ctx.offline
3284
+ ? { read: false, reason: "--offline" }
3285
+ : { read: true, cache: ctx.cache.dir, persistent: !!ctx.cache.dir, ttlSeconds: ctx.cache.ttlSeconds, fresh: ctx.cache.fresh },
3254
3286
  results,
3255
3287
  }, null, 2));
3256
3288
  return;
@@ -3272,6 +3304,10 @@ function report(results, opts, ctx) {
3272
3304
  console.log(ctx.batchHistory
3273
3305
  ? "batch: batch landing history read per local repo (colab batch-stats); advisories only against declared thresholds"
3274
3306
  : "batch: batch landing history NOT read (pass --batch-history)");
3307
+ // #593: same once-per-run statement for the remote reads.
3308
+ console.log(ctx.offline
3309
+ ? "remote: GitHub NOT read (--offline) — labels, visibility and grants unchecked; remote-only entries skipped"
3310
+ : `remote: GitHub read through ${ctx.cache.dir ? `the cache at ${ctx.cache.dir}` : "an in-memory cache (no colab home to persist it)"}, TTL ${ctx.cache.ttlSeconds}s${ctx.cache.fresh ? ", --fresh" : ""}`);
3275
3311
  console.log("");
3276
3312
 
3277
3313
  const shown = opts.quiet ? results.filter((r) => !r.clean) : results;
@@ -3287,7 +3323,8 @@ function report(results, opts, ctx) {
3287
3323
  // The handbook's own row says WHY it carries no stamp findings. Without this it
3288
3324
  // would read as clean-by-luck, which is indistinguishable from a check that
3289
3325
  // quietly stopped working.
3290
- if (r.self) lines.push("⌂ handbook source — every rule applies except its own stamps (it has nothing to copy from)");
3326
+ if (r.skipped === "offline") lines.push("– skipped (--offline: a remote-only entry has nothing local to check)");
3327
+ else if (r.self) lines.push("⌂ handbook source — every rule applies except its own stamps (it has nothing to copy from)");
3291
3328
  else if (r.adoption === "local") lines.push(`⌂ adopted locally, not committed — descriptor hidden by .git/info/exclude; a repo the fleet does not own (CONVENTIONS.md §9)${r.clean ? " ✓" : ""}`);
3292
3329
  else if (r.clean) lines.push("✓");
3293
3330
  r.findings.forEach((f) => lines.push(`${f.level === "fail" ? "⚠" : "·"} ${f.text}`));
@@ -3304,8 +3341,9 @@ function report(results, opts, ctx) {
3304
3341
 
3305
3342
  const failed = results.filter((r) => !r.ok).length;
3306
3343
  const warned = results.filter((r) => r.ok && !r.clean).length;
3344
+ const skipped = results.filter((r) => r.skipped).length;
3307
3345
  console.log("");
3308
- console.log(`${results.length} repo(s): ${results.length - failed - warned} clean, ${warned} with advisories, ${failed} with problems.`);
3346
+ console.log(`${results.length} repo(s): ${results.length - failed - warned - skipped} clean, ${warned} with advisories, ${failed} with problems${skipped ? `, ${skipped} skipped` : ""}.`);
3309
3347
  }
3310
3348
 
3311
3349
  /**
@@ -3353,13 +3391,33 @@ function runAudit(opts) {
3353
3391
  const targets = loadTargets(opts);
3354
3392
  if (!targets.length) die("nothing to audit — add entries to the repo list or pass --local <path>");
3355
3393
 
3394
+ if (opts.offline) {
3395
+ // Each of these is a read of the network the operator asked for; an offline run that quietly
3396
+ // skipped it would report clean over a check that never ran.
3397
+ if (opts.identity) die("--offline and --identity conflict: the identity scan reads repository metadata from GitHub");
3398
+ if (opts.batchHistory) die("--offline and --batch-history conflict: batch history reads CI runs from GitHub");
3399
+ if (opts.fresh) die("--offline and --fresh conflict: --fresh asks GitHub, --offline never does");
3400
+ }
3401
+ const ttlSeconds = auditCache.resolveTtlSeconds(opts.cacheTtl);
3402
+ if (ttlSeconds === null) die(`--cache-ttl / COLAB_AUDIT_CACHE_TTL must be a whole number of seconds (got "${opts.cacheTtl ?? process.env.COLAB_AUDIT_CACHE_TTL}")`);
3403
+ remoteCache = auditCache.create({
3404
+ dir: auditCache.resolveDir(process.env, COLAB_HOME), ttlSeconds, fresh: opts.fresh, offline: opts.offline,
3405
+ });
3406
+
3356
3407
  const ctx = { handbook: handbookInfo(HANDBOOK_ROOT), templateNames: templateNames(HANDBOOK_ROOT) };
3408
+ ctx.offline = !!opts.offline;
3409
+ ctx.cache = { dir: remoteCache.dir, ttlSeconds, fresh: !!opts.fresh };
3357
3410
  ctx.identity = opts.identity ? loadIdentityVocabulary() : null;
3358
3411
  ctx.batchHistory = !!opts.batchHistory;
3359
3412
  ctx.base = opts.base || null;
3360
3413
 
3361
3414
  const results = [];
3362
3415
  for (const t of targets) {
3416
+ if (ctx.offline && t.kind !== "local") {
3417
+ // A slug target has nothing local to check: every fact about it is a GitHub read.
3418
+ results.push({ repo: t.label, kind: t.kind, tier: null, ok: true, clean: true, skipped: "offline", remote: { mode: "offline" }, findings: [] });
3419
+ continue;
3420
+ }
3363
3421
  try {
3364
3422
  results.push(auditRepo(t, ctx));
3365
3423
  } catch (err) {
package/package.json CHANGED
@@ -33,5 +33,5 @@
33
33
  "engines": {
34
34
  "node": ">=18"
35
35
  },
36
- "version": "1.14.0-rc.3"
36
+ "version": "1.14.0-rc.5"
37
37
  }
@@ -29,11 +29,14 @@
29
29
  # comment above that job
30
30
  # the cut tagged a FINAL — route deploy + health check (job `deploy`, #446) — see
31
31
  # deploy-tag-fast only "DEPLOYING IN THIS RUN" below
32
+ # the cut tagged a FINAL — route published like any tag (Release marked latest, npm
33
+ # library-fast (#590) `latest`); nothing deploys — see "A LIBRARY" below
32
34
  #
33
35
  # Every decision — whether a candidate is owed, which bump, whether the test period
34
36
  # elapsed clean, whether the final is automatic on this repo at all — is the colab CLI's,
35
37
  # read from .github/project.yml's release rung. This file only schedules it and publishes
36
- # what it tagged. Where the rung leaves candidates off, every run is a recorded refusal.
38
+ # what it tagged. Where the rung leaves candidates off, every run is a recorded refusal — save on
39
+ # route library-fast, where the cut is the final (below).
37
40
  #
38
41
  # WHERE IT FITS. `colab release cut` tags origin/main — release tags land on `main` on every
39
42
  # trunk shape — so the same file, unchanged, fits two kinds of repo:
@@ -94,6 +97,14 @@
94
97
  # run still concludes on the `release` job. EDIT: on this route, a cron more frequent than daily
95
98
  # tags a head that release.final-spacing held back sooner.
96
99
  #
100
+ # A LIBRARY — THE CUT IS THE FINAL (library-fast, #590). On a repo with no production that declares
101
+ # `release.route: library-fast`, `colab release cut --auto` tags the FINAL vX.Y.Z on a green main
102
+ # head once a first final exists (the first is a human's tag) — no candidate, no test period. With
103
+ # `release.version-source: manifest` (the route's default) the version is the manifest's: a merge
104
+ # that bumps package.json releases it, a merge that does not is a no-op. This run publishes the
105
+ # final itself — the Release step marks it latest, the npm job publishes it to `latest` — because a
106
+ # publish-on-tag workflow would not fire for a tag this job pushes. The deploy job stays skipped.
107
+ #
97
108
  # DRY RUN ON A FIX BRANCH (#474). This workflow never runs on a branch by itself, so a fix to it
98
109
  # (a moved runner label, a HANDBOOK_REF naming a missing branch) had no run to prove it, and the
99
110
  # cure rule (CONVENTIONS.md §4) could only refuse it — a human ci-grant was the one door. Dispatch
@@ -475,8 +486,10 @@ jobs:
475
486
  echo "tag=$TAG" >> "$GITHUB_OUTPUT"
476
487
  echo "Cut $TAG" | tee -a "$GITHUB_STEP_SUMMARY"
477
488
  # #446: on route deploy-tag-fast the cut IS the final, and the deploy job deploys it in
478
- # this run (a tag pushed with GITHUB_TOKEN starts no `push: tags` workflow).
479
- if [ "$(jq -r '.final // false' "$OUT")" = "true" ]; then
489
+ # this run (a tag pushed with GITHUB_TOKEN starts no `push: tags` workflow). #590: route
490
+ # library-fast cuts a final too, with `deploy: null` — it is published below (Release, npm)
491
+ # and never handed to the deploy job, so key on the deploy facts, not on `final`.
492
+ if [ "$(jq -r '.final == true and .deploy != null' "$OUT")" = "true" ]; then
480
493
  echo "final=$TAG" >> "$GITHUB_OUTPUT"
481
494
  echo "health-url=$(jq -r '.deploy.healthUrl // ""' "$OUT")" >> "$GITHUB_OUTPUT"
482
495
  fi
package/tools/colab CHANGED
@@ -1335,6 +1335,18 @@ Refuses, naming each failed condition (all are reported, not just the first):
1335
1335
  There the bump reads the promoted commits (main's merge subject is skipped),
1336
1336
  and a switch-removal child counts when its Closes #N was promoted.
1337
1337
 
1338
+ Route library-fast (#590) — a library released per merge, its consumers pin; nothing deploys:
1339
+ once a first final exists (a human tags it), cut tags the next FINAL vX.Y.Z directly — no
1340
+ candidate, no test period — by hand or with --auto, publishes it as the latest GitHub Release and
1341
+ moves the stable channel. --json says final: true, deploy: null. In place of already-candidate:
1342
+ already-final main's head already carries a final — a NO-OP under --auto
1343
+ release-hold an open issue carries the release-hold label (a human veto)
1344
+ With release.version-source: manifest (the route's default) the version IS the manifest's: equal
1345
+ to the last final is a NO-OP (nothing to release until a merge bumps it), lower refuses, 0.x -> 1.0
1346
+ refuses (a human tags it), a major needs MIGRATION.md's section, and a breaking change the
1347
+ manifest under-declares refuses. --bump has nothing to override there. With version-source: tag
1348
+ the bump is computed exactly as for a candidate.
1349
+
1338
1350
  Route deploy-tag-fast (#446) — a deploy: tag repo with the operator's grant and a declared health gate:
1339
1351
  --auto tags the FINAL vX.Y.Z on main's green head — no candidate, no test period — publishes it as
1340
1352
  the latest GitHub Release, moves the stable channel, and prints final/deploy in --json so the
@@ -1682,11 +1694,23 @@ function cmdReleaseCut(argv) {
1682
1694
  const fast = releaseCut.isFastRoute(policy) && !policy.findings.length;
1683
1695
  const fastFacts = fast ? measureFastRoute(repoAbs, { policy, remote, issues, lastFinal, tags, auto, migrationPaths: migrationPathsSince }) : {};
1684
1696
  if (fast && auto) auto.spacing = fastFacts.spacing;
1697
+ // #590: route library-fast — a final with nothing deployed. The release-hold veto is its one extra
1698
+ // read; a hand cut also needs MIGRATION.md for a manifest-declared major (--auto reads it already).
1699
+ const library = !fast && releaseCut.isLibraryRoute(policy) && !policy.findings.length;
1700
+ let libraryMigration = null;
1701
+ if (library) {
1702
+ fastFacts.holds = releaseCut.holdsVerdict(issues);
1703
+ if (!auto) {
1704
+ const r = git.git(['show', `${sha}:${releaseCut.MIGRATION_FILE}`], repoAbs);
1705
+ const text = r.ok ? r.stdout : null;
1706
+ libraryMigration = (v) => releaseCut.parseMigrationSection(text, v);
1707
+ }
1708
+ }
1685
1709
 
1686
1710
  const verdict = releaseCut.decide({
1687
1711
  policy, triggers, lastFinal, suggestion, tags, tagsAtSha, ci, suite, schema, switches, manifests, ancestry, auto,
1688
1712
  override: opts.bump ? { bump: opts.bump, reason: opts.reason } : null,
1689
- finalGrant: fastFacts.finalGrant, holds: fastFacts.holds, migrations: fastFacts.migrations,
1713
+ finalGrant: fastFacts.finalGrant, holds: fastFacts.holds, migrations: fastFacts.migrations, migration: libraryMigration,
1690
1714
  trackingIssue: fastFacts.tracking ? fastFacts.tracking.number : null,
1691
1715
  });
1692
1716
 
@@ -1716,6 +1740,11 @@ function cmdReleaseCut(argv) {
1716
1740
  // on the version's tracking issue (opened if there is none), for a human to grant.
1717
1741
  let announced = null;
1718
1742
  let handoff = verdict.handoff || null;
1743
+ if (library && !opts.dry && created) {
1744
+ // #590: every issue a library final carries hears which version has it, as on deploy-tag-fast.
1745
+ const exclude = (issues || []).filter((i) => releaseFinalize.parseReleaseMarker(i.body)).map((i) => i.number);
1746
+ announced = announceCarried(repoAbs, { tagNames: [...tags, verdict.tag], exclude, version: verdict.tag, sha });
1747
+ }
1719
1748
  if (fast && !opts.dry) {
1720
1749
  if (created) {
1721
1750
  const exclude = (issues || []).filter((i) => releaseFinalize.parseReleaseMarker(i.body)).map((i) => i.number);
@@ -1745,10 +1774,11 @@ function cmdReleaseCut(argv) {
1745
1774
  repo: shortRepo(repoAbs), sha, ...(offTrunk ? { trunk } : {}), lastFinal, suggestion, dry: !!opts.dry, auto: !!opts.auto,
1746
1775
  ok: verdict.ok, noop: !!verdict.noop, standing: verdict.standing || [], tag: verdict.tag, created, published, channel, version: verdict.version, bump: verdict.bump,
1747
1776
  overridden: verdict.overridden, signals: verdict.signals ? verdict.signals.lines : null, checks: verdict.checks,
1748
- // #446: present on every route, so the workflow reads one shape — final only on deploy-tag-fast.
1749
- final: !!verdict.final,
1777
+ // #446: present on every route, so the workflow reads one shape — final on deploy-tag-fast and
1778
+ // library-fast (#590); deploy only on deploy-tag-fast, so the workflow deploys nothing a library tags.
1779
+ final: !!verdict.final, route: verdict.route || null,
1750
1780
  deploy: verdict.final && verdict.healthGate ? { healthUrl: verdict.healthGate.url, rollback: verdict.healthGate.rollback } : null,
1751
- grant: verdict.grant || null, handoff, ...(fast ? { announced } : {}),
1781
+ grant: verdict.grant || null, handoff, ...(fast || library ? { announced } : {}),
1752
1782
  }, null, 2));
1753
1783
  return verdict.ok || verdict.noop ? 0 : 1;
1754
1784
  }
@@ -1764,6 +1794,8 @@ function cmdReleaseCut(argv) {
1764
1794
  if (verdict.noop) {
1765
1795
  print(fast
1766
1796
  ? '· no-op — nothing owed, inside release.final-spacing, or main\'s head already carries a final; nothing tagged.'
1797
+ : library
1798
+ ? '· no-op — nothing owed (the manifest still says the last final), or main\'s head already carries a final; nothing tagged.'
1767
1799
  : '· no-op — nothing owed, inside the route\'s cadence window, or main\'s head is not a promotion of trunk; nothing cut.');
1768
1800
  return 0;
1769
1801
  }
@@ -1774,7 +1806,15 @@ function cmdReleaseCut(argv) {
1774
1806
  if (handoff) print(`\nA migration rides this release. The one command, for a human to run:\n ${handoff}`);
1775
1807
  return 1;
1776
1808
  }
1777
- if (verdict.final) {
1809
+ if (verdict.final && library) {
1810
+ if (opts.dry) print(`[--dry] would tag the final ${verdict.tag} on ${at}, push it to ${remote}, publish its GitHub Release and move the stable channel — route library-fast, nothing deploys. Nothing created.`);
1811
+ else {
1812
+ print(`✓ tagged the final ${verdict.tag} on ${at} and pushed it to ${remote} — route library-fast: a library released per merge, nothing deploys from it.`);
1813
+ if (published && published.ok) print(`✓ ${published.detail}`);
1814
+ else if (published) warn(`${published.detail} — the tag stands; publish it by hand: gh release create ${verdict.tag} --verify-tag --latest`);
1815
+ if (announced && announced.issues.length) print(`released in ${verdict.tag}: told ${announced.posted.length ? announced.posted.map((n) => `#${n}`).join(', ') : 'nobody new'}`);
1816
+ }
1817
+ } else if (verdict.final) {
1778
1818
  if (opts.dry) print(`[--dry] would tag the final ${verdict.tag} on ${at}, push it to ${remote}, publish its GitHub Release and move the stable channel — the workflow's deploy job would then deploy it and check ${verdict.healthGate.url}. Nothing created.`);
1779
1819
  else {
1780
1820
  print(`✓ tagged the final ${verdict.tag} on ${at} and pushed it to ${remote} — route deploy-tag-fast, by the operator's grant (decision #${verdict.grant.issue}); the release workflow deploys it in this run.`);
@@ -0,0 +1,277 @@
1
+ 'use strict';
2
+ /**
3
+ * The audit's GitHub REST reads, cached across runs (#593).
4
+ *
5
+ * Why: the audit reads GitHub for every repo on every run (`repos/<r>`, `repos/<r>/labels`, and
6
+ * for a slug target its files, branches and tags). A host that runs it often — a dashboard
7
+ * rebuilding its overview — made it the largest consumer of the account's REST quota (measured
8
+ * ≈10,000 calls/h on one machine against a 5,000/h limit), stalling everything else that machine
9
+ * does with GitHub. Repo settings and label sets change rarely.
10
+ *
11
+ * How:
12
+ * - one JSON file per repo, keyed by API path (+ Accept), holding each PAGE's body and ETag;
13
+ * - within the TTL (default 600 s) an entry is served with no request at all;
14
+ * - past it, every page is re-asked with `If-None-Match` — a 304 costs no quota and re-arms the
15
+ * TTL; a 200 replaces the page;
16
+ * - `fresh` skips the TTL (every read goes to the server, still conditional — a 304 is the
17
+ * server saying "unchanged", which is as fresh as a 200);
18
+ * - a 404 is cached as "missing" for the TTL (it has no ETag, so re-asking it past the TTL costs one call);
19
+ * - on a rate limit or no response at all, an existing entry is served and labelled `stale`;
20
+ * any other error (404, 403, unparseable) is an error, never a stale answer — a repo that
21
+ * was deleted must not keep reporting its old label set.
22
+ *
23
+ * Where: `COLAB_AUDIT_CACHE_DIR`, else `<COLAB_HOME>/cache/audit` — but only when COLAB_HOME
24
+ * already EXISTS. The audit never creates the operator's colab home; without it the cache lives
25
+ * in memory for one run (each read still made at most once per run).
26
+ *
27
+ * Partitioned by WHO answers: the `gh` binary's resolved path, GH_HOST and a hash of any token in
28
+ * the environment. Two tokens can see different repos, and a test's fake `gh` must never read —
29
+ * or write — the operator's real entries.
30
+ *
31
+ * Provenance: every read is logged against the repo currently being audited (`begin()`), and
32
+ * `summary()` reports how many reads came from cache, were revalidated, fetched, or stale, and
33
+ * the age of the oldest data served — what `--json` shows per repo.
34
+ */
35
+
36
+ const fs = require('fs');
37
+ const path = require('path');
38
+ const crypto = require('crypto');
39
+ const { spawnSync } = require('child_process');
40
+ const { parseHttp } = require('./ci-wait');
41
+
42
+ const DEFAULT_TTL_SECONDS = 600;
43
+ const PER_PAGE = 100;
44
+ const MAX_PAGES = 50; // 5,000 labels/tags/branches — a runaway Link chain must not loop forever
45
+ const PRUNE_AFTER_MS = 7 * 24 * 3600 * 1000;
46
+ const FORMAT = 1;
47
+
48
+ /** TTL in seconds from a flag value, else COLAB_AUDIT_CACHE_TTL, else the default. null = invalid. */
49
+ function resolveTtlSeconds(flag, env = process.env) {
50
+ const raw = flag !== undefined && flag !== null ? flag : env.COLAB_AUDIT_CACHE_TTL;
51
+ if (raw === undefined || raw === null || raw === '') return DEFAULT_TTL_SECONDS;
52
+ const s = String(raw).trim();
53
+ if (!/^\d+$/.test(s)) return null;
54
+ return Number(s);
55
+ }
56
+
57
+ /** The cache directory, or null when there is nowhere we are allowed to write. */
58
+ function resolveDir(env = process.env, colabHome) {
59
+ if (env.COLAB_AUDIT_CACHE_DIR) return path.resolve(env.COLAB_AUDIT_CACHE_DIR);
60
+ if (colabHome && fs.existsSync(colabHome)) return path.join(colabHome, 'cache', 'audit');
61
+ return null;
62
+ }
63
+
64
+ /** First executable `gh` on PATH, resolved — the transport half of the partition key. */
65
+ function ghOnPath(env = process.env) {
66
+ for (const d of String(env.PATH || '').split(path.delimiter)) {
67
+ if (!d) continue;
68
+ const p = path.join(d, 'gh');
69
+ try {
70
+ fs.accessSync(p, fs.constants.X_OK);
71
+ return fs.realpathSync(p);
72
+ } catch (_) { /* next */ }
73
+ }
74
+ return null;
75
+ }
76
+
77
+ function partitionKey(env = process.env) {
78
+ const token = env.GH_TOKEN || env.GITHUB_TOKEN || env.GH_ENTERPRISE_TOKEN || '';
79
+ const parts = [ghOnPath(env) || 'no-gh', env.GH_HOST || 'github.com',
80
+ token ? crypto.createHash('sha256').update(token).digest('hex') : 'ambient'];
81
+ return crypto.createHash('sha256').update(parts.join('\n')).digest('hex').slice(0, 16);
82
+ }
83
+
84
+ /**
85
+ * One GET through `gh api -i`. The path stays the first argument after `api` (callers and fakes
86
+ * match on it). Returns { kind: 'ok'|'not-modified'|'rate-limited'|'unreachable'|'error',
87
+ * etag, next, body }.
88
+ */
89
+ function ghFetch(apiPath, { etag, accept } = {}) {
90
+ const args = ['api', apiPath, '-i'];
91
+ if (etag) args.push('-H', `If-None-Match: ${etag}`);
92
+ if (accept) args.push('-H', `Accept: ${accept}`);
93
+ const r = spawnSync('gh', args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 64 * 1024 * 1024 });
94
+ if (r.error) return { kind: 'unreachable' };
95
+ return classify(r.stdout, r.stderr, r.status);
96
+ }
97
+
98
+ function classify(stdout, stderr, exitCode) {
99
+ const http = parseHttp(stdout);
100
+ const status = http.status;
101
+ const h = http.headers || {};
102
+ const rateText = /rate limit/i.test(String(stderr || '') + (status && status >= 400 ? http.body : ''));
103
+ if (status === 429 || (status === 403 && (h['x-ratelimit-remaining'] === '0' || rateText)) || (status === null && rateText)) {
104
+ return { kind: 'rate-limited' };
105
+ }
106
+ if (status === 304) return { kind: 'not-modified', etag: h.etag || null };
107
+ const next = /rel="next"/.test(h.link || '');
108
+ if (status !== null && status >= 200 && status < 300) return { kind: 'ok', etag: h.etag || null, next, linkKnown: true, body: http.body };
109
+ // No status line: a `gh` that does not print headers. Exit 0 is an answer without an ETag.
110
+ if (status === null && exitCode === 0) return { kind: 'ok', etag: null, next: false, linkKnown: false, body: String(stdout || '') };
111
+ if (status === null) return { kind: 'unreachable' };
112
+ return { kind: 'error', status };
113
+ }
114
+
115
+ function withPage(apiPath, page) {
116
+ return `${apiPath}${apiPath.includes('?') ? '&' : '?'}per_page=${PER_PAGE}&page=${page}`;
117
+ }
118
+
119
+ /**
120
+ * create({ dir, ttlSeconds, fresh, offline, now, fetch, env })
121
+ * get(slug, apiPath, { accept, paginate }) → { status: 'ok', text } | { status: 'ok', items }
122
+ * | { status: 'offline' } | { status: 'error' }
123
+ * begin() — start logging reads for the next repo; summary() — that repo's provenance.
124
+ */
125
+ function create(opts = {}) {
126
+ const env = opts.env || process.env;
127
+ const now = opts.now || Date.now;
128
+ const fetch = opts.fetch || ghFetch;
129
+ const ttlMs = (opts.ttlSeconds === undefined ? DEFAULT_TTL_SECONDS : opts.ttlSeconds) * 1000;
130
+ const fresh = !!opts.fresh;
131
+ const offline = !!opts.offline;
132
+ const dir = opts.dir ? path.join(opts.dir, opts.partition || partitionKey(env)) : null;
133
+
134
+ const files = new Map(); // slug → { entries }
135
+ const doneThisRun = new Set(); // slug|key validated or fetched in this process
136
+ let log = [];
137
+ let pruned = false;
138
+
139
+ const fileFor = (slug) => (dir ? path.join(dir, `${slug.replace(/[^A-Za-z0-9._-]/g, '__')}.json`) : null);
140
+
141
+ function load(slug) {
142
+ if (files.has(slug)) return files.get(slug);
143
+ let data = { format: FORMAT, slug, entries: {} };
144
+ const f = fileFor(slug);
145
+ if (f) {
146
+ try {
147
+ const parsed = JSON.parse(fs.readFileSync(f, 'utf8'));
148
+ if (parsed && parsed.format === FORMAT && parsed.entries && typeof parsed.entries === 'object') data = parsed;
149
+ } catch (_) { /* absent or corrupt: start empty, the next write repairs it */ }
150
+ }
151
+ files.set(slug, data);
152
+ return data;
153
+ }
154
+
155
+ function save(slug) {
156
+ const f = fileFor(slug);
157
+ if (!f) return;
158
+ try {
159
+ fs.mkdirSync(dir, { recursive: true });
160
+ const tmp = `${f}.${process.pid}.tmp`;
161
+ fs.writeFileSync(tmp, JSON.stringify(files.get(slug)));
162
+ fs.renameSync(tmp, f); // atomic: a concurrent audit reads the old file or the new one
163
+ } catch (_) { /* a cache that cannot be written is a slower run, never a failed one */ }
164
+ if (!pruned) { pruned = true; prune(); }
165
+ }
166
+
167
+ function prune() {
168
+ const root = path.dirname(dir);
169
+ const cutoff = now() - PRUNE_AFTER_MS;
170
+ let parts;
171
+ try { parts = fs.readdirSync(root); } catch (_) { return; }
172
+ for (const p of parts) {
173
+ const d = path.join(root, p);
174
+ let names;
175
+ try { names = fs.readdirSync(d); } catch (_) { continue; }
176
+ for (const n of names) {
177
+ const fp = path.join(d, n);
178
+ try { if (fs.statSync(fp).mtimeMs < cutoff) fs.unlinkSync(fp); } catch (_) { /* raced */ }
179
+ }
180
+ try { if (!fs.readdirSync(d).length) fs.rmdirSync(d); } catch (_) { /* not empty / raced */ }
181
+ }
182
+ }
183
+
184
+ function record(source, ageMs) { log.push({ source, ageSeconds: Math.max(0, Math.round(ageMs / 1000)) }); }
185
+
186
+ function answer(entry, paginate) {
187
+ if (entry.missing) return { status: 'error' };
188
+ if (!paginate) return { status: 'ok', text: entry.pages[0].body };
189
+ const items = [];
190
+ for (const p of entry.pages) {
191
+ let arr;
192
+ try { arr = JSON.parse(p.body); } catch (_) { return { status: 'error' }; }
193
+ if (!Array.isArray(arr)) return { status: 'error' };
194
+ items.push(...arr);
195
+ }
196
+ return { status: 'ok', items };
197
+ }
198
+
199
+ function get(slug, apiPath, { accept = null, paginate = false } = {}) {
200
+ if (offline) { record('offline', 0); return { status: 'offline' }; }
201
+ const key = accept ? `${apiPath}|${accept}` : apiPath;
202
+ const data = load(slug);
203
+ const entry = data.entries[key];
204
+ const runKey = `${slug}|${key}`;
205
+
206
+ if (entry && (doneThisRun.has(runKey) || (!fresh && now() - entry.at < ttlMs))) {
207
+ record(doneThisRun.has(runKey) ? 'run' : 'cache', now() - entry.at);
208
+ return answer(entry, paginate);
209
+ }
210
+
211
+ const pages = [];
212
+ let allNotModified = true;
213
+ for (let i = 0; i < (paginate ? MAX_PAGES : 1); i++) {
214
+ const cached = entry && !entry.missing && entry.pages[i];
215
+ const r = fetch(paginate ? withPage(apiPath, i + 1) : apiPath, { etag: cached ? cached.etag : null, accept });
216
+ let page;
217
+ if (r.kind === 'not-modified' && cached) page = cached;
218
+ else if (r.kind === 'ok') {
219
+ allNotModified = false;
220
+ let next = !!r.next;
221
+ if (paginate && !r.linkKnown) { // no headers to follow: a full page means there may be more
222
+ try { const a = JSON.parse(r.body); next = Array.isArray(a) && a.length >= PER_PAGE; } catch (_) { next = false; }
223
+ }
224
+ page = { etag: r.etag || null, next, body: r.body };
225
+ } else {
226
+ if (entry && (r.kind === 'rate-limited' || r.kind === 'unreachable')) {
227
+ record('stale', now() - entry.at);
228
+ return { ...answer(entry, paginate), stale: true };
229
+ }
230
+ if (r.kind === 'error' && r.status === 404 && i === 0) {
231
+ // An absent file is an answer too, and the audit asks for several on every run (a
232
+ // runbook, a tool, a workflow dir). Cached for the TTL like any other; past it, asked
233
+ // again — a 404 carries no ETag, so that one costs a call.
234
+ data.entries[key] = { at: now(), missing: true, pages: [] };
235
+ doneThisRun.add(runKey);
236
+ save(slug);
237
+ record('fetched', 0);
238
+ return { status: 'error' };
239
+ }
240
+ record('error', 0);
241
+ return { status: 'error' };
242
+ }
243
+ pages.push(page);
244
+ if (!paginate || !page.next) break;
245
+ }
246
+
247
+ data.entries[key] = { at: now(), pages };
248
+ doneThisRun.add(runKey);
249
+ save(slug);
250
+ record(allNotModified ? 'revalidated' : 'fetched', 0);
251
+ return answer(data.entries[key], paginate);
252
+ }
253
+
254
+ function begin() { log = []; }
255
+
256
+ /** This repo's remote provenance since begin(); null when it made no GitHub read at all. */
257
+ function summary() {
258
+ if (offline) return { mode: 'offline' };
259
+ if (!log.length) return null;
260
+ const count = (s) => log.filter((e) => e.source === s).length;
261
+ const served = log.filter((e) => e.source !== 'error');
262
+ return {
263
+ mode: 'live',
264
+ reads: log.length,
265
+ cache: count('cache') + count('run'),
266
+ revalidated: count('revalidated'),
267
+ fetched: count('fetched'),
268
+ stale: count('stale'),
269
+ errors: count('error'),
270
+ oldestAgeSeconds: served.length ? Math.max(...served.map((e) => e.ageSeconds)) : null,
271
+ };
272
+ }
273
+
274
+ return { get, begin, summary, dir, ttlSeconds: ttlMs / 1000, fresh, offline };
275
+ }
276
+
277
+ module.exports = { create, ghFetch, classify, resolveTtlSeconds, resolveDir, partitionKey, DEFAULT_TTL_SECONDS, PER_PAGE };
@@ -46,7 +46,7 @@
46
46
  * section carrying its measured cost (parseMigrationSection). Every signal is written into the tag
47
47
  * message, so the reason for the bump is recorded mechanically.
48
48
  *
49
- * Never a final tag — with ONE exception, `deploy-tag-fast` (#446): there the operator granted a
49
+ * Never a final tag — with two exceptions, `library-fast` (#590, below) and `deploy-tag-fast` (#446): on the latter the operator granted a
50
50
  * final on every green trunk head, so `--auto` tags `vX.Y.Z` directly (no candidate, no test period)
51
51
  * and the release workflow deploys it in the same run. That branch adds five checks, all in the
52
52
  * same closed vocabulary:
@@ -60,6 +60,14 @@
60
60
  * migration-grant no migration since the last final unless the version's tracking issue is
61
61
  * granted one — otherwise a refusal whose `handoff` names the human command
62
62
  *
63
+ * #590: route `library-fast` is the second final route — a library released per merge, nothing
64
+ * deployed. `cut` (by hand or `--auto`) tags `vX.Y.Z` directly once a first final exists, with
65
+ * `already-final` in place of `already-candidate` and the `release-hold` veto, and none of the fast
66
+ * route's grant, spacing, migration hand-off or health gate. Its version on `version-source:
67
+ * manifest` is the manifest's (decideManifestVersion): equal to the last final is a NO-OP, a break the
68
+ * manifest under-declares is a refusal; on `version-source: tag` the bump is computed as for a
69
+ * candidate.
70
+ *
63
71
  * Elsewhere finalizing a candidate is the release skill's (#339), and a final is a human act on
64
72
  * every row where a tag reaches production.
65
73
  */
@@ -110,6 +118,25 @@ function isFastRoute(policy) {
110
118
  return !!(policy && policy.effective && policy.effective.finalize === 'on-green-head');
111
119
  }
112
120
 
121
+ /**
122
+ * #590: is this policy route library-fast as declared — no candidates, an automatic final reached
123
+ * by the tag itself? There `cut` tags the FINAL directly, as on deploy-tag-fast, but nothing deploys:
124
+ * no grant, no spacing, no migration hand-off, no health gate. A `final: human` narrowing keeps
125
+ * `finalize: on-tag` but makes every final a human act, so it is not this.
126
+ */
127
+ function isLibraryRoute(policy) {
128
+ const e = policy && policy.effective;
129
+ return !!(e && e.finalize === 'on-tag' && e.final === 'auto' && e.candidates === 'off');
130
+ }
131
+
132
+ /** #590: the route a refusal names — the one in effect, never the derived default it replaced. */
133
+ function routeWhy(policy) {
134
+ const releasePolicy = require('./release-policy');
135
+ const route = policy && policy.effective && policy.effective.route;
136
+ const own = route && releasePolicy.ROUTE_POLICY[route];
137
+ return { route, why: own ? own.why : policy.derived.why };
138
+ }
139
+
113
140
  /** The file a major's migration section is read from, at the candidate commit (#422). */
114
141
  const MIGRATION_FILE = 'MIGRATION.md';
115
142
 
@@ -413,6 +440,63 @@ function decideAutoVersion({ lastFinal, signals, migration, tags }) {
413
440
  return { ok: true, detail: `${lastFinal} -> ${version} (${bump}, computed: ${why})`, version, bump, why, overridden: null, migration: mig };
414
441
  }
415
442
 
443
+ // ---- #590: library-fast — the version the manifest already says ------------------------------
444
+
445
+ /**
446
+ * Route library-fast with `release.version-source: manifest`: the release is the version a merge
447
+ * already put in the manifest, so the cut computes no bump — it checks the manifest's.
448
+ * manifests release-tag.js manifestVersions() at the commit (null = unread)
449
+ * breaking [why] — a breaking signal since the last final (autoSignals' `breaking`, or the
450
+ * manual cut's semverSuggestion when it says major); empty when none
451
+ * migration (version) => parseMigrationSection result, asked only for a major
452
+ * Returns decideVersion's shape, plus `nothing` (the manifest still says the last final — a no-op
453
+ * under --auto) and `fallback` (no manifest declares a version: the caller computes the bump as on
454
+ * version-source: tag).
455
+ */
456
+ function decideManifestVersion({ lastFinal, manifests, tags, breaking, migration }) {
457
+ const refuse = (detail, extra = {}) => ({ ok: false, detail, ...extra });
458
+ if (!lastFinal) return refuse('no final release tag (vX.Y.Z) on main yet — the first version is a human decision, not a computed bump');
459
+ const last = parseVersion(lastFinal);
460
+ if (!last) return refuse(`the last release tag ${lastFinal} is not vX.Y.Z — cannot compare the manifest against it`);
461
+ if (manifests === null || manifests === undefined) return refuse('the manifests could not be read at the commit — an unread version is not a release', { unread: true });
462
+ const bad = manifests.filter((m) => m.error).map((m) => `${m.file}: ${m.error}`);
463
+ if (bad.length) return refuse(`a manifest does not read — ${bad.join('; ')}`);
464
+ const stated = manifests.filter((m) => !m.dynamic && m.version !== undefined && m.version !== null);
465
+ if (!stated.length) return { ok: false, fallback: true, detail: 'no manifest states a version' };
466
+ const values = [...new Set(stated.map((m) => String(m.version).replace(/^v/, '')))];
467
+ if (values.length > 1) return refuse(`the manifests disagree on the version — ${stated.map((m) => `${m.file} says ${m.version}`).join('; ')}`);
468
+ const v = parseVersion(`v${values[0]}`);
469
+ const where = stated.map((m) => m.file).join(', ');
470
+ if (!v) return refuse(`${where} says ${values[0]}, which is not X.Y.Z — route library-fast tags finals only, never a pre-release`);
471
+ const version = formatVersion(v);
472
+ const cmp = (a, b) => (a.major - b.major) || (a.minor - b.minor) || (a.patch - b.patch);
473
+ if (cmp(v, last) === 0) {
474
+ return refuse(`${where} still says ${values[0]}, the last final ${lastFinal} — nothing to release until a merge bumps it (route library-fast, release.version-source: manifest)`, { nothing: true });
475
+ }
476
+ if (cmp(v, last) < 0) return refuse(`${where} says ${values[0]}, below the last final ${lastFinal} — the manifest moved backwards`);
477
+ if ((tags || []).includes(version)) return refuse(`${version} is already a final tag`);
478
+
479
+ const bump = v.major !== last.major ? 'major' : v.minor !== last.minor ? 'minor' : 'patch';
480
+ const brk = breaking || [];
481
+ let mig = null;
482
+ if (bump === 'major') {
483
+ if (last.major === 0) {
484
+ return refuse(`${where} says ${values[0]} — the step from 0.x to ${version} is a human decision (CONVENTIONS.md §6, Versioning): tag it by hand, and later finals follow the manifest`, { bump });
485
+ }
486
+ mig = typeof migration === 'function' ? migration(version) : (migration || null);
487
+ if (!mig || !mig.ok) {
488
+ return refuse(`${lastFinal} -> ${version} is a major, refused: ${mig ? mig.detail : `no migration section read for ${version}`}`, { bump, migration: mig });
489
+ }
490
+ } else if (brk.length) {
491
+ const owed = last.major === 0 ? 'minor' : 'major';
492
+ if (owed === 'major' || bump === 'patch') {
493
+ return refuse(`a breaking change since ${lastFinal} (${brk.join('; ')}) but ${where} only bumps to ${values[0]} (a ${bump}) — a break needs a ${owed}. Bump the manifest on trunk, or show the change is not breaking`, { bump });
494
+ }
495
+ }
496
+ const why = `${where} says ${values[0]}${brk.length ? ` (breaking since ${lastFinal}: ${brk.join('; ')})` : ''}`;
497
+ return { ok: true, detail: `${lastFinal} -> ${version} (${bump}, from the manifest: ${why})`, version, bump, why, overridden: null, migration: mig };
498
+ }
499
+
416
500
  // ---- --auto: cadence (#422) ------------------------------------------------------------------
417
501
 
418
502
  /**
@@ -866,17 +950,26 @@ function decide(facts) {
866
950
 
867
951
  const p = f.policy;
868
952
  const fast = isFastRoute(p) && !(p.findings && p.findings.length);
953
+ // #590: route library-fast — a final with no candidate, like the fast route, and nothing deployed.
954
+ const library = !fast && isLibraryRoute(p) && !(p.findings && p.findings.length);
955
+ const finalRoute = fast || library;
869
956
  if (!p) add('release-policy', false, 'no release policy was evaluated', true);
870
957
  else if (p.findings && p.findings.length) add('release-policy', false, `the release: block is invalid — ${p.findings.map((x) => x.text).join('; ')}`);
871
958
  else if (fast && !f.auto) {
872
959
  add('release-policy', false, 'route deploy-tag-fast tags its finals only from the release workflow (`colab release cut --auto`), where the deploy runs in the same run — a final cut by hand would reach production with no deploy job behind it');
873
960
  } else if (fast) {
874
961
  add('release-policy', true, `${p.derived.axis} (${p.derived.row}, route deploy-tag-fast): a final on every green head, granted by decision #${p.effective.finalGrant.issue}, health gate ${p.effective.healthGate.url} (rollback: ${p.effective.healthGate.rollback}), spacing ${p.effective.finalSpacingHours}h`);
962
+ } else if (library) {
963
+ add('release-policy', true, `${p.derived.axis} (${p.derived.row}, route library-fast): a final on every release the version source owes — no candidate, nothing deployed (version source: ${versionSourceOf(p)})`);
875
964
  } else if (p.effective.candidates !== 'auto') {
876
965
  const narrowed = p.declared && p.declared.candidates === 'off' && p.derived.candidates === 'auto';
966
+ const { route, why } = routeWhy(p);
967
+ const humanFinal = route === 'library-fast' && p.effective.final === 'human';
877
968
  add('release-policy', false, narrowed
878
969
  ? 'release: candidates: off — this repo narrowed its rung row to no automatic candidates'
879
- : `candidates are off on ${p.derived.axis}: ${p.derived.why} (CONVENTIONS.md §6, The release rung)`);
970
+ : humanFinal
971
+ ? `route library-fast with release.final: human — every final here is a human act: tag vX.Y.Z by hand (CONVENTIONS.md §6, The release rung)`
972
+ : `candidates are off on ${p.derived.axis}${route ? `, route ${route}` : ''}: ${why} (CONVENTIONS.md §6, The release rung)`);
880
973
  } else {
881
974
  add('release-policy', true, `${p.derived.axis} (${p.derived.row}${p.effective.route ? `, route ${p.effective.route}` : ''}): candidates auto, final ${p.effective.final}, test period ${p.effective.testPeriodDays}d`);
882
975
  }
@@ -904,23 +997,38 @@ function decide(facts) {
904
997
  if (trig.length) add('prerelease-trigger', false, `a deploy would fire on a candidate tag: ${trig.map((t) => t.text).join('; ')}`);
905
998
  else add('prerelease-trigger', true, 'no deploy workflow fires on a pre-release tag');
906
999
 
907
- const v = f.auto
1000
+ const computed = () => (f.auto
908
1001
  ? decideAutoVersion({ lastFinal: f.lastFinal, signals: f.auto.signals, migration: f.auto.migration, tags: f.tags })
909
- : decideVersion({ lastFinal: f.lastFinal, suggestion: f.suggestion, override: f.override, tags: f.tags });
1002
+ : decideVersion({ lastFinal: f.lastFinal, suggestion: f.suggestion, override: f.override, tags: f.tags }));
1003
+ let v;
1004
+ if (library && versionSourceOf(p) === 'manifest') {
1005
+ // #590: the manifest is the version; the signals only decide whether it under-declares a break.
1006
+ if (f.override && f.override.bump) v = { ok: false, detail: `--bump ${f.override.bump} has nothing to override — on route library-fast with release.version-source: manifest the version is the manifest's; bump it on trunk` };
1007
+ else {
1008
+ const sig = f.auto ? (f.auto.signals || {}) : null;
1009
+ if (sig && sig.unread && sig.unread.length) v = { ok: false, unread: true, detail: `a bump signal could not be read — fail closed: ${sig.unread.join('; ')}` };
1010
+ else {
1011
+ const breaking = sig ? (sig.breaking || [])
1012
+ : (f.suggestion && f.suggestion.bump === 'major' ? [f.suggestion.why || 'a breaking change'] : []);
1013
+ v = decideManifestVersion({ lastFinal: f.lastFinal, manifests: f.manifests, tags: f.tags, breaking, migration: f.auto ? f.auto.migration : f.migration });
1014
+ if (v.fallback) v = computed();
1015
+ }
1016
+ }
1017
+ } else v = computed();
910
1018
  add('version', v.ok, v.detail, isUnread(v));
911
1019
  // "Nothing merged since the last final" is a no-op for the release workflow, not a failure.
912
1020
  if (f.auto && v.nothing) noop = true;
913
1021
 
914
1022
  let tag = null;
915
1023
  let derivable = [];
916
- if (v.ok && fast) {
1024
+ if (v.ok && finalRoute) {
917
1025
  const finalHere = (f.tagsAtSha || []).filter((t) => VERSION_RE.test(t));
918
1026
  if (finalHere.length) {
919
1027
  add('already-final', false, `this commit is already the final ${finalHere.join(', ')} — a head that carries a final is the route holding`);
920
1028
  if (f.auto) noop = true;
921
1029
  } else {
922
1030
  tag = v.version;
923
- add('already-final', true, `next final: ${tag} (no candidate — route deploy-tag-fast)`);
1031
+ add('already-final', true, `next final: ${tag} (no candidate — route ${fast ? 'deploy-tag-fast' : 'library-fast'})`);
924
1032
  }
925
1033
  } else if (v.ok) {
926
1034
  const here = candidateNumbers(f.tagsAtSha || [], v.version);
@@ -966,6 +1074,10 @@ function decide(facts) {
966
1074
  const mig = f.migrations || { ok: false, detail: 'migrations since the last final were not measured' };
967
1075
  add('migration-grant', mig.ok, mig.detail, !f.migrations || isUnread(mig));
968
1076
  if (!mig.ok && v.ok && mig.paths && mig.paths.length) handoff = migrationHandoff(f.trackingIssue, v.version);
1077
+ } else if (library) {
1078
+ // #590: a human veto still holds an automatic final; nothing else the fast route adds applies.
1079
+ const h = f.holds || { ok: false, detail: `${HOLD_LABEL} was not measured` };
1080
+ add('release-hold', h.ok, h.detail, !f.holds || isUnread(h));
969
1081
  }
970
1082
 
971
1083
  const refusals = checks.filter((c) => !c.ok);
@@ -981,7 +1093,7 @@ function decide(facts) {
981
1093
  signals: f.auto ? f.auto.signals || null : null, migration: v.migration || null,
982
1094
  derivable,
983
1095
  versionSourceDeclared: !!(p && p.effective && p.effective.versionSourceDeclared),
984
- final: fast, grant, handoff,
1096
+ final: finalRoute, route: finalRoute ? (fast ? 'deploy-tag-fast' : 'library-fast') : null, grant, handoff,
985
1097
  healthGate: fast ? p.effective.healthGate : null,
986
1098
  };
987
1099
  }
@@ -996,8 +1108,9 @@ function tagMessage(verdict, { sha, lastFinal }) {
996
1108
  // #446: a fast-route final. Its subject deliberately does NOT end in "(colab release cut)", so no
997
1109
  // reader of candidates (cutCandidates, finalize's CUT_SUBJECT_SUFFIX) ever mistakes it for one.
998
1110
  const fast = !!verdict.final;
1111
+ const route = verdict.route || 'deploy-tag-fast';
999
1112
  const lines = [
1000
- fast ? `${verdict.tag} — release (colab release cut, deploy-tag-fast)` : `${verdict.tag} — release candidate (colab release cut)`,
1113
+ fast ? `${verdict.tag} — release (colab release cut, ${route})` : `${verdict.tag} — release candidate (colab release cut)`,
1001
1114
  '',
1002
1115
  `Commit: ${sha}`,
1003
1116
  `Since: ${lastFinal}`,
@@ -1015,14 +1128,18 @@ function tagMessage(verdict, { sha, lastFinal }) {
1015
1128
  'Conditions (CONVENTIONS.md §6):',
1016
1129
  ...verdict.checks.map((c) => `- ${c.condition}: ${c.detail}`),
1017
1130
  '',
1018
- fast ? 'A final with no candidate: route deploy-tag-fast, by the operator\'s grant (CONVENTIONS.md §6).' : 'A candidate, never a final: finalizing it is the release skill\'s, after its test period.',
1131
+ fast
1132
+ ? (route === 'library-fast'
1133
+ ? 'A final with no candidate: route library-fast — a library released per merge; nothing deploys from this tag (CONVENTIONS.md §6).'
1134
+ : 'A final with no candidate: route deploy-tag-fast, by the operator\'s grant (CONVENTIONS.md §6).')
1135
+ : 'A candidate, never a final: finalizing it is the release skill\'s, after its test period.',
1019
1136
  ];
1020
1137
  return lines.join('\n') + '\n';
1021
1138
  }
1022
1139
 
1023
1140
  module.exports = {
1024
1141
  CONDITIONS, FAST_CONDITIONS, STANDING_CONDITIONS, BUMPS, MIGRATION_FILE, RELEASE_BRANCH, HOLD_LABEL,
1025
- isFastRoute, spacingVerdict, holdsVerdict, migrationHandoff,
1142
+ isFastRoute, isLibraryRoute, decideManifestVersion, spacingVerdict, holdsVerdict, migrationHandoff,
1026
1143
  parseVersion, formatVersion, candidateNumbers, nextCandidateNumber, decideVersion,
1027
1144
  parseGuardOutput, exportsDiff, switchRemovalsSince, autoSignals, parseMigrationSection, decideAutoVersion, cadenceVerdict,
1028
1145
  fullSuiteVerdict, withoutOwnWorkflow, isMigrationPath, schemaVerdict,