diff --git a/pricing-catalog.json b/pricing-catalog.json index 7263b29..cf1d598 100644 --- a/pricing-catalog.json +++ b/pricing-catalog.json @@ -1,11 +1,11 @@ { "schemaVersion": 1, - "catalogVersion": "2026.11.11.4", + "catalogVersion": "2026.11.12.1", "updatedAt": "2026-11-13T13:20:00+09:00", "latestPluginVersion": "1.4.4", - "releaseUrl": "https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest", - "downloadUrl": "https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip", - "archiveFallbackUrl": "https://codeload.github.com/yuhuan2498281558/antigravity-usage-monitor/zip/refs/heads/main", + "releaseUrl": "https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest", + "downloadUrl": "https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip", + "archiveFallbackUrl": "https://codeload.github.com/yuhuan-dev/antigravity-usage-monitor/zip/refs/heads/main", "pricing": { "gemini-4-carbon-high": { "input": 2.00, "cache": 0.10, "output": 10.0, "short": "carbon-4-high", "family": "Gemini" }, "gemini-4-carbon-medium": { "input": 2.00, "cache": 0.10, "output": 10.0, "short": "carbon-4", "family": "Gemini" }, diff --git a/sidecars/panel/backend/config.mjs b/sidecars/panel/backend/config.mjs index b87db0a..8fee696 100644 --- a/sidecars/panel/backend/config.mjs +++ b/sidecars/panel/backend/config.mjs @@ -57,15 +57,19 @@ export const CSRF_TOKEN = process.env.ANTIGRAVITY_CSRF_TOKEN; /** * GitHub 官方云端价格目录与插件发布包地址配置。 */ +export const OFFICIAL_GITHUB_REPO = 'yuhuan-dev/antigravity-usage-monitor'; +export const LEGACY_GITHUB_REPOS = Object.freeze([ + 'yuhuan2498281558/antigravity-usage-monitor', +]); export const CLOUD_CATALOG_URLS = [ - 'https://raw.githubusercontent.com/yuhuan2498281558/antigravity-usage-monitor/main/pricing-catalog.json', + `https://raw.githubusercontent.com/${OFFICIAL_GITHUB_REPO}/main/pricing-catalog.json`, ]; export const DEFAULT_RELEASE_URL = - 'https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest'; + `https://github.com/${OFFICIAL_GITHUB_REPO}/releases/latest`; export const DEFAULT_DOWNLOAD_URL = - 'https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip'; + `https://github.com/${OFFICIAL_GITHUB_REPO}/releases/latest/download/usage-monitor.zip`; export const DEFAULT_ARCHIVE_FALLBACK_URL = - 'https://codeload.github.com/yuhuan2498281558/antigravity-usage-monitor/zip/refs/heads/main'; + `https://codeload.github.com/${OFFICIAL_GITHUB_REPO}/zip/refs/heads/main`; /** 云端目录常规自动检查间隔(6 小时)与失败冷却时间(5 分钟)。 */ export const CLOUD_SYNC_TTL_MS = 6 * 3600 * 1000; diff --git a/sidecars/panel/backend/plugin-updater.mjs b/sidecars/panel/backend/plugin-updater.mjs index dacae34..41a2a5c 100644 --- a/sidecars/panel/backend/plugin-updater.mjs +++ b/sidecars/panel/backend/plugin-updater.mjs @@ -26,7 +26,9 @@ import { DATA_DIR, DEFAULT_ARCHIVE_FALLBACK_URL, DEFAULT_DOWNLOAD_URL, + LEGACY_GITHUB_REPOS, LS_ADDR, + OFFICIAL_GITHUB_REPO, PLUGIN_ROOT, REMOTE_CATALOG_CACHE_FILE, cloudSyncState, @@ -158,6 +160,31 @@ function pruneExtraneousFiles(targetDir, referenceDir) { } } +/** + * 若本地 Git 仓库的 `origin` 仍指向已迁移的旧官方仓库地址,返回同协议的新官方仓库地址; + * 对于非旧官方仓库(如已是新地址或用户自建 Fork)返回空字符串,不做改动。 + * + * @param {string} rawUrl + * @returns {string} + */ +export function resolveMigratedGitRemoteUrl(rawUrl) { + const trimmed = String(rawUrl || '').trim(); + if (!trimmed) return ''; + for (const legacyRepo of LEGACY_GITHUB_REPOS) { + const escaped = legacyRepo.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + if (new RegExp(`^https://github\\.com/${escaped}(?:\\.git)?/?$`, 'i').test(trimmed)) { + return `https://github.com/${OFFICIAL_GITHUB_REPO}.git`; + } + if (new RegExp(`^git@github\\.com:${escaped}(?:\\.git)?/?$`, 'i').test(trimmed)) { + return `git@github.com:${OFFICIAL_GITHUB_REPO}.git`; + } + if (new RegExp(`^ssh://git@github\\.com/${escaped}(?:\\.git)?/?$`, 'i').test(trimmed)) { + return `ssh://git@github.com/${OFFICIAL_GITHUB_REPO}.git`; + } + } + return ''; +} + /** * 在真实运行环境下对目标目录的核心 JS 文件执行 `node --check` 语法预检。 * @@ -277,7 +304,31 @@ export async function performPluginUpdate({ isAuto = false } = {}) { const targetBranch = currentBranch || 'main'; const remoteRef = `origin/${targetBranch}`; - // 3. 只读拉取远端分支引用,并严格从 origin/:plugin.json 读取远端版本号(严禁回退使用缓存版本) + // 3. 存量旧仓库远程地址平滑迁移:若 origin 仍指向已更换的旧官方仓库,自动切换至新仓库地址 + try { + const remoteUrlRes = await runExecFile('git', [ + '-C', + PLUGIN_ROOT, + 'remote', + 'get-url', + 'origin', + ]); + const migratedRemoteUrl = resolveMigratedGitRemoteUrl(remoteUrlRes.stdout); + if (migratedRemoteUrl) { + await runExecFile('git', [ + '-C', + PLUGIN_ROOT, + 'remote', + 'set-url', + 'origin', + migratedRemoteUrl, + ]); + } + } catch { + // 忽略非标准 remote 配置异常,不阻断常规拉取 + } + + // 4. 只读拉取远端分支引用,并严格从 origin/:plugin.json 读取远端版本号(严禁回退使用缓存版本) await runExecFile('git', ['-C', PLUGIN_ROOT, 'fetch', 'origin', targetBranch, '--tags']); let remoteVersion = ''; @@ -298,7 +349,7 @@ export async function performPluginUpdate({ isAuto = false } = {}) { remoteVersion = ''; } - // 4. 强制版本门禁:远端版本无法确认或不高于当前版本时,严禁执行 git pull 降级/覆盖 + // 5. 强制版本门禁:远端版本无法确认或不高于当前版本时,严禁执行 git pull 降级/覆盖 if (!remoteVersion || compareSemver(remoteVersion, previousVersion) <= 0) { const msg = `当前已是最新版本 (v${previousVersion})`; const result = { @@ -317,7 +368,7 @@ export async function performPluginUpdate({ isAuto = false } = {}) { return result; } - // 5. 提交拓扑预检:确保当前 HEAD 是远端分支的祖先提交(无本地超前或分叉提交) + // 6. 提交拓扑预检:确保当前 HEAD 是远端分支的祖先提交(无本地超前或分叉提交) try { await runExecFile('git', [ '-C', @@ -343,7 +394,7 @@ export async function performPluginUpdate({ isAuto = false } = {}) { return pluginUpdateState.lastResult; } - // 6. 确认全部门禁通过后,执行快进合并并校验 JS 语法 + // 7. 确认全部门禁通过后,执行快进合并并校验 JS 语法 await runExecFile('git', ['-C', PLUGIN_ROOT, 'pull', '--ff-only', 'origin', targetBranch]); await verifyPluginJsSyntax(PLUGIN_ROOT); rebuildActiveCatalog(); diff --git a/sidecars/panel/backend/pricing-catalog.mjs b/sidecars/panel/backend/pricing-catalog.mjs index 7bedf78..6973592 100644 --- a/sidecars/panel/backend/pricing-catalog.mjs +++ b/sidecars/panel/backend/pricing-catalog.mjs @@ -16,7 +16,9 @@ import { DEFAULT_ARCHIVE_FALLBACK_URL, DEFAULT_DOWNLOAD_URL, DEFAULT_RELEASE_URL, + LEGACY_GITHUB_REPOS, LOCAL_CATALOG_FILE, + OFFICIAL_GITHUB_REPO, PLUGIN_MANIFEST_FILE, PLUGIN_ROOT, REMOTE_CATALOG_CACHE_FILE, @@ -44,7 +46,35 @@ export function isValidSemver(v) { ); } -const OFFICIAL_REPO_PATH_PREFIX = '/yuhuan2498281558/antigravity-usage-monitor'; +const OFFICIAL_REPO_PATH_PREFIX = `/${OFFICIAL_GITHUB_REPO.toLowerCase()}`; +const LEGACY_REPO_PATH_PREFIXES = LEGACY_GITHUB_REPOS.map((repo) => `/${repo.toLowerCase()}`); + +/** + * 判断来源 URL 是否属于已迁移的旧官方 GitHub 仓库地址。 + * + * @param {*} rawUrl + * @returns {boolean} + */ +function isLegacyGithubRepoUrl(rawUrl) { + if (typeof rawUrl !== 'string' || !rawUrl.trim()) return false; + try { + const parsed = new URL(rawUrl.trim()); + const host = parsed.hostname.toLowerCase(); + const pathname = parsed.pathname.toLowerCase(); + if ( + host !== 'github.com' && + host !== 'raw.githubusercontent.com' && + host !== 'codeload.github.com' + ) { + return false; + } + return LEGACY_REPO_PATH_PREFIXES.some( + (prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`) + ); + } catch { + return false; + } +} /** * 校验更新/下载链接是否属于可信的 GitHub 官方仓库与 HTTPS 域名白名单。 @@ -245,6 +275,8 @@ export function sanitizeCatalogPayload(raw) { const explicitReleaseUrl = sanitizeTrustedGithubUrl(raw.releaseUrl, ''); const explicitDownloadUrl = sanitizeTrustedGithubUrl(raw.downloadUrl, ''); const explicitArchiveUrl = sanitizeTrustedGithubUrl(raw.archiveFallbackUrl, ''); + const rawSourceUrl = typeof raw.sourceUrl === 'string' ? raw.sourceUrl.trim() : ''; + const isLegacySource = isLegacyGithubRepoUrl(rawSourceUrl); return { schemaVersion: Number(raw.schemaVersion || 1), @@ -261,8 +293,8 @@ export function sanitizeCatalogPayload(raw) { hasReleaseUrl: Boolean(explicitReleaseUrl), hasDownloadUrl: Boolean(explicitDownloadUrl), hasArchiveFallbackUrl: Boolean(explicitArchiveUrl), - fetchedAtMs: Number(raw.fetchedAtMs || 0), - sourceUrl: typeof raw.sourceUrl === 'string' ? raw.sourceUrl : '', + fetchedAtMs: isLegacySource ? 0 : Number(raw.fetchedAtMs || 0), + sourceUrl: isLegacySource ? '' : rawSourceUrl, pricing, placeholders, }; diff --git a/sidecars/panel/test/backend-harness.mjs b/sidecars/panel/test/backend-harness.mjs index e3a5693..44ce65e 100644 --- a/sidecars/panel/test/backend-harness.mjs +++ b/sidecars/panel/test/backend-harness.mjs @@ -144,6 +144,6 @@ export function backendHarness({ return {ok:true,json:async()=>data}; }, }; - vm.runInNewContext(source+'\n globalThis.api={buildTelemetryPayloadInternal,computeStepCost,resolveModelInfo,inferFamilyFromProviderOrKey,isCarbonModelIdentifier,PLACEHOLDER_MAP,normalizeQuotaFraction,classifyOfficialBucketWindow,classifyQuotaPoolIdentity,buildOfficialQuotaPools,resolveTimeWindow,sanitizeCatalogPayload,rebuildActiveCatalog,syncCloudCatalog,getCloudStatus,isValidSemver,compareSemver,performPluginUpdate,loadSettings,executeSettingsAction};',ctx); + vm.runInNewContext(source+'\n globalThis.api={buildTelemetryPayloadInternal,computeStepCost,resolveModelInfo,inferFamilyFromProviderOrKey,isCarbonModelIdentifier,PLACEHOLDER_MAP,normalizeQuotaFraction,classifyOfficialBucketWindow,classifyQuotaPoolIdentity,buildOfficialQuotaPools,resolveTimeWindow,sanitizeCatalogPayload,rebuildActiveCatalog,syncCloudCatalog,getCloudStatus,isValidSemver,compareSemver,performPluginUpdate,resolveMigratedGitRemoteUrl,loadSettings,executeSettingsAction};',ctx); return {...ctx.api,state}; } diff --git a/sidecars/panel/test/cloud-sync-and-update.test.mjs b/sidecars/panel/test/cloud-sync-and-update.test.mjs index 55bd3cf..a0112da 100644 --- a/sidecars/panel/test/cloud-sync-and-update.test.mjs +++ b/sidecars/panel/test/cloud-sync-and-update.test.mjs @@ -52,7 +52,7 @@ test('sanitizeCatalogPayload filters malformed/null/zero entries, untrusted URLs assert.ok(sanitized); assert.equal(sanitized.catalogVersion, '2026.11.03.9'); assert.equal(sanitized.latestPluginVersion, '1.5.0'); - assert.ok(sanitized.downloadUrl.startsWith('https://github.com/yuhuan2498281558/')); + assert.ok(sanitized.downloadUrl.startsWith('https://github.com/yuhuan-dev/')); assert.deepEqual(Object.keys(sanitized.pricing), ['gemini-4.5-ultra']); assert.deepEqual(Object.keys(sanitized.placeholders), ['MODEL_PLACEHOLDER_M999']); }); @@ -94,7 +94,7 @@ test('cloud catalog sync fetches from GitHub raw URL and dynamically prices newl // Sync cloud catalog from GitHub const syncStatus = await h.syncCloudCatalog({ force: true }); - assert.ok(fetchedUrl.startsWith('https://raw.githubusercontent.com/yuhuan2498281558/antigravity-usage-monitor/main/pricing-catalog.json')); + assert.ok(fetchedUrl.startsWith('https://raw.githubusercontent.com/yuhuan-dev/antigravity-usage-monitor/main/pricing-catalog.json')); assert.equal(syncStatus.source, 'remote'); assert.equal(syncStatus.catalogVersion, '2026.11.03.2'); assert.equal(syncStatus.latestPluginVersion, '1.5.0'); @@ -273,7 +273,103 @@ test('performPluginUpdate pulls fast-forward when git worktree is clean, on main assert.equal(res.mode, 'git'); assert.equal(res.previousVersion, '1.3.1'); assert.equal(res.currentVersion, '1.4.0'); - assert.equal(gitCalls.length, 6); // status, rev-parse, fetch, show, merge-base, pull + assert.equal(gitCalls.length, 7); // status, rev-parse, remote get-url, fetch, show, merge-base, pull +}); + +test('repository migration: scrubs legacy yuhuan2498281558 cache URLs/TTL and migrates git origin remote to yuhuan-dev', async () => { + let fetchedNewRepoUrl = ''; + const cacheH = backendHarness({ + pluginManifest: { name: 'usage-monitor', version: '1.4.4' }, + remoteCatalog: { + schemaVersion: 1, + catalogVersion: '2026.11.11.4', + updatedAt: '2026-11-11T23:20:00+09:00', + latestPluginVersion: '1.4.4', + releaseUrl: 'https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest', + downloadUrl: 'https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip', + archiveFallbackUrl: 'https://codeload.github.com/yuhuan2498281558/antigravity-usage-monitor/zip/refs/heads/main', + sourceUrl: 'https://raw.githubusercontent.com/yuhuan2498281558/antigravity-usage-monitor/main/pricing-catalog.json', + fetchedAtMs: Date.now() - 60_000, // 1 min ago from old repo -> must NOT block non-forced sync to yuhuan-dev + pricing: { + 'gemini-4-carbon-high': { input: 2.0, cache: 0.1, output: 10.0, short: 'carbon-4-high', family: 'Gemini' }, + }, + }, + remoteFetch: async (url) => { + fetchedNewRepoUrl = String(url); + return { + ok: true, + json: async () => ({ + schemaVersion: 1, + catalogVersion: '2026.11.12.1', + updatedAt: '2026-11-12T10:00:00+09:00', + latestPluginVersion: '1.4.5', + pricing: { + 'gemini-4-carbon-high': { input: 2.0, cache: 0.1, output: 10.0, short: 'carbon-4-high', family: 'Gemini' }, + }, + }), + }; + }, + }); + + const initialStatus = cacheH.getCloudStatus(); + assert.equal(initialStatus.releaseUrl, 'https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest'); + assert.equal(initialStatus.downloadUrl, 'https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip'); + assert.equal(initialStatus.lastSyncedAtMs, 0, 'legacy repo cache TTL must be invalidated so new repo syncs immediately'); + + const synced = await cacheH.syncCloudCatalog({ force: false }); + assert.equal( + fetchedNewRepoUrl, + 'https://raw.githubusercontent.com/yuhuan-dev/antigravity-usage-monitor/main/pricing-catalog.json' + ); + assert.equal(synced.catalogVersion, '2026.11.12.1'); + assert.equal(synced.latestPluginVersion, '1.4.5'); + + assert.equal( + cacheH.resolveMigratedGitRemoteUrl('https://github.com/yuhuan2498281558/antigravity-usage-monitor.git'), + 'https://github.com/yuhuan-dev/antigravity-usage-monitor.git' + ); + assert.equal( + cacheH.resolveMigratedGitRemoteUrl('git@github.com:yuhuan2498281558/antigravity-usage-monitor.git'), + 'git@github.com:yuhuan-dev/antigravity-usage-monitor.git' + ); + assert.equal( + cacheH.resolveMigratedGitRemoteUrl('https://github.com/custom-fork/antigravity-usage-monitor.git'), + '' + ); + + const gitCalls = []; + const migrateH = backendHarness({ + hasGitDir: true, + pluginRootPath: '/Users/test/.gemini/config/plugins/usage-monitor', + pluginManifest: { name: 'usage-monitor', version: '1.4.3' }, + execFileImpl: (_cmd, args, opts, cb) => { + const fn = typeof opts === 'function' ? opts : cb; + gitCalls.push(args); + if (args.includes('rev-parse')) { + fn(null, 'main\n', ''); + return; + } + if (args.includes('remote') && args.includes('get-url')) { + fn(null, 'https://github.com/yuhuan2498281558/antigravity-usage-monitor.git\n', ''); + return; + } + if (args.includes('show')) { + fn(null, JSON.stringify({ name: 'usage-monitor', version: '1.4.4' }), ''); + return; + } + if (args.includes('pull')) { + migrateH.state.pluginManifest = { name: 'usage-monitor', version: '1.4.4' }; + } + fn(null, '', ''); + }, + }); + + const updRes = await migrateH.performPluginUpdate({ isAuto: false }); + assert.equal(updRes.ok, true); + assert.equal(updRes.currentVersion, '1.4.4'); + const setUrlCall = gitCalls.find((args) => args.includes('remote') && args.includes('set-url')); + assert.ok(setUrlCall, 'must run git remote set-url origin before fetching'); + assert.equal(setUrlCall[setUrlCall.length - 1], 'https://github.com/yuhuan-dev/antigravity-usage-monitor.git'); }); test('pluginUpdateMode supports manual (default), auto, and off with legacy autoUpdatePlugin compatibility', async () => {