@flyingrobots/footprint 0.0.0-stage → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +446 -0
- package/LICENSE +202 -0
- package/NOTICE +14 -0
- package/README.md +129 -2
- package/RELEASE.md +14 -0
- package/package.json +47 -4
- package/schemas/footprint.blast_radius.schema.json +218 -0
- package/schemas/footprint.comment.schema.json +60 -0
- package/schemas/footprint.composition.schema.json +67 -0
- package/schemas/footprint.landing.schema.json +98 -0
- package/schemas/footprint.overlap.schema.json +489 -0
- package/skills/footprint/SKILL.md +237 -0
- package/src/args.ts +28 -0
- package/src/bound.ts +134 -0
- package/src/callsites.ts +204 -0
- package/src/cell.ts +11 -0
- package/src/classify.ts +48 -0
- package/src/cli.ts +331 -0
- package/src/comment.ts +291 -0
- package/src/exports.ts +356 -0
- package/src/footprint.ts +95 -0
- package/src/graft.ts +121 -0
- package/src/impact.ts +109 -0
- package/src/landing.ts +316 -0
- package/src/languages.ts +83 -0
- package/src/overlap.ts +274 -0
- package/src/pulls.ts +124 -0
- package/src/remote.ts +177 -0
- package/src/render.ts +604 -0
- package/src/report.ts +53 -0
- package/src/symbols.ts +551 -0
- package/src/systems.ts +175 -0
package/src/render.ts
ADDED
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
// The comment. Format follows the 2026-10-28 reflection: the gut check first, everything else
|
|
2
|
+
// collapsed, and every figure computed rather than estimated.
|
|
3
|
+
|
|
4
|
+
import type { Composition, FileChange } from "./footprint.ts";
|
|
5
|
+
import { mermaidPie } from "./footprint.ts";
|
|
6
|
+
import { classify } from "./classify.ts";
|
|
7
|
+
import { structuralSummary, type StructuralReview } from "./graft.ts";
|
|
8
|
+
import type { BeforeMergeKind, Landing } from "./landing.ts";
|
|
9
|
+
import type { Exports, ExportedSymbol } from "./exports.ts";
|
|
10
|
+
import { surfaceCallSiteRows } from "./exports.ts";
|
|
11
|
+
import { MITIGATION_RULE, NONE_NEEDED, SYSTEM_RULE_DETAIL, groupBySystem, type SystemGroup, type SystemRow } from "./systems.ts";
|
|
12
|
+
import type { UnsupportedLanguage } from "./languages.ts";
|
|
13
|
+
import type { Overlap } from "./overlap.ts";
|
|
14
|
+
import type { SymbolLevel } from "./symbols.ts";
|
|
15
|
+
import { IMPACT_COLUMNS, IMPACT_NOTE, NOT_ASSESSED, type ImpactIndex } from "./impact.ts";
|
|
16
|
+
import { cellText } from "./cell.ts";
|
|
17
|
+
import { BLAST_LIMITS, COMPOSITION_BUDGET, LANDING_BUDGET, REPORT_LIMIT, clamp, shrinkToFit, type BlastLimits, type Rendered } from "./bound.ts";
|
|
18
|
+
|
|
19
|
+
export interface GutCheck {
|
|
20
|
+
readonly headline: string;
|
|
21
|
+
readonly flags: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The one line a reviewer reads. Flags are observations, never verdicts: a large change is not
|
|
26
|
+
* automatically a risky one, and this must not become a gate people game.
|
|
27
|
+
*/
|
|
28
|
+
export function gutCheck(c: Composition, largeFileCount = 40): GutCheck {
|
|
29
|
+
const lines = c.added + c.removed;
|
|
30
|
+
const headline = `${c.files} file${c.files === 1 ? "" : "s"}, +${c.added}/-${c.removed}`;
|
|
31
|
+
const flags: string[] = [];
|
|
32
|
+
|
|
33
|
+
const source = c.byCategory.find((x) => x.category === "source");
|
|
34
|
+
const test = c.byCategory.find((x) => x.category === "test");
|
|
35
|
+
const generated = c.byCategory.find((x) => x.category === "generated");
|
|
36
|
+
|
|
37
|
+
if (c.files >= largeFileCount) {
|
|
38
|
+
flags.push(`**${c.files} files changed.** Worth checking this is the change you meant to make.`);
|
|
39
|
+
}
|
|
40
|
+
if (source !== undefined && test === undefined) {
|
|
41
|
+
flags.push("**Source changed, no tests changed.** Intentional, or missing?");
|
|
42
|
+
}
|
|
43
|
+
if (generated !== undefined && generated.share >= 50) {
|
|
44
|
+
flags.push(
|
|
45
|
+
`**${generated.share}% of changed lines are generated or vendored.** Review the ${
|
|
46
|
+
lines - generated.added - generated.removed
|
|
47
|
+
} hand-written lines; skim the rest.`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (c.byCategory.length === 1 && c.byCategory[0]?.category === "docs") {
|
|
51
|
+
flags.push("Documentation only. No executable surface touched.");
|
|
52
|
+
}
|
|
53
|
+
return { headline, flags };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function table(c: Composition): string {
|
|
57
|
+
const head = "| Kind | Files | +/- | Share |\n| --- | ---: | ---: | ---: |";
|
|
58
|
+
const rows = c.byCategory.map(
|
|
59
|
+
(r) => `| ${r.category} | ${r.files} | +${r.added}/-${r.removed} | ${r.share}% |`,
|
|
60
|
+
);
|
|
61
|
+
const total = `| **total** | **${c.files}** | **+${c.added}/-${c.removed}** | **100%** |`;
|
|
62
|
+
return [head, ...rows, total].join("\n");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function details(summary: string, body: string): string {
|
|
66
|
+
// A blank line after <details> is required or GitHub renders the body as raw HTML.
|
|
67
|
+
return `<details>\n<summary>${summary}</summary>\n\n${body}\n\n</details>`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function render(
|
|
71
|
+
c: Composition,
|
|
72
|
+
changes: readonly FileChange[],
|
|
73
|
+
range: string,
|
|
74
|
+
review?: StructuralReview | null,
|
|
75
|
+
budget: number = COMPOSITION_BUDGET,
|
|
76
|
+
): string {
|
|
77
|
+
const fit = shrinkToFit({ files: FILES_SHOWN, formatting: FORMATTING_SHOWN }, (l) => renderComposition(c, changes, range, review, l.files, l.formatting), budget);
|
|
78
|
+
return clamp(fit.text, budget, "the composition section");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** How many formatting-labelled paths the structural note names before it counts the rest. */
|
|
82
|
+
const FORMATTING_SHOWN = 20;
|
|
83
|
+
|
|
84
|
+
/** How many files the Files list names before it counts the rest. */
|
|
85
|
+
const FILES_SHOWN = 200;
|
|
86
|
+
|
|
87
|
+
function renderComposition(
|
|
88
|
+
c: Composition,
|
|
89
|
+
changes: readonly FileChange[],
|
|
90
|
+
range: string,
|
|
91
|
+
review: StructuralReview | null | undefined,
|
|
92
|
+
filesLimit: number,
|
|
93
|
+
formattingLimit: number,
|
|
94
|
+
): Rendered<"files" | "formatting"> {
|
|
95
|
+
const gut = gutCheck(c);
|
|
96
|
+
const out: string[] = ["## Footprint", "", `**${gut.headline}** · \`${range}\``, ""];
|
|
97
|
+
if (gut.flags.length > 0) out.push(...gut.flags.map((f) => `- ${f}`), "");
|
|
98
|
+
|
|
99
|
+
let formattingSize = 0;
|
|
100
|
+
if (review != null) {
|
|
101
|
+
const s = structuralSummary(review);
|
|
102
|
+
const symbols = s.symbolsAdded + s.symbolsRemoved + s.symbolsChanged;
|
|
103
|
+
out.push(
|
|
104
|
+
`**Structural**, as \`graft struct review\` reads it: ${s.structural} file${s.structural === 1 ? "" : "s"} changed shape` +
|
|
105
|
+
` (+${s.symbolsAdded}/-${s.symbolsRemoved}/~${s.symbolsChanged} symbols), ` +
|
|
106
|
+
`${s.formatting} labelled \`formatting\`.`,
|
|
107
|
+
"",
|
|
108
|
+
);
|
|
109
|
+
const formatting = review.files.filter((f) => f.category === "formatting");
|
|
110
|
+
if (formatting.length > 0) {
|
|
111
|
+
const shown = formatting.slice(0, Math.max(0, formattingLimit));
|
|
112
|
+
const left = formatting.length - shown.length;
|
|
113
|
+
const names = shown.map((f) => `\`${f.path}\``).join(", ") +
|
|
114
|
+
(left > 0 ? `${shown.length > 0 ? ", and " : ""}${left} more formatting-labelled file${left === 1 ? "" : "s"} omitted (the \`files\` field of the receipt and graft's own output name every one)` : "");
|
|
115
|
+
const note =
|
|
116
|
+
`- graft's label, not footprint's claim: it saw no symbol added, removed or changed in ` +
|
|
117
|
+
`${names}. A changed value inside an existing symbol ` +
|
|
118
|
+
`(a rule table, a constant) can carry that label, so read the diff.`;
|
|
119
|
+
formattingSize = note.length;
|
|
120
|
+
out.push(note, "");
|
|
121
|
+
}
|
|
122
|
+
if (review.breakingChanges.length > 0) {
|
|
123
|
+
out.push(`- **${review.breakingChanges.length} breaking change(s)**, as \`graft struct review\` lists them.`, "");
|
|
124
|
+
}
|
|
125
|
+
if (symbols === 0 && s.structural === 0) {
|
|
126
|
+
out.push("- No symbol was added, removed or changed. Nothing's public shape moved.", "");
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
out.push("<sub>Structural analysis unavailable: graft could not be resolved.</sub>", "");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const pie = mermaidPie(c);
|
|
133
|
+
if (pie !== "") out.push(details("Composition", `${pie}\n\n${table(c)}`), "");
|
|
134
|
+
|
|
135
|
+
const byCategory = new Map<string, FileChange[]>();
|
|
136
|
+
for (const f of changes) {
|
|
137
|
+
const k = classify(f.path);
|
|
138
|
+
byCategory.set(k, [...(byCategory.get(k) ?? []), f]);
|
|
139
|
+
}
|
|
140
|
+
// The list is cut at `filesLimit` files, in the order it would be printed, and the cut is
|
|
141
|
+
// stated with its count: a reviewer must not read a short list as the whole change.
|
|
142
|
+
let room = filesLimit;
|
|
143
|
+
const groups: string[] = [];
|
|
144
|
+
for (const [k, fs] of byCategory.entries()) {
|
|
145
|
+
const shown = fs.slice(0, Math.max(0, room));
|
|
146
|
+
room -= shown.length;
|
|
147
|
+
if (shown.length === 0) continue;
|
|
148
|
+
groups.push(`**${k}**\n\n${shown.map((f) => `- \`${f.path}\` ${f.binary ? "(binary)" : `+${f.added}/-${f.removed}`}`).join("\n")}`);
|
|
149
|
+
}
|
|
150
|
+
const omitted = Math.max(0, changes.length - filesLimit);
|
|
151
|
+
if (omitted > 0) {
|
|
152
|
+
groups.push(`<sub>${omitted} more file${omitted === 1 ? "" : "s"} omitted to keep the comment under GitHub's ${REPORT_LIMIT}-character limit; the \`files\` field of the receipt carries every one.</sub>`);
|
|
153
|
+
}
|
|
154
|
+
const listing = groups.join("\n\n");
|
|
155
|
+
const listed = listing === "" ? "" : details(`Files (${c.files})`, listing);
|
|
156
|
+
if (listed !== "") out.push(listed, "");
|
|
157
|
+
|
|
158
|
+
out.push("<sub>Figures computed from `git diff --numstat`. Composition is a sanity check, not a verdict.</sub>");
|
|
159
|
+
return { text: out.join("\n"), sizes: { files: listed.length, formatting: formattingSize } };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const BEFORE_MERGE_LABEL: Record<BeforeMergeKind, string> = {
|
|
163
|
+
migration: "Migration.",
|
|
164
|
+
generated: "Generated files.",
|
|
165
|
+
regenerate: "May need regenerating.",
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The two landing sections of the comment. Separate from `render` and from the composition result:
|
|
170
|
+
* one says what the change is, this says what it takes to land it. The unguarded warning is a
|
|
171
|
+
* GitHub alert because it is the one line here a reader must not scroll past — it is still an
|
|
172
|
+
* observation about paths, not a verdict, and the sentence says which rule found it.
|
|
173
|
+
*/
|
|
174
|
+
export function renderLanding(l: Landing, budget: number = LANDING_BUDGET): string {
|
|
175
|
+
return clamp(shrinkToFit({ rows: LANDING_ROWS_SHOWN }, (x) => landingSection(l, x.rows), budget).text, budget, "the landing section");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** How many before-merge items and after-merge steps are written out before the rest are counted. */
|
|
179
|
+
const LANDING_ROWS_SHOWN = 50;
|
|
180
|
+
|
|
181
|
+
function landingSection(l: Landing, limit: number): Rendered<"rows"> {
|
|
182
|
+
// Opens with a blank line: this follows the composition comment on the same stream, and two
|
|
183
|
+
// Markdown blocks run together without one.
|
|
184
|
+
const out: string[] = ["", "## Before merge", ""];
|
|
185
|
+
if (l.before_merge.unguarded) {
|
|
186
|
+
out.push("> [!WARNING]", `> **Nothing in this change guards it.** ${l.before_merge.unguarded_because}`, "");
|
|
187
|
+
}
|
|
188
|
+
for (const item of l.before_merge.items.slice(0, limit)) out.push(`- **${BEFORE_MERGE_LABEL[item.kind]}** ${item.says}`);
|
|
189
|
+
const itemsLeft = l.before_merge.items.length - Math.min(limit, l.before_merge.items.length);
|
|
190
|
+
if (itemsLeft > 0) out.push(`- <sub>${itemsLeft} more before-merge item${itemsLeft === 1 ? "" : "s"} omitted to keep the comment under GitHub's ${REPORT_LIMIT}-character limit; the landing result line carries every one.</sub>`);
|
|
191
|
+
if (l.before_merge.items.length > 0) out.push("");
|
|
192
|
+
if (!l.before_merge.unguarded && l.before_merge.items.length === 0) out.push(`- ${l.before_merge.unguarded_because}`, "");
|
|
193
|
+
|
|
194
|
+
out.push("## After merge", "", l.after_merge.statement, "");
|
|
195
|
+
const mark = out.length;
|
|
196
|
+
for (const s of l.after_merge.steps.slice(0, limit)) out.push(`- [ ] ${s.step} <sub>— \`${s.file}\` › ${s.heading}</sub>`);
|
|
197
|
+
const left = l.after_merge.steps.slice(limit);
|
|
198
|
+
if (left.length > 0) {
|
|
199
|
+
const files = [...new Set(left.map((s) => s.file))].map((f) => `\`${f}\``).join(", ");
|
|
200
|
+
out.push(`- <sub>${left.length} more step${left.length === 1 ? "" : "s"} omitted to keep the comment under GitHub's ${REPORT_LIMIT}-character limit; read them in ${files} or in the landing result line.</sub>`);
|
|
201
|
+
}
|
|
202
|
+
const size = out.slice(mark).join("\n").length + out.slice(0, mark).filter((x) => x.startsWith("- **")).join("\n").length;
|
|
203
|
+
if (l.after_merge.steps.length > 0) out.push("");
|
|
204
|
+
out.push("<sub>After-merge steps are read from this repository's own `RELEASE.md` and `AGENTS.md`, never invented. The guard rule is path patterns, documented in footprint's `docs/topics/landing/README.md`.</sub>");
|
|
205
|
+
return { text: out.join("\n"), sizes: { rows: size } };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ---- blast radius (flyingrobots/footprint#9) ---------------------------------------------------
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The export-surface section of the comment. One section whatever the outcome: a list when
|
|
212
|
+
* symbols moved, a sentence when none did, and the stated reason when graft could not answer —
|
|
213
|
+
* an absent section would read like a clean one.
|
|
214
|
+
*
|
|
215
|
+
* The section is held to `budget` characters (flyingrobots/footprint#51): when the full rendering
|
|
216
|
+
* is over it, the larger of the symbols table and the call-site tables is cut in half until it
|
|
217
|
+
* fits, and every cut says how many rows it left out. `limits` is where that starts.
|
|
218
|
+
*
|
|
219
|
+
* `impact` is the posting agent's reading of the call sites (`--impact`, flyingrobots/footprint#59):
|
|
220
|
+
* given, every call-site table gains its two columns and the section says whose reading they are;
|
|
221
|
+
* not given, the tables are exactly what they were. The columns count against the same budget.
|
|
222
|
+
*/
|
|
223
|
+
export function blastRadius(
|
|
224
|
+
exports: Exports,
|
|
225
|
+
unanalysed: readonly UnsupportedLanguage[] = [],
|
|
226
|
+
budget: number = REPORT_LIMIT,
|
|
227
|
+
limits: BlastLimits = BLAST_LIMITS,
|
|
228
|
+
impact?: ImpactIndex,
|
|
229
|
+
): string {
|
|
230
|
+
const start = { symbols: limits.symbols, sites: limits.sites };
|
|
231
|
+
return clamp(shrinkToFit(start, (l) => blastSections(exports, unanalysed, { ...limits, ...l }, impact), budget).text, budget, "the blast-radius section");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** One rendering of the section at the given limits, with how much each trimmable part took. */
|
|
235
|
+
function blastSections(exports: Exports, unanalysed: readonly UnsupportedLanguage[], limits: BlastLimits, impact: ImpactIndex | undefined): Rendered<"symbols" | "sites"> {
|
|
236
|
+
const out: string[] = ["## Blast radius", ""];
|
|
237
|
+
const sizes = { symbols: 0, sites: 0 };
|
|
238
|
+
if (!exports.available) {
|
|
239
|
+
out.push(
|
|
240
|
+
`<sub>Export-surface diff unavailable (\`${exports.reason.code}\`): ${exports.reason.detail}.</sub>`,
|
|
241
|
+
"",
|
|
242
|
+
FROM_GRAFT,
|
|
243
|
+
"",
|
|
244
|
+
unanalysedSection(unanalysed),
|
|
245
|
+
);
|
|
246
|
+
return { text: out.join("\n"), sizes };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const s = exports.surface;
|
|
250
|
+
const rows = [
|
|
251
|
+
...s.added.map((x) => ["added", x] as const),
|
|
252
|
+
...s.removed.map((x) => ["removed", x] as const),
|
|
253
|
+
...s.signatureChanged.map((x) => ["signature-changed", x] as const),
|
|
254
|
+
];
|
|
255
|
+
const scan = s.callSiteScan;
|
|
256
|
+
out.push(
|
|
257
|
+
`**+${s.added.length} added / -${s.removed.length} removed / ~${s.signatureChanged.length} signature-changed exported symbols**` +
|
|
258
|
+
` · \`${s.base}\` → \`${s.head}\`` +
|
|
259
|
+
(s.semverImpact === null ? "" : ` · \`graft struct exports\` reads this as a **${s.semverImpact}** change`),
|
|
260
|
+
"",
|
|
261
|
+
);
|
|
262
|
+
if (rows.length === 0) {
|
|
263
|
+
out.push("- No exported symbol was added, removed or re-signed.", "");
|
|
264
|
+
} else {
|
|
265
|
+
const head = scan.available
|
|
266
|
+
? "| Change | Symbol | File | Kind | Call sites | Signature |\n| --- | --- | --- | --- | ---: | --- |"
|
|
267
|
+
: "| Change | Symbol | File | Kind | Signature |\n| --- | --- | --- | --- | --- |";
|
|
268
|
+
// Past the limit the table keeps the symbols whose change matters most -- signature-changed,
|
|
269
|
+
// then removed, then added -- and prints them in the order the full table would.
|
|
270
|
+
const kept = keepFirst(rows, limits.symbols, ([change]) => (change === "signature-changed" ? 0 : change === "removed" ? 1 : 2));
|
|
271
|
+
const body = kept.map(([change, x]) =>
|
|
272
|
+
`| ${change} | \`${x.symbol}\` | \`${x.file}\` | ${x.kind ?? ""} | ` +
|
|
273
|
+
(scan.available ? `${x.callSites === undefined ? "—" : x.callSites.length} | ` : "") +
|
|
274
|
+
`${cell(x.previousSignature === undefined ? x.signature : `${x.previousSignature} → ${x.signature ?? ""}`)} |`,
|
|
275
|
+
);
|
|
276
|
+
const left = rows.length - kept.length;
|
|
277
|
+
const parts = [...(body.length > 0 ? [[head, ...body].join("\n")] : [])];
|
|
278
|
+
if (left > 0) {
|
|
279
|
+
parts.push(
|
|
280
|
+
`<sub>${left} more exported symbol${left === 1 ? "" : "s"} omitted (${kept.length} of ${rows.length} shown, signature-changed and removed first) ` +
|
|
281
|
+
`to keep the comment under GitHub's ${REPORT_LIMIT}-character limit; the blast-radius result line carries every one.</sub>`,
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
const block = details(`Exported symbols (${rows.length})`, parts.join("\n\n"));
|
|
285
|
+
sizes.symbols = block.length;
|
|
286
|
+
out.push(block, "");
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// The call sites themselves, grouped by system: one table per system
|
|
290
|
+
// (flyingrobots/footprint#11). Collapsed, because this is the longest part of the comment, and
|
|
291
|
+
// stated when the scan could not run: an absent list would read as a symbol nothing calls.
|
|
292
|
+
if (!scan.available) {
|
|
293
|
+
out.push(`<sub>Call sites not listed (\`${scan.reason.code}\`): ${scan.reason.detail}.</sub>`, "");
|
|
294
|
+
} else if (rows.length > 0) {
|
|
295
|
+
const siteRows = surfaceCallSiteRows(s);
|
|
296
|
+
const groups = groupBySystem(siteRows);
|
|
297
|
+
const total = rows.reduce((n, [, x]) => n + (x.callSites?.length ?? 0), 0);
|
|
298
|
+
const heavy = heavySymbols(siteRows, limits.summariseAbove);
|
|
299
|
+
const body = [
|
|
300
|
+
...(heavy.length > 0 ? [heavyTable(heavy, limits.summariseAbove, limits.sites, impact)] : []),
|
|
301
|
+
...groups.map((g) => systemTable(g, limits.sites, new Set(heavy.map((h) => h.symbol)), impact)),
|
|
302
|
+
...unreferenced(rows.map(([, x]) => x), limits.sites),
|
|
303
|
+
].join("\n\n");
|
|
304
|
+
const summary =
|
|
305
|
+
`Call sites by system (${total} across ${groups.length} system${groups.length === 1 ? "" : "s"}, ` +
|
|
306
|
+
`${scan.filesScanned} scanned file${scan.filesScanned === 1 ? "" : "s"})`;
|
|
307
|
+
const block = details(summary, body);
|
|
308
|
+
sizes.sites = block.length;
|
|
309
|
+
out.push(block, "");
|
|
310
|
+
if (impact !== undefined) out.push(IMPACT_NOTE, "");
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
out.push(FROM_GRAFT);
|
|
314
|
+
if (scan.available) out.push("", FROM_SCAN, "", FROM_GROUPING);
|
|
315
|
+
out.push("", unanalysedSection(unanalysed));
|
|
316
|
+
return { text: out.join("\n"), sizes };
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* The first `limit` items by `priority` (lower first, ties by position), returned in their
|
|
321
|
+
* original order, so a cut table reads like the full one with rows missing rather than reordered.
|
|
322
|
+
*/
|
|
323
|
+
function keepFirst<T>(items: readonly T[], limit: number, priority: (item: T) => number): T[] {
|
|
324
|
+
if (items.length <= limit) return [...items];
|
|
325
|
+
const chosen = items
|
|
326
|
+
.map((item, index) => ({ index, p: priority(item) }))
|
|
327
|
+
.sort((a, b) => a.p - b.p || a.index - b.index)
|
|
328
|
+
.slice(0, Math.max(0, limit))
|
|
329
|
+
.map((x) => x.index)
|
|
330
|
+
.sort((a, b) => a - b);
|
|
331
|
+
return chosen.map((i) => items[i]!);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** A symbol with more call sites than the summarising threshold, and what it comes to per system. */
|
|
335
|
+
interface HeavySymbol {
|
|
336
|
+
readonly symbol: string;
|
|
337
|
+
readonly total: number;
|
|
338
|
+
readonly bySystem: ReadonlyMap<string, number>;
|
|
339
|
+
/** Call sites whose mitigation is not `None needed`: the ones the skill asks a reader to check. */
|
|
340
|
+
readonly needLook: number;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function heavySymbols(rows: readonly SystemRow[], above: number): HeavySymbol[] {
|
|
344
|
+
if (!Number.isFinite(above)) return [];
|
|
345
|
+
const by = new Map<string, { total: number; bySystem: Map<string, number>; needLook: number }>();
|
|
346
|
+
for (const r of rows) {
|
|
347
|
+
const e = by.get(r.symbol) ?? { total: 0, bySystem: new Map<string, number>(), needLook: 0 };
|
|
348
|
+
e.total += 1;
|
|
349
|
+
e.bySystem.set(r.site.system, (e.bySystem.get(r.site.system) ?? 0) + 1);
|
|
350
|
+
if (r.site.mitigation !== NONE_NEEDED) e.needLook += 1;
|
|
351
|
+
by.set(r.symbol, e);
|
|
352
|
+
}
|
|
353
|
+
return [...by.entries()]
|
|
354
|
+
.filter(([, e]) => e.total > above)
|
|
355
|
+
.map(([symbol, e]) => ({ symbol, ...e }))
|
|
356
|
+
.sort((a, b) => b.total - a.total || a.symbol.localeCompare(b.symbol));
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* The symbols too widely matched to list: one row each, with the count per system. A name such as
|
|
361
|
+
* `type` is a whole-word match in nearly every file, so its sites are not evidence of reach; the
|
|
362
|
+
* count says so, and the result line still carries every site.
|
|
363
|
+
*/
|
|
364
|
+
function heavyTable(heavy: readonly HeavySymbol[], above: number, limit: number, impact: ImpactIndex | undefined): string {
|
|
365
|
+
const shown = heavy.slice(0, Math.max(0, limit));
|
|
366
|
+
const rows = shown.map((h) => {
|
|
367
|
+
const systems = [...h.bySystem.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
368
|
+
const per = systems.map(([sys, n]) => `\`${sys}\` ${n}`).join(", ");
|
|
369
|
+
// A summarised symbol is assessed per system: one line per system it is called in.
|
|
370
|
+
const assessed = (pick: "impact" | "dataFlow") =>
|
|
371
|
+
systems.map(([sys]) => `\`${sys}\`: ${cellText(impact?.forSystem(h.symbol, sys)?.[pick] ?? NOT_ASSESSED)}`).join("<br>");
|
|
372
|
+
return `| \`${h.symbol}\` | ${h.total} | ${per} | ${h.needLook} |` + (impact === undefined ? "" : ` ${assessed("impact")} | ${assessed("dataFlow")} |`);
|
|
373
|
+
});
|
|
374
|
+
const out = [
|
|
375
|
+
`**Symbols with more than ${above} call sites** — counted by system instead of listed, because a name that common matches whole-word almost anywhere. The result line carries every site.`,
|
|
376
|
+
];
|
|
377
|
+
const head = impact === undefined
|
|
378
|
+
? "| Symbol | Call sites | By system | Not `None needed` |\n| --- | ---: | --- | ---: |"
|
|
379
|
+
: `| Symbol | Call sites | By system | Not \`None needed\` | ${IMPACT_COLUMNS.impact} | ${IMPACT_COLUMNS.dataFlow} |\n| --- | ---: | --- | ---: | --- | --- |`;
|
|
380
|
+
if (rows.length > 0) out.push("", `${head}\n${rows.join("\n")}`);
|
|
381
|
+
const left = heavy.length - shown.length;
|
|
382
|
+
if (left > 0) {
|
|
383
|
+
out.push("", `<sub>${left} more symbol${left === 1 ? "" : "s"} with more than ${above} call sites omitted; the blast-radius result line carries every one.</sub>`);
|
|
384
|
+
}
|
|
385
|
+
return out.join("\n");
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* How many call sites of one symbol are spelled out inside one system's table before the comment
|
|
390
|
+
* just says how many more there are. The result line carries every one of them; this is a
|
|
391
|
+
* pull-request comment, and a symbol with four hundred call sites would bury everything else in
|
|
392
|
+
* it. The remainder is a sentence under the table rather than a row, because a row with nothing in
|
|
393
|
+
* its mitigation cell is exactly the padded row flyingrobots/footprint#11 forbids.
|
|
394
|
+
*/
|
|
395
|
+
const CALL_SITES_SHOWN = 20;
|
|
396
|
+
|
|
397
|
+
/** How many symbols one system's table names a capped remainder for, before counting the rest together. */
|
|
398
|
+
const NOTES_SHOWN = 10;
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* One system, one table: a row per call site, each with the mitigation its basis derived. Symbols
|
|
402
|
+
* in `skip` are the summarised ones and have no row here. At most `limit` rows are written; the
|
|
403
|
+
* ones with a mitigation other than `None needed` are kept first, and the rest are counted.
|
|
404
|
+
*/
|
|
405
|
+
function systemTable(group: SystemGroup, limit: number, skip: ReadonlySet<string>, impact: ImpactIndex | undefined): string {
|
|
406
|
+
const head = impact === undefined
|
|
407
|
+
? "| Symbol | Call site | Mitigation |\n| --- | --- | --- |"
|
|
408
|
+
: `| Symbol | Call site | Mitigation | ${IMPACT_COLUMNS.impact} | ${IMPACT_COLUMNS.dataFlow} |\n| --- | --- | --- | --- | --- |`;
|
|
409
|
+
const candidates: SystemRow[] = [];
|
|
410
|
+
const elided = new Map<string, number>();
|
|
411
|
+
let symbol: string | null = null;
|
|
412
|
+
let shown = 0;
|
|
413
|
+
let summarised = 0;
|
|
414
|
+
for (const row of group.rows) {
|
|
415
|
+
if (skip.has(row.symbol)) {
|
|
416
|
+
summarised += 1;
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
if (row.symbol !== symbol) {
|
|
420
|
+
symbol = row.symbol;
|
|
421
|
+
shown = 0;
|
|
422
|
+
}
|
|
423
|
+
shown += 1;
|
|
424
|
+
if (shown <= CALL_SITES_SHOWN) candidates.push(row);
|
|
425
|
+
else elided.set(row.symbol, (elided.get(row.symbol) ?? 0) + 1);
|
|
426
|
+
}
|
|
427
|
+
const kept = keepFirst(candidates, limit, (r) => (r.site.mitigation === NONE_NEEDED ? 1 : 0));
|
|
428
|
+
const assessed = (row: SystemRow): string => {
|
|
429
|
+
if (impact === undefined) return "";
|
|
430
|
+
const a = impact.forRow(row.symbol, row.site.system, row.site.file);
|
|
431
|
+
return ` ${cellText(a?.impact ?? NOT_ASSESSED)} | ${cellText(a?.dataFlow ?? NOT_ASSESSED)} |`;
|
|
432
|
+
};
|
|
433
|
+
const body = kept.map((row) => `| \`${row.symbol}\` | \`${row.site.file}:${row.site.line}\` | ${pipes(row.site.mitigation)} |${assessed(row)}`);
|
|
434
|
+
const title = `**\`${group.system}\`** — ${group.rows.length} call site${group.rows.length === 1 ? "" : "s"}`;
|
|
435
|
+
const notes: string[] = [];
|
|
436
|
+
// One note per capped symbol, up to NOTES_SHOWN of them and never more than the row limit; the
|
|
437
|
+
// symbols past that are counted together, so the total of omitted sites stays exact.
|
|
438
|
+
const all = [...elided.entries()];
|
|
439
|
+
const noted = all.slice(0, Math.max(0, Math.min(limit, NOTES_SHOWN)));
|
|
440
|
+
const rest = noted.map(([sym, n]) => `…and ${n} more for \`${sym}\``);
|
|
441
|
+
const more = all.slice(noted.length);
|
|
442
|
+
if (more.length > 0) {
|
|
443
|
+
const sites = more.reduce((n, [, c]) => n + c, 0);
|
|
444
|
+
rest.push(`…and ${sites} more call site${sites === 1 ? "" : "s"} for ${more.length} more symbol${more.length === 1 ? "" : "s"}`);
|
|
445
|
+
}
|
|
446
|
+
if (rest.length > 0) notes.push(`${rest.join(", ")}; the result line carries every one.`);
|
|
447
|
+
if (summarised > 0) notes.push(`${summarised} call site${summarised === 1 ? "" : "s"} here belong to the symbols counted above rather than listed.`);
|
|
448
|
+
const left = candidates.length - kept.length;
|
|
449
|
+
if (left > 0) {
|
|
450
|
+
const look = candidates.filter((r) => r.site.mitigation !== NONE_NEEDED).length - kept.filter((r) => r.site.mitigation !== NONE_NEEDED).length;
|
|
451
|
+
notes.push(
|
|
452
|
+
`${left} more call site${left === 1 ? "" : "s"} in this system omitted (${look} of them with a mitigation other than \`${NONE_NEEDED}\`) ` +
|
|
453
|
+
`to keep the comment under GitHub's ${REPORT_LIMIT}-character limit; the blast-radius result line carries every one.`,
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
return [title, "", ...(body.length > 0 ? [head, ...body] : []), ...(notes.length === 0 ? [] : ["", `<sub>${notes.join(" ")}</sub>`])].join("\n");
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* The symbols with no call site at all. They belong to no system, so no table holds them, and
|
|
461
|
+
* leaving them out would read as a symbol that was never looked up — which is a different claim
|
|
462
|
+
* from one nothing references.
|
|
463
|
+
*/
|
|
464
|
+
function unreferenced(symbols: readonly ExportedSymbol[], limit: number): string[] {
|
|
465
|
+
const none = symbols.filter((x) => x.callSites !== undefined && x.callSites.length === 0).map((x) => `\`${x.symbol}\``);
|
|
466
|
+
const missing = symbols.filter((x) => x.callSites === undefined).map((x) => `\`${x.symbol}\``);
|
|
467
|
+
const names = (all: readonly string[]): string => {
|
|
468
|
+
const shown = all.slice(0, Math.max(0, limit));
|
|
469
|
+
const left = all.length - shown.length;
|
|
470
|
+
if (left === 0) return shown.join(", ");
|
|
471
|
+
return `${shown.length > 0 ? `${shown.join(", ")} and ` : ""}${left} more omitted (the blast-radius result line names every one)`;
|
|
472
|
+
};
|
|
473
|
+
const out: string[] = [];
|
|
474
|
+
if (none.length > 0) out.push(`<sub>No call site found in the tracked files for ${names(none)}.</sub>`);
|
|
475
|
+
if (missing.length > 0) out.push(`<sub>Not scanned, and so in no system: ${names(missing)}. The scan carries no entry for them.</sub>`);
|
|
476
|
+
return out;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** A table cell cannot carry a pipe. Mitigations are derived from paths, which may hold one. */
|
|
480
|
+
function pipes(text: string): string {
|
|
481
|
+
return text.replace(/\|/g, "\\|");
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const FROM_GROUPING = `<sub>**The grouping.** ${SYSTEM_RULE_DETAIL} **The mitigations.** ${MITIGATION_RULE}</sub>`;
|
|
485
|
+
|
|
486
|
+
const FROM_SCAN =
|
|
487
|
+
"<sub>Call sites are footprint's own whole-word identifier scan, not graft's: every whole-word occurrence of the name in the tracked, non-binary files of the working tree (`grep -w`'s boundary -- a letter, digit or underscore in any script). It counts the declaration itself and a mention in a comment, a string or prose, and it cannot see a call through dynamic dispatch or a re-export under another name. Evidence to check, not a call graph.</sub>";
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* The languages this change could not have been symbol-analysed in, independent of whether graft
|
|
491
|
+
* itself ran: present whether the exports section above succeeded, failed, or was unavailable
|
|
492
|
+
* (flyingrobots/footprint#12).
|
|
493
|
+
*/
|
|
494
|
+
function unanalysedSection(unanalysed: readonly UnsupportedLanguage[]): string {
|
|
495
|
+
if (unanalysed.length === 0) {
|
|
496
|
+
return "<sub>Every changed source file was in a language footprint recognises graft's grammars can parse.</sub>";
|
|
497
|
+
}
|
|
498
|
+
const total = unanalysed.reduce((n, u) => n + u.count, 0);
|
|
499
|
+
const byExtension = unanalysed.map((u) => `${u.count} \`${u.extension}\``).join(", ");
|
|
500
|
+
return `**${total} changed file${total === 1 ? "" : "s"} in unanalysed language${unanalysed.length === 1 ? "" : "s"}:** ${byExtension}.`;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const FROM_GRAFT =
|
|
504
|
+
"<sub>Exported symbols from `graft struct exports --json` (`graft.cli.struct_exports` 1.0.0). Whatever graft parses counts as an export surface, including fields in config and lock files.</sub>";
|
|
505
|
+
|
|
506
|
+
/** A signature is verbatim in the result; a table cell cannot carry its newlines or pipes. */
|
|
507
|
+
function cell(signature: string | undefined): string {
|
|
508
|
+
if (signature === undefined) return "";
|
|
509
|
+
return `\`${signature.replace(/\s+/g, " ").replace(/\|/g, "\\|").trim()}\``;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* The cross-pull-request section of the comment, rendered from the same record the
|
|
514
|
+
* `footprint.overlap` result carries. It is its own section with its own provenance note, so the
|
|
515
|
+
* composition section above stays exactly what it was.
|
|
516
|
+
*/
|
|
517
|
+
export function renderOverlap(o: Overlap, budget: number = REPORT_LIMIT): string {
|
|
518
|
+
return clamp(shrinkToFit({ pulls: PULLS_SHOWN }, (l) => overlapSection(o, l.pulls), budget).text, budget, "the overlap section");
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** How many pull requests, conflicts and waves the overlap section names before it counts the rest. */
|
|
522
|
+
const PULLS_SHOWN = 50;
|
|
523
|
+
/** How many shared files one overlapping pull request lists. */
|
|
524
|
+
const SHARED_FILES_SHOWN = 10;
|
|
525
|
+
/** How many symbols of one side of one shared file the section names. */
|
|
526
|
+
const SYMBOLS_SHOWN = 5;
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* The symbol level of one overlap or edge, one nested bullet per shared file: the symbols each
|
|
530
|
+
* side changes when disjoint, the shared ones when overlapping, the reason when undetermined.
|
|
531
|
+
* Bounded like the file list it sits under, and each cut says how many it left out.
|
|
532
|
+
*/
|
|
533
|
+
function symbolLines(level: SymbolLevel, a: string, b: string, limit: number, indent: string): string[] {
|
|
534
|
+
const cap = Math.min(limit, SHARED_FILES_SHOWN);
|
|
535
|
+
const names = (xs: readonly string[]): string => {
|
|
536
|
+
if (xs.length === 0) return "no symbol";
|
|
537
|
+
const shown = xs.slice(0, Math.min(limit, SYMBOLS_SHOWN));
|
|
538
|
+
const left = xs.length - shown.length;
|
|
539
|
+
return shown.map((x) => `\`${x}\``).join(", ") + (left > 0 ? ` and ${left} more` : "");
|
|
540
|
+
};
|
|
541
|
+
const out = level.files.slice(0, cap).map((f) => {
|
|
542
|
+
const via = f.github === undefined ? "" : ` <sub>(${f.github.map((x) => (x === "a" ? a : b)).join(" and ")} read over the GitHub API)</sub>`;
|
|
543
|
+
if (f.level === "symbol-disjoint") return `${indent}- \`${f.path}\`: different symbols — ${a} ${names(f.a!.symbols)}; ${b} ${names(f.b!.symbols)}${via}`;
|
|
544
|
+
if (f.level === "symbol-overlapping") return `${indent}- \`${f.path}\`: the same symbols — ${names(f.shared!)}${via}`;
|
|
545
|
+
return `${indent}- \`${f.path}\`: symbol level undetermined — ${f.reason}`;
|
|
546
|
+
});
|
|
547
|
+
const left = level.files.length - Math.min(level.files.length, cap);
|
|
548
|
+
if (left > 0) out.push(`${indent}- <sub>${left} more shared file${left === 1 ? "" : "s"} at the symbol level omitted; the overlap result line carries every one.</sub>`);
|
|
549
|
+
return out;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function overlapSection(o: Overlap, limit: number): Rendered<"pulls"> {
|
|
553
|
+
// The leading blank line keeps the heading off the end of the composition section above it.
|
|
554
|
+
const out: string[] = ["", "### Open pull requests", ""];
|
|
555
|
+
const omitted = (n: number, what: string): string =>
|
|
556
|
+
`<sub>${n} more ${what} omitted to keep the comment under GitHub's ${REPORT_LIMIT}-character limit; the overlap result line carries every one.</sub>`;
|
|
557
|
+
|
|
558
|
+
if (!o.available) {
|
|
559
|
+
out.push(`<sub>${o.summary}</sub>`);
|
|
560
|
+
const text = out.join("\n");
|
|
561
|
+
return { text, sizes: { pulls: 0 } };
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
out.push(`**${o.summary}**`, "");
|
|
565
|
+
|
|
566
|
+
const files = (fs: readonly string[]): string => {
|
|
567
|
+
const shown = fs.slice(0, Math.min(limit, SHARED_FILES_SHOWN));
|
|
568
|
+
const left = fs.length - shown.length;
|
|
569
|
+
return shown.map((f) => `\`${f}\``).join(", ") + (left > 0 ? ` and ${left} more file${left === 1 ? "" : "s"}` : "");
|
|
570
|
+
};
|
|
571
|
+
for (const p of o.overlapping.slice(0, limit)) {
|
|
572
|
+
out.push(`- **#${p.number}** ${p.title}${p.isDraft ? " _(draft)_" : ""} — ${files(p.sharedFiles)}`);
|
|
573
|
+
out.push(...symbolLines(p.symbolLevel, "this change", `#${p.number}`, limit, " "));
|
|
574
|
+
}
|
|
575
|
+
if (o.overlapping.length > limit) out.push("", omitted(o.overlapping.length - limit, `pull request${o.overlapping.length - limit === 1 ? "" : "s"}`));
|
|
576
|
+
if (o.overlapping.length > 0) out.push("");
|
|
577
|
+
|
|
578
|
+
for (const u of o.undetermined.slice(0, limit)) out.push(`- **#${u.number}** ${u.title} — files unknown: ${u.reason}`);
|
|
579
|
+
if (o.undetermined.length > limit) out.push("", omitted(o.undetermined.length - limit, `pull requests whose files are unknown`));
|
|
580
|
+
if (o.undetermined.length > 0) out.push("");
|
|
581
|
+
|
|
582
|
+
if (o.waves.length > 0) {
|
|
583
|
+
const waves = o.waves
|
|
584
|
+
.slice(0, limit)
|
|
585
|
+
.map((w) => `**Wave ${w.wave}** — ${w.pullRequests.map((n) => `#${n}`).join(", ")}${w.wave === 1 ? "" : `, after wave ${w.wave - 1}`}`)
|
|
586
|
+
.join("\n\n");
|
|
587
|
+
const edges = o.conflicts.length === 0
|
|
588
|
+
? "No two open pull requests change the same file, so they can land in any order."
|
|
589
|
+
: o.conflicts.slice(0, limit).map((c) => [`- ${c.reason}`, ...symbolLines(c.symbolLevel, `#${c.a}`, `#${c.b}`, limit, " ")].join("\n")).join("\n");
|
|
590
|
+
const notes = [
|
|
591
|
+
...(o.waves.length > limit ? [omitted(o.waves.length - limit, `wave${o.waves.length - limit === 1 ? "" : "s"}`)] : []),
|
|
592
|
+
...(o.conflicts.length > limit ? [omitted(o.conflicts.length - limit, `conflict${o.conflicts.length - limit === 1 ? "" : "s"}`)] : []),
|
|
593
|
+
];
|
|
594
|
+
const disjoint = o.conflicts.filter((c) => c.symbolLevel.level === "symbol-disjoint").length;
|
|
595
|
+
const rule = disjoint === 0 ? "" : `<sub>${disjoint} symbol-disjoint edge${disjoint === 1 ? " is" : "s are"} listed but ${disjoint === 1 ? "does" : "do"} not separate waves; that is not a claim git will merge the two cleanly.</sub>`;
|
|
596
|
+
out.push(details(`Proposed merge order (${o.waves.length} wave${o.waves.length === 1 ? "" : "s"})`, [waves, edges, rule, ...notes].filter((x) => x !== "").join("\n\n")), "");
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
if (o.truncated) out.push(`<sub>The pull-request list came back at the ${o.limit}-request limit; there may be more.</sub>`, "");
|
|
600
|
+
out.push("<sub>Pull requests from `gh pr list`; their files from `gh pr diff --name-only`; the symbols of a shared file from `git diff -U0` against each side's merge base and the top-level symbols of `graft read outline` at both ends" +
|
|
601
|
+
` (${o.symbolAnalysis.outlinesRun} of at most ${o.symbolAnalysis.outlineBudget} outline calls${o.symbolAnalysis.remoteCalls > 0 ? ` and ${o.symbolAnalysis.remoteCalls} read-only \`gh api\` calls for pull requests not in the clone` : ""} this run). Merge waves are greedy first-fit over the conflict graph: a proposal, not a minimum, and not a gate.</sub>`);
|
|
602
|
+
const text = out.join("\n");
|
|
603
|
+
return { text, sizes: { pulls: text.length } };
|
|
604
|
+
}
|
package/src/report.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// The result record: what a run answers with, on stdout and in the receipt. Semantic content only
|
|
2
|
+
// goes into the digest (spec §7.1), so two runs over the same range and tree compare equal.
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { canonical, sha256 } from "@flyingrobots/parley-emit";
|
|
6
|
+
import type { Composition } from "./footprint.ts";
|
|
7
|
+
import { structuralSummary, type StructuralReview } from "./graft.ts";
|
|
8
|
+
import type { Landing } from "./landing.ts";
|
|
9
|
+
import type { Overlap } from "./overlap.ts";
|
|
10
|
+
import type { GutCheck } from "./render.ts";
|
|
11
|
+
|
|
12
|
+
export const COMPOSITION_SCHEMA = JSON.parse(readFileSync(join(import.meta.dir, "../schemas/footprint.composition.schema.json"), "utf8")) as Record<string, unknown>;
|
|
13
|
+
export const COMPOSITION_TYPE = { id: "footprint.composition", version: "1.0.0" } as const;
|
|
14
|
+
export const LANDING_SCHEMA = JSON.parse(readFileSync(join(import.meta.dir, "../schemas/footprint.landing.schema.json"), "utf8")) as Record<string, unknown>;
|
|
15
|
+
export const LANDING_TYPE = { id: "footprint.landing", version: "1.0.0" } as const;
|
|
16
|
+
export const OVERLAP_SCHEMA = JSON.parse(readFileSync(join(import.meta.dir, "../schemas/footprint.overlap.schema.json"), "utf8")) as Record<string, unknown>;
|
|
17
|
+
export const OVERLAP_TYPE = { id: "footprint.overlap", version: "2.2.0" } as const;
|
|
18
|
+
|
|
19
|
+
export interface Structural {
|
|
20
|
+
readonly available: boolean;
|
|
21
|
+
readonly structural?: number;
|
|
22
|
+
readonly formatting?: number;
|
|
23
|
+
readonly symbolsAdded?: number;
|
|
24
|
+
readonly symbolsRemoved?: number;
|
|
25
|
+
readonly symbolsChanged?: number;
|
|
26
|
+
readonly breakingChanges?: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function structuralOf(review: StructuralReview | null): Structural {
|
|
30
|
+
if (review === null) return { available: false };
|
|
31
|
+
return { available: true, ...structuralSummary(review), breakingChanges: review.breakingChanges };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function compositionRecord(range: string, composition: Composition, gut: GutCheck, review: StructuralReview | null) {
|
|
35
|
+
const semantic = { range, composition, gut_check: gut, structural: structuralOf(review) };
|
|
36
|
+
return { event: "result", ...semantic, digest: sha256(canonical(semantic)) };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The landing plan's own result, emitted in the same run after the composition (spec §7.1). */
|
|
40
|
+
export function landingRecord(range: string, landing: Landing) {
|
|
41
|
+
const semantic = { range, before_merge: landing.before_merge, after_merge: landing.after_merge };
|
|
42
|
+
return { event: "result", ...semantic, digest: sha256(canonical(semantic)) };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The overlap result, the last of the run's four, after the blast radius. Its digest covers the
|
|
47
|
+
* live state of the open pull requests, so — unlike the composition's — it moves when they move,
|
|
48
|
+
* under the same `inv`.
|
|
49
|
+
*/
|
|
50
|
+
export function overlapRecord(range: string, overlap: Overlap) {
|
|
51
|
+
const semantic = { range, overlap };
|
|
52
|
+
return { event: "result", ...semantic, digest: sha256(canonical(semantic)) };
|
|
53
|
+
}
|