@starci/hfs 4.7.43 → 4.7.45

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,204 +1,204 @@
1
- // release-definition.mjs - what makes a commit of the runtime repository a RELEASE commit, the one definition shared by the
2
- // pre-push hook (scripts/guards/release-push-gate.mjs) and the release cut (scripts/supervisor/release-cut.mjs). The remote
3
- // main of the runtime moves exactly when a release is cut, so a push of main or of a v* tag is judged against this list:
4
- // RELEASE_VERSION_UNCHANGED package.json `version` at the pushed commit differs from the version at the remote main's head
5
- // RELEASE_VERSION_NOT_NEXT that version is the next release after the highest v* tag (scripts/lib/release-version.mjs, owner ruling release-waves):
6
- // the next wave alpha.N.M+1 of its line or the next line alpha.N+1, never the legacy -fix form
7
- // RELEASE_TAG_VERSION the release tag is v<version> of the pushed commit
8
- // RELEASE_CHANGELOG_SECTION CHANGELOG.md holds `## [<version>] - <date>` (a dated heading) with no unfinished marker (R222)
9
- // RELEASE_TAG_MISSING an ANNOTATED tag v<version> points at the pushed commit
10
- // RELEASE_RECEIPT_MISSING the L4 record of exactly this commit (scripts/guards/release-record.mjs, written by the cut) names this tag
11
- // RELEASE_RECEIPT_INCOMPLETE that record holds a green row for each of RECEIPT_STEPS (the package clean-test, the scaffold e2e and the checks) (RAN on this commit or reused from another with the identical input digest, the record's `reusedFrom` names it; owner ruling speed-flow, 2026-10-25)
12
- // RELEASE_SUITE_MODE the record says `suite: ci` (the Linux parity delegated to CI) while the checked-out config says `local`, or it lists no delegated linux-parity: a record never claims the mode by
13
- // itself (scripts/guards/release-suite-mode.mjs); both modes ask for the same root rows, the runtime has no spec suite to delegate (owner ruling no-runtime-specs)
14
- // Each finding names what is missing and the command that produces it. Pure over the git reads; no bypass.
15
- import { catFile } from '../api/git/cat-file.mjs';
16
- import { revParseQuery } from '../api/git/rev-parse-query.mjs';
17
- import { show } from '../api/git/show.mjs';
18
- import { tag as gitTag } from '../api/git/tag.mjs';
19
- import { mergeBaseQuery } from '../api/git/merge-base-query.mjs';
20
- import { pathKey, realPath } from '../lib/path-key.mjs';
21
- import { changelogSection, releaseNotesFindings } from '../hfs/runtime-rules/release-notes.mjs';
22
- import { nextReleases, releaseVersionRefusal, taggedVersions } from '../lib/release-version.mjs';
23
- import { readL4Record } from './release-record.mjs';
24
- import { suiteModeOf } from './release-suite-mode.mjs';
25
-
26
- /** The rows the L4 record must hold green, run on the commit or reused from an identical-digest row of another, in either suite mode: the package clean-test, the scaffold e2e and the checks (the runtime's real tests). */
27
- export const RECEIPT_STEPS = Object.freeze(['npm run test:packages', 'npm run test:e2e', 'npm run check']);
28
- const CUT_COMMAND = (tag) => `starci release cut --tag ${tag}`;
29
- const REGEX_SPECIALS = /[.*+?^$()|[\]{}\\]/g;
30
- const HEADING_HEAD = String.raw`^## \[`;
31
- const DATED_HEADING_TAIL = String.raw`\] — \d{4}-\d{2}-\d{2}\s*$`;
32
- const DATED_HEADING = (version) => new RegExp([HEADING_HEAD, version.replaceAll(REGEX_SPECIALS, String.raw`\$&`), DATED_HEADING_TAIL].join(''), 'mu');
33
-
34
- const finding = (code, missing, fix) => ({ code, missing, fix });
35
- const gitText = (verb, args, cwd) => {
36
- const r = verb(args, { cwd, timeout: 60_000 });
37
- return r.status === 0 ? String(r.stdout ?? '') : null;
38
- };
39
-
40
- /** The package.json version of `commit`, or null when the commit or its manifest cannot be read. */
41
- export function versionAt(cwd, commit) {
42
- const text = gitText(show, [`${commit}:package.json`], cwd);
43
- try { return text === null ? null : JSON.parse(text).version ?? null; } catch { return null; }
44
- }
45
-
46
- const releaseUnknown = (why) => ({ ok: false, status: 'unknown', why });
47
- const ineligibleRelease = (explicit, why) => explicit ? releaseUnknown(why) : { ok: true, candidate: null };
48
-
49
- /** A runtime Git root's nearest annotated, manifest-bound release; enclosing application history is inapplicable. */
50
- export function releaseTagOf({ repo, tag = null, excludeHead = false }) {
51
- const history = runtimeGitHistory(repo);
52
- if (!history.ok) return history;
53
- const listed = tag === null ? gitText(gitTag, ['--merged', 'HEAD', '--list', 'v*'], repo) : tag;
54
- if (listed === null) return releaseUnknown('release tags are unreadable');
55
- const candidates = [];
56
- for (const named of listed.split(/\r?\n/).filter(Boolean)) {
57
- const result = releaseCandidate({ repo, named, current: history.head, explicit: tag !== null, excludeHead });
58
- if (!result.ok) return result;
59
- if (result.candidate) candidates.push(result.candidate);
60
- }
61
- return nearestRelease(repo, candidates);
62
- }
63
-
64
- /** Runtime history exists only at its own Git top-level with a readable HEAD and full ancestry. */
65
- function runtimeGitHistory(repo) {
66
- const top = revParseQuery(['--show-toplevel'], { cwd: repo });
67
- if (top.status !== 0) {
68
- if (/not a git repository/i.test(String(top.stderr ?? ''))) return { ok: false, status: 'no-repository', why: 'release history requires a Git repository' };
69
- return releaseUnknown('release repository identity is unreadable');
70
- }
71
- const gitRoot = String(top.stdout ?? '').trim();
72
- if (!gitRoot) return releaseUnknown('release repository root is unreadable');
73
- if (pathKey(realPath(gitRoot)) !== pathKey(realPath(repo))) return { ok: false, status: 'no-runtime-repository', why: 'the runtime copy is inside an enclosing Git repository; its history belongs to that repository' };
74
- const head = gitText(revParseQuery, ['HEAD'], repo)?.trim();
75
- if (!head) return releaseUnknown('release history HEAD is unreadable');
76
- if (gitText(revParseQuery, ['--is-shallow-repository'], repo)?.trim() !== 'false') return releaseUnknown('release history is shallow or unreadable; fetch complete release history');
77
- return { ok: true, head };
78
- }
79
-
80
- /** A candidate binds annotation, peeled commit, manifest spelling and ancestry; default discovery omits ineligible tags. */
81
- function releaseCandidate({ repo, named, current, explicit, excludeHead }) {
82
- const kind = gitText(catFile, ['-t', `refs/tags/${named}`], repo)?.trim();
83
- const head = gitText(revParseQuery, [`refs/tags/${named}^{commit}`], repo)?.trim();
84
- if (!kind || !head) return releaseUnknown(`release tag ${named} is unreadable`);
85
- if (kind !== 'tag') return ineligibleRelease(explicit, `release tag ${named} is not annotated`);
86
- const version = versionAt(repo, head);
87
- if (!version) return releaseUnknown(`release manifest of ${named} is unreadable`);
88
- if (named !== `v${version}`) return ineligibleRelease(explicit, `release tag ${named} differs from its manifest version ${version}`);
89
- const reachable = releaseAncestor(repo, head, current);
90
- if (reachable === null) return releaseUnknown(`release ancestry of ${named} is unreadable`);
91
- if (!reachable) return ineligibleRelease(explicit, `release tag ${named} is not merged in HEAD`);
92
- if (excludeHead && head === current) return { ok: true, candidate: null };
93
- return { ok: true, candidate: { tag: named, head } };
94
- }
95
-
96
- /** Only one unsuperseded release ancestor proves a boundary; incomparable releases hold. */
97
- function nearestRelease(repo, candidates) {
98
- if (!candidates.length) return releaseUnknown('no eligible annotated, manifest-bound release tag is merged in HEAD');
99
- const nearest = [];
100
- for (const candidate of candidates) {
101
- const superseded = candidateSuperseded(repo, candidate, candidates);
102
- if (superseded === null) return releaseUnknown('release ancestry between tags is unreadable');
103
- if (!superseded) nearest.push(candidate);
104
- }
105
- if (nearest.length !== 1) return releaseUnknown(`release history is ambiguous: ${nearest.map((entry) => entry.tag).join(', ')}`);
106
- return { ok: true, ...nearest[0] };
107
- }
108
-
109
- /** A release loses its boundary only to a proven descendant release, never to a date or version sort. */
110
- function candidateSuperseded(repo, candidate, candidates) {
111
- for (const other of candidates) {
112
- if (candidate.head === other.head) continue;
113
- const older = releaseAncestor(repo, candidate.head, other.head);
114
- if (older === null) return null;
115
- if (older) return true;
116
- }
117
- return false;
118
- }
119
-
120
- /** Missing Git proof is distinct from a proven non-ancestor. */
121
- function releaseAncestor(repo, before, after) {
122
- const result = mergeBaseQuery(['--is-ancestor', before, after], { cwd: repo });
123
- if (result.status === 0) return true;
124
- if (result.status === 1) return false;
125
- return null;
126
- }
127
-
128
- /** The next releases named from the released versions, for a fix text: "v<wave> or v<line>". */
129
- const nextNamed = (released, version = null) => {
130
- const next = nextReleases(released, version);
131
- return next ? `v${next.wave} or v${next.line}` : 'v<new version>';
132
- };
133
-
134
- function versionFindings({ cwd, remoteCommit, version, released }) {
135
- if (!remoteCommit) return [];
136
- const remoteVersion = versionAt(cwd, remoteCommit);
137
- if (remoteVersion === null) return [finding('RELEASE_REMOTE_HEAD_UNKNOWN', `the remote main head ${remoteCommit.slice(0, 9)} is not in this repository, so its version cannot be compared`, 'git fetch origin main')];
138
- if (remoteVersion === version) return [finding('RELEASE_VERSION_UNCHANGED', `package.json version ${version} is the version the remote main already carries`, `set package.json version to the next release, move the CHANGELOG section to it, commit, then ${CUT_COMMAND(nextNamed(released, version))}`)];
139
- return [];
140
- }
141
-
142
- /** The version must be the next release after the highest v* tag other than its own: a wave alpha.N.M is counted, never guessed. */
143
- function nextReleaseFindings({ version, released }) {
144
- if (released === null) return [finding('RELEASE_VERSION_NOT_NEXT', 'the v* tags are unreadable, so the next release cannot be derived', 'git fetch --tags')];
145
- const refusal = releaseVersionRefusal(version, released);
146
- return refusal ? [finding('RELEASE_VERSION_NOT_NEXT', refusal, `set package.json version to the next release, move the CHANGELOG section to it, commit, then ${CUT_COMMAND(nextNamed(released.filter((entry) => entry !== version), version))}`)] : [];
147
- }
148
-
149
- function changelogFindings({ cwd, commit, version, tag }) {
150
- const changelog = gitText(show, [`${commit}:CHANGELOG.md`], cwd);
151
- if (changelog === null) return [finding('RELEASE_CHANGELOG_SECTION', 'CHANGELOG.md is not readable at the pushed commit', 'restore CHANGELOG.md')];
152
- const notes = releaseNotesFindings({ tags: [tag], changelog });
153
- if (notes.length) return notes.map((n) => finding('RELEASE_CHANGELOG_SECTION', n.message, 'finish the CHANGELOG section of the release (no in-preparation mark, no open marker), commit'));
154
- if (!changelogSection(changelog, version).found || !DATED_HEADING(version).test(changelog)) return [finding('RELEASE_CHANGELOG_SECTION', `CHANGELOG.md has no dated heading "## [${version}] — YYYY-MM-DD"`, `date the heading of the ${version} section, commit`)];
155
- return [];
156
- }
157
-
158
- function tagFindings({ cwd, commit, tag }) {
159
- const kind = gitText(catFile, ['-t', `refs/tags/${tag}`], cwd)?.trim();
160
- const target = gitText(revParseQuery, [`refs/tags/${tag}^{commit}`], cwd)?.trim();
161
- if (kind === 'tag' && target === commit) return [];
162
- return [finding('RELEASE_TAG_MISSING', `no annotated tag ${tag} points at ${commit.slice(0, 9)}`, CUT_COMMAND(tag))];
163
- }
164
-
165
- /** The finding of a record that claims the delegated mode without the checked-out config saying so (or without naming the delegated linux-parity row), else null. */
166
- function suiteModeFinding({ record, cwd, commit, tag }) {
167
- if (record.suite !== 'ci') return null;
168
- if (suiteModeOf(cwd) !== 'ci') return finding('RELEASE_SUITE_MODE', `the release record of ${commit.slice(0, 9)} says suite: ci, but this checkout's config.yaml release.suite is not ci: a record does not choose the mode`, `set release.suite: ci in config.yaml (the owner's choice), or ${CUT_COMMAND(tag)} under suite: local`);
169
- if (!(record.delegated ?? []).some((row) => row?.name === 'linux-parity')) return finding('RELEASE_SUITE_MODE', `the suite: ci record of ${commit.slice(0, 9)} does not list linux-parity as delegated`, CUT_COMMAND(tag));
170
- return null;
171
- }
172
-
173
- function receiptFindings({ cwd, commit, tag }) {
174
- const record = readL4Record({ repo: cwd, head: commit, tag });
175
- if (!record) return [finding('RELEASE_RECEIPT_MISSING', `no release record for exactly ${commit.slice(0, 9)} and ${tag}: the package clean-test, the scaffold e2e and the check did not run green on this commit`, CUT_COMMAND(tag))];
176
- const mode = suiteModeFinding({ record, cwd, commit, tag });
177
- if (mode) return [mode];
178
- // A row reused from another commit (reusedFrom) counts: the cut reuses a row only when its input digest is identical (owner ruling speed-flow, 2026-10-25), and the record names the commit it came from.
179
- const green = new Set((record.logs ?? []).filter((row) => row?.ok === true).map((row) => row.name));
180
- const absent = RECEIPT_STEPS.filter((name) => !green.has(name));
181
- return absent.length ? [finding('RELEASE_RECEIPT_INCOMPLETE', `the release record of ${commit.slice(0, 9)} has no green row for: ${absent.join(', ')}`, CUT_COMMAND(tag))] : [];
182
- }
183
-
184
- /**
185
- * The findings that keep `commit` from being a release commit of the repository at `cwd`: [{code, missing, fix}], [] when it is one.
186
- * `remoteCommit` is the remote main's head being replaced (null for a tag push or a first push); `tag` the release tag (default v<version>);
187
- * `needTag` / `needReceipt` are false only for the cut's early look, before it has created the tag and run the suite.
188
- */
189
- export function releaseFindings({ cwd, commit, remoteCommit = null, tag = null, needTag = true, needReceipt = true }) {
190
- const version = versionAt(cwd, commit);
191
- if (!version) return [finding('RELEASE_VERSION_UNREADABLE', `package.json at ${commit.slice(0, 9)} has no readable version`, 'restore package.json')];
192
- const expected = `v${version}`;
193
- const named = tag ?? expected;
194
- if (named !== expected) return [finding('RELEASE_TAG_VERSION', `the tag ${named} is not v${version}, the version of ${commit.slice(0, 9)}`, `tag v${version}, or set package.json version to ${named.replace(/^v/, '')}`)];
195
- const listed = gitText(gitTag, ['--list', 'v*'], cwd);
196
- const released = listed === null ? null : taggedVersions(listed);
197
- return [
198
- ...versionFindings({ cwd, remoteCommit, version, released: released ?? [] }),
199
- ...nextReleaseFindings({ version, released }),
200
- ...changelogFindings({ cwd, commit, version, tag: named }),
201
- ...(needTag ? tagFindings({ cwd, commit, tag: named }) : []),
202
- ...(needReceipt ? receiptFindings({ cwd, commit, tag: named }) : []),
203
- ];
204
- }
1
+ // release-definition.mjs - what makes a commit of the runtime repository a RELEASE commit, the one definition shared by the
2
+ // pre-push hook (scripts/guards/release-push-gate.mjs) and the release cut (scripts/supervisor/release-cut.mjs). The remote
3
+ // main of the runtime moves exactly when a release is cut, so a push of main or of a v* tag is judged against this list:
4
+ // RELEASE_VERSION_UNCHANGED package.json `version` at the pushed commit differs from the version at the remote main's head
5
+ // RELEASE_VERSION_NOT_NEXT that version is the next release after the highest v* tag (scripts/lib/release-version.mjs, owner ruling release-waves):
6
+ // the next wave alpha.N.M+1 of its line or the next line alpha.N+1, never the legacy -fix form
7
+ // RELEASE_TAG_VERSION the release tag is v<version> of the pushed commit
8
+ // RELEASE_CHANGELOG_SECTION CHANGELOG.md holds `## [<version>] - <date>` (a dated heading) with no unfinished marker (R222)
9
+ // RELEASE_TAG_MISSING an ANNOTATED tag v<version> points at the pushed commit
10
+ // RELEASE_RECEIPT_MISSING the L4 record of exactly this commit (scripts/guards/release-record.mjs, written by the cut) names this tag
11
+ // RELEASE_RECEIPT_INCOMPLETE that record holds a green row for each of RECEIPT_STEPS (the package clean-test, the scaffold e2e and the checks) (RAN on this commit or reused from another with the identical input digest, the record's `reusedFrom` names it; owner ruling speed-flow, 2026-10-25)
12
+ // RELEASE_SUITE_MODE the record says `suite: ci` (the Linux parity delegated to CI) while the checked-out config says `local`, or it lists no delegated linux-parity: a record never claims the mode by
13
+ // itself (scripts/guards/release-suite-mode.mjs); both modes ask for the same root rows, the runtime has no spec suite to delegate (owner ruling no-runtime-specs)
14
+ // Each finding names what is missing and the command that produces it. Pure over the git reads; no bypass.
15
+ import { catFile } from '../api/git/cat-file.mjs';
16
+ import { revParseQuery } from '../api/git/rev-parse-query.mjs';
17
+ import { show } from '../api/git/show.mjs';
18
+ import { tag as gitTag } from '../api/git/tag.mjs';
19
+ import { mergeBaseQuery } from '../api/git/merge-base-query.mjs';
20
+ import { pathKey, realPath } from '../lib/path-key.mjs';
21
+ import { changelogSection, releaseNotesFindings } from '../hfs/runtime-rules/release-notes.mjs';
22
+ import { nextReleases, releaseVersionRefusal, taggedVersions } from '../lib/release-version.mjs';
23
+ import { readL4Record } from './release-record.mjs';
24
+ import { suiteModeOf } from './release-suite-mode.mjs';
25
+
26
+ /** The rows the L4 record must hold green, run on the commit or reused from an identical-digest row of another, in either suite mode: the package clean-test, the scaffold e2e and the checks (the runtime's real tests). */
27
+ export const RECEIPT_STEPS = Object.freeze(['npm run test:packages', 'npm run test:e2e', 'npm run check']);
28
+ const CUT_COMMAND = (tag) => `starci release cut --tag ${tag}`;
29
+ const REGEX_SPECIALS = /[.*+?^$()|[\]{}\\]/g;
30
+ const HEADING_HEAD = String.raw`^## \[`;
31
+ const DATED_HEADING_TAIL = String.raw`\] — \d{4}-\d{2}-\d{2}\s*$`;
32
+ const DATED_HEADING = (version) => new RegExp([HEADING_HEAD, version.replaceAll(REGEX_SPECIALS, String.raw`\$&`), DATED_HEADING_TAIL].join(''), 'mu');
33
+
34
+ const finding = (code, missing, fix) => ({ code, missing, fix });
35
+ const gitText = (verb, args, cwd) => {
36
+ const r = verb(args, { cwd, timeout: 60_000 });
37
+ return r.status === 0 ? String(r.stdout ?? '') : null;
38
+ };
39
+
40
+ /** The package.json version of `commit`, or null when the commit or its manifest cannot be read. */
41
+ export function versionAt(cwd, commit) {
42
+ const text = gitText(show, [`${commit}:package.json`], cwd);
43
+ try { return text === null ? null : JSON.parse(text).version ?? null; } catch { return null; }
44
+ }
45
+
46
+ const releaseUnknown = (why) => ({ ok: false, status: 'unknown', why });
47
+ const ineligibleRelease = (explicit, why) => explicit ? releaseUnknown(why) : { ok: true, candidate: null };
48
+
49
+ /** A runtime Git root's nearest annotated, manifest-bound release; enclosing application history is inapplicable. */
50
+ export function releaseTagOf({ repo, tag = null, excludeHead = false }) {
51
+ const history = runtimeGitHistory(repo);
52
+ if (!history.ok) return history;
53
+ const listed = tag === null ? gitText(gitTag, ['--merged', 'HEAD', '--list', 'v*'], repo) : tag;
54
+ if (listed === null) return releaseUnknown('release tags are unreadable');
55
+ const candidates = [];
56
+ for (const named of listed.split(/\r?\n/).filter(Boolean)) {
57
+ const result = releaseCandidate({ repo, named, current: history.head, explicit: tag !== null, excludeHead });
58
+ if (!result.ok) return result;
59
+ if (result.candidate) candidates.push(result.candidate);
60
+ }
61
+ return nearestRelease(repo, candidates);
62
+ }
63
+
64
+ /** Runtime history exists only at its own Git top-level with a readable HEAD and full ancestry. */
65
+ function runtimeGitHistory(repo) {
66
+ const top = revParseQuery(['--show-toplevel'], { cwd: repo });
67
+ if (top.status !== 0) {
68
+ if (/not a git repository/i.test(String(top.stderr ?? ''))) return { ok: false, status: 'no-repository', why: 'release history requires a Git repository' };
69
+ return releaseUnknown('release repository identity is unreadable');
70
+ }
71
+ const gitRoot = String(top.stdout ?? '').trim();
72
+ if (!gitRoot) return releaseUnknown('release repository root is unreadable');
73
+ if (pathKey(realPath(gitRoot)) !== pathKey(realPath(repo))) return { ok: false, status: 'no-runtime-repository', why: 'the runtime copy is inside an enclosing Git repository; its history belongs to that repository' };
74
+ const head = gitText(revParseQuery, ['HEAD'], repo)?.trim();
75
+ if (!head) return releaseUnknown('release history HEAD is unreadable');
76
+ if (gitText(revParseQuery, ['--is-shallow-repository'], repo)?.trim() !== 'false') return releaseUnknown('release history is shallow or unreadable; fetch complete release history');
77
+ return { ok: true, head };
78
+ }
79
+
80
+ /** A candidate binds annotation, peeled commit, manifest spelling and ancestry; default discovery omits ineligible tags. */
81
+ function releaseCandidate({ repo, named, current, explicit, excludeHead }) {
82
+ const kind = gitText(catFile, ['-t', `refs/tags/${named}`], repo)?.trim();
83
+ const head = gitText(revParseQuery, [`refs/tags/${named}^{commit}`], repo)?.trim();
84
+ if (!kind || !head) return releaseUnknown(`release tag ${named} is unreadable`);
85
+ if (kind !== 'tag') return ineligibleRelease(explicit, `release tag ${named} is not annotated`);
86
+ const version = versionAt(repo, head);
87
+ if (!version) return releaseUnknown(`release manifest of ${named} is unreadable`);
88
+ if (named !== `v${version}`) return ineligibleRelease(explicit, `release tag ${named} differs from its manifest version ${version}`);
89
+ const reachable = releaseAncestor(repo, head, current);
90
+ if (reachable === null) return releaseUnknown(`release ancestry of ${named} is unreadable`);
91
+ if (!reachable) return ineligibleRelease(explicit, `release tag ${named} is not merged in HEAD`);
92
+ if (excludeHead && head === current) return { ok: true, candidate: null };
93
+ return { ok: true, candidate: { tag: named, head } };
94
+ }
95
+
96
+ /** Only one unsuperseded release ancestor proves a boundary; incomparable releases hold. */
97
+ function nearestRelease(repo, candidates) {
98
+ if (!candidates.length) return releaseUnknown('no eligible annotated, manifest-bound release tag is merged in HEAD');
99
+ const nearest = [];
100
+ for (const candidate of candidates) {
101
+ const superseded = candidateSuperseded(repo, candidate, candidates);
102
+ if (superseded === null) return releaseUnknown('release ancestry between tags is unreadable');
103
+ if (!superseded) nearest.push(candidate);
104
+ }
105
+ if (nearest.length !== 1) return releaseUnknown(`release history is ambiguous: ${nearest.map((entry) => entry.tag).join(', ')}`);
106
+ return { ok: true, ...nearest[0] };
107
+ }
108
+
109
+ /** A release loses its boundary only to a proven descendant release, never to a date or version sort. */
110
+ function candidateSuperseded(repo, candidate, candidates) {
111
+ for (const other of candidates) {
112
+ if (candidate.head === other.head) continue;
113
+ const older = releaseAncestor(repo, candidate.head, other.head);
114
+ if (older === null) return null;
115
+ if (older) return true;
116
+ }
117
+ return false;
118
+ }
119
+
120
+ /** Missing Git proof is distinct from a proven non-ancestor. */
121
+ function releaseAncestor(repo, before, after) {
122
+ const result = mergeBaseQuery(['--is-ancestor', before, after], { cwd: repo });
123
+ if (result.status === 0) return true;
124
+ if (result.status === 1) return false;
125
+ return null;
126
+ }
127
+
128
+ /** The next releases named from the released versions, for a fix text: "v<wave> or v<line>". */
129
+ const nextNamed = (released, version = null) => {
130
+ const next = nextReleases(released, version);
131
+ return next ? `v${next.wave} or v${next.line}` : 'v<new version>';
132
+ };
133
+
134
+ function versionFindings({ cwd, remoteCommit, version, released }) {
135
+ if (!remoteCommit) return [];
136
+ const remoteVersion = versionAt(cwd, remoteCommit);
137
+ if (remoteVersion === null) return [finding('RELEASE_REMOTE_HEAD_UNKNOWN', `the remote main head ${remoteCommit.slice(0, 9)} is not in this repository, so its version cannot be compared`, 'git fetch origin main')];
138
+ if (remoteVersion === version) return [finding('RELEASE_VERSION_UNCHANGED', `package.json version ${version} is the version the remote main already carries`, `set package.json version to the next release, move the CHANGELOG section to it, commit, then ${CUT_COMMAND(nextNamed(released, version))}`)];
139
+ return [];
140
+ }
141
+
142
+ /** The version must be the next release after the highest v* tag other than its own: a wave alpha.N.M is counted, never guessed. */
143
+ function nextReleaseFindings({ version, released }) {
144
+ if (released === null) return [finding('RELEASE_VERSION_NOT_NEXT', 'the v* tags are unreadable, so the next release cannot be derived', 'git fetch --tags')];
145
+ const refusal = releaseVersionRefusal(version, released);
146
+ return refusal ? [finding('RELEASE_VERSION_NOT_NEXT', refusal, `set package.json version to the next release, move the CHANGELOG section to it, commit, then ${CUT_COMMAND(nextNamed(released.filter((entry) => entry !== version), version))}`)] : [];
147
+ }
148
+
149
+ function changelogFindings({ cwd, commit, version, tag }) {
150
+ const changelog = gitText(show, [`${commit}:CHANGELOG.md`], cwd);
151
+ if (changelog === null) return [finding('RELEASE_CHANGELOG_SECTION', 'CHANGELOG.md is not readable at the pushed commit', 'restore CHANGELOG.md')];
152
+ const notes = releaseNotesFindings({ tags: [tag], changelog });
153
+ if (notes.length) return notes.map((n) => finding('RELEASE_CHANGELOG_SECTION', n.message, 'finish the CHANGELOG section of the release (no in-preparation mark, no open marker), commit'));
154
+ if (!changelogSection(changelog, version).found || !DATED_HEADING(version).test(changelog)) return [finding('RELEASE_CHANGELOG_SECTION', `CHANGELOG.md has no dated heading "## [${version}] — YYYY-MM-DD"`, `date the heading of the ${version} section, commit`)];
155
+ return [];
156
+ }
157
+
158
+ function tagFindings({ cwd, commit, tag }) {
159
+ const kind = gitText(catFile, ['-t', `refs/tags/${tag}`], cwd)?.trim();
160
+ const target = gitText(revParseQuery, [`refs/tags/${tag}^{commit}`], cwd)?.trim();
161
+ if (kind === 'tag' && target === commit) return [];
162
+ return [finding('RELEASE_TAG_MISSING', `no annotated tag ${tag} points at ${commit.slice(0, 9)}`, CUT_COMMAND(tag))];
163
+ }
164
+
165
+ /** The finding of a record that claims the delegated mode without the checked-out config saying so (or without naming the delegated linux-parity row), else null. */
166
+ function suiteModeFinding({ record, cwd, commit, tag }) {
167
+ if (record.suite !== 'ci') return null;
168
+ if (suiteModeOf(cwd) !== 'ci') return finding('RELEASE_SUITE_MODE', `the release record of ${commit.slice(0, 9)} says suite: ci, but this checkout's config.yaml release.suite is not ci: a record does not choose the mode`, `set release.suite: ci in config.yaml (the owner's choice), or ${CUT_COMMAND(tag)} under suite: local`);
169
+ if (!(record.delegated ?? []).some((row) => row?.name === 'linux-parity')) return finding('RELEASE_SUITE_MODE', `the suite: ci record of ${commit.slice(0, 9)} does not list linux-parity as delegated`, CUT_COMMAND(tag));
170
+ return null;
171
+ }
172
+
173
+ function receiptFindings({ cwd, commit, tag }) {
174
+ const record = readL4Record({ repo: cwd, head: commit, tag });
175
+ if (!record) return [finding('RELEASE_RECEIPT_MISSING', `no release record for exactly ${commit.slice(0, 9)} and ${tag}: the package clean-test, the scaffold e2e and the check did not run green on this commit`, CUT_COMMAND(tag))];
176
+ const mode = suiteModeFinding({ record, cwd, commit, tag });
177
+ if (mode) return [mode];
178
+ // A row reused from another commit (reusedFrom) counts: the cut reuses a row only when its input digest is identical (owner ruling speed-flow, 2026-10-25), and the record names the commit it came from.
179
+ const green = new Set((record.logs ?? []).filter((row) => row?.ok === true).map((row) => row.name));
180
+ const absent = RECEIPT_STEPS.filter((name) => !green.has(name));
181
+ return absent.length ? [finding('RELEASE_RECEIPT_INCOMPLETE', `the release record of ${commit.slice(0, 9)} has no green row for: ${absent.join(', ')}`, CUT_COMMAND(tag))] : [];
182
+ }
183
+
184
+ /**
185
+ * The findings that keep `commit` from being a release commit of the repository at `cwd`: [{code, missing, fix}], [] when it is one.
186
+ * `remoteCommit` is the remote main's head being replaced (null for a tag push or a first push); `tag` the release tag (default v<version>);
187
+ * `needTag` / `needReceipt` are false only for the cut's early look, before it has created the tag and run the suite.
188
+ */
189
+ export function releaseFindings({ cwd, commit, remoteCommit = null, tag = null, needTag = true, needReceipt = true }) {
190
+ const version = versionAt(cwd, commit);
191
+ if (!version) return [finding('RELEASE_VERSION_UNREADABLE', `package.json at ${commit.slice(0, 9)} has no readable version`, 'restore package.json')];
192
+ const expected = `v${version}`;
193
+ const named = tag ?? expected;
194
+ if (named !== expected) return [finding('RELEASE_TAG_VERSION', `the tag ${named} is not v${version}, the version of ${commit.slice(0, 9)}`, `tag v${version}, or set package.json version to ${named.replace(/^v/, '')}`)];
195
+ const listed = gitText(gitTag, ['--list', 'v*'], cwd);
196
+ const released = listed === null ? null : taggedVersions(listed);
197
+ return [
198
+ ...versionFindings({ cwd, remoteCommit, version, released: released ?? [] }),
199
+ ...nextReleaseFindings({ version, released }),
200
+ ...changelogFindings({ cwd, commit, version, tag: named }),
201
+ ...(needTag ? tagFindings({ cwd, commit, tag: named }) : []),
202
+ ...(needReceipt ? receiptFindings({ cwd, commit, tag: named }) : []),
203
+ ];
204
+ }
@@ -2,6 +2,7 @@ import path from 'node:path';
2
2
  import { canonical, loadArchitectureConfig } from './config.mjs';
