Skip to content

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

fix(host-runtime): disable Git textconv for workspace diffs

vastsa3fecec213890
diff --git a/docs/spec/03-runtime/03-tools-and-permissions.md b/docs/spec/03-runtime/03-tools-and-permissions.md
index 4136803ce..f930d3b62 100644
--- a/docs/spec/03-runtime/03-tools-and-permissions.md
+++ b/docs/spec/03-runtime/03-tools-and-permissions.md
@@ -400,7 +400,8 @@ The host's workspace diff collector applies the same Git hardening to every
repository it inspects, including non-isolated workspaces. Each host-started
Git command disables repository-configured hooks and `core.fsmonitor`, and
removes environment variables that can redirect Git to another repository or
-inject command-scope configuration.
+inject command-scope configuration. Diff invocations also disable external diff
+and text-conversion helpers.
Merging into the project is an explicit user action (preview, then merge with
the preview token); it syncs the project branch into the worktree and only
diff --git a/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md b/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md
index 8a42d26c4..bc44ac87d 100644
--- a/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md
+++ b/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md
@@ -328,7 +328,7 @@ type ReviewChange = {
只删除链接本身,绝不删除其目标。
宿主的工作区差异收集器会对其检查的所有仓库应用相同的 Git 加固措施,包括非隔离工作区。每次由宿主启动
-Git 命令都会禁用仓库配置的 hooks 和 `core.fsmonitor`,并移除可将 Git 重定向到其他仓库或注入命令级配置的环境变量。
+Git 命令都会禁用仓库配置的 hooks 和 `core.fsmonitor`,并移除可将 Git 重定向到其他仓库或注入命令级配置的环境变量。差异命令也会禁用外部 diff 和文本转换辅助程序。
合并到项目是显式的用户操作(先预览,再携带预览令牌合并):先把项目分支同步进
worktree,项目只做快进,因此冲突留在 worktree 中。删除隔离会话即丢弃其 worktree
diff --git a/packages/host-runtime/src/workspace-diff.test.ts b/packages/host-runtime/src/workspace-diff.test.ts
index e2ccf612b..b2cccf2c7 100644
--- a/packages/host-runtime/src/workspace-diff.test.ts
+++ b/packages/host-runtime/src/workspace-diff.test.ts
@@ -86,4 +86,52 @@ describe("collectWorkspaceDiff", () => {
}
}
});
+
+ it("does not execute repository-configured textconv commands", async () => {
+ const tempRoot = await mkdtemp(join(tmpdir(), "pi-workspace-diff-textconv-"));
+ tempDirs.push(tempRoot);
+ const root = join(tempRoot, "repo");
+ await mkdir(root);
+
+ await runGit(root, ["init", "--quiet"]);
+ await runGit(root, ["config", "user.name", "Workspace diff test"]);
+ await runGit(root, ["config", "user.email", "[email protected]"]);
+ await writeFile(join(root, "tracked.txt"), "initial\n", "utf8");
+ await runGit(root, ["add", "tracked.txt"]);
+ await runGit(root, ["commit", "--quiet", "-m", "initial"]);
+ await writeFile(
+ join(root, ".gitattributes"),
+ "tracked.txt diff=probe\nuntracked.txt diff=probe\n",
+ "utf8",
+ );
+ await runGit(root, ["add", ".gitattributes"]);
+ await runGit(root, ["commit", "--quiet", "-m", "diff attributes"]);
+
+ const marker = join(tempRoot, "textconv-ran");
+ const command = join(tempRoot, "textconv.cjs");
+ await writeFile(
+ command,
+ `const fs = require("node:fs");\nfs.appendFileSync(${JSON.stringify(marker)}, "ran\\n");\nprocess.stdout.write(fs.readFileSync(process.argv.at(-1)));\n`,
+ "utf8",
+ );
+ const textconv = `${shellQuote(process.execPath)} ${shellQuote(command)}`;
+ await runGit(root, ["config", "diff.probe.textconv", textconv]);
+ await writeFile(join(root, "tracked.txt"), "changed\n", "utf8");
+ await writeFile(join(root, "untracked.txt"), "new file\n", "utf8");
+
+ // Prove the repository's textconv command is active before exercising the host.
+ await execFile("git", ["diff", "--textconv", "--", "tracked.txt"], {
+ cwd: root,
+ encoding: "utf8",
+ });
+ expect(existsSync(marker)).toBe(true);
+ await rm(marker, { force: true });
+
+ const diff = await collectWorkspaceDiff(root);
+
+ expect(diff.files.map((file) => file.path)).toEqual(
+ expect.arrayContaining(["tracked.txt", "untracked.txt"]),
+ );
+ expect(existsSync(marker)).toBe(false);
+ });
});
diff --git a/packages/host-runtime/src/workspace-diff.ts b/packages/host-runtime/src/workspace-diff.ts
index cc8a1a3ed..69558f97a 100644
--- a/packages/host-runtime/src/workspace-diff.ts
+++ b/packages/host-runtime/src/workspace-diff.ts
@@ -269,6 +269,7 @@ export async function collectWorkspaceDiff(cwd: string): Promise<WorkspaceDiff>
base,
"--no-color",
"--no-ext-diff",
+ "--no-textconv",
"-M",
"--unified=3",
]);
@@ -286,6 +287,7 @@ export async function collectWorkspaceDiff(cwd: string): Promise<WorkspaceDiff>
"diff",
"--no-color",
"--no-ext-diff",
+ "--no-textconv",
"--unified=3",
"--no-index",
"--",