Skip to content

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

fix: 让文件管理器 Git 截止时间直接结束等待

geng yue7f058a9d9fc5
diff --git a/apps/desktop/resources/plugins/pi.file-manager/UPSTREAM.md b/apps/desktop/resources/plugins/pi.file-manager/UPSTREAM.md
index 993a31737..fe8ca2d21 100644
--- a/apps/desktop/resources/plugins/pi.file-manager/UPSTREAM.md
+++ b/apps/desktop/resources/plugins/pi.file-manager/UPSTREAM.md
@@ -65,9 +65,9 @@ so the synthetic filesystem events could reach Node.
scopes Node's module interpretation to this plugin; other bundled plugins
retain their own module format.
-`main.js`, `remote-workspace.js`, `README.md`, `CHANGELOG.md`, `views/index.html`
+`remote-workspace.js`, `README.md`, `CHANGELOG.md`, `views/index.html`
and `views/assets/pdfjs-LICENSES.txt` are byte-identical to the pinned integration
-commit. Only the manifest and rebuilt view differ. The runtime pack has eight
+commit. The manifest, rebuilt view and Desktop-local `main.js` repairs differ. The runtime pack has eight
files; the two Desktop-local license/module files are added when vendoring.
QA dependencies, tests and `views-src/` are not included in the shipped plugin.
The pinned changelog contains trailing spaces; its narrow `.gitattributes`
@@ -83,7 +83,7 @@ is recorded here. `UPSTREAM.md` is the provenance record, not a runtime input.
| `CHANGELOG.md` | 34520 | `b7a3c06c07b2dbe5ce79577bbc6c6a53ffa00324bd64a27d0d5634493dec48b4` |
| `LICENSE` | 1067 | `ebaec3ae096498a39f6b86e3ac8017e39818fb5aaff80b452349f94bc275ec0d` |
| `README.md` | 38470 | `4ecf6e3afa2051b59b479907c485d156caca54ef6d1f4e3c410805807942a268` |
-| `main.js` | 125253 | `7eafffdb525a9ad9b16adaa5a0cd78cd66a9a99a8c3a8cb136aa987b5db44dd7` |
+| `main.js` | 125487 | `f819c13bb8e0196e92a0cbef18ffb147a5f38fdc9a8e7fbe27d58463fd991088` |
| `manifest.json` | 40092 | `ea3798770849c77193f16da5a582157cc07e5f756f7225dcbec1762ed591d461` |
| `package.json` | 25 | `8005a3491db7d92f36ac66369861589f9c47123d3a7c71e643fc2c06168cd45a` |
| `remote-workspace.js` | 3757 | `931a579801fd4b334c3d96231aafc7ff52e0c03e7baebbabaf00b4c5e17cc366` |
@@ -120,3 +120,10 @@ is recorded here. `UPSTREAM.md` is the provenance record, not a runtime input.
The bundled `main.js` restores file-name validation and moves
`entryFromStat` to module scope. This is a Desktop-local runtime repair;
the upstream pins and published artifact claims above are unchanged.
+
+## Desktop Git deadline repair (#1731)
+
+The Git timeout rejects immediately and destroys its captured output streams,
+instead of waiting for a `close` event that inherited child pipes may delay.
+The existing best-effort snapshot path returns unavailable Git metadata while
+preserving directory listing and preview. No upstream release is claimed.
diff --git a/apps/desktop/resources/plugins/pi.file-manager/main.js b/apps/desktop/resources/plugins/pi.file-manager/main.js
index c8713ca22..495608f3c 100644
--- a/apps/desktop/resources/plugins/pi.file-manager/main.js
+++ b/apps/desktop/resources/plugins/pi.file-manager/main.js
@@ -803,7 +803,11 @@ function runGit(rootPath, binary, args, { maxBytes, timeoutMs = GIT_TIMEOUT_MS }
const timer = setTimeout(() => {
timedOut = true;
+ // close 可能被后代进程继承的管道拖住;截止时间必须直接结束等待。
+ finish(reject, fail("GIT_TIMEOUT", "git command timed out"));
child.kill("SIGKILL");
+ child.stdout?.destroy?.();
+ child.stderr?.destroy?.();
}, timeoutMs);
child.stdout?.on("data", (chunk) => {
diff --git a/apps/desktop/test/file-manager-git-timeout.test.mjs b/apps/desktop/test/file-manager-git-timeout.test.mjs
new file mode 100644
index 000000000..3ff229bb2
--- /dev/null
+++ b/apps/desktop/test/file-manager-git-timeout.test.mjs
@@ -0,0 +1,56 @@
+import assert from "node:assert/strict";
+import { EventEmitter } from "node:events";
+import { createRequire } from "node:module";
+import { mkdtemp, writeFile, rm } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import test from "node:test";
+
+test("Git timeout releases file listing and preview even when child pipes never close", async t => {
+ const root = await mkdtemp(join(tmpdir(), "fm-git-timeout-"));
+ await writeFile(join(root, "note.txt"), "preview bytes");
+ const require = createRequire(import.meta.url);
+ const processModule = require("node:child_process");
+ const originalSpawn = processModule.spawn;
+ const previousPi = globalThis.pi;
+ const entry = require.resolve("../resources/plugins/pi.file-manager/main.js");
+ let spawned;
+ const ready = new Promise(resolve => { spawned = resolve; });
+ let killed = false;
+ processModule.spawn = () => {
+ const child = new EventEmitter();
+ child.stdout = new EventEmitter();
+ child.stderr = new EventEmitter();
+ child.kill = () => { killed = true; return true; };
+ spawned();
+ return child;
+ };
+ globalThis.pi = { workspace: { get: async () => ({ path: root }) }, plugin: { getDataPath: async () => null, getSettings: async () => ({}) } };
+ delete require.cache[entry];
+ const plugin = require(entry);
+ try {
+ await plugin.onLoad();
+ t.mock.timers.enable({ apis: ["setTimeout"] });
+ let listing, preview;
+ const list = plugin.onPanelInvoke("fm.list", {}).then(value => { listing = value; });
+ const read = plugin.onPanelInvoke("fm.read", { path: "note.txt" }).then(value => { preview = value; });
+ await ready;
+ t.mock.timers.tick(plugin.internals.GIT_TIMEOUT_MS);
+ await new Promise(resolve => setImmediate(resolve));
+ assert.equal(killed, true);
+ assert.equal(listing?.ok, true, "listing must not wait for close after the deadline");
+ assert.deepEqual(listing.entries.map(item => item.name), ["note.txt"]);
+ assert.equal(listing.git.available, false);
+ await read;
+ assert.equal(preview.ok, true);
+ assert.equal(preview.text, "preview bytes");
+ await list;
+ } finally {
+ t.mock.timers.reset();
+ await plugin.onUnload();
+ processModule.spawn = originalSpawn;
+ globalThis.pi = previousPi;
+ delete require.cache[entry];
+ await rm(root, { recursive: true, force: true });
+ }
+});
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 184989401..f6fe13bea 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -1,5 +1,9 @@
# 08. Component Spec
+File Manager Git deadlines settle the command at the deadline even when child
+output pipes remain open. A failed snapshot omits Git badges and does not block
+directory listings or file previews indefinitely (Refs #1731).
+
### Copied directory references
Native folder paste adds compact cards in a wrapping row above the editable
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 6b73f1bfb..ce55354e9 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1,5 +1,13 @@
# 04. E2E Test Plan
+### E2E-FILE-MANAGER-git-deadline
+
+`file-manager-git-timeout.test.mjs` drives actual bundled `fm.list` and `fm.read`
+against real fixture files with a controlled child-process boundary. Advance
+the Git deadline while the child never closes: entries and preview complete
+without Git metadata. Existing Electron directory-location and mutation
+journeys cover successful reads, saves and directory browsing.
+
## E2E-SCHEDULED-independent-loading-and-route-return
- **Preconditions:** Synthetic tasks; controllable task, latest-run, history and
diff --git a/docs/zh-CN/spec/04-ux/08-component-spec.md b/docs/zh-CN/spec/04-ux/08-component-spec.md
index 07b6adced..6bfcaf1fd 100644
--- a/docs/zh-CN/spec/04-ux/08-component-spec.md
+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md
@@ -1,5 +1,8 @@
# 08. 组件规格
+文件管理器的 Git 截止时间直接结束命令等待,即使子进程输出管道仍未关闭。
+快照失败时省略 Git 标记,目录列表和文件预览不会因此无限等待(Refs #1731)。
+
> **翻译说明:** 本页是与 [英文源规格](/spec/04-ux/08-component-spec) 一一对应的机器辅助翻译。代码、协议字段和标识符保持原文;如翻译与英文源事实有歧义,以英文版本为准。
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index d5ea19d98..3928df0f6 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -1,5 +1,12 @@
# 04. E2E 测试 Plan
+### E2E-FILE-MANAGER-git-deadline
+
+`file-manager-git-timeout.test.mjs` 对真实测试文件调用内置 `fm.list` 和
+`fm.read`,仅控制子进程边界。子进程从不关闭时推进 Git 截止时间,目录及
+预览仍完成,Git 元数据不可用。原有 Electron 目录定位和文件修改旅程验证
+正常读取、保存和目录浏览。
+
## E2E-SCHEDULED-independent-loading-and-route-return
- **Preconditions:** Synthetic tasks; controllable task, latest-run, history and