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): 权限档变化时释放旧确认卡占用的排队位置,确认卡说明补充计划模式

fmfsaisai3f6f9330a610
diff --git a/apps/desktop/src/main/remote-agent/controller/service.ts b/apps/desktop/src/main/remote-agent/controller/service.ts
index ab0a72f701..b4e3bc40b1 100644
--- a/apps/desktop/src/main/remote-agent/controller/service.ts
+++ b/apps/desktop/src/main/remote-agent/controller/service.ts
@@ -84,7 +84,7 @@ const SHARED_PROVIDER_CREDENTIAL_NOTICE =
"This task uses a shared provider, so what the agent reads passes through the sharer's computer or another computer they arrange. "
+ 'This may involve credentials, so it needs your confirmation. '
+ 'Always allow for this session skips further shared-provider credential confirmations in this task. '
- + 'Changing its permission mode or quitting Cindy requires confirmation again.';
+ + 'Changing its permission mode or Plan mode, or quitting Cindy, requires confirmation again.';
function mcpTargets(extra: PiExtraSpawnConfig | null): Map<string, LocalMcpTarget> {
const targets = new Map<string, LocalMcpTarget>();
diff --git a/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts b/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts
index e51c891b2d..6599913e6a 100644
--- a/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts
+++ b/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts
@@ -1225,6 +1225,33 @@ describe('shared provider credentials', () => {
}
});
+ it('lets a new request ask right away after the permission mode changed under an open card', async () => {
+ const answers: Array<(result: ExecutorConfirmation) => void> = [];
+ const asked = vi.fn(() => new Promise<ExecutorConfirmation>((resolve) => { answers.push(resolve); }));
+ const { executor, gate } = sharedExecutor('full', asked);
+ const env: ExecutorAction = { kind: 'exec', command: 'cat .env', cwd: project };
+ const production: ExecutorAction = { kind: 'exec', command: 'cat .env.production', cwd: project };
+ const stale = executor.confirm(env);
+ let fresh: Promise<boolean> | undefined;
+ try {
+ executor.setGateMode('normal');
+ // 旧卡还没回答:切换权限档后的新请求不必等它。
+ fresh = executor.confirm(production);
+ await vi.waitFor(() => expect(asked).toHaveBeenCalledTimes(2));
+ expect(asked).toHaveBeenNthCalledWith(2, production);
+ // 旧卡之后再回答,不建立授权。
+ answers[0]('session');
+ expect(await stale).toBe(false);
+ expect(gate.needsCredentialConsent(production)).toBe(true);
+ answers[1](true);
+ expect(await fresh).toBe(true);
+ } finally {
+ await executor.close();
+ for (const answer of answers) answer(false);
+ await Promise.all([stale, fresh]);
+ }
+ });
+
it('does not queue a git command cancelled while it was being verified', async () => {
let finishCheck!: (safe: boolean) => void;
const gitCredentials = {
diff --git a/apps/desktop/src/main/remote-agent/executor/executor.ts b/apps/desktop/src/main/remote-agent/executor/executor.ts
index 21db6c453d..251c45aed5 100644
--- a/apps/desktop/src/main/remote-agent/executor/executor.ts
+++ b/apps/desktop/src/main/remote-agent/executor/executor.ts
@@ -126,6 +126,8 @@ export class RemoteExecutor {
private closed = false;
private permissionGeneration = 0;
private credentialConfirmationTail?: Promise<void>;
+ /** 当前占着确认排队位置的请求的放行函数。 */
+ private readonly credentialSlotReleases = new Set<() => void>();
private readonly unwatchCredentialGrant?: () => void;
constructor(private readonly opts: RemoteExecutorOptions) {
@@ -150,6 +152,7 @@ export class RemoteExecutor {
setGateMode(mode: ExecutorGateMode): void {
this.permissionGeneration += 1;
this.gate.setMode(mode);
+ this.releaseCredentialQueue();
this.opts.credentialGrant?.forget();
}
@@ -157,6 +160,15 @@ export class RemoteExecutor {
private revokeCredentialGrant(): void {
this.permissionGeneration += 1;
this.gate.setMode(this.gate.getMode());
+ this.releaseCredentialQueue();
+ }
+
+ /**
+ * 等待中的确认已作废(权限档变化或授权撤销):放开它们占着的排队位置,之后的请求不必等旧卡;
+ * 旧卡之后的回答仍按 generation 丢弃。
+ */
+ private releaseCredentialQueue(): void {
+ for (const release of [...this.credentialSlotReleases]) release();
}
/** 本机用户在确认卡上允许了一个操作。 */
@@ -196,6 +208,7 @@ export class RemoteExecutor {
const settled = new Promise<void>((resolve) => { settle = resolve; });
const slot = previous ? previous.then(() => settled) : settled;
this.credentialConfirmationTail = slot;
+ this.credentialSlotReleases.add(settle);
// 自己的请求取消后立即让出:还在排队就不再等(后面的请求仍等前一张卡);
// 卡已弹出就不再挡住后面的请求,这张卡之后的回答会被丢弃。
let onAbort: (() => void) | undefined;
@@ -221,6 +234,7 @@ export class RemoteExecutor {
return true;
} finally {
if (onAbort) signal?.removeEventListener('abort', onAbort);
+ this.credentialSlotReleases.delete(settle);
settle();
void slot.then(() => {
if (this.credentialConfirmationTail === slot) this.credentialConfirmationTail = undefined;
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index a282a728dd..6bc3cb494b 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -10210,7 +10210,7 @@
"saveEdit": "Save Text"
},
"sharedProviderCredential": {
- "description": "This task uses a shared provider, so what the Agent reads passes through the sharer’s computer or another computer they arrange. This step may involve credentials (such as keys or .env) and needs your confirmation. “Always allow for this session” skips further shared-provider credential confirmations in this task. Changing its permission mode or quitting Cindy requires confirmation again."
+ "description": "This task uses a shared provider, so what the Agent reads passes through the sharer’s computer or another computer they arrange. This step may involve credentials (such as keys or .env) and needs your confirmation. “Always allow for this session” skips further shared-provider credential confirmations in this task. Changing its permission mode or Plan mode, or quitting Cindy, requires confirmation again."
},
"mediaDownload": {
"title": "Download the generated media?",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 64999c5184..47773048c9 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -10173,7 +10173,7 @@
"saveEdit": "テキストを保存"
},
"sharedProviderCredential": {
- "description": "このタスクは共有されたプロバイダーを使うため、Agent が読み取った内容は共有元または共有元が手配したパソコンを経由します。この操作は認証情報(鍵や .env など)に関わる可能性があり、確認が必要です。「このセッションで常に許可」を選ぶと、このタスクで共有に伴う認証情報の確認を繰り返しません。権限モードを変更するか Cindy を終了すると、再度確認します。"
+ "description": "このタスクは共有されたプロバイダーを使うため、Agent が読み取った内容は共有元または共有元が手配したパソコンを経由します。この操作は認証情報(鍵や .env など)に関わる可能性があり、確認が必要です。「このセッションで常に許可」を選ぶと、このタスクで共有に伴う認証情報の確認を繰り返しません。権限モードやプランモードを変更するか Cindy を終了すると、再度確認します。"
},
"mediaDownload": {
"title": "生成されたメディアをダウンロードしますか?",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 407b22a756..8cde7a3267 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -10173,7 +10173,7 @@
"saveEdit": "텍스트 저장"
},
"sharedProviderCredential": {
- "description": "이 작업은 공유받은 제공자를 사용하므로 Agent가 읽은 내용은 공유한 사람의 컴퓨터 또는 그 사람이 지정한 컴퓨터를 거칩니다. 이 단계는 자격 증명(키, .env 등)과 관련될 수 있어 확인이 필요합니다. ‘이 세션에서 항상 허용’을 선택하면 이 작업에서 공유에 따른 자격 증명 확인을 반복하지 않습니다. 권한 모드를 변경하거나 Cindy를 종료하면 다시 확인합니다."
+ "description": "이 작업은 공유받은 제공자를 사용하므로 Agent가 읽은 내용은 공유한 사람의 컴퓨터 또는 그 사람이 지정한 컴퓨터를 거칩니다. 이 단계는 자격 증명(키, .env 등)과 관련될 수 있어 확인이 필요합니다. ‘이 세션에서 항상 허용’을 선택하면 이 작업에서 공유에 따른 자격 증명 확인을 반복하지 않습니다. 권한 모드나 계획 모드를 변경하거나 Cindy를 종료하면 다시 확인합니다."
},
"mediaDownload": {
"title": "생성된 미디어를 다운로드할까요?",
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 4217f9be14..8ff18a0f80 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -10173,7 +10173,7 @@
"saveEdit": "保存文本"
},
"sharedProviderCredential": {
- "description": "这个任务用的是分享来的供应商,Agent 读到的内容会经过分享者或其安排的电脑。这一步可能涉及凭证(如密钥、.env),需要你确认后才继续。选择「本任务总是允许」后,本任务后续凭证操作不再额外确认;切换权限档或退出 Cindy 后需再次确认。"
+ "description": "这个任务用的是分享来的供应商,Agent 读到的内容会经过分享者或其安排的电脑。这一步可能涉及凭证(如密钥、.env),需要你确认后才继续。选择「本任务总是允许」后,本任务后续凭证操作不再额外确认;切换权限档、计划模式或退出 Cindy 后需再次确认。"
},
"mediaDownload": {
"title": "允许下载生成的媒体?",
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 755b754a98..00cf1445bf 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -10173,7 +10173,7 @@
"saveEdit": "儲存文字"
},
"sharedProviderCredential": {
- "description": "這個任務用的是分享來的供應商,Agent 讀到的內容會經過分享者或其安排的電腦。這一步可能涉及憑證(如金鑰、.env),需要你確認後才繼續。選擇「本任務總是允許」後,本任務後續憑證操作不再額外確認;切換權限模式或結束 Cindy 後需再次確認。"
+ "description": "這個任務用的是分享來的供應商,Agent 讀到的內容會經過分享者或其安排的電腦。這一步可能涉及憑證(如金鑰、.env),需要你確認後才繼續。選擇「本任務總是允許」後,本任務後續憑證操作不再額外確認;切換權限模式、計畫模式或結束 Cindy 後需再次確認。"
},
"mediaDownload": {
"title": "允許下載產生的媒體?",