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.

Share storage paths and fix the Windows build

Andrei Kirkouski7d1d5a748a55
diff --git a/apps/cli/src/auth.ts b/apps/cli/src/auth.ts
index a902758..5fb8b83 100644
--- a/apps/cli/src/auth.ts
+++ b/apps/cli/src/auth.ts
@@ -1,5 +1,4 @@
import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
-import { homedir } from "node:os";
import { join } from "node:path";
import { randomUUID } from "node:crypto";
import { isCancel, password, select, text } from "@clack/prompts";
@@ -14,16 +13,11 @@ import {
type CredentialProvider,
type ProviderId,
} from "@repo/core/providers";
+import { storageDirectory } from "@repo/core/storage";
import { CliError } from "./errors";
export function configDirectory() {
- return join(
- process.env.XDG_CONFIG_HOME ||
- (process.platform === "win32"
- ? process.env.APPDATA || join(homedir(), "AppData", "Roaming")
- : join(homedir(), ".config")),
- "jevgrep",
- );
+ return storageDirectory("config");
}
function validateKey(raw: string): string {
diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts
index 8b30dca..07140c7 100644
--- a/apps/cli/src/index.ts
+++ b/apps/cli/src/index.ts
@@ -1,12 +1,11 @@
#!/usr/bin/env node
import { authenticate, configDirectory, loadCredentials } from "./auth";
import { endpointFor } from "@repo/core/providers";
+import { storageDirectory } from "@repo/core/storage";
import { help, parseCommand } from "./args";
import { CliError } from "./errors";
import { renderInventory, renderResult } from "./render";
import { stat } from "node:fs/promises";
-import { homedir } from "node:os";
-import { join } from "node:path";
import { version } from "../package.json";
import { installSkill } from "./skill";
@@ -34,13 +33,7 @@ async function write(text: string) {
}
function cacheDirectory() {
- return join(
- process.env.XDG_CACHE_HOME ||
- (process.platform === "win32"
- ? process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local")
- : join(homedir(), ".cache")),
- "jevgrep",
- );
+ return storageDirectory("cache");
}
async function main() {
diff --git a/packages/core/package.json b/packages/core/package.json
index 0f026e4..af0ad2a 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -6,7 +6,8 @@
"exports": {
".": "./src/index.ts",
"./providers": "./src/providers.ts",
- "./source": "./src/source.ts"
+ "./source": "./src/source.ts",
+ "./storage": "./src/storage.ts"
},
"scripts": {
"check-types": "tsc --noEmit",
diff --git a/packages/core/src/filesystem.ts b/packages/core/src/filesystem.ts
index dc34d1a..3db698b 100644
--- a/packages/core/src/filesystem.ts
+++ b/packages/core/src/filesystem.ts
@@ -1,9 +1,9 @@
import { createHash, randomUUID } from "node:crypto";
import { constants, type BigIntStats, type Dir } from "node:fs";
import { lstat, open, opendir, realpath } from "node:fs/promises";
-import { homedir } from "node:os";
import { isAbsolute, join, relative, resolve, sep } from "node:path";
import ignore, { type Ignore } from "ignore";
+import { storageDirectory } from "./storage";
/** These independent switches broaden only their named exclusion category. */
export type FilesystemPolicy = {
@@ -142,30 +142,16 @@ export async function createFilesystem(options: FilesystemOptions) {
throw new Error(`Invalid filesystem limit: ${name}`);
}
const protectedPaths = await Promise.all(
- [
- join(
- process.env.XDG_CONFIG_HOME ||
- (process.platform === "win32"
- ? process.env.APPDATA || join(homedir(), "AppData", "Roaming")
- : join(homedir(), ".config")),
- "jevgrep",
- ),
- join(
- process.env.XDG_CACHE_HOME ||
- (process.platform === "win32"
- ? process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local")
- : join(homedir(), ".cache")),
- "jevgrep",
- ),
- ...(options.protectedPaths ?? []),
- ].map(async (path) => {
- const absolute = resolve(path);
- try {
- return await realpath(absolute);
- } catch {
- return absolute;
- }
- }),
+ [storageDirectory("config"), storageDirectory("cache"), ...(options.protectedPaths ?? [])].map(
+ async (path) => {
+ const absolute = resolve(path);
+ try {
+ return await realpath(absolute);
+ } catch {
+ return absolute;
+ }
+ },
+ ),
);
const cursors = new Map<string, Cursor>();
let closed = false;
diff --git a/packages/core/src/storage.ts b/packages/core/src/storage.ts
new file mode 100644
index 0000000..515428b
--- /dev/null
+++ b/packages/core/src/storage.ts
@@ -0,0 +1,20 @@
+import { homedir } from "node:os";
+import { join } from "node:path";
+
+/** The one source of Jevgrep's config and cache locations; filesystem policy protects the same paths. */
+export function storageDirectory(
+ kind: "config" | "cache",
+ env: NodeJS.ProcessEnv = process.env,
+ platform: NodeJS.Platform = process.platform,
+) {
+ const xdg = kind === "config" ? env.XDG_CONFIG_HOME : env.XDG_CACHE_HOME;
+ if (xdg) return join(xdg, "jevgrep");
+ if (platform === "win32") {
+ const base = kind === "config" ? env.APPDATA : env.LOCALAPPDATA;
+ return join(
+ base || join(homedir(), "AppData", kind === "config" ? "Roaming" : "Local"),
+ "jevgrep",
+ );
+ }
+ return join(homedir(), kind === "config" ? ".config" : ".cache", "jevgrep");
+}
diff --git a/scripts/package-notices.mjs b/scripts/package-notices.mjs
index 027b3ba..eeec953 100644
--- a/scripts/package-notices.mjs
+++ b/scripts/package-notices.mjs
@@ -1,6 +1,9 @@
import { readFile, readdir } from "node:fs/promises";
import { dirname, resolve } from "node:path";
+// Resolved paths use the platform separator; bundler inputs always use "/".
+const inNodeModules = (path) => path.split(/[\\/]/).includes("node_modules");
+
/** Use emitted inputs, so the notice follows the actual bundled dependency graph. */
export async function bundledNotices(metafile, root) {
const packages = new Map();
@@ -11,9 +14,9 @@ export async function bundledNotices(metafile, root) {
let needsApacheTerms = false;
for (const output of Object.values(metafile.outputs)) {
for (const [input, contribution] of Object.entries(output.inputs)) {
- if (!contribution.bytesInOutput || !input.split("/").includes("node_modules")) continue;
+ if (!contribution.bytesInOutput || !inNodeModules(input)) continue;
let directory = dirname(resolve(root, input));
- while (directory.split("/").includes("node_modules")) {
+ while (inNodeModules(directory)) {
let metadata;
try {
metadata = JSON.parse(await readFile(resolve(directory, "package.json"), "utf8"));
@@ -56,7 +59,7 @@ export async function bundledNotices(metafile, root) {
}
directory = dirname(directory);
}
- if (!directory.split("/").includes("node_modules"))
+ if (!inNodeModules(directory))
throw new Error(`No package metadata for bundled input ${input}`);
}
}