3
3
  import { sameOrUnder } from '../../lib/path-key.mjs';
4
4
  import { buildTypeScriptContext, relativePath } from './typescript.mjs';
5
+ import { withTypeScriptProgramRun } from '../typescript-programs.mjs';
5
6
  import { checkBackend } from './backend.mjs';
6
7
  import { checkBackendContracts, PUBLIC_CONTRACT_RULE_ID, READONLY_BOUNDARY_RULE_ID } from './contracts.mjs';
7
8
  import { checkFrontend } from './frontend.mjs';
@@ -324,7 +325,7 @@ function scopeFindings({ config, context, violations, paths, surface }) {
324
325
  * that read the whole repository to answer (clones, dead exports, repository-wide symbols); the pre-push check of the changed owners uses it.
325
326
  */
326
327
  export function checkArchitecture(options = {}) {
327
- return withTreeCache(() => checkArchitectureOnce(options));
328
+ return withTypeScriptProgramRun(() => withTreeCache(() => checkArchitectureOnce(options)));
328
329
  }
329
330
 
330
331
  function checkArchitectureOnce({ repositoryRoot, injectedTypeScript, paths = [], base, fast = false, hfs: openedHfs, surface = 'all' }) {
@@ -103,36 +103,35 @@ function createProjects(config, paths, state, selection, ts, helpers) {
103
103
  return projects;
104
104
  }
105
105
 
106
+ function ownershipRank(config, project, file, helpers) {
107
+ return helpers.isInside(path.dirname(path.join(config.root, ...project.relative.split('/'))), file)
108
+ ? project.relative.split('/').length : -1;
109
+ }
110
+
106
111
  function collectProjectFiles(config, projects, helpers) {
107
- const occurrences = new Map();
108
- const sourceIn = new Map();
112
+ const fileMap = new Map();
113
+ const ownerByFile = new Map();
114
+ // Retain only the winning source occurrence while visiting each project. Equal ranks keep the first project,
115
+ // as does a file outside every project directory; the deepest enclosing tsconfig otherwise owns its checker.
116
+ // Within that project the last realpath alias supplies the source, matching the compiler's occurrence order.
109
117
  for (const project of projects) {
110
- for (const sourceFile of project.program.getSourceFiles().filter(file => helpers.isProductionSource(config.root, file))) {
118
+ for (const sourceFile of project.program.getSourceFiles()) {
119
+ if (!helpers.isProductionSource(config.root, sourceFile)) continue;
111
120
  const name = helpers.canonical(sourceFile.fileName);
112
- if (!occurrences.has(name)) occurrences.set(name, []);
113
- occurrences.get(name).push(project);
114
- sourceIn.set(`${project.relative}|${name}`, sourceFile);
121
+ const owner = ownerByFile.get(name);
122
+ if (owner === project) { fileMap.set(name, sourceFile); continue; }
123
+ if (owner && ownershipRank(config, owner, name, helpers) >= ownershipRank(config, project, name, helpers)) continue;
124
+ ownerByFile.set(name, project);
125
+ fileMap.set(name, sourceFile);
115
126
  }
116
127
  }
117
- return { occurrences, sourceIn };
118
- }
119
-
120
- function owningProject(config, candidates, file, helpers) {
121
- return candidates.filter(item => helpers.isInside(path.dirname(path.join(config.root, ...item.relative.split('/'))), file))
122
- .sort((x, y) => y.relative.split('/').length - x.relative.split('/').length)[0] ?? candidates[0];
128
+ return { fileMap, ownerByFile };
123
129
  }
124
130
 
125
131
  function makeFileGraph(config, projects, helpers) {
126
- const { occurrences, sourceIn } = collectProjectFiles(config, projects, helpers);
127
- const fileMap = new Map();
132
+ const { fileMap, ownerByFile } = collectProjectFiles(config, projects, helpers);
128
133
  const checkerByFile = new Map();
129
- const ownerByFile = new Map();
130
- for (const [name, candidates] of occurrences) {
131
- const owner = owningProject(config, candidates, name, helpers);
132
- ownerByFile.set(name, owner);
133
- fileMap.set(name, sourceIn.get(`${owner.relative}|${name}`));
134
- checkerByFile.set(name, owner.program.getTypeChecker());
135
- }
134
+ for (const [name, owner] of ownerByFile) checkerByFile.set(name, owner.program.getTypeChecker());
136
135
  const files = [...fileMap.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([, file]) => file);
137
136
  const edges = new Map([...fileMap.keys()].map(file => [file, []]));
138
137
  for (const [file, sourceFile] of fileMap) {
@@ -142,6 +141,21 @@ function makeFileGraph(config, projects, helpers) {
142
141
  return { fileMap, checkerByFile, ownerByFile, files, edges };
143
142
  }
144
143
 
144
+ // Resolution entries contain failed lookup paths as well as hits. Keep only one bounded batch for the current project;
145
+ // graph edges retain the resolved targets, so rotating this scratch cache changes neither coverage nor findings.
146
+ const RESOLUTION_BATCH_SIZE = 1024;
147
+
148
+ function resolutionCache(state, project) {
149
+ if (state.resolutionProject !== project || state.resolutionCount === RESOLUTION_BATCH_SIZE) {
150
+ state.resolutionProject = project;
151
+ state.resolutionCount = 0;
152
+ state.resolutionCache = state.ts.createModuleResolutionCache(state.config.root,
153
+ file => state.ts.sys.useCaseSensitiveFileNames ? file : file.toLowerCase(), project.options);
154
+ }
155
+ state.resolutionCount += 1;
156
+ return state.resolutionCache;
157
+ }
158
+
145
159
  function addUnprovenFindings(sourceFile, project, references, errors, config, helpers) {
146
160
  for (const item of references.unproven) errors.push({
147
161
  ruleId: 'ARCH_DYNAMIC_DEPENDENCY_UNPROVEN',
@@ -229,7 +243,7 @@ function processReference(from, sourceFile, project, owningWorkspace, reference,
229
243
  const { config, ts, workspaceNames, workspaces, host, errors, helpers } = state;
230
244
  // A workspace package is read at its source, never at its build: the same import resolves whether or not dist exists.
231
245
  const workspaceTarget = workspaces.filter(item => item.root !== helpers.canonical(config.root)).map(item => helpers.workspaceSourceEntry(ts, item, reference.specifier)).find(Boolean);
232
- const resolvedName = workspaceTarget ?? helpers.resolveTypeScriptModule(ts, reference.specifier, sourceFile.fileName, project.options, host);
246
+ const resolvedName = workspaceTarget ?? helpers.resolveTypeScriptModule(ts, reference.specifier, sourceFile.fileName, project.options, host, resolutionCache(state, project));
233
247
  if (!resolvedName) {
234
248
  unresolvedReferenceFinding(reference, sourceFile, project, config, workspaceNames, errors, helpers);
235
249
  return;
@@ -279,7 +293,8 @@ export function contextFromProjects(config, loaded, paths, helpers) {
279
293
  const fileGraph = makeFileGraph(config, projects, helpers);
280
294
  const { edges, workspaces } = dependencyGraph(config, loaded, fileGraph, fileGraph.ownerByFile, errors, helpers);
281
295
  if (projects.length && fileGraph.files.length === 0) errors.push({ ruleId: 'ARCH_NO_SOURCE', message: 'The configured TypeScript projects contain no production TypeScript or JavaScript source.' });
296
+ const { checkerByFile } = fileGraph;
282
297
  return { loaded, errors, files: fileGraph.files, edges, programs: projects.map(item => item.program), program: projects[0]?.program ?? null, projects, ts, workspaces,
283
- checkerFor: file => fileGraph.checkerByFile.get(helpers.canonical(file)) ?? null,
298
+ checkerFor: file => checkerByFile.get(helpers.canonical(file)) ?? null,
284
299
  workspaceOf: file => helpers.workspaceOf(workspaces, helpers.canonical(file)) };
285
300
  }