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(pi): harden auto-review read-only roots and remote pi worker preflight

Chriscacd1cf05202
diff --git a/apps/desktop/src/main/maker-host/__tests__/autoPermissionReviewer.test.ts b/apps/desktop/src/main/maker-host/__tests__/autoPermissionReviewer.test.ts
index d065da8f6c..d41caa0538 100644
--- a/apps/desktop/src/main/maker-host/__tests__/autoPermissionReviewer.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/autoPermissionReviewer.test.ts
@@ -40,6 +40,19 @@ describe('buildAutoPermissionReviewPrompt', () => {
expect(prompt).not.toContain('current-model');
});
+ it('separates the writable workspace root from read-only reference roots', () => {
+ // Extra Dirs 是只读引用目录:prompt 拍平成一个 workspaceRoots 数组会让
+ // 「workspace edits 倾向 allow」把写入只读目录的灰区命令一并放行(codex-connector 报)。
+ const prompt = buildAutoPermissionReviewPrompt(request({
+ workspaceRoots: ['/repo', '/extra-docs'],
+ }));
+
+ expect(prompt).toContain('"workspaceRoot":"/repo"');
+ expect(prompt).toContain('"readOnlyReferenceRoots":["/extra-docs"]');
+ expect(prompt).toContain('never allow an action that writes, deletes, or modifies anything inside them');
+ expect(prompt).toContain('edits inside workspaceRoot');
+ });
+
it('delimits the action as untrusted data so command text cannot rewrite the policy', () => {
const prompt = buildAutoPermissionReviewPrompt(request({
action: {
diff --git a/apps/desktop/src/main/maker-host/auto-permission-reviewer.ts b/apps/desktop/src/main/maker-host/auto-permission-reviewer.ts
index b98e6d1b4e..a88a403fc4 100644
--- a/apps/desktop/src/main/maker-host/auto-permission-reviewer.ts
+++ b/apps/desktop/src/main/maker-host/auto-permission-reviewer.ts
@@ -53,11 +53,16 @@ function serializeUntrustedPayload(value: unknown): string {
*/
export function buildAutoPermissionReviewPrompt(request: AutoReviewRequest): string {
assertReviewableActionSize(request.action);
+ // workspaceRoots 位置语义(与 maker-core reviewAction 同契约):首元素是唯一可写的
+ // 工作目录,其余是只读引用目录(additionalDirectories)。prompt 必须保留这一区分,
+ // 否则「workspace edits 倾向 allow」会把写只读引用目录的灰区命令一并放行。
+ const [workspaceRoot, ...referenceRoots] = request.workspaceRoots;
const payload = {
userIntent: compactText(request.userIntent, MAX_USER_INTENT_CHARS),
action: request.action,
- workspaceRoots: request.workspaceRoots
- .slice(0, MAX_WORKSPACE_ROOTS)
+ workspaceRoot: compactText(workspaceRoot ?? '', MAX_WORKSPACE_ROOT_CHARS),
+ readOnlyReferenceRoots: referenceRoots
+ .slice(0, MAX_WORKSPACE_ROOTS - 1)
.map((root) => compactText(root, MAX_WORKSPACE_ROOT_CHARS)),
platform: request.platform,
};
@@ -70,10 +75,11 @@ export function buildAutoPermissionReviewPrompt(request: AutoReviewRequest): str
'{"verdict":"allow|block|ask","reason":"short reason"}',
'',
'Decision policy:',
- '- allow: routine, reversible development work aligned with the current user intent, especially normal reads, tests, lint, builds, package commands, workspace edits, ordinary HTTP fetches, and normal git operations.',
+ '- allow: routine, reversible development work aligned with the current user intent, especially normal reads, tests, lint, builds, package commands, edits inside workspaceRoot, ordinary HTTP fetches, and normal git operations.',
'- block: the action is ambiguous or risky but the agent can choose a safer alternative. Blocking is silent to the user; give the main agent a useful short reason.',
'- ask: only a genuinely high-impact consent boundary: credentials or data exfiltration, privilege/system-security changes, broad irreversible destruction, production deployment/IAM/financial action, external communication with real-world effect, or force-pushing a protected branch.',
- '- Prefer allow over block for ordinary workspace-scoped coding. Prefer block over ask whenever a safer retry can avoid interrupting the user.',
+ '- readOnlyReferenceRoots are read-only reference context: reading them is routine, but never allow an action that writes, deletes, or modifies anything inside them — block it so the agent keeps its changes inside workspaceRoot.',
+ '- Prefer allow over block for ordinary coding scoped to workspaceRoot. Prefer block over ask whenever a safer retry can avoid interrupting the user.',
'',
'<review_input>',
serializeUntrustedPayload(payload),
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
index d9e55cf9ff..069df47a04 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
@@ -1744,6 +1744,32 @@ describe('SSH remote worker model/provider compatibility gate (R23 P2)', () => {
}),
).resolves.toMatchObject({ ok: true });
});
+
+ it('rejects Pi workers for a remote lead before bootstrap (pi sessions are local-only)', async () => {
+ // codex-connector 回归:PiAgent.startSession 对 remoteHostId 一律 NotSupportedError,
+ // 不在 preflight 拒绝会让远程 Lead + Pi 组合在 bootstrap 期落成笼统 INTERNAL。
+ const { service, deps } = createDeps({
+ getLeadSessionRow: vi.fn(async () => remoteLeadRow),
+ getProviderRoutingContext: vi.fn(async () => providerRoutingContext({
+ 'claude-code': [],
+ codex: [{ id: 'xd', name: 'XD Gateway', models: ['gpt-5.5'] }],
+ pi: [{ id: 'xd', name: 'XD Gateway', models: ['claude-sonnet-4-6'] }],
+ })),
+ });
+ await expect(
+ service.createWorker({
+ leadSessionId: 'lead-1',
+ role: 'developer',
+ agent: 'pi',
+ label: 'pi-dev',
+ }),
+ ).resolves.toMatchObject({
+ ok: false,
+ errorCode: 'INVALID_PARAMS',
+ message: expect.stringContaining('local-only'),
+ });
+ expect(deps.bootstrapSession).not.toHaveBeenCalled();
+ });
});
it('rejects chat-bridged providers resolved through the default route (no explicit providerId)', async () => {
diff --git a/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts b/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts
index 9b126d347f..56049dca42 100644
--- a/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts
+++ b/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts
@@ -527,6 +527,19 @@ export function createOrcaWorkerCreationService(deps: OrcaWorkerCreationDeps): O
return { ok: false, errorCode: 'NOT_FOUND', message: `lead session ${params.leadSessionId} not found` };
}
+ // Pi 尚无远程 runtime:PiAgent.startSession 对 remoteHostId 一律 NotSupportedError,
+ // 远端 ensure 又对 pi 跳过,SSH 远程 Lead + Pi worker 必然在 bootstrap 期被包成笼统
+ // INTERNAL —— 在 preflight 就以可操作信息拒绝(codex-connector 报)。lead 侧的
+ // capabilities 层已拒 Pi 远程会话,此闸补上 worker 创建(UI popover / MCP / 批量)路径。
+ if (lead.remoteHostId && params.agent === 'pi') {
+ return {
+ ok: false,
+ errorCode: 'INVALID_PARAMS',
+ message:
+ 'Pi workers are not available for SSH remote leads: pi sessions are local-only for now — pick Claude Code or Codex for this worker',
+ };
+ }
+
const defaults = deps.getWorkerDefaults(params.agent);
// 标准面板显式选定的来源(非空 string)直接生效,由下方精确 preflight 把关「已连接且
// 提供该模型」;空串/null/undefined 一律按未显式处理(与 IPC 边界同口径,service 作为
diff --git a/packages/maker-core/src/agents/shared/auto-review-decision.ts b/packages/maker-core/src/agents/shared/auto-review-decision.ts
index 33074d4461..dba73c3bde 100644
--- a/packages/maker-core/src/agents/shared/auto-review-decision.ts
+++ b/packages/maker-core/src/agents/shared/auto-review-decision.ts
@@ -20,6 +20,11 @@ export interface AutoReviewRequest {
model: string;
userIntent: string;
action: ReviewableAction;
+ /**
+ * 位置语义(reviewAction 同契约):`[0]` 是唯一可写的工作目录,其余是只读引用目录
+ * (additionalDirectories)。所有 agent 一律传 `[workingDir, ...extraDirs]`;host 侧
+ * reviewer prompt 依赖该顺序区分可写/只读,不得打乱或拍平。
+ */
workspaceRoots: string[];
platform: NodeJS.Platform;
}
diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.ts
index 8271498e26..645b82f572 100644
--- a/packages/maker-core/src/agents/shared/auto-review.ts
+++ b/packages/maker-core/src/agents/shared/auto-review.ts
@@ -65,7 +65,8 @@ export type ReviewableAction =
/**
* 核心裁决。纯函数、确定性、无副作用(不触文件系统 —— 探文件存在性会变侧信道,且对远端
- * 路径不可行;workspaceRoots 只做字符串前缀判定)。workspaceRoots = cwd + 额外可写目录,绝对路径。
+ * 路径不可行;workspaceRoots 只做字符串前缀判定)。workspaceRoots = cwd + 额外**只读引用**
+ * 目录,绝对路径;仅首元素可写(见下方 file-write 分支),读边界取整个数组。
*/
export function reviewAction(
action: ReviewableAction,