Skip to content

Find code by asking what it does. A CLI for coding agents that uses Jev to discover relevant files and source context.

Reuse unchanged ignore rules and release 0.4.2

David Zhange4585f14cfcc
diff --git a/apps/cli/package.json b/apps/cli/package.json
index e2ebf14..405fad7 100644
--- a/apps/cli/package.json
+++ b/apps/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@dzhng/jevgrep",
- "version": "0.4.1",
+ "version": "0.4.2",
"description": "Content-aware source retrieval for coding agents",
"license": "MIT",
"repository": {
diff --git a/bun.lock b/bun.lock
index 78ee6a9..70a413c 100644
--- a/bun.lock
+++ b/bun.lock
@@ -13,7 +13,7 @@
},
"apps/cli": {
"name": "@dzhng/jevgrep",
- "version": "0.4.1",
+ "version": "0.4.2",
"bin": {
"jg": "./dist/bin/index.js",
},
diff --git a/docs/architecture.md b/docs/architecture.md
index 93ca950..ab7abe1 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -46,6 +46,10 @@ source text is a field inside those objects. Provider selection changes transpor
and authentication, not retrieval semantics. Bounded retries, cancellation and
freshness checks apply before source is uploaded or returned.
+Ignore rules are reused within a search only while fresh filesystem identity and
+canonical-path checks still match. Edits, replacement and deletion invalidate
+that reuse. Source snapshots retain their existing read and freshness checks.
+
## Version improvement
The [evaluation policy](../evals/cost-quality-policy.md) owns version improvement:
diff --git a/packages/core/src/filesystem.ts b/packages/core/src/filesystem.ts
index 65d1d98..1dcd122 100644
--- a/packages/core/src/filesystem.ts
+++ b/packages/core/src/filesystem.ts
@@ -223,23 +223,51 @@ export async function createFilesystem(options: FilesystemOptions) {
await handle?.close();
}
}
+ // Search-local reuse; eviction only requires reparsing, never changes eligibility.
+ const ruleCache = new Map<string, { stat: BigIntStats; rules: Ignore }>();
async function ruleFile(directory: string, name: string): Promise<Ignore | Issue | undefined> {
const absolute = join(directory, name);
try {
const stat = await lstat(absolute, { bigint: true });
- if (!stat.isFile() || stat.isSymbolicLink()) return undefined;
+ if (!stat.isFile() || stat.isSymbolicLink()) {
+ ruleCache.delete(absolute);
+ return undefined;
+ }
+ const cached = ruleCache.get(absolute);
+ if (cached && same(cached.stat, stat)) {
+ if (
+ !(await stable({
+ status: "eligible",
+ path: relative(root, absolute),
+ absolute,
+ stat,
+ ancestors: [],
+ }))
+ )
+ return issue("changed", relative(root, absolute));
+ ruleCache.delete(absolute);
+ ruleCache.set(absolute, cached);
+ return cached.rules;
+ }
const bytes = await readBytes(
{ status: "eligible", path: relative(root, absolute), absolute, stat, ancestors: [] },
limits.maxIgnoreBytes,
);
if (bytes.status === "issue") return bytes;
try {
- return ignore().add(new TextDecoder("utf-8", { fatal: true }).decode(bytes.bytes));
+ const rules = ignore().add(new TextDecoder("utf-8", { fatal: true }).decode(bytes.bytes));
+ ruleCache.delete(absolute);
+ ruleCache.set(absolute, { stat, rules });
+ if (ruleCache.size > 64) ruleCache.delete(ruleCache.keys().next().value!);
+ return rules;
} catch {
return issue("unreadable", relative(root, absolute));
}
} catch (error) {
- if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") {
+ ruleCache.delete(absolute);
+ return undefined;
+ }
return issue(errorKind(error), relative(root, absolute));
}
}
@@ -432,6 +460,7 @@ export async function createFilesystem(options: FilesystemOptions) {
}
async function close() {
closed = true;
+ ruleCache.clear();
await Promise.all([...cursors.keys()].map(discard));
}
return { root, readSnapshot, lookupFile, listPage, closeCursor: discard, close };
diff --git a/packages/core/test/filesystem.test.ts b/packages/core/test/filesystem.test.ts
index 37078be..8a20aa6 100644
--- a/packages/core/test/filesystem.test.ts
+++ b/packages/core/test/filesystem.test.ts
@@ -272,6 +272,46 @@ test("limits and directory changes are visible issues, and fresh queries observe
}
});
+test("one reader observes same-size ignore edits with restored timestamps and recreated rules", async () => {
+ const root = await fixture({ ".ignore": "a.txt\n", "a.txt": "a", "b.txt": "b" });
+ const rules = join(root, ".ignore");
+ const stamp = new Date("2020-01-01T00:00:00Z");
+ await utimes(rules, stamp, stamp);
+ const reader = await createFilesystem({ root });
+ try {
+ expect(await reader.readSnapshot("a.txt")).toMatchObject({
+ status: "excluded",
+ reason: "ignored",
+ });
+ expect(await reader.readSnapshot("b.txt")).toMatchObject({
+ status: "ok",
+ snapshot: { source: "b" },
+ });
+ await writeFile(rules, "b.txt\n");
+ await utimes(rules, stamp, stamp);
+ expect(await reader.readSnapshot("a.txt")).toMatchObject({
+ status: "ok",
+ snapshot: { source: "a" },
+ });
+ expect(await reader.readSnapshot("b.txt")).toMatchObject({
+ status: "excluded",
+ reason: "ignored",
+ });
+ await rm(rules);
+ expect(await reader.readSnapshot("b.txt")).toMatchObject({
+ status: "ok",
+ snapshot: { source: "b" },
+ });
+ await writeFile(rules, "a.txt\n");
+ expect(await reader.readSnapshot("a.txt")).toMatchObject({
+ status: "excluded",
+ reason: "ignored",
+ });
+ } finally {
+ await reader.close();
+ }
+});
+
test("protected storage remains excluded when explicit root resolves through its alias", async () => {
const store = await fixture({ credential: "NEVER_UPLOAD" });
const root = await fixture({});