plugins: Discover counts who uses and likes each plugin

Discover showed npm's weekly downloads, which CI, mirrors and magpie's
own keepMovedCurrent updates inflate. Now each card and the hero say
how many people use a plugin, counted by magpie itself, and a plugin's
page has a like.

- The daily stats send (stats.Send) also POSTs usemagpie.ai
  /api/plugins/report with the install id and the installed, switched-on
  plugins Discover lists, by their Discover key: the npm name, or
  github:owner/repo for a repository tagged magpie-plugin
  (plugin.Public). A folder, a private repository or an unlisted
  package is never named. It goes only while "Share the agents,
  providers, models and plugins I use" is on (noUsageStats), and only
  where the day's event goes at all (Count me as a user, DO_NOT_TRACK,
  MAGPIE_NO_STATS, release builds).
- site/pluginstats.js on D1 magpie-plugins: users are the ids that
  reported a plugin in the last 7 days, reports drop after 30 days, a
  caller's address is kept only as a hash for an hour (60 asks an
  hour). /api/plugins/stats carries no id and is cached for an hour.
- A like (POST /api/plugins/like through the GUI's /api/plugins/like)
  is taken only for a plugin installed and on here, can be taken back,
  and is kept in plugin-likes.json.
- "Most liked" sorts by likes once a plugin has 20, below that by
  GitHub's stars.
- plugincounts.js is loaded with the Plugins page, not the core, and
  redraws the cards only when the counts changed.
- The privacy text follows: README.md, README.zh-CN.md, docs/reference.md,
  the site's privacy and start pages in en, zh and ja, llms-full.txt,
  and the Privacy switch's label and description in every language.

Run at this tree (on origin/main 51da6f1f5):
- Windows box (win-run): gofmt -l clean; go vet of internal/stats,
  internal/plugin, internal/gui ok for windows and linux (-tags nogui);
  node --test site/pluginstats.test.mjs site/worker.test.mjs 44 of 44;
  TestCoreScriptBudget, TestPluginCountsAndLikes ok; GUI old-webkit,
  i18n-keys, privacy-usage-stats, plugin-git, plugin-local,
  plugin-github in both engines: 45 of 46, the one red is #5919
  (.side-foot:has, d374168d0).
- mote, one commit before the rebase onto 51da6f1f5 (Go unchanged
  since): go vet darwin ok; TestSendPlugins, TestPublicPlugins,
  TestPluginCountsAndLikes, TestCoreScriptBudget ok.
- Windows, at 7bc7af1d0 (one rebase earlier): go test internal/stats
  ok; internal/plugin and internal/gui red only in TestPiPackage and
  eight gui tests that fail the same at origin/main 72f2deebe on that
  box (#4115, #5928; TestCherryStudioImportRow added to #4115 with its
  cause). Every plugin*, market*, privacy*, i18n*, old-webkit* and
  discover* GUI file (83 files, both engines, concurrency 4): the reds
  left after the fix below match origin/main 6d7862769 on the same box,
  or are flakes red there too under concurrency: plugin-update-button
  (#4500), plugin-proxy-page (#6017, new), privacy-agent-telemetry
  (#6018, new).
- Broken by hand, caught: the first run had `const like = !local && …`,
  so a local plugin's page called false?.sync() every 600ms; 136
  "like?.sync is not a function" errors across plugin-git, plugin-local,
  plugin-github and the sign-in files. Fixed before this commit.
- Live: D1 magpie-plugins created and the worker deployed;
  /api/plugins/stats answers {"plugins":{}}, a bad report or like 400,
  /api/latest and / 200. No test data was written to production.

Not tried: the full Go suite and the full GUI suite. mote had 28 suites
waiting for its lock, and WSL on the Windows box failed with
E_UNEXPECTED while another session uninstalled a distro. Not tried
either: a real like or report from a release build (source builds
never send), so the first real counts come with this release.
This commit is contained in:
yetone
2026-11-11 04:28:18 +08:00
parent 6873638126
commit 13a9f1263a
29 changed files with 1019 additions and 30 deletions
+1 -1
View File
@@ -296,7 +296,7 @@ Find them under Plugins › Discover › Gateway middleware. See [Gateway middle
## Privacy
Your prompts, replies, keys and accounts go only to the providers you use, and with [privacy masking](#privacy-masking) on, the secrets in them don't go even there. Once a day a released magpie tells us it is in use: a random id, its version and system, and which agents, providers and models it is used with, by magpie's own ids (a provider you added yourself is only `custom`), and for each partner listed first in the add sheet, how many times a day it was shown, opened and added (counts only). No names, URLs, accounts, keys, prompts or usage. Turn part or all of it off in **Settings → Privacy**, or with `DO_NOT_TRACK=1`. A partner's website and key links go through `usemagpie.ai/go/…`, which counts the click, and usemagpie.ai counts fetches of the partner list; the server sees these whatever the settings, and keeps no id or address. Icons named by a plugin, an import link or the library are fetched through `usemagpie.ai/api/icon`, so their hosts see Cloudflare's address, not yours; the server only passes the picture on, and counts and keeps nothing. The [Privacy page](https://usemagpie.ai/docs/privacy) lists everything magpie sends by itself, with an example and every switch; the [reference](docs/reference.md#counting-users) has the rules.
Your prompts, replies, keys and accounts go only to the providers you use, and with [privacy masking](#privacy-masking) on, the secrets in them don't go even there. Once a day a released magpie tells us it is in use: a random id, its version and system, and which agents, providers and models it is used with, by magpie's own ids (a provider you added yourself is only `custom`), which of the plugins Discover lists are installed, so it can show how many use each one, and for each partner listed first in the add sheet, how many times a day it was shown, opened and added (counts only). No names, URLs, accounts, keys, prompts or usage. Turn part or all of it off in **Settings → Privacy**, or with `DO_NOT_TRACK=1`. A partner's website and key links go through `usemagpie.ai/go/…`, which counts the click, and usemagpie.ai counts fetches of the partner list; the server sees these whatever the settings, and keeps no id or address. Icons named by a plugin, an import link or the library are fetched through `usemagpie.ai/api/icon`, so their hosts see Cloudflare's address, not yours; the server only passes the picture on, and counts and keeps nothing. The [Privacy page](https://usemagpie.ai/docs/privacy) lists everything magpie sends by itself, with an example and every switch; the [reference](docs/reference.md#counting-users) has the rules.
## Community
+1 -1
View File
@@ -296,7 +296,7 @@ magpie plugin options model-map '{"mapping": {"fast": "deepseek/deepseek-chat"}}
## 隐私
你的提示词、回复、密钥和账号只发给你用的供应商;打开[隐私脱敏](#隐私脱敏)后,其中的密钥连供应商也收不到。正式版 magpie 每天告诉我们一次它在用:一个随机 ID、版本和系统,以及用了哪些 agent、供应商和模型,只用 magpie 自己的 ID(你自己添加的供应商只记作 `custom`),以及添加供应商页里排在最前的合作伙伴每天被展示、打开和添加的次数(只有次数)。不发送名称、URL、账号、密钥、提示词和用量。可以在 **设置 → 隐私** 里关掉一部分或全部,也可以设 `DO_NOT_TRACK=1`。合作伙伴的官网和获取 Key 链接经 `usemagpie.ai/go/…` 跳转并计一次点击,usemagpie.ai 也统计合作伙伴列表的拉取次数;这是服务器本身看到的,不受设置影响,不记录 ID 和 IP。插件、导入链接和库里的图标经 `usemagpie.ai/api/icon` 获取,图标所在的服务器只看到 Cloudflare 的地址,看不到你的 IP;这台服务器只转发图片,不计数也不记录。[隐私页](https://usemagpie.ai/docs/zh/privacy)列出了 magpie 自己发出的所有内容,附示例和每个开关;规则见[参考文档](docs/reference.md#counting-users)。
你的提示词、回复、密钥和账号只发给你用的供应商;打开[隐私脱敏](#隐私脱敏)后,其中的密钥连供应商也收不到。正式版 magpie 每天告诉我们一次它在用:一个随机 ID、版本和系统,以及用了哪些 agent、供应商和模型,只用 magpie 自己的 ID(你自己添加的供应商只记作 `custom`),装了 Discover 里的哪些插件(用于显示每个插件的在用人数),以及添加供应商页里排在最前的合作伙伴每天被展示、打开和添加的次数(只有次数)。不发送名称、URL、账号、密钥、提示词和用量。可以在 **设置 → 隐私** 里关掉一部分或全部,也可以设 `DO_NOT_TRACK=1`。合作伙伴的官网和获取 Key 链接经 `usemagpie.ai/go/…` 跳转并计一次点击,usemagpie.ai 也统计合作伙伴列表的拉取次数;这是服务器本身看到的,不受设置影响,不记录 ID 和 IP。插件、导入链接和库里的图标经 `usemagpie.ai/api/icon` 获取,图标所在的服务器只看到 Cloudflare 的地址,看不到你的 IP;这台服务器只转发图片,不计数也不记录。[隐私页](https://usemagpie.ai/docs/zh/privacy)列出了 magpie 自己发出的所有内容,附示例和每个开关;规则见[参考文档](docs/reference.md#counting-users)。
## 社区
+11 -2
View File
@@ -4162,10 +4162,19 @@ and models to look after first, by magpie's own ids only:
many times a day the add sheet showed it, its row was opened, its key
page was opened and a provider was added from it (at most 20 of each,
5 adds), kept in `~/.cache/magpie/partner-counts.json` for at most 14
days and sent the day after as `magpie partner` events.
days and sent the day after as `magpie partner` events;
- to usemagpie.ai, not PostHog, which of the plugins Discover lists are
installed and on (npm names, or `github:owner/repo` for a repository
tagged `magpie-plugin`; never a folder, a private repository or an
unlisted package), with the same id, so Discover can say how many use
each (the ids that reported it in 7 days). A like on a plugin's page
goes there too, only for a plugin installed here, and is kept in
`~/.config/magpie/plugin-likes.json`. The code is
[internal/stats/plugins.go](../internal/stats/plugins.go) and
[site/pluginstats.js](../site/pluginstats.js).
No names, base URLs, accounts, keys, prompts or usage go. Turn that part off
in Settings → Privacy → Share the agents, providers and models I use; the
in Settings → Privacy → Share the agents, providers, models and plugins I use; the
day's event then has the id, version and system only. Turn it all off in
Settings → Privacy → Count me as a user, or with `DO_NOT_TRACK=1` or
`MAGPIE_NO_STATS=1`. Builds from source never send it. The code is
+1 -1
View File
@@ -21915,7 +21915,7 @@ function renderRedact(s, keep) {
}, settingsErr))).id = "agentTelemetryAllRow";
rowIn(share, t("Count me as a user"), t("Once a day, a random id for this computer with magpie's version and system"),
onOff(!s.noStats, (on) => savePrefs({ ...keep, noStats: !on })));
if (!s.noStats) rowIn(share, t("Share the agents, providers and models I use"), t("Sent with that event, by magpie's own ids, with how many of each, and how often each partner was shown, opened and added; a provider you added yourself is only “custom”. No names, addresses, accounts, keys or usage"),
if (!s.noStats) rowIn(share, t("Share the agents, providers, models and plugins I use"), t("Sent with that event, by magpie's own ids, with how many of each, and how often each partner was shown, opened and added; a provider you added yourself is only “custom”. Which of Discover's plugins are installed goes to usemagpie.ai for its counts. No names, addresses, accounts, keys or usage"),
onOff(!s.noUsageStats, (on) => savePrefs({ ...keep, noUsageStats: !on })));
if (!featureHides($('#nav button[data-view="masking"]'))) {
const open = el("button", "", t("Open"));
+36 -8
View File
@@ -48,6 +48,13 @@ const I18N = {
"Other authors": "第三方",
"Not installed only": "只看未安装",
"Most popular": "最热",
"Most liked": "最受好评",
"Users": "在用",
"{n} people use it, counted from the last week": "{n} 人在用(近 7 天)",
"{n} people like it": "{n} 人点赞",
"Take back your like": "取消点赞",
"Like it": "点赞",
"Install it to like it": "安装后才能点赞",
"Unreviewed": "未审核",
"No plugin matches": "没有符合的插件",
"At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "下限:首字后 {ms} 输出 {n} 个正文 token,{r} 个推理 token 不计。没有记录首个正文的时间,首字后的推理时间也算在里面",
@@ -1313,8 +1320,8 @@ const I18N = {
"Mask personal data": "脱敏个人信息",
"Count me as a user": "计入用户数",
"Once a day, a random id for this computer with magpie's version and system": "每天一次,发送本机随机 ID、magpie 版本和系统",
"Share the agents, providers and models I use": "分享我用的 agent、provider 和模型",
"Sent with that event, by magpie's own ids, with how many of each, and how often each partner was shown, opened and added; a provider you added yourself is only “custom”. No names, addresses, accounts, keys or usage": "随上面那条一起发送:只用 magpie 内置的 ID 和各自的数量,以及每个合作伙伴被展示、打开和添加的次数;你自己添加的 provider 只记作“custom”。不含名称、地址、账号、密钥和用量",
"Share the agents, providers, models and plugins I use": "分享我用的 agent、provider、模型和插件",
"Sent with that event, by magpie's own ids, with how many of each, and how often each partner was shown, opened and added; a provider you added yourself is only “custom”. Which of Discover's plugins are installed goes to usemagpie.ai for its counts. No names, addresses, accounts, keys or usage": "随上面那条一起发送:只用 magpie 内置的 ID 和各自的数量,以及每个合作伙伴被展示、打开和添加的次数;你自己添加的 provider 只记作“custom”。装了 Discover 里的哪些插件会发给 usemagpie.ai,用于插件的使用人数。不含名称、地址、账号、密钥和用量",
"Warm-up and check-in": "预热与签到",
"Warm up on reset": "窗口重置时预热",
"Daily warm-up": "每日定时预热",
@@ -5046,6 +5053,13 @@ const I18N = {
"Other authors": "第三方",
"Not installed only": "只看未安裝",
"Most popular": "最熱門",
"Most liked": "最受好評",
"Users": "在用",
"{n} people use it, counted from the last week": "{n} 人在用(近 7 天)",
"{n} people like it": "{n} 人按讚",
"Take back your like": "收回讚",
"Like it": "按讚",
"Install it to like it": "安裝後才能按讚",
"Unreviewed": "未審核",
"No plugin matches": "沒有符合的外掛",
"At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "下限:首字後 {ms} 輸出 {n} 個正文 token,{r} 個推理 token 不計。沒有記錄首個正文的時間,首字後的推理時間也算在裡面",
@@ -6312,8 +6326,8 @@ const I18N = {
"Mask personal data": "脫敏個人資訊",
"Count me as a user": "計入使用者數",
"Once a day, a random id for this computer with magpie's version and system": "每天一次,傳送本機隨機 ID、magpie 版本和系統",
"Share the agents, providers and models I use": "分享我用的 agent、provider 和模型",
"Sent with that event, by magpie's own ids, with how many of each, and how often each partner was shown, opened and added; a provider you added yourself is only “custom”. No names, addresses, accounts, keys or usage": "隨上面那則一起傳送:只用 magpie 內建的 ID 和各自的數量,以及每個合作夥伴被展示、開啟和新增的次數;你自己新增的 provider 只記作「custom」。不含名稱、位址、帳號、金鑰和用量",
"Share the agents, providers, models and plugins I use": "分享我用的 agent、provider、模型和外掛",
"Sent with that event, by magpie's own ids, with how many of each, and how often each partner was shown, opened and added; a provider you added yourself is only “custom”. Which of Discover's plugins are installed goes to usemagpie.ai for its counts. No names, addresses, accounts, keys or usage": "隨上面那則一起傳送:只用 magpie 內建的 ID 和各自的數量,以及每個合作夥伴被展示、開啟和新增的次數;你自己新增的 provider 只記作「custom」。裝了 Discover 裡的哪些外掛會傳給 usemagpie.ai,用於外掛的使用人數。不含名稱、位址、帳號、金鑰和用量",
"Warm-up and check-in": "預熱與簽到",
"Warm up on reset": "時段重置時預熱",
"Daily warm-up": "每日定時預熱",
@@ -10029,6 +10043,13 @@ const I18N = {
"Other authors": "他の作者",
"Not installed only": "未インストールのみ",
"Most popular": "人気順",
"Most liked": "高評価順",
"Users": "利用者",
"{n} people use it, counted from the last week": "{n} 人が利用中(直近 7 日)",
"{n} people like it": "{n} 人がいいね",
"Take back your like": "いいねを取り消す",
"Like it": "いいね",
"Install it to like it": "インストールするといいねできます",
"Unreviewed": "未審査",
"No plugin matches": "該当するプラグインはありません",
"At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "下限:最初のトークン後 {ms} で回答 {n} トークン(推論 {r} トークンは含めず)。最初の本文の時刻が記録されていないため、最初のトークン後の推論の時間も含まれます",
@@ -11282,8 +11303,8 @@ const I18N = {
"Mask personal data": "個人情報をマスク",
"Count me as a user": "ユーザー数に含める",
"Once a day, a random id for this computer with magpie's version and system": "1 日 1 回、このコンピュータのランダムな ID と magpie のバージョン、システムを送信します",
"Share the agents, providers and models I use": "使っているエージェント、プロバイダー、モデルを共有",
"Sent with that event, by magpie's own ids, with how many of each, and how often each partner was shown, opened and added; a provider you added yourself is only “custom”. No names, addresses, accounts, keys or usage": "上の送信に含めます。magpie 組み込みの ID とそれぞれの数、各パートナーが表示・選択・追加された回数だけで、自分で追加したプロバイダーは「custom」とだけ記録します。名前、アドレス、アカウント、キー、使用量は含みません",
"Share the agents, providers, models and plugins I use": "使っているエージェント、プロバイダー、モデル、プラグインを共有",
"Sent with that event, by magpie's own ids, with how many of each, and how often each partner was shown, opened and added; a provider you added yourself is only “custom”. Which of Discover's plugins are installed goes to usemagpie.ai for its counts. No names, addresses, accounts, keys or usage": "上の送信に含めます。magpie 組み込みの ID とそれぞれの数、各パートナーが表示・選択・追加された回数だけで、自分で追加したプロバイダーは「custom」とだけ記録します。Discover のどのプラグインを入れているかは、利用者数のために usemagpie.ai に送ります。名前、アドレス、アカウント、キー、使用量は含みません",
"Warm-up and check-in": "ウォームアップとチェックイン",
"Warm up on reset": "リセット時にウォームアップ",
"Daily warm-up": "毎日のウォームアップ",
@@ -15014,6 +15035,13 @@ const I18N = {
"Other authors": "Andere Autoren",
"Not installed only": "Nur nicht installierte",
"Most popular": "Beliebteste",
"Most liked": "Beliebt bei Nutzern",
"Users": "Nutzer",
"{n} people use it, counted from the last week": "{n} nutzen es (letzte 7 Tage)",
"{n} people like it": "{n} gefällt es",
"Take back your like": "Gefällt mir zurücknehmen",
"Like it": "Gefällt mir",
"Install it to like it": "Installieren, um es zu mögen",
"Unreviewed": "Ungeprüft",
"No plugin matches": "Kein Plugin passt",
"At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "Mindestens: {n} Antwort-Token in {ms} nach dem ersten Token, ohne die {r} Reasoning-Token. Kein erster Text aufgezeichnet, also zählt Reasoning nach dem ersten Token mit",
@@ -16267,8 +16295,8 @@ const I18N = {
"Mask personal data": "Personenbezogene Daten maskieren",
"Count me as a user": "Mich als Nutzer zählen",
"Once a day, a random id for this computer with magpie's version and system": "Einmal täglich eine zufällige ID dieses Computers mit magpie-Version und System",
"Share the agents, providers and models I use": "Meine Agents, Anbieter und Modelle teilen",
"Sent with that event, by magpie's own ids, with how many of each, and how often each partner was shown, opened and added; a provider you added yourself is only “custom”. No names, addresses, accounts, keys or usage": "Mit diesem Ereignis, nur mit magpies eigenen IDs und ihrer Anzahl sowie wie oft jeder Partner gezeigt, geöffnet und hinzugefügt wurde; ein selbst hinzugefügter Anbieter heißt nur „custom“. Keine Namen, Adressen, Konten, Schlüssel oder Nutzung",
"Share the agents, providers, models and plugins I use": "Meine Agents, Anbieter, Modelle und Plugins teilen",
"Sent with that event, by magpie's own ids, with how many of each, and how often each partner was shown, opened and added; a provider you added yourself is only “custom”. Which of Discover's plugins are installed goes to usemagpie.ai for its counts. No names, addresses, accounts, keys or usage": "Mit diesem Ereignis, nur mit magpies eigenen IDs und ihrer Anzahl sowie wie oft jeder Partner gezeigt, geöffnet und hinzugefügt wurde; ein selbst hinzugefügter Anbieter heißt nur „custom“. Welche Plugins aus Discover installiert sind, geht für deren Zählung an usemagpie.ai. Keine Namen, Adressen, Konten, Schlüssel oder Nutzung",
"Warm-up and check-in": "Vorwärmen und Check-in",
"Warm up on reset": "Beim Reset vorwärmen",
"Daily warm-up": "Tägliches Vorwärmen",
+75
View File
@@ -0,0 +1,75 @@
// Discover's counts (plugins.js): how many use each plugin and how many
// like it, from usemagpie.ai through /api/plugins/counts, and the like on
// a plugin's page. Loaded when the Plugins page loads, not with the core.
// A like comes only from a computer that has the plugin installed.
(() => {
const HEART = "M8 13.4S2.6 10.2 2.6 6.3A2.8 2.8 0 0 1 8 5a2.8 2.8 0 0 1 5.4 1.3c0 3.9-5.4 7.1-5.4 7.1z";
const USER = "M8 7.8a2.4 2.4 0 1 0 0-4.8 2.4 2.4 0 0 0 0 4.8z M3.2 13.4c.6-2.3 2.5-3.6 4.8-3.6s4.2 1.3 4.8 3.6";
const ENOUGH = 20; // likes before the order goes by them, not by GitHub's stars
let got = {}, liked = new Set();
const n = (k) => got[k] || {};
const num = (v) => v >= 1e3 ? (v / 1e3).toFixed(v >= 1e4 ? 0 : 1) + "k" : String(v);
const chipOf = (d, v, title) => {
const c = el("span", "pm-dl");
c.append(svg(d, 11, 1.5), el("span", "", num(v)));
c.title = title;
return c;
};
window.pmCounts = {
async load(redraw) {
let r;
try { r = await api("plugins/counts"); } catch { return; }
const was = JSON.stringify([got, [...liked]]);
got = r.plugins || {};
liked = new Set(r.liked || []);
// the cards are drawn already: draw them again only for a change
if (JSON.stringify([got, [...liked]]) !== was) redraw();
},
users: (k) => n(k).users || 0,
// a card's facts: who uses it, who likes it
chips(meta, k) {
const { users, likes } = n(k);
if (users) meta.append(chipOf(USER, users, t("{n} people use it, counted from the last week", { n: users.toLocaleString(intlLang()) })));
if (likes) meta.append(chipOf(HEART, likes, t("{n} people like it", { n: likes.toLocaleString(intlLang()) })));
},
// Most liked: by likes once a plugin has ENOUGH, the rest by stars
order(a, b, then) {
const la = n(a.package).likes || 0, lb = n(b.package).likes || 0;
const ea = la >= ENOUGH, eb = lb >= ENOUGH;
if (ea !== eb) return ea ? -1 : 1;
if (ea) return lb - la || then(a, b);
return (b.github?.stars || 0) - (a.github?.stars || 0) || lb - la || then(a, b);
},
// the like on a plugin's page; installed says whether it may be given
like(k, installed) {
const b = el("button", "pm-like");
b.type = "button";
let busy = false;
const paint = () => {
if (busy) return;
const on = liked.has(k), may = on || installed();
b.classList.toggle("on", on);
b.disabled = !may;
b.setAttribute("aria-pressed", String(on));
b.title = may ? (on ? t("Take back your like") : t("Like it")) : t("Install it to like it");
b.replaceChildren(svg(HEART, 12, 1.5), el("span", "", num(n(k).likes || 0)));
};
b.onclick = async () => {
const on = !liked.has(k);
b.disabled = busy = true;
try {
const r = await api("plugins/like", { name: k, on });
liked = new Set(r.liked || []);
got[k] = { ...n(k), likes: r.likes };
} catch (e) {
b.title = e.message;
}
busy = false;
paint();
};
b.sync = paint;
paint();
return b;
},
};
})();
+6
View File
@@ -360,3 +360,9 @@ body.window .pm-manual { --bleed-l: 16px; }
.proto-menu.pm-srcmenu .pm-name, .proto-menu.pm-sortmenu .pm-name { display: block; }
.proto-menu.pm-srcmenu .pm-note:empty, .proto-menu.pm-sortmenu .pm-note:empty { display: none; }
.proto-menu.pm-srcmenu .pm-item:last-child { margin-top: 4px; box-shadow: 0 -1px 0 var(--line-2); }
.pm-like { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px; border: 0; border-radius: 7px; background: var(--pill); color: var(--fg-2); font: inherit; font-size: 11.5px; font-variant-numeric: tabular-nums; cursor: pointer; transition: background .15s ease, color .15s ease, transform .12s cubic-bezier(.23, 1, .32, 1); }
.pm-like:disabled { cursor: default; opacity: .55; }
.pm-like.on { color: var(--fg); }
.pm-like.on svg path { fill: currentColor; }
.pm-like:not(:disabled):active { transform: scale(.97); }
@media (hover: hover) and (pointer: fine) { .pm-like:not(:disabled):hover { background: var(--pill-hover); color: var(--fg); } }
+9 -3
View File
@@ -235,6 +235,7 @@
loadBuiltins(),
providers ? null : loadProviders().then(drawBody, () => {}),
];
import("./plugincounts.js").then(() => window.pmCounts.load(drawBody), () => {});
await Promise.all(parts);
askNPM();
askGit();
@@ -581,6 +582,7 @@
meta.append(o);
}
if (l.github) meta.append(stars(l.github.stars));
window.pmCounts?.chips(meta, l.package);
if (l.npm?.weekly) {
const d = el("span", "pm-dl");
d.append(glyph(DOWN, 11, 1.5), el("span", "", t("{n}/week", { n: count(l.npm.weekly) })));
@@ -655,13 +657,13 @@
const SHORT = { pv: "Subscriptions", mw: "Middleware", ag: "Agents", tl: "Tools", pg: "Pages" };
const SHELF_N = { pv: 6 };
const SOURCES = [["", "All sources"], ["ours", "magpie community"], ["third", "Other authors"], ["gh", "Unofficial, on GitHub"]];
const SORTS = [["hot", "Most popular"], ["name", "Name"]];
const SORTS = [["hot", "Most popular"], ["liked", "Most liked"], ["name", "Name"]];
let kindPick = "", srcPick = "", onlyNew = false, sortPick = "hot";
const srcOf = (l) => l.github ? "gh" : l.community ? "ours" : "third";
const hotOf = (l) => l.npm?.weekly || 0;
const nameOrder = (a, b) => a.name.localeCompare(b.name, intlLang());
const byHot = (a, b) => hotOf(b) - hotOf(a) || (b.github?.stars || 0) - (a.github?.stars || 0) || nameOrder(a, b);
const ranked = (list, how = sortPick) => [...list].sort(how === "name" ? nameOrder : byHot);
const ranked = (list, how = sortPick) => [...list].sort(how === "name" ? nameOrder : how === "liked" && window.pmCounts ? (a, b) => pmCounts.order(a, b, byHot) : byHot);
// the day in the reader's own calendar, which the daily pick turns on
const today = () => { const d = new Date(); return Math.floor((d.getTime() - d.getTimezoneOffset() * 6e4) / 864e5); };
@@ -728,6 +730,8 @@
const stats = el("div", "pm-stats");
const stat = (v, k) => { const s = el("div", "pm-stat"); s.append(el("b", "", v), el("span", "", k)); stats.append(s); };
stat(count(hotOf(l)), t("Downloads last week"));
const u = window.pmCounts?.users(l.package);
if (u) stat(count(u), t("Users"));
stat(t(SHORT[kindOf(l)]), t("Kind"));
if (l.npm?.version) stat("v" + l.npm.version, t("Version"));
const acts = el("div", "pm-hact");
@@ -1820,6 +1824,8 @@
if (!local) link("npm", "https://www.npmjs.com/package/" + l.package);
link(l.github ? "GitHub" : t("Source"), l.npm?.repository);
if (l.npm?.homepage && l.npm.homepage !== l.npm.repository && !l.npm.homepage.startsWith(l.npm.repository + "#")) link(t("Homepage"), l.npm.homepage);
const like = local ? null : window.pmCounts?.like(l.package, () => { const e = entryOf(l.package); return !!e && !e.off; });
if (like) links.append(like);
main.append(links);
if (l.github) {
const w = el("p", "pm-note warn");
@@ -1852,7 +1858,7 @@
confirmAsk = ed;
openModal(ed);
// the button follows an install or a sign-in made while it's open
const tick = setInterval(() => { if (!ed.isConnected) return stop(); redrawAct(); }, 600);
const tick = setInterval(() => { if (!ed.isConnected) return stop(); redrawAct(); like?.sync(); }, 600);
function stop() { clearInterval(tick); }
// the README takes the skeleton's place, and the dialog grows to it on
// the spring it opened on, centred as it goes, not in one jump; the
+1
View File
@@ -591,6 +591,7 @@ var (
)
func pluginRoutes(mux *http.ServeMux, w Windows) {
pluginCountRoutes(mux)
// the updates waiting for the reader, which put a dot on Plugins
mux.HandleFunc("GET /api/plugins/updates", func(rw http.ResponseWriter, r *http.Request) {
writeJSON(rw, plugin.PendingUpdates())
+132
View File
@@ -0,0 +1,132 @@
package gui
import (
"context"
"encoding/json"
"errors"
"io"
"net/http"
"os"
"path/filepath"
"slices"
"sync"
"time"
"github.com/yetone/magpie/internal/plugin"
"github.com/yetone/magpie/internal/settings"
"github.com/yetone/magpie/internal/stats"
)
// Discover's counts, from usemagpie.ai (stats): each plugin's users and
// likes, asked at most every hour, and the plugins liked here, kept on
// this computer.
var (
countsMu sync.Mutex
countsAt time.Time
countsGot map[string]stats.Counts
)
// pluginCountsAsk and pluginLike are stats', for tests to stand in for.
var (
pluginCountsAsk = stats.PluginCounts
pluginLike = stats.Like
pluginPublic = plugin.Public
)
func likedPath() string { return filepath.Join(settings.Dir(), "plugin-likes.json") }
// liked is the plugins liked on this computer; none when the file can't be
// read, which only leaves the hearts empty.
func liked() []string {
var l []string
if b, err := os.ReadFile(likedPath()); err == nil {
_ = json.Unmarshal(b, &l)
}
if l == nil {
l = []string{}
}
return l
}
func saveLiked(l []string) error {
b, _ := json.Marshal(l)
if err := os.MkdirAll(settings.Dir(), 0o755); err != nil {
return err
}
tmp := likedPath() + ".tmp"
if err := os.WriteFile(tmp, b, 0o644); err != nil {
return err
}
return os.Rename(tmp, likedPath())
}
// pluginCounts is the counts held, asked again when an hour old; a failed
// ask keeps what was held, tried again in a minute.
func pluginCounts(ctx context.Context) (map[string]stats.Counts, error) {
countsMu.Lock()
defer countsMu.Unlock()
if countsGot != nil && time.Since(countsAt) < time.Hour {
return countsGot, nil
}
got, err := pluginCountsAsk(ctx)
if err != nil {
countsAt = time.Now().Add(-time.Hour + time.Minute)
return countsGot, err
}
countsGot, countsAt = got, time.Now()
return got, nil
}
func pluginCountRoutes(mux *http.ServeMux) {
mux.HandleFunc("GET /api/plugins/counts", func(rw http.ResponseWriter, r *http.Request) {
got, err := pluginCounts(r.Context())
out := map[string]any{"plugins": got, "liked": liked()}
if got == nil {
out["plugins"] = map[string]stats.Counts{}
}
if err != nil {
out["error"] = err.Error()
}
writeJSON(rw, out)
})
// a like, or taking one back: only a plugin installed here, which
// Discover lists, can be liked
mux.HandleFunc("POST /api/plugins/like", func(rw http.ResponseWriter, r *http.Request) {
var in struct {
Name string `json:"name"`
On bool `json:"on"`
}
if err := json.NewDecoder(io.LimitReader(r.Body, 4<<10)).Decode(&in); err != nil || in.Name == "" {
fail(rw, errors.New("which plugin?"))
return
}
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
defer cancel()
if in.On && !slices.Contains(pluginPublic(ctx), in.Name) {
fail(rw, errors.New("only a plugin installed here can be liked"))
return
}
n, err := pluginLike(ctx, in.Name, in.On)
if err != nil {
fail(rw, err)
return
}
l := slices.DeleteFunc(liked(), func(x string) bool { return x == in.Name })
if in.On {
l = append(l, in.Name)
}
if err := saveLiked(l); err != nil {
fail(rw, err)
return
}
countsMu.Lock()
if countsGot != nil {
c := countsGot[in.Name]
c.Likes = n
countsGot[in.Name] = c
}
countsMu.Unlock()
writeJSON(rw, map[string]any{"likes": n, "liked": l})
})
}
+96
View File
@@ -0,0 +1,96 @@
package gui
import (
"context"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"slices"
"strings"
"testing"
"github.com/yetone/magpie/internal/stats"
)
// Discover's counts are asked once an hour; a like is taken only for a
// plugin installed here that Discover lists, is kept on this computer,
// and moves the count held at once.
func TestPluginCountsAndLikes(t *testing.T) {
h := builtinHome(t)
asked, likes := 0, map[string]bool{}
wasAsk, wasLike, wasPublic := pluginCountsAsk, pluginLike, pluginPublic
t.Cleanup(func() {
pluginCountsAsk, pluginLike, pluginPublic = wasAsk, wasLike, wasPublic
countsGot, countsAt = nil, countsAt.AddDate(-1, 0, 0)
})
countsGot = nil
fail := false
pluginCountsAsk = func(context.Context) (map[string]stats.Counts, error) {
asked++
if fail {
return nil, errors.New("offline")
}
return map[string]stats.Counts{"opencode-a": {Users: 12, Likes: 3}}, nil
}
pluginLike = func(_ context.Context, name string, on bool) (int, error) {
likes[name] = on
if on {
return 4, nil
}
return 3, nil
}
pluginPublic = func(context.Context) []string { return []string{"opencode-a"} }
get := func() (out struct {
Plugins map[string]stats.Counts `json:"plugins"`
Liked []string `json:"liked"`
Error string `json:"error"`
}) {
rec := httptest.NewRecorder()
h.ServeHTTP(rec, httptest.NewRequest("GET", "/api/plugins/counts", nil))
if rec.Code != http.StatusOK {
t.Fatalf("counts: %d %s", rec.Code, rec.Body)
}
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
t.Fatal(err)
}
return
}
like := func(body string) *httptest.ResponseRecorder {
rec := httptest.NewRecorder()
h.ServeHTTP(rec, httptest.NewRequest("POST", "/api/plugins/like", strings.NewReader(body)))
return rec
}
if c := get(); c.Plugins["opencode-a"] != (stats.Counts{Users: 12, Likes: 3}) || len(c.Liked) != 0 {
t.Fatalf("first: %+v", c)
}
get()
if asked != 1 {
t.Fatalf("asked %d times within the hour", asked)
}
if rec := like(`{"name":"opencode-b","on":true}`); rec.Code == http.StatusOK || likes["opencode-b"] {
t.Fatalf("a plugin not installed here was liked: %d %s", rec.Code, rec.Body)
}
if rec := like(`{"name":"opencode-a","on":true}`); rec.Code != http.StatusOK || !likes["opencode-a"] {
t.Fatalf("like: %d %s", rec.Code, rec.Body)
}
if c := get(); c.Plugins["opencode-a"].Likes != 4 || !slices.Equal(c.Liked, []string{"opencode-a"}) {
t.Fatalf("after a like: %+v", c)
}
// taking it back needs no install: a plugin removed since keeps no like
pluginPublic = func(context.Context) []string { return nil }
if rec := like(`{"name":"opencode-a","on":false}`); rec.Code != http.StatusOK || likes["opencode-a"] {
t.Fatalf("unlike: %d %s", rec.Code, rec.Body)
}
if c := get(); c.Plugins["opencode-a"].Likes != 3 || len(c.Liked) != 0 {
t.Fatalf("after unlike: %+v", c)
}
// an hour on, a failed ask keeps what was held
countsAt = countsAt.Add(-2 * 60 * 60 * 1e9)
fail = true
if c := get(); c.Plugins["opencode-a"].Users != 12 || c.Error == "" {
t.Fatalf("a failed ask: %+v", c)
}
}
+2 -1
View File
@@ -170,9 +170,10 @@ test("compat.js is the first of the page's own scripts", async () => {
// Agents page's Manage is pressed, agentsuffix.js when an agent's Details
// open, phonetabs.js when magpie web is laid out for a phone,
// pluginmd.js (a README's renderer) once plugins.js has run;
// plugincounts.js (Discover's counts) when the Plugins page loads;
// the checks above
// still read them
for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quitask.js", "checkinnow.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "balfound.js", "passerrors.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js", "setfeats.js", "pageshare.js", "panelfirst.js", "panelarrange.js", "modelfind.js", "agentsmanager.js", "agentsuffix.js", "phonetabs.js", "pluginmd.js", "bark.js", "acctexport.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quitask.js", "checkinnow.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "balfound.js", "passerrors.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js", "setfeats.js", "pageshare.js", "panelfirst.js", "panelarrange.js", "modelfind.js", "agentsmanager.js", "agentsuffix.js", "phonetabs.js", "pluginmd.js", "bark.js", "acctexport.js", "plugincounts.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
});
test("the styles hold up in Safari 15.0", async () => {
@@ -35,8 +35,8 @@ function serve(lang, settings, saved) {
}
const words = {
en: { count: "Count me as a user", share: "Share the agents, providers and models I use", personal: "Mask personal data", on: "On", off: "Off" },
zh: { count: "计入用户数", share: "分享我用的 agent、provider 和模型", personal: "脱敏个人信息", on: "开启", off: "关闭" },
en: { count: "Count me as a user", share: "Share the agents, providers, models and plugins I use", personal: "Mask personal data", on: "On", off: "Off" },
zh: { count: "计入用户数", share: "分享我用的 agent、provider、模型和插件", personal: "脱敏个人信息", on: "开启", off: "关闭" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
+66
View File
@@ -0,0 +1,66 @@
package plugin
import (
"context"
"slices"
"strings"
)
// Public is the plugins installed and on here that Discover shows to
// everyone, each by the key Discover gives it: a package magpie's list
// names, or a repository tagged Topic, by its Spec. A plugin from a
// private repository, a folder, or a package neither names is never in
// it: what the day's report and a like send of the user's plugins is
// this and nothing else (internal/stats).
func Public(ctx context.Context) []string {
installed := Load().Plugins
if len(installed) == 0 {
return nil
}
listed := map[string]bool{}
for _, l := range Market(ctx) {
listed[l.Package] = true
}
// GitHub not answering keeps the list it gave last
tagged, _ := TaggedRepos(ctx)
return public(installed, listed, tagged)
}
func public(installed []Entry, listed map[string]bool, tagged []Tagged) []string {
byRepo := map[string]string{}
for _, t := range tagged {
byRepo[strings.ToLower(t.Repo)] = t.Spec
// one published on npm from its repository is installed by
// that name too
if t.Spec != "" && !IsGit(t.Spec) {
listed[t.Spec] = true
}
}
out := []string{}
for _, e := range installed {
if e.Off || IsPath(e.Spec) {
continue
}
key := ""
if IsGit(e.Spec) {
// a repository by the repository it is, never by the package
// name it gives, which another repository can give too
key = byRepo[strings.ToLower(githubRepo(gitHubSpec(e.Spec)))]
} else if n := Name(e.Spec); listed[n] {
key = n
}
if key != "" && !slices.Contains(out, key) {
out = append(out, key)
}
}
return out
}
// gitHubSpec is spec as githubRepo reads it: owner/repo, GitHub's
// shorthand, as github:owner/repo.
func gitHubSpec(spec string) string {
if !strings.Contains(spec, ":") {
return "github:" + spec
}
return spec
}
+38
View File
@@ -0,0 +1,38 @@
package plugin
import (
"slices"
"testing"
)
// What the day's report may say of the plugins installed: a package
// magpie's list names, a repository tagged magpie-plugin by its spec,
// and nothing else: not a folder, a private repository, a package no
// list names, nor one turned off.
func TestPublicPlugins(t *testing.T) {
installed := []Entry{
{Spec: "@magpie-community/opencode-cursor-auth@0.2.44"},
{Spec: "opencode-third-party"},
{Spec: "github:Alice/Tagged#main"},
{Spec: "https://github.com/alice/tagged2.git"},
{Spec: "bob/tagged3"},
{Spec: "carol-npm-from-repo@1.0.0"},
{Spec: "github:corp/private-plugin"},
{Spec: "@corp/internal-plugin"},
{Spec: "/Users/me/my-plugin"},
{Spec: "./plugin.js"},
{Spec: "opencode-turned-off", Off: true},
}
listed := map[string]bool{"@magpie-community/opencode-cursor-auth": true, "opencode-third-party": true, "opencode-turned-off": true}
tagged := []Tagged{
{Repo: "alice/tagged", Spec: "github:alice/tagged"},
{Repo: "alice/tagged2", Spec: "github:alice/tagged2"},
{Repo: "bob/tagged3", Spec: "github:bob/tagged3"},
{Repo: "carol/npm-from-repo", Spec: "carol-npm-from-repo"},
}
got := public(installed, listed, tagged)
want := []string{"@magpie-community/opencode-cursor-auth", "opencode-third-party", "github:alice/tagged", "github:alice/tagged2", "github:bob/tagged3", "carol-npm-from-repo"}
if !slices.Equal(got, want) {
t.Fatalf("public = %q\nwant %q", got, want)
}
}
+126
View File
@@ -0,0 +1,126 @@
package stats
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"strings"
"time"
"github.com/yetone/magpie/internal/plugin"
"github.com/yetone/magpie/internal/update"
)
// Discover's counts: how many computers use each plugin, and its likes.
// With the day's event, unless the user turned off what magpie is used
// with, usemagpie.ai is told which plugins Discover lists are installed
// and on here (plugin.Public: never a private repository, a folder or a
// package no list names), under the same random id; it counts the
// computers that said so in the last seven days. A like is the user's
// own act, sent when they make it.
// Site takes the day's plugins and the likes; MAGPIE_SITE_HOST points
// them elsewhere, for testing.
func Site() string {
if h := os.Getenv("MAGPIE_SITE_HOST"); h != "" {
return strings.TrimRight(h, "/")
}
return update.Site
}
// publicPlugins is plugin.Public; tests put their own.
var publicPlugins = plugin.Public
// sendPlugins tells usemagpie.ai the plugins installed here Discover
// lists; nothing when there are none.
func sendPlugins(ctx context.Context, id string) error {
names := publicPlugins(ctx)
if len(names) == 0 {
return nil
}
if len(names) > most {
names = names[:most]
}
return post(ctx, "/api/plugins/report", map[string]any{"id": id, "plugins": names}, nil)
}
// Counts is what usemagpie.ai says of each plugin: the computers that
// had it in the last seven days, and its likes.
type Counts struct {
Users int `json:"users,omitempty"`
Likes int `json:"likes,omitempty"`
}
// PluginCounts asks usemagpie.ai each plugin's counts, by Discover's key.
func PluginCounts(ctx context.Context) (map[string]Counts, error) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "GET", Site()+"/api/plugins/stats", nil)
if err != nil {
return nil, err
}
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode/100 != 2 {
return nil, fmt.Errorf("plugin counts: %s", res.Status)
}
var out struct {
Plugins map[string]Counts `json:"plugins"`
}
if err := json.NewDecoder(http.MaxBytesReader(nil, res.Body, 4<<20)).Decode(&out); err != nil {
return nil, err
}
if out.Plugins == nil {
out.Plugins = map[string]Counts{}
}
return out.Plugins, nil
}
// Like likes the plugin Discover keys name, or takes the like back, under
// this computer's id; the answer is its likes now. The page lets only a
// plugin installed here be liked (gui), and the like says it is.
func Like(ctx context.Context, name string, on bool) (int, error) {
id, err := installID()
if err != nil {
return 0, err
}
var out struct {
Likes int `json:"likes"`
}
err = post(ctx, "/api/plugins/like", map[string]any{"id": id, "plugin": name, "on": on}, &out)
return out.Likes, err
}
func post(ctx context.Context, path string, in any, out any) error {
body, _ := json.Marshal(in)
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "POST", Site()+path, bytes.NewReader(body))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode/100 != 2 {
var e struct{ Error string }
_ = json.NewDecoder(http.MaxBytesReader(nil, res.Body, 64<<10)).Decode(&e)
if e.Error != "" {
return fmt.Errorf("usemagpie.ai: %s", e.Error)
}
return fmt.Errorf("usemagpie.ai: %s", res.Status)
}
if out != nil {
return json.NewDecoder(http.MaxBytesReader(nil, res.Body, 64<<10)).Decode(out)
}
return nil
}
+91
View File
@@ -0,0 +1,91 @@
package stats
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"slices"
"testing"
"time"
"github.com/yetone/magpie/internal/settings"
)
// The day's plugins go to usemagpie.ai with the day's event, under its
// id, as plugin.Public has them; not when the user turned off what magpie
// is used with, nor when stats are off, nor with no plugin to name. A like
// goes under the same id.
func TestSendPlugins(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
t.Setenv("DO_NOT_TRACK", "")
t.Setenv("MAGPIE_NO_STATS", "")
usage = func() Usage { return Usage{} }
plugins := []string{"@magpie-community/opencode-cursor-auth", "github:alice/tagged"}
was := publicPlugins
publicPlugins = func(context.Context) []string { return plugins }
defer func() { usage, publicPlugins = readUsage, was }()
type report struct {
ID string `json:"id"`
Plugins []string `json:"plugins"`
Plugin string `json:"plugin"`
On bool `json:"on"`
}
var reports, likes []report
var posthogID string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/batch/":
var b struct {
Batch []map[string]any `json:"batch"`
}
json.NewDecoder(r.Body).Decode(&b)
posthogID = b.Batch[0]["distinct_id"].(string)
case "/api/plugins/report":
var b report
json.NewDecoder(r.Body).Decode(&b)
reports = append(reports, b)
case "/api/plugins/like":
var b report
json.NewDecoder(r.Body).Decode(&b)
likes = append(likes, b)
w.Write([]byte(`{"likes":7}`))
default:
t.Errorf("asked %s", r.URL.Path)
}
}))
defer srv.Close()
t.Setenv("MAGPIE_STATS_HOST", srv.URL)
t.Setenv("MAGPIE_SITE_HOST", srv.URL)
day := time.Date(2026, 11, 11, 9, 0, 0, 0, time.UTC)
if err := Send(context.Background(), "0.1.300", "app", day); err != nil {
t.Fatal(err)
}
if len(reports) != 1 || reports[0].ID != posthogID || len(posthogID) != 32 || !slices.Equal(reports[0].Plugins, plugins) {
t.Fatalf("reports %+v (event's id %q)", reports, posthogID)
}
// once a day
Send(context.Background(), "0.1.300", "app", day.Add(time.Hour))
if len(reports) != 1 {
t.Fatalf("sent again the same day: %+v", reports)
}
n, err := Like(context.Background(), "github:alice/tagged", true)
if err != nil || n != 7 || len(likes) != 1 || likes[0].ID != posthogID || likes[0].Plugin != "github:alice/tagged" || !likes[0].On {
t.Fatalf("like: %d %v %+v", n, err, likes)
}
// none to name: nothing goes
plugins = nil
Send(context.Background(), "0.1.300", "app", day.Add(24*time.Hour))
plugins = []string{"opencode-x"}
settings.Save(settings.Settings{NoUsageStats: true})
Send(context.Background(), "0.1.300", "app", day.Add(48*time.Hour))
settings.Save(settings.Settings{NoStats: true})
Send(context.Background(), "0.1.300", "app", day.Add(72*time.Hour))
if len(reports) != 1 {
t.Fatalf("sent with nothing to name, or turned off: %+v", reports)
}
}
+6 -1
View File
@@ -3,7 +3,9 @@
// version and system, and, unless the user turned that part off, which
// agents, providers and models it is used with, by their built-in ids
// (Usage): a provider of the user's own is only "custom". No names, URLs,
// accounts, keys, prompts or usage go. Settings → Privacy turns it off,
// accounts, keys, prompts or usage go. With that part, usemagpie.ai is
// told which of the plugins Discover lists are installed here, for
// Discover's counts (plugins.go). Settings → Privacy turns it off,
// and so do DO_NOT_TRACK=1 and MAGPIE_NO_STATS=1; a build from source
// never sends it.
package stats
@@ -137,6 +139,9 @@ func Send(ctx context.Context, version, what string, now time.Time) error {
}
if !settings.Load().NoUsageStats {
provider.PartnerCountsSent(now)
// Discover's counts; the day's event went, so this isn't tried
// again till tomorrow when it fails
_ = sendPlugins(ctx, id)
}
return os.WriteFile(stamp, []byte(day+"\n"), 0o644)
}
+151
View File
@@ -0,0 +1,151 @@
// Discover's counts (the app's internal/stats/plugins.go): how many
// computers use each plugin Discover lists, and how many like it.
//
// Each app that lets its usage stats go reports once a day which of
// Discover's plugins are installed, under its random install id, never an
// account or address. A plugin's users are the ids that reported it in
// the last seven days. A like is one per id, can be taken back, and comes
// only from an app that has the plugin (the app checks; here a like also
// counts as that id having it). The caller's address is kept only hashed,
// for an hour, to hold each one to RATE asks an hour.
//
// D1 (wrangler.jsonc's PLUGINS) holds three tables; the quarter-hour
// cron prunes what is old.
const ID = /^[0-9a-f]{32}$/;
const NPM = /^(@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
const GIT = /^github:[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
export const MOST = 50; // plugins in one report, as the app's most
export const RATE = 60; // asks an address makes in an hour
const WEEK = 7 * 864e5;
const KEEP = 30 * 864e5;
const SCHEMA = [
"CREATE TABLE IF NOT EXISTS installs (device TEXT NOT NULL, plugin TEXT NOT NULL, day TEXT NOT NULL, PRIMARY KEY (device, plugin))",
"CREATE INDEX IF NOT EXISTS installs_day ON installs (day)",
"CREATE TABLE IF NOT EXISTS likes (device TEXT NOT NULL, plugin TEXT NOT NULL, PRIMARY KEY (device, plugin))",
"CREATE TABLE IF NOT EXISTS asks (who TEXT NOT NULL, hour INTEGER NOT NULL, n INTEGER NOT NULL, PRIMARY KEY (who, hour))",
];
// the tables are made once an isolate, for each database it is given
const made = new WeakMap();
function schema(db) {
if (!made.has(db))
made.set(
db,
db.batch(SCHEMA.map((s) => db.prepare(s))).catch((e) => {
made.delete(db);
throw e;
}),
);
return made.get(db);
}
export function validName(n) {
return typeof n === "string" && n.length <= 214 && (NPM.test(n) || GIT.test(n));
}
const day = (t) => new Date(t).toISOString().slice(0, 10);
function answer(body, status = 200, headers = {}) {
return new Response(JSON.stringify(body), {
status,
headers: { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store", ...headers },
});
}
async function who(req) {
const ip = req.headers.get("CF-Connecting-IP") || "";
const h = await crypto.subtle.digest("SHA-256", new TextEncoder().encode("magpie-plugins:" + ip));
return [...new Uint8Array(h).slice(0, 12)].map((b) => b.toString(16).padStart(2, "0")).join("");
}
// held reports whether the caller has made RATE asks this hour already
async function held(db, req, now) {
const row = await db
.prepare("INSERT INTO asks (who, hour, n) VALUES (?1, ?2, 1) ON CONFLICT (who, hour) DO UPDATE SET n = n + 1 RETURNING n")
.bind(await who(req), Math.floor(now / 36e5))
.first();
return (row?.n ?? 0) > RATE;
}
async function body(req) {
if (req.method !== "POST") return null;
try {
const text = await req.text();
if (text.length > 64 << 10) return null;
return JSON.parse(text);
} catch {
return null;
}
}
// handle answers /api/plugins/*, or null for any other path.
export async function handle(req, env, ctx, now = Date.now()) {
const path = new URL(req.url).pathname;
if (!["/api/plugins/report", "/api/plugins/like", "/api/plugins/stats"].includes(path)) return null;
const db = env.PLUGINS;
if (!db) return answer({ error: "counts aren't kept here" }, 503);
await schema(db);
if (path === "/api/plugins/stats") {
if (req.method !== "GET" && req.method !== "HEAD") return answer({ error: "GET" }, 405);
return stats(req, db, ctx, now);
}
const b = await body(req);
if (!b || !ID.test(b.id ?? "")) return answer({ error: "a report needs the app's id" }, 400);
if (await held(db, req, now)) return answer({ error: "too many asks; try again in an hour" }, 429);
if (path === "/api/plugins/report") {
const names = Array.isArray(b.plugins) ? [...new Set(b.plugins)] : null;
if (!names || names.length > MOST || !names.every(validName)) return answer({ error: "plugins: names Discover lists" }, 400);
const today = day(now);
const marks = names.map((_, i) => `?${i + 2}`).join(",");
const gone = db.prepare(`DELETE FROM installs WHERE device = ?1${names.length ? ` AND plugin NOT IN (${marks})` : ""}`).bind(b.id, ...names);
const put = names.map((n) =>
db
.prepare("INSERT INTO installs (device, plugin, day) VALUES (?1, ?2, ?3) ON CONFLICT (device, plugin) DO UPDATE SET day = ?3")
.bind(b.id, n, today),
);
await db.batch([gone, ...put]);
return answer({ ok: true });
}
// a like, or one taken back
if (!validName(b.plugin) || typeof b.on !== "boolean") return answer({ error: "which plugin, and on or off?" }, 400);
const steps = b.on
? [
db.prepare("INSERT INTO likes (device, plugin) VALUES (?1, ?2) ON CONFLICT DO NOTHING").bind(b.id, b.plugin),
db
.prepare("INSERT INTO installs (device, plugin, day) VALUES (?1, ?2, ?3) ON CONFLICT (device, plugin) DO UPDATE SET day = ?3")
.bind(b.id, b.plugin, day(now)),
]
: [db.prepare("DELETE FROM likes WHERE device = ?1 AND plugin = ?2").bind(b.id, b.plugin)];
await db.batch(steps);
const row = await db.prepare("SELECT COUNT(*) AS n FROM likes WHERE plugin = ?1").bind(b.plugin).first();
return answer({ likes: row?.n ?? 0 });
}
// stats is every plugin's users and likes, held at the edge for an hour
async function stats(req, db, ctx, now) {
const key = new Request(new URL("/api/plugins/stats", req.url).toString());
const hit = await caches.default.match(key);
if (hit) return hit;
const [users, likes] = await db.batch([
db.prepare("SELECT plugin, COUNT(*) AS n FROM installs WHERE day >= ?1 GROUP BY plugin").bind(day(now - WEEK)),
db.prepare("SELECT plugin, COUNT(*) AS n FROM likes GROUP BY plugin"),
]);
const plugins = {};
for (const r of users.results) (plugins[r.plugin] ??= {}).users = r.n;
for (const r of likes.results) (plugins[r.plugin] ??= {}).likes = r.n;
const res = answer({ plugins }, 200, { "Cache-Control": "public, max-age=3600" });
ctx.waitUntil(caches.default.put(key, res.clone()));
return res;
}
// prune drops installs not reported in a month and addresses' old counts
export async function prune(env, now = Date.now()) {
const db = env.PLUGINS;
if (!db) return;
await schema(db);
await db.batch([
db.prepare("DELETE FROM installs WHERE day < ?1").bind(day(now - KEEP)),
db.prepare("DELETE FROM asks WHERE hour < ?1").bind(Math.floor(now / 36e5) - 1),
]);
}
+134
View File
@@ -0,0 +1,134 @@
// node --test site/: Discover's counts (pluginstats.js), on a D1 stood in
// for by node:sqlite.
import { test } from "node:test";
import assert from "node:assert/strict";
import { DatabaseSync } from "node:sqlite";
import { handle, prune, RATE, MOST } from "./pluginstats.js";
// d1 is the part of D1's API pluginstats.js uses
function d1() {
const db = new DatabaseSync(":memory:");
const stmt = (sql, args = []) => ({
bind: (...a) => stmt(sql, a),
run: async () => (db.prepare(sql).run(...args), { success: true }),
first: async () => db.prepare(sql).get(...args) ?? null,
all: async () => ({ results: db.prepare(sql).all(...args) }),
async exec() {
return /^\s*(SELECT|.*RETURNING)/is.test(sql) ? this.all() : this.run().then(() => ({ results: [] }));
},
});
return {
prepare: (sql) => stmt(sql),
async batch(list) {
db.exec("BEGIN");
try {
const out = [];
for (const s of list) out.push(await s.exec());
db.exec("COMMIT");
return out;
} catch (e) {
db.exec("ROLLBACK");
throw e;
}
},
};
}
const store = new Map();
globalThis.caches = {
default: {
match: async (req) => (store.has(req.url) ? new Response(store.get(req.url)) : undefined),
put: async (req, res) => void store.set(req.url, await res.text()),
},
};
const ctx = { waitUntil: (p) => p };
const id = (n) => n.toString(16).padStart(32, "0");
const DAY = 864e5;
const T0 = Date.parse("2026-11-10T12:00:00Z");
function ask(env, path, body, now = T0, ip = "203.0.113.1") {
const req = new Request("https://usemagpie.ai" + path, {
method: body === undefined ? "GET" : "POST",
headers: { "CF-Connecting-IP": ip, "Content-Type": "application/json" },
body: body === undefined ? undefined : typeof body === "string" ? body : JSON.stringify(body),
});
return handle(req, env, ctx, now);
}
async function counts(env, now = T0) {
store.clear();
return (await (await ask(env, "/api/plugins/stats", undefined, now)).json()).plugins;
}
test("users are the ids that reported a plugin in the last week", async () => {
const env = { PLUGINS: d1() };
assert.equal((await ask(env, "/api/plugins/report", { id: id(1), plugins: ["opencode-a", "github:alice/b"] })).status, 200);
await ask(env, "/api/plugins/report", { id: id(2), plugins: ["opencode-a"] });
// the same id again is one user
await ask(env, "/api/plugins/report", { id: id(2), plugins: ["opencode-a"] }, T0 + DAY);
assert.deepEqual(await counts(env, T0 + DAY), { "opencode-a": { users: 2 }, "github:alice/b": { users: 1 } });
// an id that removed a plugin stops counting for it at its next report
await ask(env, "/api/plugins/report", { id: id(1), plugins: [] }, T0 + DAY);
assert.deepEqual(await counts(env, T0 + DAY), { "opencode-a": { users: 1 } });
// eight days on without a report, nobody
assert.deepEqual(await counts(env, T0 + 9 * DAY), {});
// the cron drops rows a month old
await prune(env, T0 + 40 * DAY);
assert.equal((await env.PLUGINS.prepare("SELECT COUNT(*) AS n FROM installs").first()).n, 0);
});
test("a like is one per id, can be taken back, and counts the id as a user", async () => {
const env = { PLUGINS: d1() };
const like = async (n, on) => (await (await ask(env, "/api/plugins/like", { id: id(n), plugin: "opencode-a", on })).json()).likes;
assert.equal(await like(1, true), 1);
assert.equal(await like(1, true), 1);
assert.equal(await like(2, true), 2);
assert.equal(await like(1, false), 1);
assert.deepEqual(await counts(env), { "opencode-a": { users: 2, likes: 1 } });
});
test("the counts are held at the edge for an hour", async () => {
const env = { PLUGINS: d1() };
await ask(env, "/api/plugins/report", { id: id(1), plugins: ["opencode-a"] });
store.clear();
const first = await ask(env, "/api/plugins/stats");
assert.match(first.headers.get("Cache-Control"), /max-age=3600/);
await ask(env, "/api/plugins/report", { id: id(2), plugins: ["opencode-a"] });
assert.deepEqual((await (await ask(env, "/api/plugins/stats")).json()).plugins, { "opencode-a": { users: 1 } });
});
test("only an app's id and the names Discover lists are taken", async () => {
const env = { PLUGINS: d1() };
const bad = [
"not json",
{ plugins: ["opencode-a"] },
{ id: "me@example.com", plugins: ["opencode-a"] },
{ id: id(1), plugins: "opencode-a" },
{ id: id(1), plugins: ["/Users/me/secret-plugin"] },
{ id: id(1), plugins: ["git+ssh://git@corp.example/x.git"] },
{ id: id(1), plugins: ["https://github.com/a/b"] },
{ id: id(1), plugins: ["x".repeat(215)] },
{ id: id(1), plugins: Array.from({ length: MOST + 1 }, (_, i) => `p${i}`) },
];
for (const b of bad) assert.equal((await ask(env, "/api/plugins/report", b)).status, 400, JSON.stringify(b).slice(0, 80));
for (const b of [{ id: id(1), plugin: "../x", on: true }, { id: id(1), plugin: "opencode-a", on: "yes" }])
assert.equal((await ask(env, "/api/plugins/like", b)).status, 400);
assert.deepEqual(await counts(env), {});
// the caller's address is kept only hashed
const rows = await env.PLUGINS.prepare("SELECT who FROM asks").all();
assert.ok(rows.results.length > 0 && rows.results.every((r) => !r.who.includes("203.0.113")));
});
test("an address makes RATE asks an hour", async () => {
const env = { PLUGINS: d1() };
for (let i = 0; i < RATE; i++)
assert.equal((await ask(env, "/api/plugins/like", { id: id(i), plugin: "opencode-a", on: true })).status, 200);
assert.equal((await ask(env, "/api/plugins/like", { id: id(99), plugin: "opencode-a", on: true })).status, 429);
// another address, or the next hour, is let through
assert.equal((await ask(env, "/api/plugins/like", { id: id(99), plugin: "opencode-a", on: true }, T0, "198.51.100.2")).status, 200);
assert.equal((await ask(env, "/api/plugins/like", { id: id(98), plugin: "opencode-a", on: true }, T0 + 36e5)).status, 200);
});
test("without the database, the counts are refused, not made up", async () => {
assert.equal((await ask({}, "/api/plugins/stats")).status, 503);
assert.equal(await handle(new Request("https://usemagpie.ai/api/plugins/other"), {}, ctx), null);
});
+4 -1
View File
@@ -122,6 +122,7 @@
<li><b>モデル</b>:つないだエージェントに設定されたモデルを、プロバイダー ID とベンダーのモデル ID で(<code>deepseek/deepseek-v4</code>)。キーのプロバイダーで <a href="https://models.dev">models.dev</a> に載っていないモデル ID(ローカルモデル、ファインチューン)は <code>&lt;プロバイダー&gt;/other</code>、自分のプロバイダーのモデルは <code>custom</code>、ルーティンググループは <code>group</code> です。</li>
</ul>
<p>あわせて <code>magpie partner</code> イベントも送ります。プロバイダー追加シートの先頭に載る各パートナーについて、その ID で、終わった日にシートに表示された回数、行が開かれた回数、キーのページが開かれた回数、そこからプロバイダーが追加された回数です(<code>what</code>:<code>shown</code>、<code>opened</code>、<code>keys</code>、<code>added</code>。1 日にそれぞれ最大 20 回、追加は 5 回)。回数だけで、自分のプロバイダーは含みません。</p>
<p id="plugins">この部分がオンのとき、magpie は同じ日に、Discover に載っているどのプラグインを入れて(オンにして)いるかを <code>usemagpie.ai</code> に伝え、Discover が各プラグインの利用者数を示せるようにします:<code>POST /api/plugins/report</code> に同じランダムな ID とプラグインの npm パッケージ名、<code>magpie-plugin</code> タグのリポジトリは <code>github:owner/repo</code>(最大 50 個)。フォルダーから入れたもの、非公開リポジトリ、Discover に載っていないパッケージのプラグインは送りません。プラグインのページでのいいねは <code>POST /api/plugins/like</code> で、ID、プラグイン、オンかオフかを送ります。いいねできるのはこのコンピューターに入っているプラグインだけで、いいねしたものは <code>plugin-likes.json</code> に残ります。サイトは直近 7 日に報告した ID の数を数え、報告は 30 日で消します。アドレスはハッシュだけを 1 時間、頻度の制限のために残します。Discover は ID を含まない <code>GET /api/plugins/stats</code> で数を読みます。コードは <a href="https://github.com/yetone/magpie/blob/main/internal/stats/plugins.go">internal/stats/plugins.go</a> と <a href="https://github.com/yetone/magpie/blob/main/site/pluginstats.js">site/pluginstats.js</a> です。</p>
<p>どのイベントにも <code>$process_person_profile: false</code> が付き、PostHog はこの ID の人物プロファイルを作りません。名前、Base URL、アカウント、キー、プロンプト、返答、使用量は送りません。まとめ全体はこのような形です。</p>
<div class="code">
<span class="lang">POST https://us.i.posthog.com/batch/</span>
@@ -155,7 +156,7 @@
<ul>
<li><span class="ui">設定</span> → <span class="ui">プライバシー</span> → <span class="ui">ユーザー数に含める</span> をオフ、または <code>settings.json</code> に <code>"noStats": true</code>:毎日のカウント全体。</li>
<li>magpie の環境に <code>DO_NOT_TRACK=1</code> か <code>MAGPIE_NO_STATS=1</code>(空、<code>0</code>、<code>false</code> 以外の値):設定にかかわらず、毎日のカウント全体。</li>
<li><span class="ui">設定</span> → <span class="ui">プライバシー</span> → <span class="ui">使っているエージェント、プロバイダー、モデルを共有</span> をオフ、または <code>"noUsageStats": true</code>:<code>magpie uses</code> と <code>magpie partner</code> イベント、<code>magpie active</code> の数。ID、バージョン、システムは送られます。パートナーの回数も記録しなくなります。</li>
<li><span class="ui">設定</span> → <span class="ui">プライバシー</span> → <span class="ui">使っているエージェント、プロバイダー、モデル、プラグインを共有</span> をオフ、または <code>"noUsageStats": true</code>:<code>magpie uses</code> と <code>magpie partner</code> イベント、<code>magpie active</code> の数、<a href="#plugins">プラグインの報告</a>。ID、バージョン、システムは送られます。パートナーの回数も記録しなくなります。</li>
<li><span class="ui">設定</span> → <span class="ui">情報</span> → <span class="ui">自動アップデート</span> をオフ、または <code>"noAutoUpdate": true</code>:magpie が自分から <code>usemagpie.ai</code> に新しいバージョンを尋ねること(そうでなければ 6 時間ごと)。カウントの一部ではありません。</li>
</ul>
<p>設定の変更は次の 1 時間ごとの確認で反映され、再起動はいりません。<code>settings.json</code> は magpie のフォルダーにあります(<a href="#files">下記</a>)。</p>
@@ -175,6 +176,7 @@
<tr><th>ファイル</th><th>内容</th></tr>
<tr><td><code>install-id</code></td><td>ランダムな ID。初めてカウントを送るときに作られます</td></tr>
<tr><td><code>stats-sent</code></td><td>最後に送った日(UTC)。1 日 1 回にするため</td></tr>
<tr><td><code>plugin-likes.json</code></td><td>Discover でいいねしたプラグイン</td></tr>
<tr><td><code>partner-counts.json</code>(キャッシュフォルダー)</td><td>まだ送っていないパートナーの回数。最大 14 日分</td></tr>
</table></div>
<p><code>install-id</code> と <code>stats-sent</code> は magpie のフォルダーにあります。macOS と Linux では <code>~/.config/magpie</code>、Windows では <code>%USERPROFILE%\.config\magpie</code>、<code>$XDG_CONFIG_HOME</code> が設定されていれば <code>$XDG_CONFIG_HOME/magpie</code>、ポータブル版ではそのデータフォルダーです。<code>partner-counts.json</code> は <code>~/.cache/magpie</code>(<code>$XDG_CACHE_HOME/magpie</code>、ポータブル版ではデータフォルダーの <code>cache</code>)にあります。どれも削除できます。<code>install-id</code> を消すと次の送信で新しいランダムな ID が作られ、新しいユーザーとして数えられます。カウントをオフにすれば、どれも再び書かれません。</p>
@@ -188,6 +190,7 @@
<li><code>/files/&lt;バージョン&gt;/&lt;ファイル&gt;</code>:更新とインストーラがダウンロードするリリースファイルで、Cloudflare R2 から配信されます。サイトにないファイルは github.com へ転送されます。何も計測しません。</li>
<li><code>/api/partners</code>:プロバイダー追加シートのパートナー一覧。6 時間ごと。パートナーが載っている間、10 回に 1 回の取得を Cloudflare が示す国とともに <code>magpie partners fetch</code> として数えます。</li>
<li><code>/go/&lt;パートナー&gt;/site</code> と <code>/go/&lt;パートナー&gt;/keys</code>:パートナーの公式サイトとキーのページへのリンクをブラウザーで開くと、移動の前に <code>magpie partner go</code>(どのパートナーか、どのリンクか、地域、国)として数えます。</li>
<li><code>/api/plugins/stats</code>:Discover の各プラグインの利用者数といいねの数。多くて 1 時間に 1 回で、ID は含みません。<a href="#plugins">プラグインの報告</a>といいねは ID を含み、共有がオンのときだけ送ります。</li>
<li><code>/api/icon?url=…</code>:プラグイン、インポートリンク、ライブラリが示すアイコンはここを経由して取得するので、アイコンのあるホストに見えるのはあなたではなく Cloudflare のアドレスです。画像を中継するだけで、数えることも記録することもしません。</li>
</ul>
<p>サイト自身のページ(このドキュメント、ホーム)には Cloudflare Web Analytics と PostHog Web Analytics(<code>us.i.posthog.com</code>)が入っており、どちらも Cookie は使いません。PostHog はこのサイト用のランダムな訪問者 ID をブラウザのローカルストレージに保存し、再訪問を同じ訪問者として数えます。受け取るのは各ページのアドレス、参照元のページ、ページ上でクリックしたもの(入力内容は含みません)、ページとそのリクエストの読み込み速度、ページで起きたエラー、ブラウザ・OS・画面サイズ、IP アドレスの国と都市、そして訪問の録画(ページの表示、マウスの動き、クリック、スクロール、コンソールのメッセージ)で、入力欄はすべて伏せられます。ブラウザが Do Not Track か Global Privacy Control を送っていれば何も送りません。PostHog へのリクエストはこのサイトの <code>usemagpie.ai/r/</code> を経由し、IP アドレスとともに PostHog へ渡されます。サイトの Cookie は渡しません。<code>/download</code> のリンクを開くか <code>install.sh</code> を取得すると、PostHog に別のカウントが 1 件送られます。どのファイルか、国、ブラウザかコマンドか、だけで、ID も IP アドレスも含みません。アプリはどちらも読み込みません。コードは <a href="https://github.com/yetone/magpie/blob/main/site/worker.js">site/worker.js</a> です。</p>
+1 -1
View File
@@ -320,7 +320,7 @@ magpie claude group/opus-anywhere <span class="c"># これを使う</span></p
<p>アプリ(ウィンドウ、メニューバーやトレイのアイコン、パネル。どう開いたかによらず)は <code>app.log</code> を書きます。macOS では <code>~/Library/Logs/magpie/app.log</code>、Windows では <code>%LOCALAPPDATA%\magpie\logs\app.log</code>、Linux では <code>~/.local/state/magpie/app.log</code>(<code>$XDG_STATE_HOME</code> が設定されていれば <code>$XDG_STATE_HOME/magpie</code>)、ポータブル版ではデータフォルダーの <code>logs</code> です。<span class="ui">設定</span> → <span class="ui">情報</span> → <span class="ui">ログ</span>にパスがあり、<span class="ui">開く</span>でそのフォルダーを表示します。<code>magpie log</code> はパスを表示し、<code>magpie log -f</code> は追いかけます。5 MiB に達すると隣の <code>app.old.log</code> になり、残るのは最大 2 ファイルです。記録されるのは magpie がしたことと出会ったエラー(プロバイダーがリクエストを断った、再試行した、プラグインが起動しなかった)で、キー、プロンプト、返答は含みません。キーやトークンに見えるものも伏せられます。サービスとして動く <code>magpie serve</code> のログは別の場所です。macOS では <code>~/Library/Logs/magpie/serve.log</code>、Linux では <code>journalctl --user -u magpie</code>。<code>magpie log</code> はそれも示します。</p>
<h3 id="privacy">magpie は何を送信しますか?</h3>
<p>プロンプト、返答、キー、アカウントは、使っているプロバイダーにだけ送られます。間に magpie 自身のサーバーはありません。リリース版の magpie は 1 日 1 回、使われていることを知らせます。何人が使っていて、何を優先して面倒を見るべきかを知るためです。送るのは、このコンピュータで作ったランダムな ID、magpie のバージョンとシステム、そして使っているエージェント、プロバイダー、モデルを magpie 自身の ID(<code>claude</code>、<code>deepseek</code>、<code>deepseek/deepseek-v4</code>)で、それぞれの数とともに。自分で追加したプロバイダーとそのモデルは <code>custom</code> とだけ記録します。プロバイダー追加シートの先頭に載るパートナーについては、1 日に表示された回数、開かれた回数、追加された回数も送ります(回数のみ)。名前、Base URL、アカウント、キー、プロンプト、使用量は送りません。<span class="ui">設定</span> → <span class="ui">プライバシー</span> → <span class="ui">使っているエージェント、プロバイダー、モデルを共有</span> でエージェント、プロバイダー、モデルとパートナーの回数を外せます。<span class="ui">ユーザー数に含める</span>、<code>DO_NOT_TRACK=1</code>、<code>MAGPIE_NO_STATS=1</code> のどれかですべてオフになります。ソースからのビルドは送信しません。パートナーの公式サイトと「キーを取得」のリンクは <code>usemagpie.ai/go/…</code> を経由し、移動の前にクリックを 1 回数えます(どのパートナーか、どのリンクか、国)。usemagpie.ai はパートナー一覧が取得された回数も数えます。これはサーバー自身が見るもので、どの Web サイトのアクセス集計とも同じく、上の設定には左右されません。ID、IP アドレス、アカウントは記録しません。プラグイン、インポートリンク、ライブラリが示すアイコンは <code>usemagpie.ai/api/icon</code> を経由して取得するので、アイコンのあるサーバーに見えるのはあなたの IP ではなく Cloudflare のアドレスです。このサーバーは画像を中継するだけで、数えることも記録することもしません。magpie が自分から送るものすべては、毎日のカウントの例、手元に残すファイル、各スイッチとともに<a href="/docs/ja/privacy">プライバシー</a>のページに挙げています。</p>
<p>プロンプト、返答、キー、アカウントは、使っているプロバイダーにだけ送られます。間に magpie 自身のサーバーはありません。リリース版の magpie は 1 日 1 回、使われていることを知らせます。何人が使っていて、何を優先して面倒を見るべきかを知るためです。送るのは、このコンピュータで作ったランダムな ID、magpie のバージョンとシステム、そして使っているエージェント、プロバイダー、モデルを magpie 自身の ID(<code>claude</code>、<code>deepseek</code>、<code>deepseek/deepseek-v4</code>)で、それぞれの数とともに。自分で追加したプロバイダーとそのモデルは <code>custom</code> とだけ記録します。プロバイダー追加シートの先頭に載るパートナーについては、1 日に表示された回数、開かれた回数、追加された回数も送ります(回数のみ)。名前、Base URL、アカウント、キー、プロンプト、使用量は送りません。<span class="ui">設定</span> → <span class="ui">プライバシー</span> → <span class="ui">使っているエージェント、プロバイダー、モデル、プラグインを共有</span> でエージェント、プロバイダー、モデル、パートナーの回数、Discover のどのプラグインを入れているか(各プラグインの利用者数といいねの集計用)を外せます。<span class="ui">ユーザー数に含める</span>、<code>DO_NOT_TRACK=1</code>、<code>MAGPIE_NO_STATS=1</code> のどれかですべてオフになります。ソースからのビルドは送信しません。パートナーの公式サイトと「キーを取得」のリンクは <code>usemagpie.ai/go/…</code> を経由し、移動の前にクリックを 1 回数えます(どのパートナーか、どのリンクか、国)。usemagpie.ai はパートナー一覧が取得された回数も数えます。これはサーバー自身が見るもので、どの Web サイトのアクセス集計とも同じく、上の設定には左右されません。ID、IP アドレス、アカウントは記録しません。プラグイン、インポートリンク、ライブラリが示すアイコンは <code>usemagpie.ai/api/icon</code> を経由して取得するので、アイコンのあるサーバーに見えるのはあなたの IP ではなく Cloudflare のアドレスです。このサーバーは画像を中継するだけで、数えることも記録することもしません。magpie が自分から送るものすべては、毎日のカウントの例、手元に残すファイル、各スイッチとともに<a href="/docs/ja/privacy">プライバシー</a>のページに挙げています。</p>
<h3 id="proxy-loopback">エージェントが 502 を返す、または接続できず、magpie の Routing タブに何も出ない?</h3>
<p>プロキシアプリ(Surge、Clash、mihomo など。システムプロキシ、TUN、拡張モードのいずれかが有効)が、エージェントから <code>http://127.0.0.1:3425</code> へのリクエストを横取りして別の場所へ送っているため、magpie に届いていません。除外リスト(<code>skip-proxy</code>、バイパス)に 127.0.0.1 を書くだけでは足りないことがあります。Codex など一部のエージェントは、それでもプロキシを通します。ローカルアドレスを直結にするルールを、他のルールより前に追加してください:</p>
+4 -1
View File
@@ -122,6 +122,7 @@
<li><b>models</b> the connected agents are set to, as provider id and vendor model id (<code>deepseek/deepseek-v4</code>). On a key’s provider, a model id that <a href="https://models.dev">models.dev</a> doesn’t list (a local model, a fine-tune) is only <code>&lt;provider&gt;/other</code>; a model on your own provider is <code>custom</code>; a routing group is <code>group</code>.</li>
</ul>
<p>With them go <code>magpie partner</code> events: for each partner listed first in the add sheet, by its id, how many times on a day that has ended the sheet showed it, its row was opened, its key page was opened, and a provider was added from it (<code>what</code>: <code>shown</code>, <code>opened</code>, <code>keys</code>, <code>added</code>; at most 20 a day each, 5 adds). Counts only, never a provider of your own.</p>
<p id="plugins">With that part on, magpie also tells <code>usemagpie.ai</code>, on the same day, which of the plugins Discover lists are installed and on, so Discover can say how many use each one: <code>POST /api/plugins/report</code> with the same random id and the plugins’ npm names, or <code>github:owner/repo</code> for a repository tagged <code>magpie-plugin</code> (at most 50). A plugin from a folder, a private repository or a package Discover doesn’t list is never named. A like on a plugin’s page goes as <code>POST /api/plugins/like</code> with the id, the plugin and whether it is on, and only for a plugin installed here; the plugins you liked are kept in <code>plugin-likes.json</code>. The site counts the ids that reported a plugin in the last 7 days, drops a report after 30 days, and keeps your address only hashed, for an hour, to limit how often it is asked. Discover reads the counts from <code>GET /api/plugins/stats</code>, which carries no id. The code is <a href="https://github.com/yetone/magpie/blob/main/internal/stats/plugins.go">internal/stats/plugins.go</a> and <a href="https://github.com/yetone/magpie/blob/main/site/pluginstats.js">site/pluginstats.js</a>.</p>
<p>Every event carries <code>$process_person_profile: false</code>, so PostHog keeps no person profile for the id. No names, base URLs, accounts, keys, prompts, replies or usage are sent. A whole batch looks like this:</p>
<div class="code">
<span class="lang">POST https://us.i.posthog.com/batch/</span>
@@ -155,7 +156,7 @@
<ul>
<li><span class="ui">Settings</span> → <span class="ui">Privacy</span> → <span class="ui">Count me as a user</span> off, or <code>"noStats": true</code> in <code>settings.json</code> stops the whole daily count.</li>
<li><code>DO_NOT_TRACK=1</code> or <code>MAGPIE_NO_STATS=1</code> in magpie’s environment (any value but empty, <code>0</code> or <code>false</code>) stops the whole daily count, whatever the settings say.</li>
<li><span class="ui">Settings</span> → <span class="ui">Privacy</span> → <span class="ui">Share the agents, providers and models I use</span> off, or <code>"noUsageStats": true</code> leaves out the <code>magpie uses</code> and <code>magpie partner</code> events and the counts in <code>magpie active</code>; the id, version and system are still sent. Partner counts stop being kept too.</li>
<li><span class="ui">Settings</span> → <span class="ui">Privacy</span> → <span class="ui">Share the agents, providers, models and plugins I use</span> off, or <code>"noUsageStats": true</code> leaves out the <code>magpie uses</code> and <code>magpie partner</code> events, the counts in <code>magpie active</code> and the <a href="#plugins">plugin report</a>; the id, version and system are still sent. Partner counts stop being kept too.</li>
<li><span class="ui">Settings</span> → <span class="ui">About</span> → <span class="ui">Automatic updates</span> off, or <code>"noAutoUpdate": true</code> stops magpie asking <code>usemagpie.ai</code> for a newer version by itself (it asks every 6 hours otherwise). This is not part of the count.</li>
</ul>
<p>A change in Settings takes effect at the next hourly look; no restart is needed. <code>settings.json</code> sits in magpie’s folder (see <a href="#files">below</a>):</p>
@@ -175,6 +176,7 @@
<tr><th>File</th><th>What it is</th></tr>
<tr><td><code>install-id</code></td><td>The random id, made the first time the count is sent</td></tr>
<tr><td><code>stats-sent</code></td><td>The last day (UTC) the count went, so a day is sent once</td></tr>
<tr><td><code>plugin-likes.json</code></td><td>The plugins you liked in Discover</td></tr>
<tr><td><code>partner-counts.json</code> (in the cache folder)</td><td>Partner counts not yet sent, at most 14 days</td></tr>
</table></div>
<p><code>install-id</code> and <code>stats-sent</code> are in magpie’s folder: <code>~/.config/magpie</code> on macOS and Linux, <code>%USERPROFILE%\.config\magpie</code> on Windows, <code>$XDG_CONFIG_HOME/magpie</code> when that is set, and the data folder of a portable magpie. <code>partner-counts.json</code> is in <code>~/.cache/magpie</code> (<code>$XDG_CACHE_HOME/magpie</code>, or <code>cache</code> in a portable magpie’s data folder). You can delete any of them: a deleted <code>install-id</code> is replaced by a new random one at the next send, so you are counted as a new user; with the count off, none of them is written again.</p>
@@ -188,6 +190,7 @@
<li><code>/files/&lt;version&gt;/&lt;file&gt;</code>: the release files an update and the installer download, served from Cloudflare R2. A file the site doesn’t hold is sent on to github.com. Nothing is counted.</li>
<li><code>/api/partners</code>: the add sheet’s partner list, every 6 hours. One fetch in ten is counted as a <code>magpie partners fetch</code> event, with the country Cloudflare gives, while a partner is listed.</li>
<li><code>/go/&lt;partner&gt;/site</code> and <code>/go/&lt;partner&gt;/keys</code>: a partner’s website and key-page links, opened in your browser, are counted (the partner, which link, a region, a country) as <code>magpie partner go</code> before you are sent on.</li>
<li><code>/api/plugins/stats</code>: Discover’s counts of how many use and like each plugin, at most once an hour. It carries no id; the <a href="#plugins">plugin report</a> and likes do, and go only with sharing what you use on.</li>
<li><code>/api/icon?url=…</code>: icons named by a plugin, an import link or the library are fetched through it, so their hosts see Cloudflare’s address, not yours. The worker passes the picture on and counts and keeps nothing.</li>
</ul>
<p>The site’s own pages (these docs, the home page) carry Cloudflare Web Analytics and PostHog Web Analytics (<code>us.i.posthog.com</code>), without cookies. PostHog keeps a random visitor id in your browser’s local storage for this site, so a return visit counts as the same visitor. It gets each page’s address, the page that sent you, what you click on the page (not what you type), how fast the page and its requests loaded, errors the page hit, your browser, system and screen size, the country and city your address is in, and a recording of the visit (what the page showed, mouse moves, clicks and scrolls, its console messages) with every input box masked; nothing at all when your browser sends Do Not Track or Global Privacy Control. PostHog’s requests go through this site, under <code>usemagpie.ai/r/</code>, which passes them and your address on to PostHog and keeps the site’s cookies. Following a <code>/download</code> link, or fetching <code>install.sh</code>, sends PostHog a count of its own: which file, your country, and whether a browser or a command asked; no id and no address. The app doesn’t load either. The code is <a href="https://github.com/yetone/magpie/blob/main/site/worker.js">site/worker.js</a>.</p>
+1 -1
View File
@@ -320,7 +320,7 @@ magpie claude group/opus-anywhere <span class="c"># use it</span></pre>
<p>The app (its window, the menu bar or tray icon and the panel, however it was opened) writes <code>app.log</code>: <code>~/Library/Logs/magpie/app.log</code> on macOS, <code>%LOCALAPPDATA%\magpie\logs\app.log</code> on Windows, <code>~/.local/state/magpie/app.log</code> on Linux (<code>$XDG_STATE_HOME/magpie</code> when that is set), and <code>logs</code> in a portable magpie’s data folder. <span class="ui">Settings</span> → <span class="ui">About</span> → <span class="ui">Log</span> has its path and an <span class="ui">Open</span> that shows its folder; <code>magpie log</code> prints it, and <code>magpie log -f</code> follows it. At 5 MiB it becomes <code>app.old.log</code> beside it, so two files at most are kept. It holds what magpie did and the errors it met (a provider refusing a request, a retry, a plugin that failed to start), not your keys, prompts or replies; what looks like a key or token is masked anyway. <code>magpie serve</code> run as a service logs elsewhere: <code>~/Library/Logs/magpie/serve.log</code> on macOS, <code>journalctl --user -u magpie</code> on Linux; <code>magpie log</code> names it too.</p>
<h3 id="privacy">What does magpie send about me?</h3>
<p>Your prompts, replies, keys and accounts go only to the providers you use; magpie has no server of its own in the path. Once a day a released magpie tells us it is in use, so we know how many people use it and what to look after first: a random id made up on your computer, magpie’s version and your system, and which agents, providers and models it is used with, by magpie’s own ids (<code>claude</code>, <code>deepseek</code>, <code>deepseek/deepseek-v4</code>) with how many of each. A provider you added yourself, and a model on it, is only <code>custom</code>. For each partner listed first in the add sheet, how many times a day it was shown, opened and added from goes with them, as counts only. No names, base URLs, accounts, keys, prompts or usage are sent. <span class="ui">Settings</span> → <span class="ui">Privacy</span> → <span class="ui">Share the agents, providers and models I use</span> leaves out the agents, providers and models, and the partner counts; <span class="ui">Count me as a user</span>, <code>DO_NOT_TRACK=1</code> or <code>MAGPIE_NO_STATS=1</code> turns it all off. Builds from source never send it. A partner's website and key-page links go through <code>usemagpie.ai/go/…</code>, which counts the click (the partner, which link, and a country) before sending you on, and usemagpie.ai counts how many times the partner list is fetched. The server sees these whatever the settings say, as any website sees its visits; no id, address or account is kept with them. Icons named by a plugin, an import link or the library are fetched through <code>usemagpie.ai/api/icon</code>, so their hosts see Cloudflare's address, not yours; the server only passes the picture on, and counts and keeps nothing. The <a href="/docs/privacy">Privacy page</a> lists everything magpie sends by itself, with an example of the daily count, the files it keeps and every switch.</p>
<p>Your prompts, replies, keys and accounts go only to the providers you use; magpie has no server of its own in the path. Once a day a released magpie tells us it is in use, so we know how many people use it and what to look after first: a random id made up on your computer, magpie’s version and your system, and which agents, providers and models it is used with, by magpie’s own ids (<code>claude</code>, <code>deepseek</code>, <code>deepseek/deepseek-v4</code>) with how many of each. A provider you added yourself, and a model on it, is only <code>custom</code>. For each partner listed first in the add sheet, how many times a day it was shown, opened and added from goes with them, as counts only. No names, base URLs, accounts, keys, prompts or usage are sent. <span class="ui">Settings</span> → <span class="ui">Privacy</span> → <span class="ui">Share the agents, providers, models and plugins I use</span> leaves out the agents, providers and models, the partner counts and which of Discover’s plugins are installed (for its counts of who uses and likes each); <span class="ui">Count me as a user</span>, <code>DO_NOT_TRACK=1</code> or <code>MAGPIE_NO_STATS=1</code> turns it all off. Builds from source never send it. A partner's website and key-page links go through <code>usemagpie.ai/go/…</code>, which counts the click (the partner, which link, and a country) before sending you on, and usemagpie.ai counts how many times the partner list is fetched. The server sees these whatever the settings say, as any website sees its visits; no id, address or account is kept with them. Icons named by a plugin, an import link or the library are fetched through <code>usemagpie.ai/api/icon</code>, so their hosts see Cloudflare's address, not yours; the server only passes the picture on, and counts and keeps nothing. The <a href="/docs/privacy">Privacy page</a> lists everything magpie sends by itself, with an example of the daily count, the files it keeps and every switch.</p>
<h3 id="proxy-loopback">The agent gets 502 or can’t connect, and nothing shows in magpie’s Routing tab?</h3>
<p>A proxy app (Surge, Clash, mihomo and the like, with system proxy, TUN or enhanced mode on) has taken the agent’s request to <code>http://127.0.0.1:3425</code> and sent it somewhere else, so it never reaches magpie. The bypass list (<code>skip-proxy</code>, “bypass”) isn’t always enough: some agents, Codex among them, send it through the proxy anyway. Add rules that send the local addresses direct, ahead of your other rules:</p>
+4 -1
View File
@@ -122,6 +122,7 @@
<li><b>模型</b>:接入的 agent 设定的模型,记为供应商 ID 加厂商模型 ID(<code>deepseek/deepseek-v4</code>)。密钥类供应商上 <a href="https://models.dev">models.dev</a> 没收录的模型 ID(本地模型、微调模型)只记作 <code>&lt;供应商&gt;/other</code>;你自己供应商上的模型记作 <code>custom</code>;路由组记作 <code>group</code>。</li>
</ul>
<p>同时发送 <code>magpie partner</code> 事件:添加供应商页里排在最前的每个合作伙伴,按它的 ID,在已结束的某一天里被展示、行被打开、Key 页面被打开、从它添加供应商的次数(<code>what</code>:<code>shown</code>、<code>opened</code>、<code>keys</code>、<code>added</code>;每天每项最多 20 次,添加最多 5 次)。只有次数,从不包含你自己的供应商。</p>
<p id="plugins">这部分开着时,magpie 当天还会告诉 <code>usemagpie.ai</code> 装了 Discover 里列出的哪些插件(且已开启),让 Discover 显示每个插件有多少人在用:<code>POST /api/plugins/report</code>,带同一个随机 ID 和插件的 npm 包名;打了 <code>magpie-plugin</code> 标签的仓库记作 <code>github:owner/repo</code>(最多 50 个)。来自本地文件夹、私有仓库或 Discover 没列出的包的插件,永远不会发送。在插件页点赞时发 <code>POST /api/plugins/like</code>,带 ID、插件名和点赞还是取消,只有本机装了的插件才能点赞;点过赞的插件记在 <code>plugin-likes.json</code>。网站只统计近 7 天上报过某个插件的 ID 数,30 天后删除上报记录;你的 IP 只以哈希形式保存一小时,用来限制请求频率。Discover 从 <code>GET /api/plugins/stats</code> 读取计数,这个请求不带 ID。代码见 <a href="https://github.com/yetone/magpie/blob/main/internal/stats/plugins.go">internal/stats/plugins.go</a> 和 <a href="https://github.com/yetone/magpie/blob/main/site/pluginstats.js">site/pluginstats.js</a>。</p>
<p>每个事件都带 <code>$process_person_profile: false</code>,PostHog 不为这个 ID 建用户档案。不发送名称、Base URL、账号、密钥、提示词、回复和用量。一整批大致如下:</p>
<div class="code">
<span class="lang">POST https://us.i.posthog.com/batch/</span>
@@ -155,7 +156,7 @@
<ul>
<li>关掉 <span class="ui">设置</span> → <span class="ui">隐私</span> → <span class="ui">计入用户数</span>,或在 <code>settings.json</code> 里写 <code>"noStats": true</code>:整个每日计数。</li>
<li>在 magpie 的环境变量里设 <code>DO_NOT_TRACK=1</code> 或 <code>MAGPIE_NO_STATS=1</code>(除空、<code>0</code>、<code>false</code> 之外的任何值):整个每日计数,不管设置里怎么选。</li>
<li>关掉 <span class="ui">设置</span> → <span class="ui">隐私</span> → <span class="ui">分享我用的 agent、provider 和模型</span>,或 <code>"noUsageStats": true</code>:<code>magpie uses</code>、<code>magpie partner</code> 事件和 <code>magpie active</code> 里的数量;ID、版本和系统仍会发送。合作伙伴次数也不再记录。</li>
<li>关掉 <span class="ui">设置</span> → <span class="ui">隐私</span> → <span class="ui">分享我用的 agent、provider、模型和插件</span>,或 <code>"noUsageStats": true</code>:<code>magpie uses</code>、<code>magpie partner</code> 事件、<code>magpie active</code> 里的数量和<a href="#plugins">插件上报</a>;ID、版本和系统仍会发送。合作伙伴次数也不再记录。</li>
<li>关掉 <span class="ui">设置</span> → <span class="ui">关于</span> → <span class="ui">自动更新</span>,或 <code>"noAutoUpdate": true</code>:magpie 自己向 <code>usemagpie.ai</code> 询问新版本(否则每 6 小时一次)。这不属于计数。</li>
</ul>
<p>设置里的改动在下一次每小时检查时生效,不用重启。<code>settings.json</code> 在 magpie 的文件夹里(见<a href="#files">下文</a>):</p>
@@ -175,6 +176,7 @@
<tr><th>文件</th><th>用途</th></tr>
<tr><td><code>install-id</code></td><td>随机 ID,第一次发送计数时生成</td></tr>
<tr><td><code>stats-sent</code></td><td>上次发送的日期(UTC),保证每天只发一次</td></tr>
<tr><td><code>plugin-likes.json</code></td><td>你在 Discover 里点过赞的插件</td></tr>
<tr><td><code>partner-counts.json</code>(缓存文件夹)</td><td>还没发送的合作伙伴次数,最多保留 14 天</td></tr>
</table></div>
<p><code>install-id</code> 和 <code>stats-sent</code> 在 magpie 的文件夹里:macOS 和 Linux 上是 <code>~/.config/magpie</code>,Windows 上是 <code>%USERPROFILE%\.config\magpie</code>,设置了 <code>$XDG_CONFIG_HOME</code> 时是 <code>$XDG_CONFIG_HOME/magpie</code>,便携版则在它的数据文件夹里。<code>partner-counts.json</code> 在 <code>~/.cache/magpie</code>(或 <code>$XDG_CACHE_HOME/magpie</code>,便携版数据文件夹里的 <code>cache</code>)。这些文件都可以删:删掉 <code>install-id</code> 后,下次发送会生成新的随机 ID,你会被算作新用户;关掉计数后,它们都不会再写入。</p>
@@ -188,6 +190,7 @@
<li><code>/files/&lt;版本&gt;/&lt;文件&gt;</code>:更新和安装脚本下载的发布文件,由 Cloudflare R2 提供;站点上没有的文件会转到 github.com。不做任何统计。</li>
<li><code>/api/partners</code>:添加供应商页的合作伙伴列表,每 6 小时一次。在有合作伙伴上架时,每十次拉取记一次 <code>magpie partners fetch</code> 事件,附 Cloudflare 给出的国家。</li>
<li><code>/go/&lt;合作伙伴&gt;/site</code> 和 <code>/go/&lt;合作伙伴&gt;/keys</code>:在浏览器里打开合作伙伴的官网和 Key 页面链接时,先记一次 <code>magpie partner go</code>(哪个合作伙伴、哪个链接、地区、国家),再跳转。</li>
<li><code>/api/plugins/stats</code>:Discover 里每个插件的在用人数和点赞数,最多每小时取一次,不带 ID;<a href="#plugins">插件上报</a>和点赞带 ID,只在开着分享时发送。</li>
<li><code>/api/icon?url=…</code>:插件、导入链接和库里的图标经它获取,图标所在的服务器只看到 Cloudflare 的地址,看不到你的。它只转发图片,不计数也不记录。</li>
</ul>
<p>网站自己的页面(这些文档、首页)带 Cloudflare Web Analytics 和 PostHog Web Analytics(<code>us.i.posthog.com</code>),都不用 Cookie。PostHog 在浏览器的本地存储里为本站记一个随机访客 id,再次访问算同一位访客。它收到每个页面的地址、来源页面、你在页面上点了什么(不含输入的内容)、页面及其请求的加载速度、页面遇到的报错、浏览器、系统和屏幕尺寸、IP 所在的国家和城市,以及这次访问的录屏(页面显示的内容、鼠标移动、点击、滚动和控制台消息),所有输入框都被遮住;浏览器开了 Do Not Track 或 Global Privacy Control 就什么都不发。PostHog 的请求经由本站的 <code>usemagpie.ai/r/</code> 转给 PostHog,连同你的 IP 一起转发,本站的 Cookie 不转发。打开 <code>/download</code> 下载链接或获取 <code>install.sh</code> 时,会另外向 PostHog 发一次计数:哪个文件、你所在的国家、是浏览器还是命令发起的;不带 id,也不带 IP。应用两者都不加载。代码见 <a href="https://github.com/yetone/magpie/blob/main/site/worker.js">site/worker.js</a>。</p>
+1 -1
View File
@@ -320,7 +320,7 @@ magpie claude group/opus-anywhere <span class="c"># 使用它</span></pre>
<p>应用(窗口、菜单栏或托盘图标、快捷面板,不论怎样打开)写入 <code>app.log</code>:macOS 上是 <code>~/Library/Logs/magpie/app.log</code>,Windows 上是 <code>%LOCALAPPDATA%\magpie\logs\app.log</code>,Linux 上是 <code>~/.local/state/magpie/app.log</code>(设置了 <code>$XDG_STATE_HOME</code> 时是 <code>$XDG_STATE_HOME/magpie</code>),便携版则在数据文件夹的 <code>logs</code> 里。<span class="ui">设置</span> → <span class="ui">关于</span> → <span class="ui">日志</span>里有它的路径,<span class="ui">打开</span>会显示它所在的文件夹;<code>magpie log</code> 打印路径,<code>magpie log -f</code> 持续跟随。满 5 MiB 后它变成旁边的 <code>app.old.log</code>,最多保留两个文件。它记的是 magpie 做了什么、遇到了哪些错误(服务商拒绝请求、重试、插件没能启动),不含你的密钥、提示词或回复;看起来像密钥或令牌的内容也会被遮掉。作为服务运行的 <code>magpie serve</code> 日志在别处:macOS 上是 <code>~/Library/Logs/magpie/serve.log</code>,Linux 上是 <code>journalctl --user -u magpie</code>;<code>magpie log</code> 也会列出它。</p>
<h3 id="privacy">magpie 会发送我的哪些信息?</h3>
<p>你的提示词、回复、密钥和账号只发给你用的供应商,中间没有 magpie 自己的服务器。正式发布的 magpie 每天告诉我们一次它在用,好让我们知道有多少人在用、该先照顾哪些:本机随机生成的 ID、magpie 版本和系统,以及用了哪些 agent、供应商和模型,只用 magpie 自己的 ID(<code>claude</code>、<code>deepseek</code>、<code>deepseek/deepseek-v4</code>)和各自的数量。你自己添加的供应商及其上的模型只记作 <code>custom</code>。添加供应商页里排在最前的合作伙伴,每天被展示、打开和添加的次数也一并发送,只有次数。不发送名称、Base URL、账号、密钥、提示词和用量。<span class="ui">设置</span> → <span class="ui">隐私</span> → <span class="ui">分享我用的 agent、provider 和模型</span> 可以去掉 agent、供应商、模型和合作伙伴次数这部分;<span class="ui">计入用户数</span>、<code>DO_NOT_TRACK=1</code> 或 <code>MAGPIE_NO_STATS=1</code> 全部关闭。从源码构建的版本从不发送。合作伙伴的官网和「获取 Key」链接经 <code>usemagpie.ai/go/…</code> 跳转,跳转前记一次点击(哪个合作伙伴、哪个链接、哪个国家),usemagpie.ai 也会统计合作伙伴列表被拉取的次数。这部分是服务器本身看到的,和任何网站统计访问一样,不受上面的设置影响;不记录 ID、IP 和账号。插件、导入链接和库里的图标经 <code>usemagpie.ai/api/icon</code> 获取,图标所在的服务器只看到 Cloudflare 的地址,看不到你的 IP;这台服务器只转发图片,不计数也不记录。<a href="/docs/zh/privacy">隐私页</a>列出了 magpie 自己发出的所有内容,附每日计数的示例、它在本机留下的文件和每个开关。</p>
<p>你的提示词、回复、密钥和账号只发给你用的供应商,中间没有 magpie 自己的服务器。正式发布的 magpie 每天告诉我们一次它在用,好让我们知道有多少人在用、该先照顾哪些:本机随机生成的 ID、magpie 版本和系统,以及用了哪些 agent、供应商和模型,只用 magpie 自己的 ID(<code>claude</code>、<code>deepseek</code>、<code>deepseek/deepseek-v4</code>)和各自的数量。你自己添加的供应商及其上的模型只记作 <code>custom</code>。添加供应商页里排在最前的合作伙伴,每天被展示、打开和添加的次数也一并发送,只有次数。不发送名称、Base URL、账号、密钥、提示词和用量。<span class="ui">设置</span> → <span class="ui">隐私</span> → <span class="ui">分享我用的 agent、provider、模型和插件</span> 可以去掉 agent、供应商、模型、合作伙伴次数,以及装了 Discover 里哪些插件(用于统计每个插件的在用人数和点赞)这部分;<span class="ui">计入用户数</span>、<code>DO_NOT_TRACK=1</code> 或 <code>MAGPIE_NO_STATS=1</code> 全部关闭。从源码构建的版本从不发送。合作伙伴的官网和「获取 Key」链接经 <code>usemagpie.ai/go/…</code> 跳转,跳转前记一次点击(哪个合作伙伴、哪个链接、哪个国家),usemagpie.ai 也会统计合作伙伴列表被拉取的次数。这部分是服务器本身看到的,和任何网站统计访问一样,不受上面的设置影响;不记录 ID、IP 和账号。插件、导入链接和库里的图标经 <code>usemagpie.ai/api/icon</code> 获取,图标所在的服务器只看到 Cloudflare 的地址,看不到你的 IP;这台服务器只转发图片,不计数也不记录。<a href="/docs/zh/privacy">隐私页</a>列出了 magpie 自己发出的所有内容,附每日计数的示例、它在本机留下的文件和每个开关。</p>
<h3 id="proxy-loopback">Agent 报 502 或连不上,magpie 的路由标签页里却什么都没有?</h3>
<p>代理软件(Surge、Clash、mihomo 等,开了系统代理、TUN 或增强模式)把 Agent 发往 <code>http://127.0.0.1:3425</code> 的请求接走、转去了别处,请求根本没到 magpie。只在跳过列表(<code>skip-proxy</code>、「绕过」)里写 127.0.0.1 不一定够:有些 Agent(比如 Codex)照样会走代理。在代理软件里加两条本地地址直连的规则,放在其他规则前面:</p>
+6 -2
View File
@@ -265,7 +265,7 @@ The app (its window, the menu bar or tray icon and the panel, however it was ope
### What does magpie send about me?
Your prompts, replies, keys and accounts go only to the providers you use; magpie has no server of its own in the path. Once a day a released magpie tells us it is in use, so we know how many people use it and what to look after first: a random id made up on your computer, magpie’s version and your system, and which agents, providers and models it is used with, by magpie’s own ids (`claude`, `deepseek`, `deepseek/deepseek-v4`) with how many of each. A provider you added yourself, and a model on it, is only `custom`. For each partner listed first in the add sheet, how many times a day it was shown, opened and added from goes with them, as counts only. No names, base URLs, accounts, keys, prompts or usage are sent. Settings → Privacy → Share the agents, providers and models I use leaves out the agents, providers and models, and the partner counts; Count me as a user, `DO_NOT_TRACK=1` or `MAGPIE_NO_STATS=1` turns it all off. Builds from source never send it. A partner's website and key-page links go through `usemagpie.ai/go/…`, which counts the click (the partner, which link, and a country) before sending you on, and usemagpie.ai counts how many times the partner list is fetched. The server sees these whatever the settings say, as any website sees its visits; no id, address or account is kept with them. Icons named by a plugin, an import link or the library are fetched through `usemagpie.ai/api/icon`, so their hosts see Cloudflare's address, not yours; the server only passes the picture on, and counts and keeps nothing. The [Privacy page](https://usemagpie.ai/docs/privacy) lists everything magpie sends by itself, with an example of the daily count, the files it keeps and every switch.
Your prompts, replies, keys and accounts go only to the providers you use; magpie has no server of its own in the path. Once a day a released magpie tells us it is in use, so we know how many people use it and what to look after first: a random id made up on your computer, magpie’s version and your system, and which agents, providers and models it is used with, by magpie’s own ids (`claude`, `deepseek`, `deepseek/deepseek-v4`) with how many of each. A provider you added yourself, and a model on it, is only `custom`. For each partner listed first in the add sheet, how many times a day it was shown, opened and added from goes with them, as counts only. No names, base URLs, accounts, keys, prompts or usage are sent. Settings → Privacy → Share the agents, providers, models and plugins I use leaves out the agents, providers and models, the partner counts and which of Discover’s plugins are installed (for its counts of who uses and likes each); Count me as a user, `DO_NOT_TRACK=1` or `MAGPIE_NO_STATS=1` turns it all off. Builds from source never send it. A partner's website and key-page links go through `usemagpie.ai/go/…`, which counts the click (the partner, which link, and a country) before sending you on, and usemagpie.ai counts how many times the partner list is fetched. The server sees these whatever the settings say, as any website sees its visits; no id, address or account is kept with them. Icons named by a plugin, an import link or the library are fetched through `usemagpie.ai/api/icon`, so their hosts see Cloudflare's address, not yours; the server only passes the picture on, and counts and keeps nothing. The [Privacy page](https://usemagpie.ai/docs/privacy) lists everything magpie sends by itself, with an example of the daily count, the files it keeps and every switch.
### The agent gets 502 or can’t connect, and nothing shows in magpie’s Routing tab?
@@ -4790,6 +4790,8 @@ Unless you turn that part off, one `magpie uses` event follows for each agent, p
With them go `magpie partner` events: for each partner listed first in the add sheet, by its id, how many times on a day that has ended the sheet showed it, its row was opened, its key page was opened, and a provider was added from it (`what`: `shown`, `opened`, `keys`, `added`; at most 20 a day each, 5 adds). Counts only, never a provider of your own.
With that part on, magpie also tells `usemagpie.ai`, on the same day, which of the plugins Discover lists are installed and on, so Discover can say how many use each one: `POST /api/plugins/report` with the same random id and the plugins’ npm names, or `github:owner/repo` for a repository tagged `magpie-plugin` (at most 50). A plugin from a folder, a private repository or a package Discover doesn’t list is never named. A like on a plugin’s page goes as `POST /api/plugins/like` with the id, the plugin and whether it is on, and only for a plugin installed here; the plugins you liked are kept in `plugin-likes.json`. The site counts the ids that reported a plugin in the last 7 days, drops a report after 30 days, and keeps your address only hashed, for an hour, to limit how often it is asked. Discover reads the counts from `GET /api/plugins/stats`, which carries no id. The code is [internal/stats/plugins.go](https://github.com/yetone/magpie/blob/main/internal/stats/plugins.go) and [site/pluginstats.js](https://github.com/yetone/magpie/blob/main/site/pluginstats.js).
Every event carries `$process_person_profile: false`, so PostHog keeps no person profile for the id. No names, base URLs, accounts, keys, prompts, replies or usage are sent. A whole batch looks like this:
```
@@ -4824,7 +4826,7 @@ Each of these switches stops part or all of it:
- Settings → Privacy → Count me as a user off, or `"noStats": true` in `settings.json` stops the whole daily count.
- `DO_NOT_TRACK=1` or `MAGPIE_NO_STATS=1` in magpie’s environment (any value but empty, `0` or `false`) stops the whole daily count, whatever the settings say.
- Settings → Privacy → Share the agents, providers and models I use off, or `"noUsageStats": true` leaves out the `magpie uses` and `magpie partner` events and the counts in `magpie active`; the id, version and system are still sent. Partner counts stop being kept too.
- Settings → Privacy → Share the agents, providers, models and plugins I use off, or `"noUsageStats": true` leaves out the `magpie uses` and `magpie partner` events, the counts in `magpie active` and the plugin report; the id, version and system are still sent. Partner counts stop being kept too.
- Settings → About → Automatic updates off, or `"noAutoUpdate": true` stops magpie asking `usemagpie.ai` for a newer version by itself (it asks every 6 hours otherwise). This is not part of the count.
A change in Settings takes effect at the next hourly look; no restart is needed. `settings.json` sits in magpie’s folder (see below):
@@ -4845,6 +4847,7 @@ A change in Settings takes effect at the next hourly look; no restart is needed.
| --- | --- |
| `install-id` | The random id, made the first time the count is sent |
| `stats-sent` | The last day (UTC) the count went, so a day is sent once |
| `plugin-likes.json` | The plugins you liked in Discover |
| `partner-counts.json` (in the cache folder) | Partner counts not yet sent, at most 14 days |
`install-id` and `stats-sent` are in magpie’s folder: `~/.config/magpie` on macOS and Linux, `%USERPROFILE%\.config\magpie` on Windows, `$XDG_CONFIG_HOME/magpie` when that is set, and the data folder of a portable magpie. `partner-counts.json` is in `~/.cache/magpie` (`$XDG_CACHE_HOME/magpie`, or `cache` in a portable magpie’s data folder). You can delete any of them: a deleted `install-id` is replaced by a new random one at the next send, so you are counted as a new user; with the count off, none of them is written again.
@@ -4861,6 +4864,7 @@ magpie asks its own site for a few things, whatever the privacy settings say, as
- `/files/<version>/<file>`: the release files an update and the installer download, served from Cloudflare R2. A file the site doesn’t hold is sent on to github.com. Nothing is counted.
- `/api/partners`: the add sheet’s partner list, every 6 hours. One fetch in ten is counted as a `magpie partners fetch` event, with the country Cloudflare gives, while a partner is listed.
- `/go/<partner>/site` and `/go/<partner>/keys`: a partner’s website and key-page links, opened in your browser, are counted (the partner, which link, a region, a country) as `magpie partner go` before you are sent on.
- `/api/plugins/stats`: Discover’s counts of how many use and like each plugin, at most once an hour. It carries no id; the plugin report and likes do, and go only with sharing what you use on.
- `/api/icon?url=…`: icons named by a plugin, an import link or the library are fetched through it, so their hosts see Cloudflare’s address, not yours. The worker passes the picture on and counts and keeps nothing.
The site’s own pages (these docs, the home page) carry Cloudflare Web Analytics and PostHog Web Analytics (`us.i.posthog.com`), without cookies. PostHog keeps a random visitor id in your browser’s local storage for this site, so a return visit counts as the same visitor. It gets each page’s address, the page that sent you, what you click on the page (not what you type), how fast the page and its requests loaded, errors the page hit, your browser, system and screen size, the country and city your address is in, and a recording of the visit (what the page showed, mouse moves, clicks and scrolls, its console messages) with every input box masked; nothing at all when your browser sends Do Not Track or Global Privacy Control. PostHog’s requests go through this site, under `usemagpie.ai/r/`, which passes them and your address on to PostHog and keeps the site’s cookies. Following a `/download` link, or fetching `install.sh`, sends PostHog a count of its own: which file, your country, and whether a browser or a command asked; no id and no address. The app doesn’t load either. The code is [site/worker.js](https://github.com/yetone/magpie/blob/main/site/worker.js).
+10 -2
View File
@@ -53,6 +53,7 @@ import { LANGS } from "./i18n.js";
import { PARTNERS } from "./partners.js";
import { SPONSORS } from "./sponsors.js";
import { serve as serveFile, held, onR2, mirror, githubFile } from "./files.js";
import { handle as pluginStats, prune as prunePlugins } from "./pluginstats.js";
const REPO = "yetone/magpie-releases";
const SITE = "https://usemagpie.ai";
@@ -85,6 +86,10 @@ export default {
url.hostname = url.hostname.slice(4);
return Response.redirect(url.toString(), 301);
}
if (url.pathname.startsWith("/api/plugins/")) {
const got = await pluginStats(req, env, ctx);
if (got) return got;
}
if (url.pathname === "/api/latest") {
const lang = url.searchParams.get("lang");
// Settings' Stable channel; any other channel, or none, is every
@@ -193,11 +198,14 @@ export default {
return beacon(await withWall(await env.ASSETS.fetch(req), env, url));
},
// the crons (wrangler.jsonc's triggers): every quarter hour the ledger
// the Stable channel is chosen from, every five minutes the newest and
// the Stable channel is chosen from and Discover's old counts pruned, every five minutes the newest and
// the Stable release's files into R2
async scheduled(event, env, ctx) {
if (event.cron === MIRROR_CRON) ctx.waitUntil(keepFiles(ctx, env));
else ctx.waitUntil(keepLedger(env, Date.now()));
else {
ctx.waitUntil(keepLedger(env, Date.now()));
ctx.waitUntil(prunePlugins(env));
}
},
};
+3
View File
@@ -23,6 +23,9 @@
// RELEASES: each release's files, copied from GitHub by the five-minute
// cron and served at /files (files.js)
"r2_buckets": [{ "binding": "RELEASES", "bucket_name": "magpie-releases" }],
// PLUGINS: Discover's counts, each plugin's users and likes
// (pluginstats.js)
"d1_databases": [{ "binding": "PLUGINS", "database_name": "magpie-plugins", "database_id": "ec0a0670-9de4-4906-8534-ac83c8ba3cd6" }],
"triggers": { "crons": ["*/15 * * * *", "*/5 * * * *"] },
"observability": { "enabled": true }
}