Skip to content

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

fix(host-runtime): preserve UTF-8 filenames in workspace index (#1914)

FuYukiH605d413fc6d0
diff --git a/apps/desktop/test/composer-deep-file-search-user-path.test.mjs b/apps/desktop/test/composer-deep-file-search-user-path.test.mjs
index 9aa64680b..0f48b018e 100644
--- a/apps/desktop/test/composer-deep-file-search-user-path.test.mjs
+++ b/apps/desktop/test/composer-deep-file-search-user-path.test.mjs
@@ -51,6 +51,7 @@ const SAVE = "Assets/_Game/Scripts/Systems/Save/SaveSlots.cs";
const STALE = "Assets/Stale/SaveFeature.cs";
// Short enough to rank inside the bare @ menu if a searched row leaked into it.
const SHORT = "a.cs";
+const UNICODE = "src/café-竞赛-🚀.ts";
// The shallowest 8000 entries of a large tree; the deep scripts are not among them.
const shallow = Array.from({ length: 8000 }, (_, index) => ({
path: "Assets/Art/Group" + Math.floor(index / 300) + "/asset_" + index + ".png",
@@ -173,9 +174,15 @@ window.deepFileSearchProbe = async () => {
await settle();
check(noteShown(), "a failed search must keep the truncation note");
- fileIndex = { entries: [{ path: "README.md", kind: "file" }], truncated: false };
+ fileIndex = { entries: ["README.md", UNICODE].map((path) => ({ path, kind: "file" })), truncated: false };
useAppStore.setState({ workspace: { path: "/small", name: "small" } });
await type("");
+ await type("@竞赛");
+ await until(() => rows().includes(UNICODE), "the Unicode file name was not preserved in the menu");
+ editor().dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
+ await settle();
+ check(draft.fileReferencesRef.current.some((reference) => reference.path === UNICODE),
+ "accepting the Unicode row changed the file reference");
await type("@nothing");
await new Promise((resolve) => setTimeout(resolve, 400));
check(searches.length === 5, "a complete index must not search");
@@ -216,8 +223,10 @@ const { app, BrowserWindow } = require("electron");
const path = require("node:path");
app.setPath("userData", path.join(__dirname, "profile"));
app.whenReady().then(async () => {
+ // Hidden Windows windows need offscreen painting to advance animation frames.
const win = new BrowserWindow({ show: false, width: 900, height: 700,
- webPreferences: { sandbox: true, contextIsolation: true, nodeIntegration: false, backgroundThrottling: false } });
+ webPreferences: { sandbox: true, contextIsolation: true, nodeIntegration: false, backgroundThrottling: false,
+ offscreen: process.platform === "win32" } });
win.webContents.on("console-message", (event) => console.error(event.message));
try {
await win.loadFile(path.join(__dirname, "index.html"));
diff --git a/docs/spec/03-runtime/01-ipc-protocol.md b/docs/spec/03-runtime/01-ipc-protocol.md
index f92d539ce..6588604a1 100644
--- a/docs/spec/03-runtime/01-ipc-protocol.md
+++ b/docs/spec/03-runtime/01-ipc-protocol.md
@@ -2206,6 +2206,10 @@ through a source blip.
### fs/index
+Git listings are decoded as a continuous UTF-8 stream. File names, including
+non-ASCII characters split across process output chunks, retain their exact
+spelling in both the index and `fs/search` results.
+
```ts
fs/index() -> { entries: FsIndexEntry[]; truncated: boolean }
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index aa5f00a70..7d57524ec 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -9029,6 +9029,10 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.
never overflows the menu.
- The tooltip and accessible name retain the complete relative path so
duplicate leaf names remain distinguishable.
+ - In a Git workspace containing accented, CJK, and emoji file names,
+ indexing and filtering retain each name exactly, including when Git's
+ stdout chunks split a UTF-8 character. Accepting the result names the
+ existing file, without replacement characters in its path.
- Enter/Tab/click on a file replaces the `@` token with an inline chip that
stays in the draft; that key does not send. File acceptance retains the
original complete `entry.path` behind the chip; directory acceptance
@@ -9041,7 +9045,9 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.
- **Acceptance**: C (conversation & stream), Quality
- **Milestone**: M5
- **Status**: Unit-covered
- (`apps/desktop/test/composer-file-reference-display.test.mjs`); file-mode row
+ (`apps/desktop/test/composer-file-reference-display.test.mjs` and
+ `packages/host-runtime/src/fs-index-encoding.test.ts`); Unicode filtering and
+ file acceptance run in `composer-deep-file-search-user-path.test.mjs`; file-mode row
layout covered by `scripts/e2e-composer-autocomplete.mjs`; full UI journey
Draft (run only in a capable environment when this surface changes)
diff --git a/packages/host-runtime/src/fs-index-encoding.test.ts b/packages/host-runtime/src/fs-index-encoding.test.ts
new file mode 100644
index 000000000..0cba4cc4e
--- /dev/null
+++ b/packages/host-runtime/src/fs-index-encoding.test.ts
@@ -0,0 +1,36 @@
+import * as childProcess from "node:child_process";
+import { PassThrough } from "node:stream";
+import { afterEach, expect, it, vi } from "vitest";
+import { getWorkspaceFileIndex, searchWorkspaceFiles } from "./fs-index.js";
+
+vi.mock("node:child_process", async (importOriginal) => ({
+ ...await importOriginal<typeof childProcess>(),
+ spawn: vi.fn(),
+}));
+
+afterEach(() => vi.clearAllMocks());
+
+it.each([1, 2, 3, 7])("preserves UTF-8 file names across %i-byte Git chunks", async (chunkSize) => {
+ const stdout = new PassThrough();
+ const child = new childProcess.ChildProcess();
+ child.stdout = stdout;
+ vi.mocked(childProcess.spawn).mockReturnValueOnce(child);
+ stdout.on("end", () => child.emit("close", 0));
+
+ const paths = ["README.md", "src/café.ts", "src/竞赛.ts", "src/🚀.ts"];
+ const output = Buffer.from([...paths, "node_modules/pkg/竞赛.ts", ""].join("\0"));
+ const root = `/pi-index-encoding-${chunkSize}`;
+ const pending = getWorkspaceFileIndex(root);
+ for (let offset = 0; offset < output.length; offset += chunkSize) {
+ stdout.write(output.subarray(offset, offset + chunkSize));
+ }
+ stdout.end();
+
+ const index = await pending;
+ expect(index.truncated).toBe(false);
+ expect(index.entries.filter((entry) => entry.kind === "file").map((entry) => entry.path).sort())
+ .toEqual([...paths].sort());
+ expect(index.entries).toContainEqual({ path: "src", kind: "dir" });
+ expect((await searchWorkspaceFiles(root, "竞赛")).entries)
+ .toEqual([{ path: "src/竞赛.ts", kind: "file" }]);
+});
diff --git a/packages/host-runtime/src/fs-index.ts b/packages/host-runtime/src/fs-index.ts
index e3d2ca987..02c2794c5 100644
--- a/packages/host-runtime/src/fs-index.ts
+++ b/packages/host-runtime/src/fs-index.ts
@@ -65,8 +65,10 @@ function gitListFiles(root: string): Promise<string[] | null> {
failed = true;
child.kill();
}, GIT_TIMEOUT_MS);
+ // A filename's UTF-8 bytes can straddle stdout chunks.
+ child.stdout.setEncoding("utf8");
child.stdout.on("data", (chunk) => {
- out += String(chunk);
+ out += chunk;
if (out.length > MAX_GIT_BUFFER) {
failed = true;
child.kill();