Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(plugin-market): 添加/刷新市场源给出发现回执,submodule 空市场专门提示 (#2162)

nanacoecebc96efb50
diff --git a/apps/desktop/src/main/plugin-market/__tests__/sources-manager.test.ts b/apps/desktop/src/main/plugin-market/__tests__/sources-manager.test.ts
index e37941d99b..0d066240c6 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/sources-manager.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/sources-manager.test.ts
@@ -118,6 +118,32 @@ describe('MarketSourceManager local sources', () => {
});
});
+ it('surfaces the submodule-shaped empty market (entries declared, dirs empty) in add and refresh summaries', async () => {
+ // Git submodule 未递归检出的典型形态:清单合法、插件目录存在但没有 ghost.json。
+ // 不触发任何错误码,summary 必须给出 pluginCount 0 + 全额 skippedCount,
+ // renderer 才有依据展示"插件目录为空(submodule)"的专门提示(B3)。
+ const root = makeRoot();
+ const market = path.join(root, 'my-market');
+ writeMarketplace(market, 'local-lib', [{ rel: 'plugins/a', id: 'alpha' }]);
+ // 掏空插件目录:目录保留,ghost.json 与入口都不在(= submodule 空壳)。
+ fs.rmSync(path.join(market, 'plugins', 'a', 'ghost.json'));
+ fs.rmSync(path.join(market, 'plugins', 'a', 'main.js'));
+ const manager = makeManager(root);
+
+ const added = await manager.addSource({ source: market });
+ expect(added).toMatchObject({
+ name: 'local-lib',
+ pluginCount: 0,
+ skippedCount: 1,
+ unreadableCount: 0,
+ status: 'ok',
+ errorCode: null,
+ });
+
+ const refreshed = await manager.refreshSource('local-lib');
+ expect(refreshed).toMatchObject({ pluginCount: 0, skippedCount: 1, unreadableCount: 0 });
+ });
+
it('rejects a local source that is not a directory', async () => {
const manager = makeManager(makeRoot());
await expect(
diff --git a/apps/desktop/src/renderer/features/plugin/AddMarketplaceDialog.tsx b/apps/desktop/src/renderer/features/plugin/AddMarketplaceDialog.tsx
index 2ec4cb1038..88637b3edf 100644
--- a/apps/desktop/src/renderer/features/plugin/AddMarketplaceDialog.tsx
+++ b/apps/desktop/src/renderer/features/plugin/AddMarketplaceDialog.tsx
@@ -18,6 +18,7 @@ import { extractIpcError } from '@/utils/ipcError';
import type { MarketSourceSummary } from '../../../shared/pluginMarket';
import { marketplaceSourceErrorKey } from './lib/pluginMarketErrorKey';
+import { MarketplaceDiscoveryNotice } from './MarketplaceDiscoveryNotice';
import { MarketplaceGuideDialog } from './MarketplaceGuideDialog';
import { MarketplaceSourcesDialog } from './MarketplaceSourcesDialog';
@@ -64,6 +65,8 @@ export function AddMarketplaceDialog({
key: string;
detail: string | null;
} | null>(null);
+ // 添加成功的发现回执:插件数 + 跳过/暂不可读提示(与错误互斥,新一轮操作前清空)。
+ const [addedSummary, setAddedSummary] = useState<MarketSourceSummary | null>(null);
// 只有 git 克隆类错误码的 detail 是消毒后的 stderr 摘录,值得原文展示;
// 其它错误码的 message 是内部英文文案,展示反而会和本地化引导重复。
@@ -97,6 +100,8 @@ export function AddMarketplaceDialog({
setSources(null);
setSourcesOpen(false);
setOperationError(null);
+ // 回执含上一账号的市场名与计数,作用域同来源列表:切号/重开一并清空。
+ setAddedSummary(null);
if (!open) return;
void loadSources();
}, [mode, dataOwnerId, open, loadSources]);
@@ -122,25 +127,29 @@ export function AddMarketplaceDialog({
if (addDisabled) return;
setAdding(true);
setOperationError(null);
+ setAddedSummary(null);
try {
// 本地目录的授权必须来自 Main 原生目录选择器(选择即授权):Renderer 直传
// 绝对路径在 IPC 层会被拒——XSS 控制下的自报路径不构成用户授权。输入的
// 路径只作为原生框的初始定位提示;用户取消则静默结束。
+ let summary: MarketSourceSummary;
if (sourceIsLocal) {
const picked = await window.electronAPI.pluginMarket.pickLocalSource(sourceInput.trim());
if (picked.canceled) return;
+ summary = picked.summary;
} else {
const sparsePaths = sparseInput
.split('\n')
.map((entry) => entry.trim())
.filter((entry) => entry.length > 0);
const ref = refInput.trim();
- await window.electronAPI.pluginMarket.addSource({
+ summary = await window.electronAPI.pluginMarket.addSource({
source: sourceInput.trim(),
...(ref ? { ref } : {}),
...(sparsePaths.length > 0 ? { sparsePaths } : {}),
});
}
+ setAddedSummary(summary);
setSourceInput('');
setRefInput('');
setSparseInput('');
@@ -282,6 +291,12 @@ export function AddMarketplaceDialog({
</div>
) : null}
+ {addedSummary ? (
+ <div className="mt-3">
+ <MarketplaceDiscoveryNotice summary={addedSummary} action="added" />
+ </div>
+ ) : null}
+
{sources && sources.length > 0 ? (
<button
type="button"
diff --git a/apps/desktop/src/renderer/features/plugin/MarketplaceDiscoveryNotice.tsx b/apps/desktop/src/renderer/features/plugin/MarketplaceDiscoveryNotice.tsx
new file mode 100644
index 0000000000..75fb2e2201
--- /dev/null
+++ b/apps/desktop/src/renderer/features/plugin/MarketplaceDiscoveryNotice.tsx
@@ -0,0 +1,62 @@
+/**
+ * 添加 / 刷新市场源成功后的发现回执:插件数 + 跳过 / 暂不可读条目提示。
+ *
+ * 三类信息刻意分行、语义分开(与 discover.ts 的注释要求一致):
+ * - skippedCount:内容**永久**非法,跳过即结论;
+ * - 可用 0 且存在被跳过条目:典型成因是市场仓库把插件目录做成了 Git submodule
+ * (clone 有意不递归,见 sources/git.ts),目录存在但内容为空——清单完全合法,
+ * 不触发任何错误码,不专门点明的话用户与市场作者完全无从排查;
+ * - unreadableCount:**事实不明**(权限 / 文件锁 / 瞬时 I/O),刷新可解,
+ * 不得与 skipped 混同展示。
+ */
+import { useTranslation } from 'react-i18next';
+
+import type { MarketSourceSummary } from '../../../shared/pluginMarket';
+
+export interface MarketplaceDiscoveryNoticeProps {
+ /** add / refresh 返回的来源摘要。 */
+ summary: Pick<MarketSourceSummary, 'name' | 'pluginCount' | 'skippedCount' | 'unreadableCount'>;
+ /** 回执动词:added(添加)或 refreshed(刷新)。 */
+ action: 'added' | 'refreshed';
+}
+
+export function MarketplaceDiscoveryNotice({ summary, action }: MarketplaceDiscoveryNoticeProps) {
+ const { t } = useTranslation();
+ // "清单有条目但可用 0"由既有字段推导,不在 IPC 上加冗余布尔。推导依据的不变量:
+ // discover.ts 对每个清单条目恰好计入 plugins/skipped/unreadable 三者之一,即
+ // declared = accepted + skipped + unreadable 恒成立——改 summary 字段语义时必须
+ // 同步审视这里。unreadable-only 的 0 可用不算:那是瞬时问题,刷新提示已覆盖。
+ const emptyWithSkips = summary.pluginCount === 0 && summary.skippedCount > 0;
+ return (
+ <div
+ role="status"
+ className="rounded-xl border border-[var(--border-default)] bg-[var(--surface-elevated)] px-4 py-3"
+ >
+ <p className="text-12 leading-5 text-[var(--text-primary)]">
+ {t(
+ action === 'added'
+ ? 'settings.ghosts.market.sources.addedReceipt'
+ : 'settings.ghosts.market.sources.refreshedReceipt',
+ { name: summary.name, count: summary.pluginCount },
+ )}
+ </p>
+ {summary.skippedCount > 0 ? (
+ <p className="mt-1 text-11 leading-4 text-[var(--text-tertiary)]">
+ {t('settings.ghosts.market.sources.skippedEntries', { count: summary.skippedCount })}
+ </p>
+ ) : null}
+ {emptyWithSkips ? (
+ <p className="mt-1 text-11 leading-4 text-[var(--warning-fg)]">
+ {t('settings.ghosts.market.sources.emptyWithEntries')}
+ </p>
+ ) : null}
+ {summary.unreadableCount > 0 ? (
+ <p className="mt-1 text-11 leading-4 text-[var(--warning-fg)]">
+ {t('settings.ghosts.market.sources.unreadableEntries', {
+ count: summary.unreadableCount,
+ })}
+ </p>
+ ) : null}
+ </div>
+ );
+}
diff --git a/apps/desktop/src/renderer/features/plugin/MarketplaceSourcesDialog.tsx b/apps/desktop/src/renderer/features/plugin/MarketplaceSourcesDialog.tsx
index 0c093cf252..751145b5ce 100644
--- a/apps/desktop/src/renderer/features/plugin/MarketplaceSourcesDialog.tsx
+++ b/apps/desktop/src/renderer/features/plugin/MarketplaceSourcesDialog.tsx
@@ -17,6 +17,7 @@ import { extractIpcError } from '@/utils/ipcError';
import type { MarketSourceSummary } from '../../../shared/pluginMarket';
import { marketplaceSourceErrorKey } from './lib/pluginMarketErrorKey';
+import { MarketplaceDiscoveryNotice } from './MarketplaceDiscoveryNotice';
export interface MarketplaceSourcesDialogProps {
open: boolean;
@@ -52,6 +53,8 @@ export function MarketplaceSourcesDialog({
key: string;
detail: string | null;
} | null>(null);
+ // 刷新成功的发现回执(与错误互斥;新一轮操作前清空)。
+ const [refreshedSummary, setRefreshedSummary] = useState<MarketSourceSummary | null>(null);
const toOperationError = (error: unknown) => {
const ipc = extractIpcError(error);
@@ -70,14 +73,18 @@ export function MarketplaceSourcesDialog({
setPendingRemove(null);
setBusySource(null);
setOperationError(null);
+ // 回执含市场名与计数,与来源列表同作用域:父级一关(含切号)即清空。
+ setRefreshedSummary(null);
}, [open]);
const handleRefresh = useCallback(
async (name: string) => {
setBusySource(name);
setOperationError(null);
+ setRefreshedSummary(null);
try {
- await window.electronAPI.pluginMarket.refreshSource(name);
+ const summary = await window.electronAPI.pluginMarket.refreshSource(name);
+ setRefreshedSummary(summary);
onChanged();
} catch (error) {
setOperationError(toOperationError(error));
@@ -92,6 +99,8 @@ export function MarketplaceSourcesDialog({
async (source: MarketSourceSummary) => {
setBusySource(source.name);
setOperationError(null);
+ // 被移除的可能正是回执指向的来源,残留会指向已不存在的市场。
+ setRefreshedSummary(null);
try {
await window.electronAPI.pluginMarket.removeSource(source.name);
onChanged();
@@ -176,6 +185,12 @@ export function MarketplaceSourcesDialog({
</div>
) : null}
+ {refreshedSummary ? (
+ <div className="mb-3">
+ <MarketplaceDiscoveryNotice summary={refreshedSummary} action="refreshed" />
+ </div>
+ ) : null}
+
<div className="flex flex-col gap-2">
{sources.map((source) => (
<div
@@ -220,6 +235,16 @@ export function MarketplaceSourcesDialog({
})}
</p>
) : null}
+ {source.pluginCount === 0 && source.skippedCount > 0 ? (
+ // 可用 0 但清单有条目:常见成因是插件目录被做成 Git
+ // submodule(clone 有意不递归),清单合法、无错误码,
+ // 不点明成因用户无从排查。推导不变量见
+ // MarketplaceDiscoveryNotice(declared = accepted +
+ // skipped + unreadable)。
+ <p className="text-[var(--warning-fg)]">
+ {t('settings.ghosts.market.sources.emptyWithEntries')}
+ </p>
+ ) : null}
{source.unreadableCount > 0 ? (
<p className="text-[var(--warning-fg)]">
{t('settings.ghosts.market.sources.unreadableEntries', {
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/AddMarketplaceDialog.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/AddMarketplaceDialog.test.tsx
index 64f02f465e..411f4181ad 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/AddMarketplaceDialog.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/AddMarketplaceDialog.test.tsx
@@ -115,6 +115,32 @@ describe('AddMarketplaceDialog', () => {
auth.dataOwnerId = 'user-1';
});
+ it('shows the discovery receipt (with submodule hint) after a successful add', async () => {
+ // submodule 空目录形态:清单有条目、可用 0。回执必须点明成因而非静默。
+ addSource.mockResolvedValueOnce({
+ name: 'hub',
+ addedAt: '2026-08-08T00:00:00.000Z',
+ lastSyncedAt: '2026-08-08T00:00:00.000Z',
+ lastRevision: 'abc123',
+ source: { type: 'git', url: 'https://github.com/acme/hub.git', sparsePaths: [] },
+ pluginCount: 0,
+ skippedCount: 2,
+ unreadableCount: 0,
+ status: 'ok',
+ errorCode: null,
+ } as never);
+ render(<AddMarketplaceDialog open onOpenChange={() => {}} onSourcesChanged={() => {}} />);
+ fireEvent.change(input('settings.ghosts.market.sources.sourcePlaceholder'), {
+ target: { value: 'acme/hub' },
+ });
+ fireEvent.click(screen.getByRole('button', { name: 'settings.ghosts.market.sources.add' }));
+ await waitFor(() =>
+ expect(screen.getByText('settings.ghosts.market.sources.addedReceipt')).toBeTruthy(),
+ );
+ expect(screen.getByText('settings.ghosts.market.sources.emptyWithEntries')).toBeTruthy();
+ expect(screen.getByText('settings.ghosts.market.sources.skippedEntries')).toBeTruthy();
+ });
+
it('still forwards ref and sparse paths for git sources', async () => {
render(<AddMarketplaceDialog open onOpenChange={() => {}} onSourcesChanged={() => {}} />);
fireEvent.change(input('settings.ghosts.market.sources.sourcePlaceholder'), {
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/MarketplaceDiscoveryNotice.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/MarketplaceDiscoveryNotice.test.tsx
new file mode 100644
index 0000000000..c21d1532d3
--- /dev/null
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/MarketplaceDiscoveryNotice.test.tsx
@@ -0,0 +1,82 @@
+/**
+ * 市场发现回执:插件数回执、skipped 与 unreadable 分开、submodule 空目录专门提示。
+ * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
+ * @vitest-environment jsdom
+ */
+
+import { render, screen } from '@testing-library/react';
+import { describe, expect, it, vi } from 'vitest';
+
+vi.mock('react-i18next', () => ({
+ // 回显 key + 参数,便于断言 count/name 是否被传入。
+ useTranslation: () => ({
+ t: (key: string, params?: Record<string, unknown>) =>
+ params ? `${key}:${JSON.stringify(params)}` : key,
+ }),
+}));
+
+import { MarketplaceDiscoveryNotice } from '../MarketplaceDiscoveryNotice';
+
+const base = { name: 'team-lib', pluginCount: 3, skippedCount: 0, unreadableCount: 0 };
+
+describe('MarketplaceDiscoveryNotice', () => {
+ it('shows the added receipt with market name and plugin count', () => {
+ render(<MarketplaceDiscoveryNotice summary={base} action="added" />);
+ expect(
+ screen.getByText('settings.ghosts.market.sources.addedReceipt:{"name":"team-lib","count":3}'),
+ ).toBeTruthy();
+ expect(screen.queryByText(/skippedEntries/)).toBeNull();
+ expect(screen.queryByText(/unreadableEntries/)).toBeNull();
+ expect(screen.queryByText(/emptyWithEntries/)).toBeNull();
+ });
+
+ it('shows the refreshed receipt verb for refresh flows', () => {
+ render(<MarketplaceDiscoveryNotice summary={base} action="refreshed" />);
+ expect(
+ screen.getByText(
+ 'settings.ghosts.market.sources.refreshedReceipt:{"name":"team-lib","count":3}',
+ ),
+ ).toBeTruthy();
+ });
+
+ it('keeps skipped and unreadable notices separate (invalid vs transient semantics)', () => {
+ render(
+ <MarketplaceDiscoveryNotice
+ summary={{ ...base, pluginCount: 2, skippedCount: 3, unreadableCount: 1 }}
+ action="added"
+ />,
+ );
+ expect(
+ screen.getByText('settings.ghosts.market.sources.skippedEntries:{"count":3}'),
+ ).toBeTruthy();
+ expect(
+ screen.getByText('settings.ghosts.market.sources.unreadableEntries:{"count":1}'),
+ ).toBeTruthy();
+ // 可用数 > 0:不出 submodule 空目录提示。
+ expect(screen.queryByText(/emptyWithEntries/)).toBeNull();
+ });
+
+ it('calls out the submodule-shaped empty market when entries exist but none are usable', () => {
+ render(
+ <MarketplaceDiscoveryNotice
+ summary={{ ...base, pluginCount: 0, skippedCount: 2 }}
+ action="added"
+ />,
+ );
+ expect(screen.getByText('settings.ghosts.market.sources.emptyWithEntries')).toBeTruthy();
+ });
+
+ it('does not blame submodules for an unreadable-only zero result', () => {
+ // 0 可用但只有 unreadable:是瞬时读取问题,submodule 提示会误导,只提示刷新重试。
+ render(
+ <MarketplaceDiscoveryNotice
+ summary={{ ...base, pluginCount: 0, skippedCount: 0, unreadableCount: 2 }}
+ action="refreshed"
+ />,
+ );
+ expect(screen.queryByText(/emptyWithEntries/)).toBeNull();
+ expect(
+ screen.getByText('settings.ghosts.market.sources.unreadableEntries:{"count":2}'),
+ ).toBeTruthy();
+ });
+});
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index eb6198bb16..9662672f6f 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -3307,6 +3307,9 @@
"empty": "No plugin entries in this marketplace",
"skippedEntries": "Skipped {{count}} invalid plugin entries",
"unreadableEntries": "{{count}} plugin entries are temporarily unreadable; refresh to retry",
+ "addedReceipt": "Added \"{{name}}\" with {{count}} plugins discovered",
+ "refreshedReceipt": "Refreshed \"{{name}}\" with {{count}} plugins discovered",
+ "emptyWithEntries": "The manifest lists entries but no usable plugins were discovered. A common cause is plugin directories being git submodules (their contents are not fetched) — ask the marketplace author to put plugin directories directly into the repository.",
"localBadge": "Local",
"defaultRef": "Default branch",
"neverSynced": "Never synced",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 21cbdd1dbd..1c48783023 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -3306,6 +3306,9 @@
"empty": "このマーケットにはプラグイン項目がありません",
"skippedEntries": "無効なプラグイン項目 {{count}} 件をスキップしました",
"unreadableEntries": "プラグイン項目 {{count}} 件を一時的に読み込めません。更新して再試行してください",
+ "addedReceipt": "「{{name}}」を追加し、プラグイン {{count}} 件を検出しました",
+ "refreshedReceipt": "「{{name}}」を更新し、プラグイン {{count}} 件を検出しました",
+ "emptyWithEntries": "マニフェストに項目はありますが、利用可能なプラグインは見つかりませんでした。よくある原因はプラグインディレクトリが git submodule になっていること(内容は取得されません)です。マーケットプレイス作者にプラグインディレクトリを直接リポジトリに入れるよう依頼してください。",
"localBadge": "ローカル",
"defaultRef": "デフォルトブランチ",
"neverSynced": "未同期",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 417a7ff886..1e7d252bcd 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -3306,6 +3306,9 @@
"empty": "이 마켓에는 플러그인 항목이 없습니다",
"skippedEntries": "잘못된 플러그인 항목 {{count}}개를 건너뛰었습니다",
"unreadableEntries": "플러그인 항목 {{count}}개를 일시적으로 읽을 수 없습니다. 새로고침하여 다시 시도하세요",
+ "addedReceipt": "\"{{name}}\"을(를) 추가했고 플러그인 {{count}}개를 발견했습니다",
+ "refreshedReceipt": "\"{{name}}\"을(를) 새로고침했고 플러그인 {{count}}개를 발견했습니다",
+ "emptyWithEntries": "매니페스트에 항목이 있지만 사용 가능한 플러그인을 찾지 못했습니다. 흔한 원인은 플러그인 디렉터리가 git submodule인 경우입니다(내용을 가져오지 않음). 마켓플레이스 작성자에게 플러그인 디렉터리를 저장소에 직접 넣도록 요청하세요.",
"localBadge": "로컬",
"defaultRef": "기본 브랜치",
"neverSynced": "동기화되지 않음",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 5f5059110c..aefa06b1a3 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -3306,6 +3306,9 @@
"empty": "市场清单中没有插件条目",
"skippedEntries": "已跳过 {{count}} 个无效插件条目",
"unreadableEntries": "{{count}} 个插件条目暂时无法读取,请刷新重试",
+ "addedReceipt": "已添加“{{name}}”,发现 {{count}} 个插件",
+ "refreshedReceipt": "已刷新“{{name}}”,发现 {{count}} 个插件",
+ "emptyWithEntries": "清单有条目但没有发现可用插件。常见原因是插件目录为 git submodule(内容不会被拉取)——请市场作者将插件目录直接放入仓库。",
"localBadge": "本地",
"defaultRef": "默认分支",
"neverSynced": "尚未同步",