Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(composer): pipe Finder metadata to plutil

贾湘君4746dbf46e56
diff --git a/apps/desktop/electron/main/composer-clipboard-directories.ts b/apps/desktop/electron/main/composer-clipboard-directories.ts
index 7b8849b7a..de6378bd5 100644
--- a/apps/desktop/electron/main/composer-clipboard-directories.ts
+++ b/apps/desktop/electron/main/composer-clipboard-directories.ts
@@ -14,6 +14,7 @@ async function execFileAsync(
command: string,
args: string[],
options: { timeout?: number; maxBuffer?: number; [key: string]: unknown },
+ input?: Buffer,
): Promise<Buffer> {
const child = execFile(command, args, options);
return new Promise<Buffer>((resolve, reject) => {
@@ -28,6 +29,7 @@ async function execFileAsync(
if (code === 0) resolve(stdout);
else reject(new Error("clipboard file list read failed"));
});
+ child.stdin?.end(input);
});
}
@@ -62,22 +64,12 @@ export async function nativeClipboardPaths(
const macList = platform === "darwin" ? read("NSFilenamesPboardType") : Buffer.alloc(0);
if (platform === "win32") paths = await readWindowsPaths();
else if (macList.length) {
- const child = execFile("/usr/bin/plutil", ["-convert", "json", "-o", "-", "--", "-"], {
- input: macList, maxBuffer: MAX_METADATA_BYTES, timeout: 10000,
- } as any);
const value: unknown = JSON.parse(
(
- await new Promise<Buffer>((resolve, reject) => {
- let buf = Buffer.alloc(0);
- child.stdout?.on("data", (chunk: Buffer) => {
- buf = Buffer.concat([buf, chunk]);
- });
- child.on("error", reject);
- child.on("close", (code) => {
- if (code === 0) resolve(buf);
- else reject(new Error("invalid clipboard file list"));
- });
- })
+ await execFileAsync("/usr/bin/plutil", ["-convert", "json", "-o", "-", "--", "-"], {
+ maxBuffer: MAX_METADATA_BYTES,
+ timeout: 10000,
+ }, macList)
).toString("utf8"),
);
if (!Array.isArray(value) || !value.every(path => typeof path === "string")) throw new Error("invalid clipboard file list");
diff --git a/apps/desktop/test/composer-clipboard-directories.test.mjs b/apps/desktop/test/composer-clipboard-directories.test.mjs
index 7decd765c..b58142404 100644
--- a/apps/desktop/test/composer-clipboard-directories.test.mjs
+++ b/apps/desktop/test/composer-clipboard-directories.test.mjs
@@ -71,6 +71,36 @@ test("an asynchronous Windows clipboard probe keeps the event loop responsive",
assert.ok(ticks >= 3, "the event loop must keep running while the clipboard probe is pending");
});
+test("macOS Finder metadata is piped to plutil asynchronously", async () => {
+ const plist = Buffer.from("synthetic Finder plist");
+ const paths = ["/tmp/first folder", "/tmp/second"];
+ const calls = [];
+ let stdinBytes;
+ const child = new EventEmitter();
+ child.stdout = new EventEmitter();
+ child.stdin = {
+ end(input) {
+ stdinBytes = Buffer.from(input);
+ setImmediate(() => {
+ child.stdout.emit("data", Buffer.from(JSON.stringify(paths)));
+ child.emit("close", 0);
+ });
+ },
+ };
+ const { nativeClipboardPaths: readPaths } = loadWithExecFile((command, args, options) => {
+ calls.push({ command, args, options });
+ return child;
+ });
+
+ assert.deepEqual(await readPaths(clipboard({ NSFilenamesPboardType: plist }), "darwin"), paths);
+ assert.deepEqual(stdinBytes, plist);
+ assert.equal(calls[0].command, "/usr/bin/plutil");
+ assert.deepEqual(calls[0].args, ["-convert", "json", "-o", "-", "--", "-"]);
+ assert.equal(calls[0].options.timeout, 10_000);
+ assert.equal(calls[0].options.maxBuffer, 1024 * 1024);
+ assert.equal("input" in calls[0].options, false);
+});
+
test("Windows PowerShell clipboard adapter reads stdout asynchronously with process bounds", async () => {
const paths = ["C:\\first folder", "D:\\中文"];
const calls = [];