Skip to content

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

fix: 文件索引在 Git 截止时间直接回退

geng yuef13c792dc043
diff --git a/apps/desktop/test/fs-index-git-deadline.test.mjs b/apps/desktop/test/fs-index-git-deadline.test.mjs
new file mode 100644
index 000000000..cf6b080c0
--- /dev/null
+++ b/apps/desktop/test/fs-index-git-deadline.test.mjs
@@ -0,0 +1,51 @@
+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 { fileURLToPath } from "node:url";
+import test from "node:test";
+import { buildSync } from "esbuild";
+
+test("workspace file index and search fall back at the Git deadline without a close event", async t => {
+ const root = await mkdtemp(join(tmpdir(), "pi-index-deadline-"));
+ await writeFile(join(root, "note.txt"), "fixture");
+ const require = createRequire(import.meta.url);
+ const processModule = require("node:child_process");
+ const originalSpawn = processModule.spawn;
+ let spawned;
+ const ready = new Promise(resolve => { spawned = resolve; });
+ let killed = false;
+ processModule.spawn = () => {
+ const child = new EventEmitter();
+ child.stdout = new EventEmitter();
+ child.stdout.setEncoding = () => {};
+ child.stdout.destroy = () => {};
+ child.stderr = new EventEmitter();
+ child.stderr.destroy = () => {};
+ child.kill = () => { killed = true; return true; };
+ spawned();
+ return child;
+ };
+ try {
+ const result = buildSync({ entryPoints: [fileURLToPath(new URL("../../../packages/host-runtime/src/fs-index.ts", import.meta.url))], bundle: true, write: false, platform: "node", format: "cjs" });
+ const module = { exports: {} };
+ new Function("require", "module", "exports", result.outputFiles[0].text)(require, module, module.exports);
+ t.mock.timers.enable({ apis: ["setTimeout"] });
+ let listing;
+ const pending = module.exports.getWorkspaceFileIndex(root).then(value => { listing = value; });
+ await ready;
+ t.mock.timers.tick(4000);
+ for (let tick = 0; tick < 20 && !listing; tick++) await new Promise(resolve => setImmediate(resolve));
+ assert.equal(killed, true);
+ assert.ok(listing, "the file index must settle without Git close");
+ assert.deepEqual(listing.entries, [{ path: "note.txt", kind: "file" }]);
+ await pending;
+ assert.deepEqual((await module.exports.searchWorkspaceFiles(root, "note")).entries, listing.entries);
+ } finally {
+ t.mock.timers.reset();
+ processModule.spawn = originalSpawn;
+ 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 19943bf0f..3bc6c551b 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
+Workspace file index Git queries settle at their deadline or output limit,
+even when inherited child pipes do not close. Composer file search and the
+Files index then use the existing bounded filesystem fallback (Refs #1731).
+
Live delegation reconstruction crosses system notices as well as steering
messages. An ordinary user prompt remains the run boundary. A running Task
behind a system notice must not become aborted on navigation (Refs #1990).
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 3344c904c..f7c553cea 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1,5 +1,12 @@
# 04. E2E Test Plan
+### E2E-FILE-INDEX-git-deadline
+
+Drive `getWorkspaceFileIndex` and `searchWorkspaceFiles` against real fixture
+files. Hold Git's close event beyond its deadline: both calls return the bounded
+filesystem listing. Coverage: `fs-index-git-deadline.test.mjs`. Existing index
+tests cover Git ignore semantics, Unicode chunk boundaries and deep search.
+
### E2E-SUBAGENT-system-notice-reconstruction
Reconstruct a transcript with a running Task followed by a system notice.
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 69011ffcb..d8741bb7d 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 查询在截止时间或输出上限直接结束等待,即使继承的
+子进程管道未关闭。输入框文件搜索及 Files 索引使用现有有界目录回退(Refs #1731)。
+
运行中子代理状态重建跨过系统通知及 steering 消息,普通用户提示仍作为回合边界。
系统通知之前仍在运行的 Task 不会因导航而显示已停止(Refs #1990)。
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 a1e9b5c5d..7c1cfd013 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-INDEX-git-deadline
+
+对真实测试文件调用 `getWorkspaceFileIndex` 和 `searchWorkspaceFiles`,
+保持 Git 的 close 事件未到达,推进截止时间后两者均返回有界目录列表。
+覆盖:`fs-index-git-deadline.test.mjs`。原有索引测试覆盖 Git 忽略规则、
+Unicode 字节分块及深层搜索。
+
### E2E-SUBAGENT-system-notice-reconstruction
重建运行中的 Task 后接系统通知的会话,生产条目构建、运行状态选择及结果
diff --git a/packages/host-runtime/src/fs-index.ts b/packages/host-runtime/src/fs-index.ts
index 02c2794c5..ef3f25963 100644
--- a/packages/host-runtime/src/fs-index.ts
+++ b/packages/host-runtime/src/fs-index.ts
@@ -61,9 +61,20 @@ function gitListFiles(root: string): Promise<string[] | null> {
);
let out = "";
let failed = false;
+ let settled = false;
+ const finish = (files: string[] | null) => {
+ if (settled) return;
+ settled = true;
+ clearTimeout(timer);
+ resolve(files);
+ };
const timer = setTimeout(() => {
failed = true;
+ // 截止时间直接结束等待,继承 stdout 的进程可能永远不发 close。
+ finish(null);
child.kill();
+ child.stdout.destroy();
+ child.stderr?.destroy();
}, GIT_TIMEOUT_MS);
// A filename's UTF-8 bytes can straddle stdout chunks.
child.stdout.setEncoding("utf8");
@@ -71,17 +82,18 @@ function gitListFiles(root: string): Promise<string[] | null> {
out += chunk;
if (out.length > MAX_GIT_BUFFER) {
failed = true;
+ finish(null);
child.kill();
+ child.stdout.destroy();
+ child.stderr?.destroy();
}
});
child.on("error", () => {
- clearTimeout(timer);
- resolve(null);
+ finish(null);
});
child.on("close", (code) => {
- clearTimeout(timer);
- if (failed || code !== 0) return resolve(null);
- resolve(out.split("\0").filter((p) => p.length > 0));
+ if (failed || code !== 0) return finish(null);
+ finish(out.split("\0").filter((p) => p.length > 0));
});
});
}