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(browser): 临时上传副本复用任务成果目录

Dashcb8b6ea4ae43
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/rsb-webview-upload-policy.test.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/rsb-webview-upload-policy.test.ts
index f983e58e0b..6a62b5dec7 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/rsb-webview-upload-policy.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/rsb-webview-upload-policy.test.ts
@@ -3,6 +3,7 @@ import os from 'node:os';
import path from 'node:path';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { withRecipeHost, recipeDiagnosticPath } from '../../../../../../../packages/opencli-vendor/cindy/host.js';
import { resolveUploadFiles, resolveRecipeOutputPath } from '../rsb-webview-upload-policy.js';
@@ -23,6 +24,20 @@ afterEach(async () => {
});
describe('resolveUploadFiles', () => {
+ // #6826: sanitized temporary upload copies must stay within the invoking
+ // browser task's existing artifact root. Minimum input: one temporary PNG;
+ // the earlier output tests had no subsequent native-upload policy check.
+ it('accepts own temporary upload copies without granting another task access', async () => {
+ let file = '';
+ await withRecipeHost(undefined, async () => {
+ file = recipeDiagnosticPath('upload-copy.png');
+ await fs.writeFile(file, 'test-only-image');
+ await expect(resolveUploadFiles([file], [allowedRoot])).resolves.toEqual([await fs.realpath(file)]);
+ await expect(resolveUploadFiles([file], [outsideRoot])).rejects.toThrow('inside the current session directory');
+ }, { read: () => Buffer.alloc(0), open: () => -1, temporaryRoot: allowedRoot });
+ await expect(fs.access(path.dirname(file))).rejects.toThrow();
+ });
+
// #6826: output paths need not exist yet. Existing upload-only cases cannot
// detect writes via missing children, symlink parents or absent SSH roots.
// Real host resolver, unit tier; smallest failure is one outside output path.
diff --git a/apps/desktop/src/main/mcp-integrations/browser.ts b/apps/desktop/src/main/mcp-integrations/browser.ts
index cfb8e03aa6..7c4bc82b46 100644
--- a/apps/desktop/src/main/mcp-integrations/browser.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser.ts
@@ -485,6 +485,9 @@ export function getBrowserMcpDeps(): {
read: (file) => fs.readFileSync(resolve(file)),
open: (file) => fs.openSync(resolve(file), 'r'),
directory: sessionRoots[0],
+ // Temporary upload copies belong to this task's existing browser artifact
+ // root so the ordinary upload policy accepts them without extra grants.
+ temporaryRoot: sessionId ? roots[0] : undefined,
output: (file: string) => resolveRecipeOutputPath(file, sessionRoots),
};
},
diff --git a/packages/opencli-vendor/cindy/host.ts b/packages/opencli-vendor/cindy/host.ts
index 35822ce95a..bffcbdb7d9 100644
--- a/packages/opencli-vendor/cindy/host.ts
+++ b/packages/opencli-vendor/cindy/host.ts
@@ -1,12 +1,15 @@
import { AsyncLocalStorage } from "node:async_hooks";
-import { readFileSync, mkdtempSync, rmSync, openSync, closeSync } from "node:fs";
+import { readFileSync, mkdirSync, mkdtempSync, rmSync, openSync, closeSync } from "node:fs";
import { tmpdir } from 'node:os';
import { join, resolve, relative, isAbsolute, basename } from 'node:path';
/** Lazy allocation: importing the catalog never touches the filesystem. */
export function recipeTemporaryDirectory(): string {
const host = activeHost();
- return host.temporaryDirectory ??= mkdtempSync(join(tmpdir(), 'cindy-recipe-'));
+ if (host.temporaryDirectory) return host.temporaryDirectory;
+ const parent = host.files?.temporaryRoot ?? tmpdir();
+ mkdirSync(parent, { recursive: true });
+ return host.temporaryDirectory = mkdtempSync(join(parent, 'cindy-recipe-'));
}
export function recipeDiagnosticPath(name: string): string {
@@ -22,6 +25,7 @@ export interface RecipeFiles {
read(file: string): Buffer;
open(file: string): number;
directory?: string;
+ temporaryRoot?: string;
output?(file: string): string;
}