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(desktop): explain unauthorized broker installs

fmfsaisai06587f730161
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostTokenBrokerInstallError.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostTokenBrokerInstallError.test.ts
new file mode 100644
index 0000000000..0bce7c443d
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostTokenBrokerInstallError.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from 'vitest';
+
+import { ghostTokenBrokerInstallError } from '../ghostTokenBrokerInstallError.js';
+
+describe('ghostTokenBrokerInstallError', () => {
+ it('keeps manual install and unknown runtime facts on distinct actionable codes', () => {
+ expect(ghostTokenBrokerInstallError('manual')).toMatchObject({
+ code: 'GHOST_BROKER_MANUAL_INSTALL_NOT_AUTHORIZED',
+ reason: expect.stringContaining('手动装入'),
+ });
+ expect(ghostTokenBrokerInstallError('agent-forge')).toMatchObject({
+ code: 'GHOST_BROKER_NOT_AUTHORIZED',
+ reason: expect.stringContaining('组织身份'),
+ });
+ expect(ghostTokenBrokerInstallError()).toMatchObject({
+ code: 'GHOST_BROKER_NOT_AUTHORIZED',
+ });
+ // Distinct literal codes prevent Renderer copy from guessing the reason
+ // from Main's localized message or remapping all GHOST_FILE_INVALID errors.
+ expect(ghostTokenBrokerInstallError('manual').code).not.toBe(
+ ghostTokenBrokerInstallError().code,
+ );
+ });
+});
diff --git a/apps/desktop/src/main/cindy-brain/ghostTokenBrokerInstallError.ts b/apps/desktop/src/main/cindy-brain/ghostTokenBrokerInstallError.ts
new file mode 100644
index 0000000000..5274ff7ae0
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/ghostTokenBrokerInstallError.ts
@@ -0,0 +1,25 @@
+import type { IpcErrorCode } from '../../shared/ipc-errors.js';
+
+export interface GhostTokenBrokerInstallError {
+ code: Extract<
+ IpcErrorCode,
+ 'GHOST_BROKER_MANUAL_INSTALL_NOT_AUTHORIZED' | 'GHOST_BROKER_NOT_AUTHORIZED'
+ >;
+ reason: string;
+}
+
+/** Copy classification only; authorization remains owned by the caller. */
+export function ghostTokenBrokerInstallError(
+ installOrigin?: 'manual' | 'agent-forge',
+): GhostTokenBrokerInstallError {
+ return installOrigin === 'manual'
+ ? {
+ code: 'GHOST_BROKER_MANUAL_INSTALL_NOT_AUTHORIZED',
+ reason:
+ '手动装入的 .cindy 不能使用授权 broker;请改从组织插件市场安装,或让插件作者在组织身份下使用 ghost_forge_pack 构建',
+ }
+ : {
+ code: 'GHOST_BROKER_NOT_AUTHORIZED',
+ reason: '当前安装来源或组织身份无权使用授权 broker',
+ };
+}
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index 19734d3627..36fe166931 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -303,6 +303,7 @@ import {
type GhostFirstPartyFactsPurpose,
} from './ghostFirstPartyFacts.js';
import { authorizeGhostTokenBroker } from './ghostFirstPartyPrivilege.js';
+import { ghostTokenBrokerInstallError } from './ghostTokenBrokerInstallError.js';
import { ConnectionTokenProvider, type IssuedConnectionToken } from './connectionTokenProvider.js';
import { GhostFsSlot } from './fsSlot.js';
import { GhostLibrarySlot } from './librarySlot.js';
@@ -5269,13 +5270,10 @@ function rejectUnauthorizedTokenBroker(
);
if (!brokered) return;
if (isGhostTokenBrokerAuthorized(manifest.id, 'install', overrides)) return;
- const reason =
- overrides?.installOrigin === 'manual'
- ? '手动装入的 .cindy 不能使用授权 broker;请改从组织插件市场安装,或让插件作者在组织身份下使用 ghost forge 构建'
- : '当前安装来源或组织身份无权使用授权 broker';
+ const authorizationError = ghostTokenBrokerInstallError(overrides?.installOrigin);
throwIpcError(
- 'GHOST_FILE_INVALID',
- `id "${manifest.id}" 声明了 oauth.tokenBroker——${reason}`,
+ authorizationError.code,
+ `id "${manifest.id}" 声明了 oauth.tokenBroker——${authorizationError.reason}`,
);
}
diff --git a/apps/desktop/src/renderer/cindy-brain/__tests__/installErrorKey.test.ts b/apps/desktop/src/renderer/cindy-brain/__tests__/installErrorKey.test.ts
index 3583449769..c49626c629 100644
--- a/apps/desktop/src/renderer/cindy-brain/__tests__/installErrorKey.test.ts
+++ b/apps/desktop/src/renderer/cindy-brain/__tests__/installErrorKey.test.ts
@@ -12,6 +12,32 @@ describe('ghostInstallErrorKey', () => {
expect(ghostInstallErrorKey('GHOST_FILE_INVALID')).toBe('settings.ghosts.errors.fileInvalid');
});
+ it('maps Broker authorization failures without changing generic invalid-file copy', () => {
+ expect(ghostInstallErrorKey('GHOST_BROKER_MANUAL_INSTALL_NOT_AUTHORIZED')).toBe(
+ 'settings.ghosts.errors.brokerManualInstallNotAuthorized',
+ );
+ expect(ghostInstallErrorKey('GHOST_BROKER_NOT_AUTHORIZED')).toBe(
+ 'settings.ghosts.errors.brokerNotAuthorized',
+ );
+ // This control kills a broad remap that turns every malformed .cindy error
+ // into the Broker guidance.
+ expect(ghostInstallErrorKey('GHOST_FILE_INVALID')).toBe('settings.ghosts.errors.fileInvalid');
+ });
+
+ it.each(['zh-CN', 'en', 'ja', 'ko', 'zh-TW'])(
+ 'keeps both Broker authorization reasons actionable in %s',
+ (locale) => {
+ for (const code of [
+ 'GHOST_BROKER_MANUAL_INSTALL_NOT_AUTHORIZED',
+ 'GHOST_BROKER_NOT_AUTHORIZED',
+ ]) {
+ const message = i18n.getFixedT(locale)(ghostInstallErrorKey(code)).toString();
+ expect(message).toContain('ghost_forge_pack');
+ expect(message).not.toBe(i18n.getFixedT(locale)('settings.ghosts.errors.fileInvalid'));
+ }
+ },
+ );
+
it.each(['zh-CN', 'en', 'ja', 'ko', 'zh-TW'])(
'renders the complete reserved-prefix authority in the %s install error',
(locale) => {
diff --git a/apps/desktop/src/renderer/cindy-brain/installErrorKey.ts b/apps/desktop/src/renderer/cindy-brain/installErrorKey.ts
index cf4d9b2729..80d241e88e 100644
--- a/apps/desktop/src/renderer/cindy-brain/installErrorKey.ts
+++ b/apps/desktop/src/renderer/cindy-brain/installErrorKey.ts
@@ -15,6 +15,10 @@ export function ghostInstallErrorKey(code: string | undefined): string {
return 'settings.ghosts.errors.commandConflict';
case 'GHOST_ID_RESERVED':
return 'settings.ghosts.errors.idReserved';
+ case 'GHOST_BROKER_MANUAL_INSTALL_NOT_AUTHORIZED':
+ return 'settings.ghosts.errors.brokerManualInstallNotAuthorized';
+ case 'GHOST_BROKER_NOT_AUTHORIZED':
+ return 'settings.ghosts.errors.brokerNotAuthorized';
case 'NOT_FOUND':
return 'settings.ghosts.errors.sourceMissing';
// 批准状态相关的前置条件失败在这条链路上只有一种下一步动作:重新确认权限。
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 9384f40cd8..5154b8d29c 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -4438,6 +4438,8 @@
"approvalRequired": "This plugin's permissions must be reviewed again before continuing.",
"commandConflict": "Its command conflicts with an installed plugin. Uninstall the other one or rename the command.",
"idReserved": "{{reservedGhostIdPrefixes}} are reserved for official plugins and can’t be installed by dragging in a package, choosing a file, transferring from ghost_forge_pack, or using a custom plugin marketplace. Install the corresponding official plugin from the Cindy plugin market",
+ "brokerManualInstallNotAuthorized": "A manually installed .cindy package is not authorized to use the authorization broker. Install it from your organization’s plugin market, or ask the author to build it with ghost_forge_pack while signed in to the organization.",
+ "brokerNotAuthorized": "This installation source or organization identity is not authorized to use the authorization broker. Install it from your organization’s plugin market, or ask the author to build it with ghost_forge_pack while signed in to the organization.",
"sourceMissing": "The selected file could not be found",
"generic": "Operation failed. Please try again.",
"updateIdMismatch": "The selected file is plugin \"{{id}}\", which does not match this plugin \"{{expected}}\""
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index eb9f0257f7..cfae2e83ea 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -4437,6 +4437,8 @@
"approvalRequired": "続けるには、このプラグインの権限を再確認する必要があります",
"commandConflict": "コマンドがインストール済みのプラグインと重複しています。先に相手をアンインストールするか、コマンド名を変更してください。",
"idReserved": "{{reservedGhostIdPrefixes}} は公式プラグイン用の予約済みプレフィックスです。ドラッグ、ファイル選択、ghost_forge_pack からの受け渡し、カスタムプラグインマーケットからはインストールできません。対応する公式プラグインは Cindy プラグインマーケットからインストールしてください",
+ "brokerManualInstallNotAuthorized": "手動でインストールした .cindy は認可 broker を使用できません。組織のプラグインマーケットからインストールするか、作者に組織アカウントで ghost_forge_pack を使ってビルドするよう依頼してください。",
+ "brokerNotAuthorized": "現在のインストール元または組織アカウントには、認可 broker を使用する権限がありません。組織のプラグインマーケットからインストールするか、作者に組織アカウントで ghost_forge_pack を使ってビルドするよう依頼してください。",
"sourceMissing": "選択したファイルが見つかりません",
"generic": "操作に失敗しました。もう一度お試しください",
"updateIdMismatch": "選択したファイルはプラグイン「{{id}}」で、このプラグイン「{{expected}}」と一致しません"
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 80c6332266..b210dd0b10 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -4437,6 +4437,8 @@
"approvalRequired": "계속하려면 이 플러그인의 권한을 다시 확인해야 합니다",
"commandConflict": "명령어가 설치된 플러그인과 충돌합니다. 먼저 상대를 제거하거나 명령어 이름을 변경하세요.",
"idReserved": "{{reservedGhostIdPrefixes}}는 공식 플러그인용 예약 접두사입니다. 끌어다 놓기, 파일 선택, ghost_forge_pack 전달 또는 사용자 지정 플러그인 마켓으로는 설치할 수 없습니다. 해당 공식 플러그인은 Cindy 플러그인 마켓에서 설치하세요",
+ "brokerManualInstallNotAuthorized": "수동으로 설치한 .cindy는 인증 broker를 사용할 수 없습니다. 조직 플러그인 마켓에서 설치하거나, 작성자에게 조직 계정으로 ghost_forge_pack을 사용해 빌드하도록 요청하세요.",
+ "brokerNotAuthorized": "현재 설치 출처 또는 조직 계정에는 인증 broker 사용 권한이 없습니다. 조직 플러그인 마켓에서 설치하거나, 작성자에게 조직 계정으로 ghost_forge_pack을 사용해 빌드하도록 요청하세요.",
"sourceMissing": "선택한 파일을 찾을 수 없습니다",
"generic": "작업에 실패했습니다. 다시 시도해 주세요",
"updateIdMismatch": "선택한 파일은 플러그인 \"{{id}}\"로, 현재 플러그인 \"{{expected}}\"와 일치하지 않습니다"
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 ddd207ac8a..b698034c1b 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -4437,6 +4437,8 @@
"approvalRequired": "需要重新确认这个插件的权限后才能继续",
"commandConflict": "它的指令和已装插件撞名了,先卸载占用方或让作者改名",
"idReserved": "{{reservedGhostIdPrefixes}} 是官方插件保留前缀,不能通过拖入、选择文件、ghost_forge_pack 转交或自定义插件市场装入;请从 Cindy 插件市场安装对应的官方插件",
+ "brokerManualInstallNotAuthorized": "手动装入的 .cindy 不能使用授权 broker;请改从组织插件市场安装,或让作者在组织身份下使用 ghost_forge_pack 构建",
+ "brokerNotAuthorized": "当前安装来源或组织身份无权使用授权 broker;请从组织插件市场安装,或让作者在组织身份下使用 ghost_forge_pack 构建",
"sourceMissing": "找不到所选文件",
"generic": "操作失败,请稍后重试",
"updateIdMismatch": "所选文件是插件「{{id}}」,与当前插件「{{expected}}」不一致"
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 8d99f9c257..4a50e5a222 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -4437,6 +4437,8 @@
"approvalRequired": "繼續前需要重新確認這個插件的權限",
"commandConflict": "它的指令和已裝插件撞名了,先解除安裝佔用方或讓作者改名",
"idReserved": "{{reservedGhostIdPrefixes}} 是官方插件保留字首,無法透過拖入、選取檔案、ghost_forge_pack 轉交或自訂插件市場安裝;請從 Cindy 插件市場安裝對應的官方插件",
+ "brokerManualInstallNotAuthorized": "手動安裝的 .cindy 無法使用授權 broker;請改從組織插件市場安裝,或請作者以組織身分使用 ghost_forge_pack 建置",
+ "brokerNotAuthorized": "目前的安裝來源或組織身分無權使用授權 broker;請從組織插件市場安裝,或請作者以組織身分使用 ghost_forge_pack 建置",
"sourceMissing": "找不到所選檔案",
"generic": "操作失敗,請稍後重試",
"updateIdMismatch": "所選檔案是插件「{{id}}」,與當前插件「{{expected}}」不一致"
diff --git a/apps/desktop/src/shared/ipc-errors.ts b/apps/desktop/src/shared/ipc-errors.ts
index 616894b333..0251856b73 100644
--- a/apps/desktop/src/shared/ipc-errors.ts
+++ b/apps/desktop/src/shared/ipc-errors.ts
@@ -179,6 +179,8 @@ export type IpcErrorCode =
| 'GHOST_HOST_UNSUPPORTED' // 插件包合法,但当前 Cindy 不认识其 schema / capability slot
| 'GHOST_COMMAND_CONFLICT' // 显式指令与已装意识撞名(装入拒绝)
| 'GHOST_ID_RESERVED' // id 属 shared/ghost.ts 登记的官方保留前缀,用户通道拒装(防抢注蹭凭证别名)
+ | 'GHOST_BROKER_MANUAL_INSTALL_NOT_AUTHORIZED' // 手动 .cindy 来源无权使用授权 broker
+ | 'GHOST_BROKER_NOT_AUTHORIZED' // 当前来源或组织身份无权使用授权 broker
// 自定义插件市场源(Git / 本地文件夹)
| 'MARKET_SOURCE_INVALID' // 来源格式非法 / 本地路径不是目录 / 参数组合不允许
| 'MARKET_GIT_UNAVAILABLE' // 未安装 Git 或版本 < 2.25(稀疏检出下限)
@@ -377,6 +379,8 @@ const IPC_ERROR_CODES: ReadonlySet<IpcErrorCode> = new Set<IpcErrorCode>([
'GHOST_HOST_UNSUPPORTED',
'GHOST_COMMAND_CONFLICT',
'GHOST_ID_RESERVED',
+ 'GHOST_BROKER_MANUAL_INSTALL_NOT_AUTHORIZED',
+ 'GHOST_BROKER_NOT_AUTHORIZED',
'MARKET_SOURCE_INVALID',
'MARKET_GIT_UNAVAILABLE',
'MARKET_CLONE_AUTH_FAILED',