Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
feat(badges): count desktop downloads in the download total (#274)
Salman Qureshi76a220c8d86e
diff --git a/.github/workflows/downloads-badge.yml b/.github/workflows/downloads-badge.ymlindex 78e8659f..5d21065b 100644--- a/.github/workflows/downloads-badge.yml+++ b/.github/workflows/downloads-badge.yml@@ -1,6 +1,6 @@name: Downloads badge-# Refreshes .github/badges/downloads.json (npm + installer binary downloads),+# Refreshes .github/badges/downloads.json (npm + installer binaries + desktop downloads),# read by the README's shields.io endpoint badge via raw.githubusercontent.com.on:schedule:diff --git a/scripts/download-stats.mjs b/scripts/download-stats.mjsindex f5f81330..6571dec6 100644--- a/scripts/download-stats.mjs+++ b/scripts/download-stats.mjs@@ -1,14 +1,20 @@#!/usr/bin/env node/**- * Total installs across both distribution paths, for the README badge:+ * Total downloads across every distribution path, for the README badge:* - npm: all-time downloads of @cosmicstack/mercury-agent- * - binaries: GitHub release asset downloads (what install.sh / install.ps1+ * - binaries: GitHub release executables (what install.sh / install.ps1* and `mercury upgrade` fetch). Only the executables are* counted: every install also fetches checksums.txt and* web.tar.gz, which would triple-count one install.+ * - desktop: Mercury Desktop packages on the same releases (.dmg,+ * -setup.exe, .msi, .AppImage, .deb, .rpm, and the .app.tar.gz+ * that install-desktop.sh fetches). Signatures and latest.json+ * are skipped.*- * Writes a shields.io endpoint document (.github/badges/downloads.json, read- * by the badge through raw.githubusercontent.com) plus a breakdown file. Usage: node scripts/download-stats.mjs [--dry-run]+ * All three add up to one total. Writes a shields.io endpoint document+ * (.github/badges/downloads.json, read by the badge through+ * raw.githubusercontent.com) plus a breakdown file.+ * Usage: node scripts/download-stats.mjs [--dry-run]*/import { writeFileSync, mkdirSync } from 'node:fs';import { dirname } from 'node:path';@@ -48,14 +54,27 @@ async function npmTotal() {const isExecutable = (name) => /^mercury(-dev)?-(macos|linux|win)-/.test(name);-async function binaryTotal() {- let total = 0;+/** The desktop package's platform, or null when the asset isn't a desktop download. */+function desktopPlatform(name) {+ if (!name.startsWith('Mercury') || name.endsWith('.sig')) return null;+ if (/\.dmg$|\.app\.tar\.gz$/.test(name)) return 'macos';+ if (/-setup\.exe$|\.msi$/.test(name)) return 'windows';+ if (/\.AppImage$|\.deb$|\.rpm$/.test(name)) return 'linux';+ return null;+}++async function releaseTotals() {+ const out = { binaries: 0, desktop: { macos: 0, windows: 0, linux: 0 } };for (let page = 1; ; page++) {const releases = await json(`https://api.github.com/repos/${REPO}/releases?per_page=100&page=${page}`, { headers });if (releases.length === 0) break;- for (const r of releases) for (const a of r.assets ?? []) if (isExecutable(a.name)) total += a.download_count;+ for (const r of releases) for (const a of r.assets ?? []) {+ if (isExecutable(a.name)) out.binaries += a.download_count;+ const platform = desktopPlatform(a.name);+ if (platform) out.desktop[platform] += a.download_count;+ }}- return total;+ return out;}function short(n) {@@ -64,10 +83,12 @@ function short(n) {return String(n);}-const [npm, binaries] = await Promise.all([npmTotal(), binaryTotal()]);-const total = npm + binaries;+const [npm, releases] = await Promise.all([npmTotal(), releaseTotals()]);+const { binaries } = releases;+const desktop = Object.values(releases.desktop).reduce((a, n) => a + n, 0);+const total = npm + binaries + desktop;const badge = { schemaVersion: 1, label: 'downloads', message: short(total), color: '0ea5e9', cacheSeconds: 21600 };-const breakdown = { total, npm, binaries, updatedAt: new Date().toISOString() };+const breakdown = { total, npm, binaries, desktop, desktopByPlatform: releases.desktop, updatedAt: new Date().toISOString() };console.log(JSON.stringify(breakdown));if (!dryRun) {mkdirSync(dirname(OUT), { recursive: true });