contributor-magnet 0.0.0-stage → 1.0.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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +211 -2
  3. package/bin/cli.mjs +70 -0
  4. package/package.json +20 -4
  5. package/skills/magnet/SKILL.md +50 -0
  6. package/skills/magnet/agents/openai.yaml +4 -0
  7. package/skills/magnet-audit/SKILL.md +45 -0
  8. package/skills/magnet-audit/agents/openai.yaml +4 -0
  9. package/skills/magnet-audit/references/scoring.md +82 -0
  10. package/skills/magnet-audit/scripts/audit.mjs +216 -0
  11. package/skills/magnet-audit/scripts/card.mjs +69 -0
  12. package/skills/magnet-audit/scripts/checks.mjs +455 -0
  13. package/skills/magnet-audit/scripts/files.mjs +103 -0
  14. package/skills/magnet-audit/scripts/github.mjs +69 -0
  15. package/skills/magnet-bots/SKILL.md +56 -0
  16. package/skills/magnet-bots/agents/openai.yaml +4 -0
  17. package/skills/magnet-bots/references/bots.md +82 -0
  18. package/skills/magnet-bots/scripts/install.mjs +107 -0
  19. package/skills/magnet-bots/templates/workflows/magnet-claim.yml +132 -0
  20. package/skills/magnet-bots/templates/workflows/magnet-duplicates.yml +62 -0
  21. package/skills/magnet-bots/templates/workflows/magnet-issue-level.yml +33 -0
  22. package/skills/magnet-bots/templates/workflows/magnet-merged-thanks.yml +63 -0
  23. package/skills/magnet-bots/templates/workflows/magnet-pr-hygiene.yml +60 -0
  24. package/skills/magnet-bots/templates/workflows/magnet-pr-labels.yml +85 -0
  25. package/skills/magnet-bots/templates/workflows/magnet-program.yml +139 -0
  26. package/skills/magnet-bots/templates/workflows/magnet-shoutout.yml +96 -0
  27. package/skills/magnet-bots/templates/workflows/magnet-stale.yml +44 -0
  28. package/skills/magnet-bots/templates/workflows/magnet-unassign-idle.yml +122 -0
  29. package/skills/magnet-bots/templates/workflows/magnet-welcome.yml +68 -0
  30. package/skills/magnet-issues/SKILL.md +44 -0
  31. package/skills/magnet-issues/agents/openai.yaml +4 -0
  32. package/skills/magnet-issues/references/issue-recipes.md +76 -0
  33. package/skills/magnet-issues/scripts/file-issues.mjs +82 -0
  34. package/skills/magnet-issues/scripts/scan.mjs +104 -0
  35. package/skills/magnet-launch/SKILL.md +31 -0
  36. package/skills/magnet-launch/agents/openai.yaml +4 -0
  37. package/skills/magnet-launch/references/launch.md +92 -0
  38. package/skills/magnet-programs/SKILL.md +37 -0
  39. package/skills/magnet-programs/agents/openai.yaml +4 -0
  40. package/skills/magnet-programs/references/playbook.md +71 -0
  41. package/skills/magnet-programs/references/programs.md +204 -0
  42. package/skills/magnet-readme/SKILL.md +28 -0
  43. package/skills/magnet-readme/agents/openai.yaml +4 -0
  44. package/skills/magnet-readme/references/readme-blocks.md +138 -0
  45. package/skills/magnet-retain/SKILL.md +33 -0
  46. package/skills/magnet-retain/agents/openai.yaml +4 -0
  47. package/skills/magnet-retain/references/retention.md +60 -0
  48. package/skills/magnet-review/SKILL.md +49 -0
  49. package/skills/magnet-review/agents/openai.yaml +4 -0
  50. package/skills/magnet-review/references/review-playbook.md +72 -0
  51. package/skills/magnet-review/scripts/merge-chain.mjs +126 -0
  52. package/skills/magnet-review/scripts/pr-queue.mjs +120 -0
  53. package/skills/magnet-setup/SKILL.md +46 -0
  54. package/skills/magnet-setup/agents/openai.yaml +4 -0
  55. package/skills/magnet-setup/scripts/labels.mjs +111 -0
  56. package/skills/magnet-setup/scripts/scaffold.mjs +118 -0
  57. package/skills/magnet-setup/templates/CONTRIBUTING.md +77 -0
  58. package/skills/magnet-setup/templates/SECURITY.md +13 -0
  59. package/skills/magnet-setup/templates/devcontainer/devcontainer.json +11 -0
  60. package/skills/magnet-setup/templates/github/ISSUE_TEMPLATE/bug_report.yml +62 -0
  61. package/skills/magnet-setup/templates/github/ISSUE_TEMPLATE/config.yml +11 -0
  62. package/skills/magnet-setup/templates/github/ISSUE_TEMPLATE/feature_request.yml +38 -0
  63. package/skills/magnet-setup/templates/github/ISSUE_TEMPLATE/task.yml +60 -0
  64. package/skills/magnet-setup/templates/github/pull_request_template.md +29 -0
  65. package/skills/magnet-setup/templates/labels.json +37 -0
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env node
2
+ // Contributor-Readiness audit for an open source repo.
3
+ //
4
+ // node audit.mjs [path] local checkout (GitHub repo read from git remote)
5
+ // node audit.mjs --repo owner/name any public GitHub repo, no checkout needed
6
+ // node audit.mjs . --out magnet-report where to write report.md, report.json and card.svg
7
+ // node audit.mjs . --offline file checks only, no network
8
+ // node audit.mjs . --name acme/app name shown on the report and card
9
+ //
10
+ // Zero dependencies. Node 18+. Uses GITHUB_TOKEN, GH_TOKEN or `gh auth token` when available.
11
+
12
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
13
+ import { resolve, join, basename } from 'node:path';
14
+ import { api, paginate, parseRepo, repoFromGitRemote, token } from './github.mjs';
15
+ import { localFiles, remoteFiles, interestingFiles } from './files.mjs';
16
+ import { runChecks, CATEGORIES, _internal } from './checks.mjs';
17
+ import { renderCard, badgeMarkdown } from './card.mjs';
18
+
19
+ const { median, hours, MAINTAINER, GFI, HELP } = _internal;
20
+ const DAY = 864e5;
21
+
22
+ function parseArgs(argv) {
23
+ const args = { path: null, repo: null, name: null, out: 'magnet-report', offline: false, json: false, sample: null };
24
+ for (let i = 0; i < argv.length; i++) {
25
+ const a = argv[i];
26
+ if (a === '--repo') args.repo = argv[++i];
27
+ else if (a === '--out') args.out = argv[++i];
28
+ else if (a === '--name') args.name = argv[++i];
29
+ else if (a === '--offline') args.offline = true;
30
+ else if (a === '--json') args.json = true;
31
+ else if (a === '--sample') args.sample = Number(argv[++i]);
32
+ else if (a === '-h' || a === '--help') args.help = true;
33
+ else if (!a.startsWith('--')) args.path = a;
34
+ }
35
+ return args;
36
+ }
37
+
38
+ const isHuman = (u) => u && u.type !== 'Bot' && !/\[bot\]$/.test(u.login || '');
39
+
40
+ async function mapLimit(items, limit, fn) {
41
+ const out = new Array(items.length);
42
+ let i = 0;
43
+ await Promise.all(
44
+ Array.from({ length: Math.min(limit, items.length) }, async () => {
45
+ while (i < items.length) {
46
+ const idx = i++;
47
+ out[idx] = await fn(items[idx]);
48
+ }
49
+ }),
50
+ );
51
+ return out;
52
+ }
53
+
54
+ async function gatherApi({ owner, repo }, meta, sampleSize) {
55
+ const base = `/repos/${owner}/${repo}`;
56
+ const now = Date.now();
57
+ const onlyIssues = (xs) => xs.filter((i) => !i.pull_request);
58
+
59
+ const [labels, gfi, helpWanted, recent, closedPrs, openPrs] = await Promise.all([
60
+ paginate(`${base}/labels`, 2000), // big projects have 1,000+ labels
61
+ paginate(`${base}/issues?state=open&labels=${encodeURIComponent(GFI)}`, 300).then(onlyIssues),
62
+ paginate(`${base}/issues?state=open&labels=${encodeURIComponent(HELP)}`, 300).then(onlyIssues),
63
+ api(`${base}/issues?state=all&sort=created&direction=desc&per_page=100`),
64
+ api(`${base}/pulls?state=closed&sort=updated&direction=desc&per_page=100`),
65
+ paginate(`${base}/pulls?state=open`, 300),
66
+ ]);
67
+
68
+ // Time to first maintainer response on issues and PRs opened by outside people.
69
+ const outside = (recent || [])
70
+ .filter((i) => isHuman(i.user) && !MAINTAINER.has(i.author_association))
71
+ .filter((i) => now - Date.parse(i.created_at) < 180 * DAY)
72
+ .slice(0, sampleSize);
73
+ const responseTimes = await mapLimit(outside, 6, async (item) => {
74
+ const author = item.user.login;
75
+ const byMaintainer = (x) => isHuman(x.user) && x.user.login !== author && MAINTAINER.has(x.author_association);
76
+ const comments = (await api(`${base}/issues/${item.number}/comments?per_page=50`)) || [];
77
+ const reviews = item.pull_request ? (await api(`${base}/pulls/${item.number}/reviews?per_page=50`)) || [] : [];
78
+ const times = [
79
+ ...comments.filter(byMaintainer).map((c) => Date.parse(c.created_at)),
80
+ ...reviews.filter(byMaintainer).map((r) => Date.parse(r.submitted_at)),
81
+ ];
82
+ if (item.closed_at) times.push(Date.parse(item.closed_at)); // closing is an answer too
83
+ const first = times.length ? Math.min(...times) : now; // still waiting: count the wait so far
84
+ return hours(first - Date.parse(item.created_at));
85
+ });
86
+
87
+ const merged = (closedPrs || [])
88
+ .filter((p) => p.merged_at && isHuman(p.user) && !MAINTAINER.has(p.author_association))
89
+ .slice(0, 30)
90
+ .map((p) => hours(Date.parse(p.merged_at) - Date.parse(p.created_at)));
91
+
92
+ const humanOpen = openPrs.filter((p) => isHuman(p.user));
93
+ const stale = humanOpen.filter((p) => now - Date.parse(p.updated_at) > 30 * DAY).length;
94
+
95
+ return {
96
+ meta,
97
+ labels,
98
+ gfi,
99
+ helpWanted,
100
+ response: { samples: responseTimes.length, medianHours: median(responseTimes) },
101
+ merge: { samples: merged.length, medianHours: median(merged) },
102
+ prs: { open: humanOpen.length, stale },
103
+ };
104
+ }
105
+
106
+ // Orgs can share CONTRIBUTING, CODE_OF_CONDUCT and more from their `.github` repo.
107
+ // GitHub's community profile reports those; read them so the doc checks see the real text.
108
+ async function addInheritedDocs({ owner, repo }, files) {
109
+ const profile = await api(`/repos/${owner}/${repo}/community/profile`).catch(() => null);
110
+ const wanted = { contributing: 'CONTRIBUTING.md', code_of_conduct: 'CODE_OF_CONDUCT.md', pull_request_template: '.github/pull_request_template.md' };
111
+ for (const [key, virtualPath] of Object.entries(wanted)) {
112
+ const url = profile?.files?.[key]?.html_url;
113
+ const m = url && url.match(/github\.com\/([^/]+)\/([^/]+)\/blob\/([^/]+)\/(.+)$/);
114
+ if (!m || (m[1].toLowerCase() === owner.toLowerCase() && m[2].toLowerCase() === repo.toLowerCase())) continue;
115
+ const text = await api(`/repos/${m[1]}/${m[2]}/contents/${m[4]}?ref=${m[3]}`, { accept: 'application/vnd.github.raw+json', raw: true }).catch(() => null);
116
+ if (text) files.addVirtual(virtualPath, text);
117
+ }
118
+ }
119
+
120
+ function markdownReport({ name, report, badge, mode }) {
121
+ const lines = [];
122
+ lines.push(`# Contributor-Readiness: ${name}`, '');
123
+ lines.push(`**${report.score}/100 · ${report.grade.name}**${report.partial ? ' (partial: some checks were skipped, see below)' : ''}`, '');
124
+ lines.push(badge, '');
125
+ lines.push(`Mode: ${mode}. Generated ${new Date().toISOString().slice(0, 10)} by [contributor-magnet](https://github.com/Priyanshu-byte-coder/contributor-magnet).`, '');
126
+ lines.push('| Category | Score |', '|---|---|');
127
+ for (const c of report.categories) lines.push(`| ${c.title} | ${c.skipped ? 'not measured' : `${c.earned}/${c.possible}`} |`);
128
+ lines.push('');
129
+ if (report.fixes.length) {
130
+ lines.push('## Biggest wins first', '');
131
+ report.fixes.forEach((f, i) => {
132
+ lines.push(`${i + 1}. **${f.title}** (+${f.points - f.earned}) · ${f.detail}. ${f.fix} → \`/${f.skill}\``);
133
+ });
134
+ lines.push('');
135
+ }
136
+ lines.push('## All checks', '');
137
+ for (const cat of CATEGORIES) {
138
+ lines.push(`### ${cat.title}`, '');
139
+ for (const r of report.results.filter((x) => x.category === cat.id)) {
140
+ const mark = r.skipped ? '⏭' : r.earned === r.points ? '✅' : r.earned > 0 ? '🟡' : '❌';
141
+ const score = r.skipped ? `skipped: ${r.skipped}` : `${r.earned}/${r.points} · ${r.detail}`;
142
+ lines.push(`- ${mark} ${r.title}: ${score}`);
143
+ }
144
+ lines.push('');
145
+ }
146
+ return lines.join('\n');
147
+ }
148
+
149
+ async function main() {
150
+ const args = parseArgs(process.argv.slice(2));
151
+ if (args.help) {
152
+ console.log('Usage: node audit.mjs [path] [--repo owner/name] [--out dir] [--name label] [--offline] [--json] [--sample N]');
153
+ return;
154
+ }
155
+
156
+ const localPath = args.path && existsSync(args.path) ? resolve(args.path) : !args.path && !args.repo ? process.cwd() : null;
157
+ const repo = parseRepo(args.repo) || (!localPath && parseRepo(args.path)) || (localPath ? repoFromGitRemote(localPath) : null);
158
+ if (!localPath && !repo) {
159
+ console.error('Give a local path or --repo owner/name.');
160
+ process.exit(2);
161
+ }
162
+ if (!localPath && args.offline) {
163
+ console.error('--offline needs a local checkout: an audit by --repo reads everything from GitHub.');
164
+ process.exit(2);
165
+ }
166
+
167
+ let meta = null;
168
+ let apiData = null;
169
+ if (repo && !args.offline) {
170
+ meta = await api(`/repos/${repo.owner}/${repo.repo}`);
171
+ if (!meta) {
172
+ console.error(`Repo ${repo.owner}/${repo.repo} not found or private.`);
173
+ if (!localPath) process.exit(2);
174
+ }
175
+ }
176
+
177
+ const files = localPath ? localFiles(localPath) : await remoteFiles(repo, meta.default_branch);
178
+ if (files.prefetch) await files.prefetch(interestingFiles(files));
179
+
180
+ if (meta) await addInheritedDocs(repo, files);
181
+
182
+ if (meta) {
183
+ const sample = args.sample || (token() ? 30 : 8);
184
+ apiData = await gatherApi(repo, meta, sample);
185
+ }
186
+
187
+ const report = runChecks({ files, api: apiData });
188
+ const name = args.name || (repo ? `${repo.owner}/${repo.repo}` : basename(localPath));
189
+ const mode = apiData ? (localPath ? 'local files + GitHub data' : 'GitHub repo (remote)') : 'local files only';
190
+ const badge = badgeMarkdown(report.score, report.grade, { partial: report.partial });
191
+
192
+ const outDir = resolve(args.out);
193
+ mkdirSync(outDir, { recursive: true });
194
+ const json = { name, mode, generated: new Date().toISOString(), badge, ...report };
195
+ writeFileSync(join(outDir, 'report.json'), JSON.stringify(json, null, 2));
196
+ writeFileSync(join(outDir, 'report.md'), markdownReport({ name, report, badge, mode }));
197
+ writeFileSync(join(outDir, 'card.svg'), renderCard({ name, report }));
198
+
199
+ if (args.json) {
200
+ console.log(JSON.stringify(json, null, 2));
201
+ return;
202
+ }
203
+ console.log(`\n${name}: ${report.score}/100 · ${report.grade.name}${report.partial ? ' (partial)' : ''} [${mode}]\n`);
204
+ for (const c of report.categories) console.log(` ${c.title.padEnd(18)} ${c.skipped ? 'not measured' : `${c.earned}/${c.possible}`}`);
205
+ if (report.fixes.length) {
206
+ console.log('\nTop fixes:');
207
+ report.fixes.slice(0, 5).forEach((f, i) => console.log(` ${i + 1}. +${f.points - f.earned} ${f.title}: ${f.detail} → /${f.skill}`));
208
+ }
209
+ console.log(`\nWrote ${join(outDir, 'report.md')}, report.json and card.svg`);
210
+ console.log(`Badge: ${badge}`);
211
+ }
212
+
213
+ main().catch((e) => {
214
+ console.error(e.message);
215
+ process.exit(1);
216
+ });
@@ -0,0 +1,69 @@
1
+ // Shareable report card: a 1200x630 SVG (the social preview size) with the score and category bars.
2
+
3
+ const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
4
+
5
+ export function renderCard({ name, report, date = new Date().toISOString().slice(0, 10) }) {
6
+ const { score, grade, categories, partial } = report;
7
+ const W = 1200;
8
+ const H = 630;
9
+ const color = `#${grade.color}`;
10
+ const barX = 560;
11
+ const barW = 520;
12
+ const rows = categories
13
+ .map((c, i) => {
14
+ const y = 150 + i * 56;
15
+ const pct = c.skipped || !c.possible ? 0 : c.earned / c.possible;
16
+ const label = c.skipped ? 'not measured' : `${c.earned}/${c.possible}`;
17
+ const fill = c.skipped ? '#30363d' : pct >= 0.75 ? '#3fb950' : pct >= 0.5 ? '#d29922' : '#f85149';
18
+ return `
19
+ <text x="${barX}" y="${y}" class="label">${esc(c.title)}</text>
20
+ <text x="${barX + barW}" y="${y}" class="value" text-anchor="end">${label}</text>
21
+ <rect x="${barX}" y="${y + 12}" width="${barW}" height="10" rx="5" fill="#21262d"/>
22
+ <rect x="${barX}" y="${y + 12}" width="${Math.max(pct * barW, c.skipped ? 0 : 6)}" height="10" rx="5" fill="${fill}"/>`;
23
+ })
24
+ .join('');
25
+
26
+ // Score ring
27
+ const r = 150;
28
+ const cx = 260;
29
+ const cy = 300;
30
+ const circ = 2 * Math.PI * r;
31
+ const dash = (score / 100) * circ;
32
+
33
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" role="img" aria-label="Contributor-Readiness score for ${esc(name)}: ${score} out of 100">
34
+ <style>
35
+ .title { font: 600 30px system-ui, -apple-system, 'Segoe UI', sans-serif; fill: #e6edf3; }
36
+ .sub { font: 400 20px system-ui, -apple-system, 'Segoe UI', sans-serif; fill: #8b949e; }
37
+ .score { font: 700 112px system-ui, -apple-system, 'Segoe UI', sans-serif; fill: #e6edf3; }
38
+ .out { font: 500 24px system-ui, -apple-system, 'Segoe UI', sans-serif; fill: #8b949e; }
39
+ .grade { font: 700 28px system-ui, -apple-system, 'Segoe UI', sans-serif; }
40
+ .label { font: 500 20px system-ui, -apple-system, 'Segoe UI', sans-serif; fill: #c9d1d9; }
41
+ .value { font: 600 20px ui-monospace, 'SFMono-Regular', Consolas, monospace; fill: #8b949e; }
42
+ .foot { font: 500 18px ui-monospace, 'SFMono-Regular', Consolas, monospace; fill: #6e7681; }
43
+ </style>
44
+ <rect width="${W}" height="${H}" fill="#0d1117"/>
45
+ <text x="60" y="76" class="title">${esc(name)}</text>
46
+ <text x="60" y="108" class="sub">Contributor-Readiness score${partial ? ' (partial: some checks need GitHub data)' : ''}</text>
47
+ <circle cx="${cx}" cy="${cy}" r="${r}" fill="none" stroke="#21262d" stroke-width="22"/>
48
+ <circle cx="${cx}" cy="${cy}" r="${r}" fill="none" stroke="${color}" stroke-width="22" stroke-linecap="round"
49
+ stroke-dasharray="${dash.toFixed(1)} ${circ.toFixed(1)}" transform="rotate(-90 ${cx} ${cy})"/>
50
+ <text x="${cx}" y="${cy + 30}" class="score" text-anchor="middle">${score}</text>
51
+ <text x="${cx}" y="${cy + 70}" class="out" text-anchor="middle">out of 100</text>
52
+ <text x="${cx}" y="${cy + 210}" class="grade" text-anchor="middle" fill="${color}">${esc(grade.name)}</text>
53
+ ${rows}
54
+ <g transform="translate(60 ${H - 64}) scale(0.28)">
55
+ <path d="M34 50 V78 a30 30 0 0 0 60 0 V50" fill="none" stroke="#3fb950" stroke-width="18" stroke-linecap="round"/>
56
+ <path d="M34 50 V58 M94 50 V58" stroke="#e6edf3" stroke-width="18" stroke-linecap="round"/>
57
+ <circle cx="64" cy="54" r="9" fill="#e6edf3"/><circle cx="64" cy="28" r="6.5" fill="#e6edf3" opacity=".6"/><circle cx="64" cy="10" r="4.5" fill="#e6edf3" opacity=".3"/>
58
+ </g>
59
+ <text x="104" y="${H - 36}" class="foot">contributor-magnet · /magnet-audit · ${esc(date)}</text>
60
+ </svg>
61
+ `;
62
+ }
63
+
64
+ // A partial score (file checks only) says so on the badge, so an offline 100 can't pass for a full one.
65
+ export function badgeMarkdown(score, grade, { partial = false, link = 'https://github.com/Priyanshu-byte-coder/contributor-magnet' } = {}) {
66
+ const value = `${score}%2F100${partial ? '%20%28files%20only%29' : ''}`;
67
+ const url = `https://img.shields.io/badge/contributor%20magnet-${value}-${grade.color}`;
68
+ return `[![Contributor Magnet score: ${score}/100${partial ? ' (files only)' : ''}](${url})](${link})`;
69
+ }