gitsona 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kanywst
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,121 @@
1
- # Temporary Holding Version
1
+ # gitsona
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Draws your GitHub profile README from what you actually do on GitHub. One command, no hosted service.
4
+
5
+ ```sh
6
+ npx gitsona
7
+ ```
8
+
9
+ To run the unreleased code on `main` instead, use `npx --allow-git=all github:kanywst/gitsona`. `--allow-git=all` is needed on npm 12 and later, which refuses packages fetched from git by default. Older npm ignores it.
10
+
11
+ It reads your public activity, works out what you build and how you work, and writes a `README.md` and a folder of SVGs to `./<you>`. Push that folder to your `<you>/<you>` repository and it shows on your profile.
12
+
13
+ <picture>
14
+ <source media="(prefers-color-scheme: dark)" srcset="docs/example/hero-dark.svg">
15
+ <img alt="Example hero: a contour map of the last 12 months of contributions next to the name kt, the headline Security, authorization and AI agents, and four numbers" src="docs/example/hero-light.svg" width="100%">
16
+ </picture>
17
+
18
+ The example above and below is the author's own profile, drawn from live data.
19
+
20
+ ## What it draws
21
+
22
+ | Section | What it shows | Where it comes from |
23
+ | --- | --- | --- |
24
+ | Hero | Headline, one-line summary, four numbers, and the last 12 months as contour relief | Topics and descriptions of your repos, languages by bytes, contribution calendar |
25
+ | Working style | Own repos or upstream, specialist or generalist, in bursts or every day, few or many projects | Each spectrum prints the numbers that placed the marker |
26
+ | Rhythm | Weekday by hour of your commits, and commits per month | A year of commit search, read in each commit's own time zone |
27
+ | Projects | Cards for notable repositories you have not pinned, since GitHub shows pins right below | Stars, releases, recent pushes and fit with your main domains |
28
+ | Languages over time | The language mix of repositories created each year | Language bytes per repository |
29
+ | Upstream | Projects owned by others where your pull requests were merged | PR search, with your own organizations left out |
30
+
31
+ <picture>
32
+ <source media="(prefers-color-scheme: dark)" srcset="docs/example/traits-dark.svg">
33
+ <img alt="Working style: four spectra with evidence, such as 64 merged PRs across 46 projects owned by others" src="docs/example/traits-light.svg" width="100%">
34
+ </picture>
35
+
36
+ <picture>
37
+ <source media="(prefers-color-scheme: dark)" srcset="docs/example/rhythm-dark.svg">
38
+ <img alt="Rhythm: a weekday by hour dot grid with the 22:00 to 02:00 window highlighted, labelled Night owl" src="docs/example/rhythm-light.svg" width="100%">
39
+ </picture>
40
+
41
+ <picture>
42
+ <source media="(prefers-color-scheme: dark)" srcset="docs/example/upstream-dark.svg">
43
+ <img alt="Upstream: merged pull requests per project, led by dexidp/dex and spiffe/spire" src="docs/example/upstream-light.svg" width="100%">
44
+ </picture>
45
+
46
+ ## Usage
47
+
48
+ ```sh
49
+ npx gitsona [user] [options]
50
+ ```
51
+
52
+ With no user, it draws the account behind your token. The token comes from `GITHUB_TOKEN`, `GH_TOKEN`, or `gh auth token`.
53
+
54
+ | Option | Effect |
55
+ | --- | --- |
56
+ | `-o, --out <dir>` | Output directory. Defaults to `./<user>`, or `.` inside a `<user>/<user>` checkout |
57
+ | `--preview` | Also write `gitsona-preview.html`, a local page framed like a GitHub profile with a light/dark switch |
58
+ | `--push` | Create `<user>/<user>` if needed, commit and push. Asks before each step unless `-y` |
59
+ | `--action` | Add a weekly workflow that redraws the profile |
60
+ | `--sections <list>` | Pick and order sections: `hero,traits,rhythm,projects,strata,upstream` |
61
+ | `--font <name>` | Typeface preset, see below. Defaults to `pixel` |
62
+ | `--display-font <file>` | Use your own `.ttf` or `.otf` for the name and headlines |
63
+ | `--accent <hex>` | Accent colour. Defaults to your top language's colour |
64
+ | `--private` | Let private repositories count toward language and topic stats. Their names are never drawn |
65
+ | `--no-motion` | Skip the contour draw-in on the hero |
66
+ | `--no-cursor` | Leave out the accent `_` after your name |
67
+ | `--save-raw <file>`, `--from-raw <file>` | Save the fetched data, or render from it without calling GitHub |
68
+
69
+ `gitsona --help` lists everything.
70
+
71
+ ## Typefaces
72
+
73
+ Six presets ship with the package, all under the SIL Open Font License. The first face sets the name and headlines, the second the text and numbers.
74
+
75
+ | `--font` | Faces |
76
+ | --- | --- |
77
+ | `pixel` | Pixelify Sans, Geist Mono |
78
+ | `geist` | Geist Mono and Geist, Geist Mono |
79
+ | `mono` | Geist Mono throughout |
80
+ | `grotesk` | Space Grotesk, Space Mono |
81
+ | `rounded` | Rubik throughout |
82
+ | `retro` | Departure Mono, Geist Mono |
83
+
84
+ ![pixel](docs/fonts/pixel.svg)
85
+
86
+ ![geist](docs/fonts/geist.svg)
87
+
88
+ ![mono](docs/fonts/mono.svg)
89
+
90
+ ![grotesk](docs/fonts/grotesk.svg)
91
+
92
+ ![rounded](docs/fonts/rounded.svg)
93
+
94
+ ![retro](docs/fonts/retro.svg)
95
+
96
+ ## Re-running
97
+
98
+ The generated part of `README.md` sits between `<!-- gitsona:start -->` and `<!-- gitsona:end -->`. Anything you write outside those markers stays. A README without markers keeps its old content below the new block; `--replace` overwrites it instead.
99
+
100
+ With `--action`, a workflow redraws the profile every Monday and commits only when something changed. It runs the gitsona version that wrote it, so a new release never changes your profile on its own; run `--action` again to move to it. The default `GITHUB_TOKEN` sees public activity. For private contribution counts, add a token with read access to your repositories as the `GITSONA_TOKEN` secret.
101
+
102
+ ## Notes
103
+
104
+ - The images make no outside requests. Text is drawn as glyph outlines shaped with HarfBuzz, because GitHub serves README images under a CSP that can block embedded fonts. Characters outside the chosen faces, such as a name in kanji, fall back to the viewer's system font.
105
+ - The GitHub mobile app ignores `<picture>` and always shows the light images.
106
+ - Commit search only covers default branches. The rhythm panel is a sample of up to 100 commits per month, so it describes habits, not totals.
107
+
108
+ ## Development
109
+
110
+ ```sh
111
+ bun install
112
+ bun test
113
+ bun src/cli.ts <user> --preview
114
+ scripts/shot.sh out/<user>/gitsona/*.svg
115
+ ```
116
+
117
+ `scripts/shot.sh` renders SVGs to PNG with headless Chromium for a visual check.
118
+
119
+ ## License
120
+
121
+ MIT. The bundled fonts are under the SIL Open Font License 1.1; see `fonts/`.
@@ -0,0 +1,386 @@
1
+ import { DOMAINS, domainById, domainVotes, tokens } from "./taxonomy.js";
2
+ const DAY = 86_400_000;
3
+ const FALLBACK_COLOR = "#8b949e";
4
+ // Generic domains are everywhere (most repos are a CLI or a web page); they only lead when nothing else does.
5
+ const DOMAIN_DAMPING = { devtools: 0.45, web: 0.6, knowledge: 0.8 };
6
+ export function isRetired(r) {
7
+ const d = (r.description ?? "").toLowerCase();
8
+ return (r.isArchived || /^\[(deprecated|merged into|moved|archived)/.test(d) || /^(moved to|pointer to|deprecated)/.test(d));
9
+ }
10
+ export function analyze(raw, now = new Date(raw.fetchedAt)) {
11
+ const login = raw.user.login;
12
+ const ownOrgs = new Set(raw.user.orgs.map((o) => o.toLowerCase()));
13
+ const repos = raw.repos.filter((r) => !r.isFork && r.name.toLowerCase() !== login.toLowerCase());
14
+ const live = repos.filter((r) => !isRetired(r));
15
+ const languages = languageShares(repos);
16
+ const domains = scoreDomains(live, now);
17
+ const lastYear = lastYearStats(raw, now);
18
+ const upstream = upstreamStats(raw.prs, ownOrgs, raw.externalIssues);
19
+ const rhythm = rhythmStats(raw);
20
+ const traits = buildTraits(raw, { languages, domains, lastYear, upstream, live, now });
21
+ const accent = languages[0]?.color ?? "#5fb3a1";
22
+ const headline = buildHeadline(domains);
23
+ const summary = buildSummary(domains, languages, upstream);
24
+ return {
25
+ login,
26
+ displayName: raw.user.name?.trim() || login,
27
+ bio: raw.user.bio?.trim() || null,
28
+ website: raw.user.websiteUrl,
29
+ twitter: raw.user.twitter,
30
+ avatarUrl: raw.user.avatarUrl,
31
+ joined: raw.user.createdAt,
32
+ accent,
33
+ headline,
34
+ summary,
35
+ domains,
36
+ languages,
37
+ strata: strata(repos),
38
+ lastYear,
39
+ lifetime: lifetimeStats(raw),
40
+ traits,
41
+ rhythm,
42
+ upstream,
43
+ landmarks: pickLandmarks(raw, live, domains, now),
44
+ recent: live
45
+ .filter((r) => !r.isPrivate && r.pushedAt && now.getTime() - Date.parse(r.pushedAt) < 30 * DAY)
46
+ .sort((a, b) => Date.parse(b.pushedAt) - Date.parse(a.pushedAt))
47
+ .slice(0, 4),
48
+ totals: {
49
+ stars: repos.reduce((s, r) => s + r.stars, 0),
50
+ repos: repos.length,
51
+ releases: repos.reduce((s, r) => s + r.releases, 0),
52
+ followers: raw.user.followers,
53
+ },
54
+ generatedAt: raw.fetchedAt,
55
+ };
56
+ }
57
+ export function languageShares(repos) {
58
+ const bytes = new Map();
59
+ for (const r of repos) {
60
+ for (const l of r.languages) {
61
+ const cur = bytes.get(l.name) ?? { color: l.color ?? FALLBACK_COLOR, bytes: 0 };
62
+ cur.bytes += l.size;
63
+ bytes.set(l.name, cur);
64
+ }
65
+ }
66
+ const total = [...bytes.values()].reduce((s, v) => s + v.bytes, 0) || 1;
67
+ return [...bytes.entries()]
68
+ .map(([name, v]) => ({ name, color: v.color, bytes: v.bytes, share: v.bytes / total }))
69
+ .sort((a, b) => b.bytes - a.bytes);
70
+ }
71
+ function scoreDomains(repos, now) {
72
+ const score = new Map();
73
+ for (const r of repos) {
74
+ const votes = domainVotes(r.topics, tokens(`${r.name} ${r.description ?? ""}`));
75
+ const sum = [...votes.values()].reduce((a, b) => a + b, 0);
76
+ if (!sum)
77
+ continue;
78
+ const age = r.pushedAt ? (now.getTime() - Date.parse(r.pushedAt)) / DAY : 9999;
79
+ const weight = (1 + Math.log2(1 + r.stars) * 0.5) * (age < 365 ? 1.5 : 1);
80
+ for (const [id, v] of votes) {
81
+ score.set(id, (score.get(id) ?? 0) + (v / sum) * weight * (DOMAIN_DAMPING[id] ?? 1));
82
+ }
83
+ }
84
+ const total = [...score.values()].reduce((a, b) => a + b, 0) || 1;
85
+ return [...score.entries()]
86
+ .map(([id, s]) => ({ id, label: domainById(id).label, share: s / total }))
87
+ .sort((a, b) => b.share - a.share);
88
+ }
89
+ function strata(repos) {
90
+ const byYear = new Map();
91
+ for (const r of repos) {
92
+ const y = new Date(r.createdAt).getUTCFullYear();
93
+ byYear.set(y, [...(byYear.get(y) ?? []), r]);
94
+ }
95
+ return [...byYear.entries()]
96
+ .sort((a, b) => a[0] - b[0])
97
+ .map(([year, rs]) => {
98
+ const parts = languageShares(rs);
99
+ return { year, bytes: parts.reduce((s, p) => s + p.bytes, 0), repos: rs.length, parts };
100
+ })
101
+ .filter((s) => s.bytes > 0);
102
+ }
103
+ function allDays(raw) {
104
+ const m = new Map();
105
+ for (const y of raw.years)
106
+ for (const d of y.days)
107
+ m.set(d.date, d.count);
108
+ return [...m.entries()].map(([date, count]) => ({ date, count })).sort((a, b) => a.date.localeCompare(b.date));
109
+ }
110
+ function streaks(days) {
111
+ let longest = 0;
112
+ let run = 0;
113
+ for (const d of days) {
114
+ run = d.count > 0 ? run + 1 : 0;
115
+ longest = Math.max(longest, run);
116
+ }
117
+ // Today may still be empty without breaking the streak.
118
+ let current = 0;
119
+ for (let i = days.length - 1; i >= 0; i--) {
120
+ if (days[i].count > 0)
121
+ current++;
122
+ else if (i === days.length - 1)
123
+ continue;
124
+ else
125
+ break;
126
+ }
127
+ return { longest, current };
128
+ }
129
+ function lastYearStats(raw, now) {
130
+ const today = now.toISOString().slice(0, 10);
131
+ const from = new Date(now.getTime() - 364 * DAY).toISOString().slice(0, 10);
132
+ const days = allDays(raw).filter((d) => d.date >= from && d.date <= today);
133
+ const { longest, current } = streaks(days);
134
+ const wd = new Array(7).fill(0);
135
+ for (const d of days)
136
+ wd[(new Date(`${d.date}T00:00:00Z`).getUTCDay() + 6) % 7] += d.count;
137
+ const peak = days.reduce((p, d) => (d.count > p.count ? d : p), days[0] ?? { date: today, count: 0 });
138
+ return {
139
+ days,
140
+ total: days.reduce((s, d) => s + d.count, 0),
141
+ activeDays: days.filter((d) => d.count > 0).length,
142
+ longestStreak: longest,
143
+ currentStreak: current,
144
+ peak,
145
+ busiestWeekday: wd.indexOf(Math.max(...wd)),
146
+ };
147
+ }
148
+ function lifetimeStats(raw) {
149
+ const days = allDays(raw);
150
+ return {
151
+ contributions: days.reduce((s, d) => s + d.count, 0),
152
+ commits: raw.years.reduce((s, y) => s + y.commits, 0),
153
+ prs: raw.years.reduce((s, y) => s + y.pullRequests, 0),
154
+ reviews: raw.years.reduce((s, y) => s + y.reviews, 0),
155
+ issues: raw.years.reduce((s, y) => s + y.issues, 0),
156
+ longestStreak: streaks(days).longest,
157
+ };
158
+ }
159
+ function upstreamStats(prs, ownOrgs, issues) {
160
+ const external = prs.filter((p) => !ownOrgs.has(p.owner.toLowerCase()));
161
+ const byRepo = new Map();
162
+ for (const p of external) {
163
+ if (p.state === "CLOSED")
164
+ continue;
165
+ const cur = byRepo.get(p.repo) ?? {
166
+ repo: p.repo,
167
+ owner: p.owner,
168
+ ownerAvatar: p.ownerAvatar,
169
+ merged: 0,
170
+ open: 0,
171
+ stars: p.repoStars,
172
+ firstAt: p.createdAt,
173
+ lastAt: p.createdAt,
174
+ };
175
+ if (p.state === "MERGED")
176
+ cur.merged++;
177
+ else
178
+ cur.open++;
179
+ if (p.createdAt < cur.firstAt)
180
+ cur.firstAt = p.createdAt;
181
+ if (p.createdAt > cur.lastAt)
182
+ cur.lastAt = p.createdAt;
183
+ byRepo.set(p.repo, cur);
184
+ }
185
+ const orgs = new Map();
186
+ for (const p of prs) {
187
+ if (ownOrgs.has(p.owner.toLowerCase()) && p.state === "MERGED")
188
+ orgs.set(p.owner, (orgs.get(p.owner) ?? 0) + 1);
189
+ }
190
+ return {
191
+ merged: external.filter((p) => p.state === "MERGED").length,
192
+ open: external.filter((p) => p.state === "OPEN").length,
193
+ projects: [...byRepo.values()].filter((p) => p.merged > 0).sort((a, b) => b.merged - a.merged || b.stars - a.stars),
194
+ recentMerged: external
195
+ .filter((p) => p.state === "MERGED" && p.mergedAt)
196
+ .sort((a, b) => b.mergedAt.localeCompare(a.mergedAt)),
197
+ orgsRun: [...orgs.entries()].map(([org, merged]) => ({ org, merged })).sort((a, b) => b.merged - a.merged),
198
+ issues,
199
+ };
200
+ }
201
+ /** Parses "2026-11-16T00:55:35.000+09:00" into local weekday/hour as the author saw them. */
202
+ export function localTime(iso) {
203
+ const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):/.exec(iso);
204
+ if (!m)
205
+ return null;
206
+ // A "Z" suffix means the offset was lost; the wall-clock fields are still the best we have.
207
+ const date = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3]));
208
+ return { weekday: (date.getUTCDay() + 6) % 7, hour: +m[4] };
209
+ }
210
+ const fmtHour = (h) => `${String(((h % 24) + 24) % 24).padStart(2, "0")}:00`;
211
+ function rhythmStats(raw) {
212
+ const grid = Array.from({ length: 7 }, () => new Array(24).fill(0));
213
+ const hours = new Array(24).fill(0);
214
+ let samples = 0;
215
+ for (const c of raw.commitTimes) {
216
+ const t = localTime(c.date);
217
+ if (!t)
218
+ continue;
219
+ grid[t.weekday][t.hour]++;
220
+ hours[t.hour]++;
221
+ samples++;
222
+ }
223
+ // Busiest 4-hour window, wrapping past midnight.
224
+ let best = 0;
225
+ let bestStart = 0;
226
+ for (let s = 0; s < 24; s++) {
227
+ let v = 0;
228
+ for (let k = 0; k < 4; k++)
229
+ v += hours[(s + k) % 24];
230
+ if (v > best) {
231
+ best = v;
232
+ bestStart = s;
233
+ }
234
+ }
235
+ const peakHour = hours.indexOf(Math.max(...hours));
236
+ const mid = (bestStart + 2) % 24;
237
+ const chronotype = mid >= 22 || mid < 4
238
+ ? "Night owl"
239
+ : mid < 9
240
+ ? "Early riser"
241
+ : mid < 13
242
+ ? "Morning worker"
243
+ : mid < 18
244
+ ? "Daytime worker"
245
+ : "Evening worker";
246
+ const share = samples ? Math.round((best / samples) * 100) : 0;
247
+ const sentence = samples
248
+ ? `${share}% of sampled commits land between ${fmtHour(bestStart)} and ${fmtHour(bestStart + 4)}, local time.`
249
+ : "No public commits to sample yet.";
250
+ return {
251
+ grid,
252
+ samples,
253
+ peakHour,
254
+ window: [bestStart, (bestStart + 4) % 24],
255
+ chronotype,
256
+ sentence,
257
+ monthly: raw.monthlyCommits,
258
+ };
259
+ }
260
+ const clamp = (v, lo = 0, hi = 1) => Math.min(hi, Math.max(lo, v));
261
+ const pct = (v) => `${Math.round(v * 100)}%`;
262
+ function buildTraits(raw, ctx) {
263
+ const { languages, domains, lastYear, upstream, live, now } = ctx;
264
+ const traits = [];
265
+ // Upstream: merged PRs in projects the person doesn't own, on a log scale.
266
+ const projects = upstream.projects.length;
267
+ traits.push({
268
+ id: "upstream",
269
+ left: "Own repos",
270
+ right: "Upstream",
271
+ value: clamp((Math.log10(1 + upstream.merged) / 2) * 0.6 + Math.min(projects / 15, 1) * 0.4),
272
+ evidence: upstream.merged > 0
273
+ ? `${upstream.merged} merged PRs across ${projects} ${projects === 1 ? "project" : "projects"} owned by others`
274
+ : "No merged PRs in projects owned by others yet",
275
+ });
276
+ // Breadth: how many languages it takes to cover 80% of the code, plus how spread the domains are.
277
+ let acc = 0;
278
+ let l80 = 0;
279
+ for (const l of languages) {
280
+ if (acc >= 0.8)
281
+ break;
282
+ acc += l.share;
283
+ l80++;
284
+ }
285
+ const entropy = domains.length > 1 ? -domains.reduce((s, d) => s + d.share * Math.log(d.share), 0) / Math.log(domains.length) : 0;
286
+ const topDomain = domains[0];
287
+ traits.push({
288
+ id: "breadth",
289
+ left: "Specialist",
290
+ right: "Generalist",
291
+ value: clamp(clamp((l80 - 1) / 5) * 0.5 + entropy * 0.5),
292
+ evidence: `${l80} ${l80 === 1 ? "language covers" : "languages cover"} 80% of the code${topDomain ? `; ${pct(topDomain.share)} of the work is ${topDomain.label}` : ""}`,
293
+ });
294
+ // Cadence: active days and how even the weeks are.
295
+ const ratio = lastYear.days.length ? lastYear.activeDays / lastYear.days.length : 0;
296
+ const weeks = [];
297
+ for (let i = 0; i < lastYear.days.length; i += 7) {
298
+ weeks.push(lastYear.days.slice(i, i + 7).reduce((s, d) => s + d.count, 0));
299
+ }
300
+ const mean = weeks.reduce((a, b) => a + b, 0) / (weeks.length || 1);
301
+ const sd = Math.sqrt(weeks.reduce((s, w) => s + (w - mean) ** 2, 0) / (weeks.length || 1));
302
+ const cv = mean ? sd / mean : 2;
303
+ traits.push({
304
+ id: "cadence",
305
+ left: "In bursts",
306
+ right: "Every day",
307
+ value: clamp(ratio * 0.7 + (1 - Math.min(cv, 2) / 2) * 0.3),
308
+ evidence: `Active on ${lastYear.activeDays} of the last ${lastYear.days.length} days; longest run ${lastYear.longestStreak} days`,
309
+ });
310
+ // Focus: many new repositories, or commits concentrated in a few.
311
+ const newRepos = live.filter((r) => now.getTime() - Date.parse(r.createdAt) < 365 * DAY).length;
312
+ const thisYear = raw.years.filter((y) => y.year >= now.getUTCFullYear() - 1).flatMap((y) => y.commitsByRepo);
313
+ const perRepo = new Map();
314
+ for (const c of thisYear)
315
+ perRepo.set(c.repo, (perRepo.get(c.repo) ?? 0) + c.count);
316
+ const counts = [...perRepo.values()].sort((a, b) => b - a);
317
+ const totalCommits = counts.reduce((a, b) => a + b, 0) || 1;
318
+ const top3 = counts.slice(0, 3).reduce((a, b) => a + b, 0) / totalCommits;
319
+ traits.push({
320
+ id: "focus",
321
+ left: "Few projects",
322
+ right: "Many projects",
323
+ value: clamp((1 - top3) * 0.6 + Math.min(newRepos / 20, 1) * 0.4),
324
+ evidence: `${newRepos} new public ${newRepos === 1 ? "repository" : "repositories"} this year; the top 3 take ${pct(top3)} of commits`,
325
+ });
326
+ return traits;
327
+ }
328
+ function joinList(items) {
329
+ if (items.length <= 1)
330
+ return items.join("");
331
+ return `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
332
+ }
333
+ /** Specific domains first: "developer tools" or "web" only name someone when nothing else does. */
334
+ function characteristic(domains) {
335
+ const specific = domains.filter((d) => !(d.id in DOMAIN_DAMPING));
336
+ return specific.length >= 2 ? specific : domains;
337
+ }
338
+ export function buildHeadline(domains) {
339
+ const top = characteristic(domains)
340
+ .filter((d, i) => i === 0 || d.share >= 0.08)
341
+ .slice(0, 3)
342
+ .map((d) => d.label);
343
+ if (!top.length)
344
+ return "Software on GitHub";
345
+ const s = joinList(top);
346
+ return s.charAt(0).toUpperCase() + s.slice(1);
347
+ }
348
+ export function buildSummary(domains, languages, upstream) {
349
+ const nouns = characteristic(domains)
350
+ .slice(0, 2)
351
+ .map((d) => domainById(d.id).noun);
352
+ const langs = languages
353
+ .filter((l, i) => i === 0 || l.share >= 0.1)
354
+ .slice(0, 3)
355
+ .map((l) => l.name);
356
+ let s = nouns.length ? `Builds ${joinList(nouns)}` : "Builds software";
357
+ if (langs.length)
358
+ s += ` in ${joinList(langs)}`;
359
+ const named = upstream.projects.slice(0, 2).map((p) => p.repo.split("/")[1]);
360
+ if (upstream.merged >= 3 && named.length)
361
+ s += `, and lands fixes upstream in ${joinList(named)}`;
362
+ return `${s}.`;
363
+ }
364
+ /**
365
+ * Repositories worth a card. GitHub already shows pinned repositories right under the README, so
366
+ * those are left out. The rest are ranked on stars, shipped releases, recent work and how much they
367
+ * belong to the person's main domains, so a side project does not outrank the work they are known for.
368
+ */
369
+ function pickLandmarks(raw, live, domains, now) {
370
+ const pinned = new Set(raw.pinned.map((r) => r.nameWithOwner));
371
+ const main = new Set(domains.slice(0, 3).map((d) => d.id));
372
+ const score = (r) => {
373
+ const votes = domainVotes(r.topics, tokens(`${r.name} ${r.description ?? ""}`));
374
+ const total = [...votes.values()].reduce((a, b) => a + b, 0);
375
+ const inMain = [...votes].filter(([id]) => main.has(id)).reduce((a, [, v]) => a + v, 0);
376
+ const recent = r.pushedAt && now.getTime() - Date.parse(r.pushedAt) < 90 * DAY ? 1 : 0;
377
+ return Math.log2(1 + r.stars) * 2 + (r.releases > 0 ? 1.5 : 0) + recent + (total ? (inMain / total) * 2.5 : 0);
378
+ };
379
+ return live
380
+ .filter((r) => !pinned.has(r.nameWithOwner) && !r.isPrivate && r.description)
381
+ .map((r) => ({ r, s: score(r) }))
382
+ .sort((a, b) => b.s - a.s || (a.r.name < b.r.name ? -1 : a.r.name > b.r.name ? 1 : 0))
383
+ .slice(0, 6)
384
+ .map((x) => x.r);
385
+ }
386
+ export { DOMAINS };