Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(plugins): 接入后台累计下载统计
nana74dc90f16b1d
diff --git a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts b/apps/desktop/src/main/plugin-market/__tests__/service.test.tsindex f29d4809f2..0cba1909eb 100644--- a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts+++ b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts@@ -1051,6 +1051,14 @@ describe('PluginMarketService migration and defaultInstall', () => {expect(runtime.install).not.toHaveBeenCalled();});+ it('passes exact server download statistics through snapshots and details', async () => {+ const downloadStatistics = { requestCount: '18446744073709551615', last7DaysRequestCount: '12' };+ const item = { ...summary(), downloadStatistics };+ const h = harness([item]);+ await expect(h.service.snapshot()).resolves.toMatchObject({ items: [{ downloadStatistics }] });+ await expect(h.service.detail(item.id)).resolves.toMatchObject({ downloadStatistics });+ });+it('remembers the listed organization prefix after a successful snapshot', async () => {const item = summary();const h = harness([item]);diff --git a/apps/desktop/src/main/plugin-market/service.ts b/apps/desktop/src/main/plugin-market/service.tsindex 5031bc453d..c4943464ce 100644--- a/apps/desktop/src/main/plugin-market/service.ts+++ b/apps/desktop/src/main/plugin-market/service.ts@@ -2532,6 +2532,7 @@ export class PluginMarketService {const { target, ghost, matchesUpdateRoute, installState } = this.serverMarketBinding(plugin, local);return {...(plugin.usageStatistics ? { usageStatistics: plugin.usageStatistics } : {}),+ ...(plugin.downloadStatistics ? { downloadStatistics: plugin.downloadStatistics } : {}),pluginId: plugin.id,ghostId: plugin.ghostId,...deliveryNamespaceFields(target),diff --git a/apps/desktop/src/renderer/features/plugin/PluginSharedUsage.tsx b/apps/desktop/src/renderer/features/plugin/PluginSharedUsage.tsxindex ed07da9b7c..14e03f79db 100644--- a/apps/desktop/src/renderer/features/plugin/PluginSharedUsage.tsx+++ b/apps/desktop/src/renderer/features/plugin/PluginSharedUsage.tsx@@ -1,45 +1,63 @@-import { PackageCheck, Tally5 } from 'lucide-react';+import { ArrowDownToLine, PackageCheck, Tally5 } from 'lucide-react';import { useTranslation } from 'react-i18next';import { Tip } from '@/components/ui/tooltip';import type { PluginMarketItem } from '../../../shared/pluginMarket';/** Only server-authorized aggregates; custom public flags never grant shared statistics. */export function PluginSharedUsage({ detail }: { detail: PluginMarketItem }) {- const { t } = useTranslation();+ const { t, i18n } = useTranslation();if (detail.sourceType !== 'server' || detail.scope === 'personal') return null;const stats = detail.usageStatistics;- if (!stats) return null;- const explanation =- t('settings.ghosts.usage.sharedExplanation', {- scope: t(`settings.ghosts.usage.sharedScope.${detail.scope}`),- }) + ` ${t('settings.ghosts.usage.asOf', { time: stats.asOf })}`;+ const downloads = detail.downloadStatistics;+ if (!stats && !downloads) return null;+ const explanation = stats+ ? t('settings.ghosts.usage.sharedExplanation', {+ scope: t(`settings.ghosts.usage.sharedScope.${detail.scope}`),+ }) + ` ${t('settings.ghosts.usage.asOf', { time: stats.asOf })}`+ : '';return (<><span aria-hidden="true">·</span>- <Tip text={explanation}>- <button- type="button"- className="inline-flex min-h-7 items-center gap-1 rounded-full focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"- >- <PackageCheck size={12} aria-hidden="true" />- <span>- {t('settings.ghosts.usage.installs')}{' '}- {stats.installationCount}- </span>- </button>- </Tip>- <Tip text={explanation}>- <button- type="button"- className="inline-flex min-h-7 items-center gap-1 rounded-full focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"- >- <Tally5 size={12} aria-hidden="true" />- <span>- {t('settings.ghosts.usage.uses')}{' '}- {stats.usageCount}- </span>- </button>- </Tip>+ {downloads ? (+ <Tip text={t('settings.ghosts.usage.downloadExplanation')}>+ <button+ type="button"+ className="inline-flex min-h-7 items-center gap-1 rounded-full focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"+ >+ <ArrowDownToLine size={12} aria-hidden="true" />+ <span>+ {t('settings.ghosts.usage.downloads')}{' '}+ {BigInt(downloads.requestCount).toLocaleString(i18n.language)}+ </span>+ </button>+ </Tip>+ ) : null}+ {stats ? (+ <>+ <Tip text={explanation}>+ <button+ type="button"+ className="inline-flex min-h-7 items-center gap-1 rounded-full focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"+ >+ <PackageCheck size={12} aria-hidden="true" />+ <span>+ {t('settings.ghosts.usage.installs')} {stats.installationCount}+ </span>+ </button>+ </Tip>+ <Tip text={explanation}>+ <button+ type="button"+ className="inline-flex min-h-7 items-center gap-1 rounded-full focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"+ >+ <Tally5 size={12} aria-hidden="true" />+ <span>+ {t('settings.ghosts.usage.uses')} {stats.usageCount}+ </span>+ </button>+ </Tip>+ </>+ ) : null}</>);}diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/PluginUsageCard.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/PluginUsageCard.test.tsxindex 6655f5ab11..e78e8ebf72 100644--- a/apps/desktop/src/renderer/features/plugin/__tests__/PluginUsageCard.test.tsx+++ b/apps/desktop/src/renderer/features/plugin/__tests__/PluginUsageCard.test.tsx@@ -94,6 +94,7 @@ it.each([const detail = {sourceType,scope,+ downloadStatistics: { requestCount: '12' },usageStatistics: {installationCount: '12',usageCount: '10',@@ -104,3 +105,31 @@ it.each([const view = render(<PluginSharedUsage detail={detail} />);expect(view.container.textContent).toBe('');});++it.each(['public', 'organization'] as const)(+ 'shows only the cumulative download value in %s without invented installs or usage',+ (scope) => {+ const detail = {+ sourceType: 'server',+ scope,+ downloadStatistics: { requestCount: '123456', last7DaysRequestCount: '12' },+ } as PluginMarketItem;+ const view = render(<PluginSharedUsage detail={detail} />);+ expect(screen.getByText('settings.ghosts.usage.downloads 123,456')).toBeTruthy();+ expect(view.container.textContent).not.toContain('installs');+ expect(view.container.textContent).not.toContain('uses');+ expect(view.container.textContent).not.toContain('last7Days');+ view.rerender(+ <PluginSharedUsage detail={{ ...detail, downloadStatistics: { requestCount: '0' } }} />,+ );+ expect(screen.getByText('settings.ghosts.usage.downloads 0')).toBeTruthy();+ view.rerender(+ <PluginSharedUsage+ detail={{ ...detail, downloadStatistics: { requestCount: '18446744073709551615' } }}+ />,+ );+ expect(+ screen.getByText('settings.ghosts.usage.downloads 18,446,744,073,709,551,615'),+ ).toBeTruthy();+ },+);diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 3955c0733a..a2c3fbaae8 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -6724,6 +6724,8 @@"localSince": "{{device}} · Recording since {{time}}","clearTitle": "Clear this Plugin’s usage records?","clearDescription": "Remove call records and Session links for this account on this computer. New calls start a fresh history. Shared totals already received by the server are not withdrawn.",+ "downloads": "Downloads",+ "downloadExplanation": "Cumulative download URL requests. Each successfully issued package URL counts once, including updates, reinstalls and retries that request a new URL. This is not a count of completed installations.","installs": "Installs","uses": "Uses","sharedUnavailable": "Unavailable",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 924a7faf53..3c41979b57 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -6699,6 +6699,8 @@"localSince": "{{device}} · {{time}} から記録","clearTitle": "このプラグインの使用記録を消去しますか?","clearDescription": "この端末の現在のアカウントの呼び出し記録とセッションへの関連を消去します。以降の呼び出しから記録を再開します。サーバーが受信済みの共有累計は取り消されません。",+ "downloads": "ダウンロード",+ "downloadExplanation": "ダウンロード URL の累計リクエスト数です。パッケージ URL の発行成功ごとに 1 回と数え、更新、再インストール、新しい URL を取得する再試行も含みます。インストール成功数ではありません。","installs": "インストール","uses": "使用","sharedUnavailable": "取得不可",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 3c68de8ff7..204777fd2d 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -6699,6 +6699,8 @@"localSince": "{{device}} · {{time}}부터 기록","clearTitle": "이 플러그인의 사용 기록을 지울까요?","clearDescription": "이 컴퓨터의 현재 계정에서 호출 기록과 세션 연결을 지웁니다. 이후 호출부터 새로 기록합니다. 서버가 이미 받은 공유 합계는 취소되지 않습니다.",+ "downloads": "다운로드",+ "downloadExplanation": "누적 다운로드 URL 요청 수입니다. 패키지 URL 발급 성공마다 1회로 집계하며 업데이트, 재설치, 새 URL을 요청하는 재시도도 포함합니다. 설치 완료 횟수가 아닙니다.","installs": "설치","uses": "사용","sharedUnavailable": "사용 불가",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 6d98b3dc8a..18f9d5b5f6 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -6699,6 +6699,8 @@"localSince": "{{device}} · 从 {{time}} 开始记录","clearTitle": "清除该插件的使用记录?","clearDescription": "清除本机当前账户的调用记录及任务关联,后续调用重新开始记录。已共享的累计统计不会撤回。",+ "downloads": "下载",+ "downloadExplanation": "累计下载请求次数:成功获取安装包下载地址后计一次,包括更新、重装及重新获取地址的重试;不代表成功安装次数。","installs": "安装","uses": "使用","sharedUnavailable": "暂不可用",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex efb72e08e4..19f04dab73 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -6699,6 +6699,8 @@"localSince": "{{device}} · 從 {{time}} 開始記錄","clearTitle": "清除此插件的使用記錄?","clearDescription": "清除本機目前帳戶的呼叫記錄及任務關聯,後續呼叫重新開始記錄。已共享的累計統計不會撤回。",+ "downloads": "下載",+ "downloadExplanation": "累計下載請求次數:成功取得安裝包下載位址後計一次,包括更新、重新安裝及重新取得位址的重試;不代表成功安裝次數。","installs": "安裝","uses": "使用","sharedUnavailable": "暫時無法使用",diff --git a/apps/desktop/src/shared/pluginMarket.ts b/apps/desktop/src/shared/pluginMarket.tsindex 28d7943459..08dfa7f963 100644--- a/apps/desktop/src/shared/pluginMarket.ts+++ b/apps/desktop/src/shared/pluginMarket.ts@@ -1,5 +1,5 @@import type { GhostManifest, InstalledGhost } from './ghost';-import type { PluginIconMetadata, PluginUsageStatistics } from '@cindy/plugin-protocol';+import type { PluginDownloadStatistics, PluginIconMetadata, PluginUsageStatistics } from '@cindy/plugin-protocol';export type PluginMarketScope = 'public' | 'organization' | 'personal';export type PluginMarketInstallState =@@ -14,6 +14,7 @@ export type PluginMarketItemSource = 'server' | 'git-market' | 'local-market';/** Renderer-safe Plugin 市场列表项;所有字段都来自协议或本地安装事实。 */export interface PluginMarketItem {usageStatistics?: PluginUsageStatistics;+ downloadStatistics?: PluginDownloadStatistics;pluginId: string;ghostId: string;/** Host-verified namespace. Missing is legacy wire; null is root. */diff --git a/docs/plugin-usage-statistics-implementation.md b/docs/plugin-usage-statistics-implementation.mdindex e197ac3373..81b4412844 100644--- a/docs/plugin-usage-statistics-implementation.md+++ b/docs/plugin-usage-statistics-implementation.md@@ -23,8 +23,8 @@## 服务端依赖与协议-现有 `PluginDownload` 仍是获取下载地址次数,本次没有把它当作安装回执。没有重新使用已关闭的-#2310/#2337 分支,也没有修改服务端。+现有 `PluginDownload` 是获取下载地址次数,不是安装回执。没有重新使用已关闭的+#2310/#2337 分支。初次个人记录实施未修改服务端;后续累计下载接入见下节。现有 v2 列表和详情可选扩展 `usageStatistics`,不提升 `PLUGIN_API_SCHEMA_VERSION`:@@ -83,3 +83,29 @@ outbox 文件、定时发送器、联网重试或对历史个人记录的补传- 在本 worktree 独立 Electron 开发版中通过前端热更新查看真实 TapTap Maker 详情,Light/Dark均已目检无统计时的头部;截图位于 `apps/desktop/logs/plugin-usage-acceptance/shared-usage-followup/`。服务端当前未提供统计,带数字与新图标的真实市场状态尚未实机验证;没有伪造市场数字。++## 2026-10-12 接入累计下载++用户要求接入 Platform 已有的累计数字。实际核对服务端 main `8e0ae149` 和 release 后,+确认后台统计为下载地址签发次数:`downloadStatistics.requestCount`(累计)和+`downloadStatistics.last7DaysRequestCount`(滚动 168 小时)。客户端头部只显示累计“下载”,+使用 `ArrowDownToLine`,提示说明包括更新、重装和重新请求地址的重试,不代表安装成功。++- 客户端沿 `PluginMarketApi` → v2 协议解析 → 市场服务投影 → 详情组件传递同名字段。+ 精确字符串用 BigInt 格式化,无 Number 精度损失;缺失或无效字段隐藏,明确的 0 正常显示。+ 不合成成功安装或使用次数;个人/custom 插件不展示共享下载数。+- 服务端独立本地分支 `/Users/huangxiaowen/Developer/cindy-server` 的+ `feat/plugin-client-download-statistics`,给 `/api/plugins` 列表和详情加可选字段,+ 复用已有 `pluginDownloadStatistics` 批量聚合,不新增表、上报或 Platform 凭证。+ 企业统计在原可见性/部门/角色门禁通过后查询;统计读取失败省略字段,不伪造 0。+- 服务端契约与客户端一致,schemaVersion 仍为 2;旧服务不发字段时客户端继续正常工作。+ 两仓均只在本地实现,未推送、创建 PR 或部署。线上数字显示仍取决于服务端发布此扩展。++验证:客户端协议包 128 项、三个受影响 Desktop 测试文件 192 项通过;服务端协议包+145 项、plugin-server 609 项通过(41 项数据库集成测试未配置安全数据库而跳过)。+两仓协议类型检查、plugin-server 与 Desktop 类型检查、相关 ESLint、五语完整性、术语与 diff 检查通过。+独立 Global Electron 沙箱启动返回 `DESKTOP_DEV_VERDICT=ready`,当前代码下真实 TapTap Maker+详情的缺失指标隐藏在 Light/Dark 均已目检,截图在+`apps/desktop/logs/plugin-usage-acceptance/cumulative-download/market-{light,dark}.png`。+线上服务尚未返回下载统计,带数字的生产数据联调未完成,不将测试中的 123 当成实际累计数。+本次未运行客户端整仓全量测试;按影响面完成协议包与市场/详情定向验证,完整门禁待后续 PR CI。diff --git a/packages/plugin-protocol/src/__tests__/delivery.test.ts b/packages/plugin-protocol/src/__tests__/delivery.test.tsindex 8468a94670..b66cd6a544 100644--- a/packages/plugin-protocol/src/__tests__/delivery.test.ts+++ b/packages/plugin-protocol/src/__tests__/delivery.test.ts@@ -46,6 +46,35 @@ const oidcManifest = {} as const;describe('plugin delivery contract', () => {+ it('preserves optional cumulative download statistics in list and detail without conflating installs', () => {+ const plugin = {+ id: pluginId, ghostId: validManifest.id, name: validManifest.name,+ description: null, author: null, scope: 'public', organizationId: null,+ defaultInstall: false,+ currentRelease: {+ id: 'release-1', version: validManifest.version, sha256: 'a'.repeat(64),+ sizeBytes: 1024, publishedAt: '2026-07-19T00:00:00.000Z', icon: null,+ manifest: validManifest,+ },+ };+ for (const downloadStatistics of [+ { requestCount: '0', last7DaysRequestCount: '0' },+ { requestCount: '18446744073709551615', last7DaysRequestCount: '12' },+ { requestCount: '123' },+ ]) {+ const withStatistics = { ...plugin, downloadStatistics };+ const list = parseListPluginsResponse({ schemaVersion: 2, plugins: [withStatistics], nextCursor: null });+ const detail = parseGetPluginResponse({ schemaVersion: 2, plugin: withStatistics });+ expect(list.plugins[0]?.downloadStatistics).toEqual(downloadStatistics);+ expect(detail.plugin.downloadStatistics).toEqual(downloadStatistics);+ expect(detail.plugin).not.toHaveProperty('usageStatistics');+ }+ for (const downloadStatistics of [undefined, null, {}, { requestCount: 0 }, { requestCount: '-1' }, { requestCount: '01' }]) {+ const detail = parseGetPluginResponse({ schemaVersion: 2, plugin: { ...plugin, downloadStatistics } });+ expect(detail.plugin).not.toHaveProperty('downloadStatistics');+ }+ });+it('parses a paginated visible Plugin summary without requiring a manifest', () => {const response = parseListPluginsResponse({schemaVersion: PLUGIN_API_SCHEMA_VERSION,diff --git a/packages/plugin-protocol/src/delivery.ts b/packages/plugin-protocol/src/delivery.tsindex f7497e0d52..233aaf2a40 100644--- a/packages/plugin-protocol/src/delivery.ts+++ b/packages/plugin-protocol/src/delivery.ts@@ -93,7 +93,27 @@ export interface PluginReleaseDetail extends PluginReleaseSummary {manifest: GhostManifest & { namespace?: string | null };}-/** Plugin 列表项;只含市场展示和版本对账所需的摘要。 */+/** Optional aggregate of successfully issued client download URLs, not completed installs. */+export interface PluginDownloadStatistics {+ /** Decimal count of successfully issued download URLs across all releases. */+ requestCount: string;+ /** Rolling 168 hours; optional for compatibility with older servers. */+ last7DaysRequestCount?: string;+}++/** Preserve exact counters while allowing older servers to omit statistics. */+export function parsePluginDownloadStatistics(value: unknown): PluginDownloadStatistics | undefined {+ if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined;+ const raw = value as Record<string, unknown>;+ const isCount = (count: unknown): count is string =>+ typeof count === 'string' && /^(0|[1-9][0-9]{0,19})$/.test(count);+ if (!isCount(raw.requestCount)) return undefined;+ return {+ requestCount: raw.requestCount,+ ...(isCount(raw.last7DaysRequestCount) ? { last7DaysRequestCount: raw.last7DaysRequestCount } : {}),+ };+}+/** Optional, already-authorized audience aggregate. Downloads are not install receipts. */export interface PluginUsageStatistics {installationCount: string;@@ -113,6 +133,7 @@ export function parsePluginUsageStatistics(value: unknown): PluginUsageStatisticusageCountLast7Days: raw.usageCountLast7Days as string, asOf: raw.asOf };}+/** Plugin 列表项;只含市场展示和版本对账所需的摘要。 */export interface VisiblePluginSummary {/** plugin-server 生成的永久资源 ID,也是客户端管理安装实例的主键。 */id: string;@@ -134,6 +155,7 @@ export interface VisiblePluginSummary {/** 服务端为该客户端选择的 Release;优先 current,不兼容时回退到历史兼容版本。 */currentRelease: PluginReleaseSummary;usageStatistics?: PluginUsageStatistics;+ downloadStatistics?: PluginDownloadStatistics;}/** Plugin 详情;展示字段必须与 `currentRelease.manifest` 保持一致。 */@@ -158,6 +180,7 @@ export interface VisiblePluginDetail {/** 服务端为该客户端选择的 Release,包含完整 manifest。 */currentRelease: PluginReleaseDetail;usageStatistics?: PluginUsageStatistics;+ downloadStatistics?: PluginDownloadStatistics;}/** 清理通告支持的处置动作;解析器会跳过动作未知的通告(未来扩展位)。 */@@ -382,15 +405,18 @@ function parseVisiblePluginBase(function parseVisiblePluginSummary(value: unknown, index: number): VisiblePluginSummary {const path = `plugins[${index}]`;const { raw, ...base } = parseVisiblePluginBase(value, path);+ const downloadStatistics = parsePluginDownloadStatistics(raw.downloadStatistics);return {...base,...(parsePluginUsageStatistics(raw.usageStatistics) ? { usageStatistics: parsePluginUsageStatistics(raw.usageStatistics) } : {}),+ ...(downloadStatistics ? { downloadStatistics } : {}),currentRelease: parseReleaseSummary(raw.currentRelease, `${path}.currentRelease`),};}function parseVisiblePluginDetail(value: unknown, path: string): VisiblePluginDetail {const { raw, ...parsed } = parseVisiblePluginBase(value, path);+ const downloadStatistics = parsePluginDownloadStatistics(raw.downloadStatistics);const currentRelease = parseReleaseDetail(raw.currentRelease,parsed.ghostId,@@ -420,6 +446,7 @@ function parseVisiblePluginDetail(value: unknown, path: string): VisiblePluginDereturn {...parsed,...(parsePluginUsageStatistics(raw.usageStatistics) ? { usageStatistics: parsePluginUsageStatistics(raw.usageStatistics) } : {}),+ ...(downloadStatistics ? { downloadStatistics } : {}),currentRelease,};}