Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: git config reads, npmrc held

ogsamrat365f65eb146f
diff --git a/apps/server/src/session-archive/files-used-policy.ts b/apps/server/src/session-archive/files-used-policy.ts
index d8e91dba..26d0352a 100644
--- a/apps/server/src/session-archive/files-used-policy.ts
+++ b/apps/server/src/session-archive/files-used-policy.ts
@@ -140,7 +140,8 @@ export function homeConfigKind(homeRel: string): HomeConfigKind | null {
const rel = homeRel.replaceAll("\\", "/");
if ([".gitconfig", ".config/git/config"].includes(rel)) return "git";
if ([".gitignore_global", ".gitignore", ".config/git/ignore", ".config/git/attributes", ".gitattributes"].includes(rel)) return "text";
- if ([".npmrc", ".yarnrc", ".yarnrc.yml", ".config/pnpm/rc", "Library/Preferences/pnpm/rc", "AppData/Local/pnpm/config/rc", ".bunfig.toml"].includes(rel)) return "npmrc";
+ // .npmrc and .pypirc are credential files (the backend holds them back from every export): never allowlisted.
+ if ([".yarnrc", ".yarnrc.yml", ".config/pnpm/rc", "Library/Preferences/pnpm/rc", "AppData/Local/pnpm/config/rc", ".bunfig.toml"].includes(rel)) return "npmrc";
if ([".config/pip/pip.conf", ".pip/pip.conf", "pip/pip.ini", "AppData/Roaming/pip/pip.ini", "Library/Application Support/pip/pip.conf", ".config/uv/uv.toml", ".pydistutils.cfg", ".condarc", ".cargo/config.toml", ".cargo/config", ".m2/settings.xml"].includes(rel)) return "ini";
if ([".editorconfig", ".prettierrc", ".prettierrc.json", ".prettierrc.yaml", ".prettierrc.yml", ".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", ".pylintrc", ".flake8", ".pycodestyle", ".isort.cfg", ".tool-versions", ".nvmrc", ".node-version", ".python-version", ".ruby-version", ".mypy.ini", ".clang-format", ".rustfmt.toml", ".jshintrc", ".babelrc", ".browserslistrc"].includes(rel)) return "text";
if (/^\.config\/(?:ruff|black|pnpm|starship|mise|rtx|yamllint|flake8|pycodestyle|pylintrc|mypy|direnv|bat|fd|ripgrep|jj|lazygit|helix|nvim|zellij|tmux|alacritty|kitty|wezterm|yarn|prettier|eslint|stylua|taplo|rustfmt|clangd|pre-commit|uv|pip|git)(?:\/[^/]+)*\/[^/]+$/.test(rel) && !/(?:^|\/)(?:hosts\.ya?ml|credentials?.*|auth.*|token.*|.*\.(?:key|pem|db|sqlite))$/i.test(rel)) return "text";
@@ -252,7 +253,7 @@ export function classifyUse(absolute: string, context: UseContext): UseClass | n
if (homeRel !== null) {
if (HOME_SECRET_DIRS.some((dir) => homeRel === dir || homeRel.startsWith(`${dir}/`))) return hold("home", "denylisted");
const kind = homeConfigKind(homeRel);
- // An allowlisted config is scrubbed before it is staged, so its name alone (.npmrc) does not hold it.
+ // An allowlisted config is scrubbed before it is staged, so a name the secret checks would hold does not hold it.
if (kind && archivePath) return { scope: "home", path: absolute, plan: "stage", reason: "captured", scrub: kind, archivePath };
if (secret) return hold("home", "denylisted");
if (HOME_CACHE_DIRS.some((dir) => homeRel === dir || homeRel.startsWith(`${dir}/`))) return hold("home", "dependency_dir");
diff --git a/apps/server/src/session-archive/files-used-shell.ts b/apps/server/src/session-archive/files-used-shell.ts
index 1829752c..c2a1129a 100644
--- a/apps/server/src/session-archive/files-used-shell.ts
+++ b/apps/server/src/session-archive/files-used-shell.ts
@@ -17,7 +17,12 @@
* write); `source`/`.` and `./script` run a file; `node -r ./x` reads;
* - build and test tools read the config files they always load
* (`package.json`, `tsconfig.json`, `pytest.ini`, `Makefile`, ...) and
- * the ones named with `-f`/`-c`/`--config`/`-r`.
+ * the ones named with `-f`/`-c`/`--config`/`-r`;
+ * - every `git` command reads the user's git config (`~/.gitconfig`,
+ * `~/.config/git/config`: `implicit`, so one that is not there is not
+ * listed); `git config` keys and values are never paths (`--file x`
+ * is, and a write to `--global` writes `~/.gitconfig`, to the repository
+ * `.git/config`); other git commands name files only after `--`.
*
* Any other path-looking word counts as a read. Candidates are absolute;
* whether each is a file is checked later. Nothing here touches the disk.
@@ -26,7 +31,8 @@
import { isAbsolute, join, resolve } from "node:path";
export type ShellUseOp = "read" | "write" | "exec";
-export type ShellUse = { path: string; op: ShellUseOp };
+/** `implicit`: the program reads it without naming it (a config it always loads): not listed when it is not there. */
+export type ShellUse = { path: string; op: ShellUseOp; implicit?: true };
const MAX_COMMAND_CHARS = 256 * 1024;
const MAX_PATH_CHARS = 4_096;
@@ -239,6 +245,14 @@ const TOOL_CONFIGS: Record<string, string[]> = {
alembic: ["alembic.ini"],
manage: [],
};
+/** The user's git config files, which every git command loads (home scope: allowlisted, scrubbed). */
+const GIT_HOME_CONFIGS = ["~/.gitconfig", "~/.config/git/config"];
+/** git's global options that take a value (`-c key=value`, `--git-dir x`). */
+const GIT_VALUE_OPTIONS = new Set(["-c", "--git-dir", "--work-tree", "--namespace", "--exec-path", "--config-env"]);
+/** `git config` options that change the file. */
+const GIT_CONFIG_WRITES = new Set(["--unset", "--unset-all", "--add", "--replace-all", "--rename-section", "--remove-section", "--edit", "-e"]);
+/** `git config` options that take a value (`--type bool`, `--default x`). */
+const GIT_CONFIG_VALUE_OPTIONS = new Set(["--type", "--default", "--blob", "--comment", "--value"]);
/** Options naming a file the tool reads (`-f Makefile`, `--config x`, `-r requirements.txt`). */
const FILE_OPTIONS = new Set(["-f", "--file", "-c", "--config", "--config-file", "--rcfile", "-r", "--requirement", "--constraint", "-p", "--project", "--env-file", "--settings", "-C"]);
const FILE_OPTION_TOOLS = new Set(["make", "docker", "docker-compose", "awk", "gawk", "pip", "pip3", "pytest", "tsc", "eslint", "prettier", "jest", "vitest", "mypy", "ruff", "pylint", "flake8", "black", "uv", "terraform", "alembic", "gradle", "mvn", "cmake", "helm", "kubectl", "ansible-playbook"]);
@@ -300,7 +314,7 @@ export function shellCommandUses(command: string, cwd: string, home: string | nu
const seen = new Set<string>();
try {
let dir = cwd;
- const add = (raw: string | undefined, op: ShellUseOp, at = dir) => {
+ const add = (raw: string | undefined, op: ShellUseOp, at = dir, implicit = false) => {
if (out.length >= MAX_USES || raw === undefined) return;
const word = cleanPathWord(raw);
if (!word) return;
@@ -313,7 +327,7 @@ export function shellCommandUses(command: string, cwd: string, home: string | nu
const key = `${op}\0${path}`;
if (seen.has(key)) return;
seen.add(key);
- out.push({ path, op });
+ out.push(implicit ? { path, op, implicit: true } : { path, op });
};
const tokens = shellTokens(command);
// Simple commands between control operators.
@@ -542,6 +556,56 @@ export function shellCommandUses(command: string, cwd: string, home: string | nu
for (const word of operands(args)) add(word, "write", commandDir);
continue;
}
+ if (name === "git") {
+ // The user's git config, which every git command loads.
+ for (const file of GIT_HOME_CONFIGS) add(file, "read", commandDir, true);
+ let at = commandDir;
+ let index = 0;
+ // Global options before the sub-command (`-C dir`, `-c key=value`, `--git-dir=x`).
+ while (index < args.length && args[index]!.startsWith("-")) {
+ const option = args[index]!;
+ if (option === "-C" && args[index + 1] !== undefined) {
+ const target = args[index + 1]!;
+ const expanded = target === "~" || target.startsWith("~/") ? (home ? join(home, target.slice(2)) : null) : target;
+ if (expanded) at = resolve(at, expanded);
+ index += 2;
+ continue;
+ }
+ index += GIT_VALUE_OPTIONS.has(option) ? 2 : 1;
+ }
+ const sub = args[index];
+ const rest = args.slice(index + 1);
+ if (sub === "config") {
+ // Keys and values are not paths; only `--file`/`-f` names one, and a write goes to its file.
+ let file: string | null = null;
+ let scope: "global" | "system" | "local" = "local";
+ let write = false;
+ const positional: string[] = [];
+ for (let at2 = 0; at2 < rest.length; at2 += 1) {
+ const word = rest[at2]!;
+ if (word === "-f" || word === "--file") {
+ file = rest[at2 + 1] ?? null;
+ at2 += 1;
+ } else if (word.startsWith("--file=")) file = word.slice("--file=".length);
+ else if (word === "--global") scope = "global";
+ else if (word === "--system") scope = "system";
+ else if (GIT_CONFIG_WRITES.has(word) || GIT_CONFIG_WRITES.has(word.split("=")[0]!)) write = true;
+ else if (GIT_CONFIG_VALUE_OPTIONS.has(word)) at2 += 1;
+ else if (!word.startsWith("-")) positional.push(word);
+ }
+ // `git config set|unset ...` (git 2.46+), or `git config <key> <value>`.
+ if (positional[0] === "set" || positional[0] === "unset" || positional[0] === "rename-section" || positional[0] === "remove-section") write = true;
+ else if (positional[0] !== "get" && positional[0] !== "list" && positional.length >= 2) write = true;
+ if (file) add(file, write ? "write" : "read", at);
+ else if (write && scope === "global") add("~/.gitconfig", "write", at);
+ else if (write && scope === "local") add(".git/config", "write", at);
+ continue;
+ }
+ // Other sub-commands: only explicit pathspecs after `--`.
+ const separator = rest.indexOf("--");
+ if (separator >= 0) for (const word of rest.slice(separator + 1)) if (looksLikePath(word)) add(word, "read", at);
+ continue;
+ }
if (name === "tar") {
const mode = args.find((word) => /^-?[a-zA-Z]*[ctxru][a-zA-Z]*$/.test(word)) ?? "";
const fIndex = args.findIndex((word) => word === "-f" || word === "--file" || /^-?[a-zA-Z]*f$/.test(word));
diff --git a/apps/server/src/session-archive/files-used.test.ts b/apps/server/src/session-archive/files-used.test.ts
index 6927a83a..decd14aa 100644
--- a/apps/server/src/session-archive/files-used.test.ts
+++ b/apps/server/src/session-archive/files-used.test.ts
@@ -69,9 +69,23 @@ describe("shell command parsing (shared with the CLI)", () => {
expect(uses("sed -i 's/a/b/' conf.ini")).toEqual(["write /w/conf.ini"]);
});
+ test("git: every command loads the user's git config (implicit); config keys and values are not paths; pathspecs only after --", () => {
+ const git = (command: string) => shell.shellCommandUses(command, "/w", "/home/u").map((use) => `${use.op} ${use.path}${use.implicit ? " (implicit)" : ""}`).sort();
+ const config = ["read /home/u/.config/git/config (implicit)", "read /home/u/.gitconfig (implicit)"];
+ expect(git("git config --global --get user.name")).toEqual(config);
+ expect(git("git config --get-all remote.origin.url")).toEqual(config);
+ expect(git("git log -1")).toEqual(config);
+ expect(git("git add src/a.py")).toEqual(config);
+ expect(git("git config user.email [email protected]")).toEqual([...config, "write /w/.git/config"].sort());
+ expect(git("git config --global core.editor vim")).toEqual([...config, "write /home/u/.gitconfig"].sort());
+ expect(git("git config -f ci/git.cfg --get x.y")).toEqual([...config, "read /w/ci/git.cfg"].sort());
+ expect(git("git -C sub diff HEAD~1 -- src/a.py README.md")).toEqual([...config, "read /w/sub/README.md", "read /w/sub/src/a.py"].sort());
+ });
+
test("variables, globs, URLs and options are never paths", () => {
expect(uses("curl -s https://example.com/a.json -o $OUT; ls *.py; echo $HOME/x")).toEqual([]);
- expect(uses("git commit -m 'fix: a.b'")).toEqual([]);
+ // A commit message is no path (git's own config reads are the only uses).
+ expect(uses("git commit -m 'fix: a.b'")).toEqual(["read /home/u/.config/git/config", "read /home/u/.gitconfig"]);
});
});
@@ -94,7 +108,10 @@ describe("policy (shared with the CLI)", () => {
test("home settings only through the allowlist; dependency and build folders hash only; system files never", () => {
expect(classify("/home/u/.gitconfig")).toBe("home stage captured");
- expect(classify("/home/u/.npmrc")).toBe("home stage captured");
+ expect(classify("/home/u/.npmrc")).toBe("home hold denylisted");
+ expect(classify("/home/u/.pypirc")).toBe("home hold denylisted");
+ expect(classify("/home/u/.yarnrc.yml")).toBe("home stage captured");
+ expect(classify("/home/u/.config/pip/pip.conf")).toBe("home stage captured");
expect(classify("/home/u/.bashrc")).toBe("home hold not_allowlisted");
expect(classify("/home/u/.cache/pip/x.whl")).toBe("home hold dependency_dir");
expect(classify("/w/node_modules/a/index.js")).toBe("project hold dependency_dir");
@@ -303,7 +320,7 @@ describe("a files-used chain", () => {
const script = write(join(scratch, "gen.py"), "print(open('config.local.yaml').read())\n");
const call1 = toolPart("call_1", "write", { filePath: script, content: "..." });
await tracker.toolCallEnded(sessionId, root, callOf(call1));
- const call2 = toolPart("call_2", "bash", { command: `python3 ${script} config.local.yaml && cat ~/.gitconfig ~/.npmrc ~/.bashrc .env node_modules/a/index.js && rm ${script}` });
+ const call2 = toolPart("call_2", "bash", { command: `python3 ${script} config.local.yaml && git config --global --get user.name && cat ~/.npmrc ~/.bashrc .env node_modules/a/index.js && rm ${script}` });
await tracker.toolCallEnded(sessionId, root, callOf(call2));
rmSync(script);
// Written by the script without being named: only the end-of-turn snapshot sees it.
@@ -324,11 +341,14 @@ describe("a files-used chain", () => {
expectItem("config.local.yaml", "project", "read", true, "captured");
expectItem("results/report.csv", "project", "write", true, "captured");
expectItem(join(home, ".gitconfig"), "home", "read", true, "captured");
- expectItem(join(home, ".npmrc"), "home", "read", true, "captured");
+ expectItem(join(home, ".npmrc"), "home", "read", false, "denylisted");
expectItem(join(home, ".bashrc"), "home", "read", false, "not_allowlisted");
expectItem(".env", "project", "read", false, "denylisted");
expectItem("node_modules/a/index.js", "project", "read", false, "dependency_dir");
expect(items.get(script)!.call_id).toBe("call_1");
+ // git loaded ~/.gitconfig without naming it (listed, scrubbed); ~/.config/git/config is not there (not listed).
+ expect(items.has(join(home, ".config", "git", "config"))).toBe(false);
+ expect([...items.keys()].some((key) => key.endsWith("user.name"))).toBe(false);
// Hashes the turn end left to the scan come from the chain.
expect(items.get("config.local.yaml")!.sha256).toBe(sha256("mode: local\n"));
expect(items.get("results/report.csv")!.sha256).toBe(sha256("a,b\n1,2\n"));
diff --git a/apps/server/src/session-archive/files-used.ts b/apps/server/src/session-archive/files-used.ts
index 5df60601..da2c7dab 100644
--- a/apps/server/src/session-archive/files-used.ts
+++ b/apps/server/src/session-archive/files-used.ts
@@ -367,9 +367,12 @@ function patchPaths(value: unknown): string[] {
}
/** The files one tool call names, absolute, with how it used them: file tool paths and shell command words. */
-export function toolCallUses(call: UsedToolCall, root: string, home: string | null): Array<{ path: string; op: FilesUsedOp }> {
+export function toolCallUses(call: UsedToolCall, root: string, home: string | null): Array<{ path: string; op: FilesUsedOp; implicit?: true }> {
const out = new Map<string, FilesUsedOp>();
- const add = (raw: unknown, op: FilesUsedOp, cwd: string) => {
+ /** Paths only ever read implicitly (a config a program loads): not listed when they are not there. */
+ const implicit = new Set<string>();
+ const explicit = new Set<string>();
+ const add = (raw: unknown, op: FilesUsedOp, cwd: string, unnamed = false) => {
if (out.size >= MAX_CALL_USES || typeof raw !== "string") return;
const value = raw.trim();
if (!value || value.length > 4_096 || value.includes("\0") || value.includes("\n") || value.includes("://")) return;
@@ -377,6 +380,7 @@ export function toolCallUses(call: UsedToolCall, root: string, home: string | nu
if (!expanded) return;
const path = resolve(cwd, expanded);
out.set(path, strongerOp(out.get(path) ?? op, op));
+ (unnamed ? implicit : explicit).add(path);
};
const input = call.input;
const cwdValue = CWD_KEYS.map((key) => text(input[key])).find(Boolean);
@@ -385,7 +389,7 @@ export function toolCallUses(call: UsedToolCall, root: string, home: string | nu
for (const key of ["command", "cmd", "script"]) {
const value = input[key];
const command = typeof value === "string" ? value : Array.isArray(value) && value.every((item) => typeof item === "string") ? value.join(" ") : null;
- if (command) for (const use of shellCommandUses(command, cwd, home)) add(use.path, use.op, cwd);
+ if (command) for (const use of shellCommandUses(command, cwd, home)) add(use.path, use.op, cwd, use.implicit === true);
}
} else {
const op: FilesUsedOp | null = WRITE_TOOLS.has(call.tool) ? "write" : READ_TOOLS.has(call.tool) ? "read" : null;
@@ -396,7 +400,7 @@ export function toolCallUses(call: UsedToolCall, root: string, home: string | nu
}
for (const key of ["patchText", "patch", "input", "content"]) for (const path of patchPaths(input[key])) add(path, "write", cwd);
}
- return [...out].map(([path, op]) => ({ path, op }));
+ return [...out].map(([path, op]) => (implicit.has(path) && !explicit.has(path) ? { path, op, implicit: true as const } : { path, op }));
}
/** The files under a temp folder a call named that changed during the call (mtime or ctime in its window). */
@@ -611,7 +615,7 @@ export class FilesUsedTracker {
}
/** A call's files: what it names, and the files changed during it in a temp folder it names. */
- private async callFiles(call: UsedToolCall, root: string, context: UseContext): Promise<Array<{ path: string; op: FilesUsedOp }>> {
+ private async callFiles(call: UsedToolCall, root: string, context: UseContext): Promise<Array<{ path: string; op: FilesUsedOp; implicit?: true }>> {
const uses = toolCallUses(call, root, this.home);
if (!SHELL_TOOLS.has(call.tool) || call.start === null) return uses;
const out = [...uses];
@@ -690,15 +694,17 @@ export class FilesUsedTracker {
state.turn += 1;
const context = await this.useContext(root);
const limits = store.currentLimits;
- const uses = new Map<string, { op: FilesUsedOp; callId: string | null }>();
+ const uses = new Map<string, { op: FilesUsedOp; callId: string | null; implicit: boolean }>();
const calls = usedToolCalls(messages);
for (const call of calls) {
result.staged += await this.keepCall(sessionId, root, call);
for (const use of await this.callFiles(call, root, context)) {
const absolute = (await canonicalFile(use.path)) ?? resolve(use.path);
const known = uses.get(absolute);
- if (known) known.op = strongerOp(known.op, use.op);
- else if (uses.size < MAX_FILES_USED_ITEMS) uses.set(absolute, { op: use.op, callId: state.firstCall.get(absolute) ?? call.callId });
+ if (known) {
+ known.op = strongerOp(known.op, use.op);
+ known.implicit &&= use.implicit === true;
+ } else if (uses.size < MAX_FILES_USED_ITEMS) uses.set(absolute, { op: use.op, callId: state.firstCall.get(absolute) ?? call.callId, implicit: use.implicit === true });
}
}
// The end-of-turn snapshot: files of the project created or changed during the turn (gitignored ones
@@ -708,7 +714,7 @@ export class FilesUsedTracker {
const realRoot = (await pathForms(root)).at(-1) ?? root;
for (const file of await changedSince(realRoot, since, Math.min(deadline, started + SNAPSHOT_BUDGET_MS))) {
if (uses.has(file) || uses.size >= MAX_FILES_USED_ITEMS) continue;
- uses.set(file, { op: "write", callId: null });
+ uses.set(file, { op: "write", callId: null, implicit: false });
result.snapshot += 1;
}
}
@@ -720,7 +726,8 @@ export class FilesUsedTracker {
// hashed here while the budget lasts; a denylisted one never is.
const hashBytes = kind.plan === "hold" && kind.reason !== "denylisted" && this.now() < deadline ? limits.maxFileBytes : -1;
const facts = await fileFacts(absolute, hashBytes);
- if (facts === "not_file") continue;
+ // A config a program loads without naming it is listed only when it is there.
+ if (facts === "not_file" || (facts === "missing" && use.implicit)) continue;
const present = facts !== "missing";
let size = present ? facts.size : null;
let sha256 = present ? facts.sha256 : null;
diff --git a/docs/project-archive.md b/docs/project-archive.md
index 43f8d14b..ac2b1dd7 100644
--- a/docs/project-archive.md
+++ b/docs/project-archive.md
@@ -217,9 +217,10 @@ What is saved and what is not:
- Files inside the project folder are saved like touched files, gitignored
inputs included.
- Temporary files are copied when the tool call that used them ends.
-- In the home folder, only allowlisted config files (`.gitconfig`, `.npmrc`,
+- In the home folder, only allowlisted config files (`.gitconfig`,
`.yarnrc`, `pip.conf`, `uv.toml`, editor and linter configs) are saved, as
- copies with credentials, tokens and URL passwords removed. Other dotfiles and
+ copies with credentials, tokens and URL passwords removed. `.npmrc` and
+ `.pypirc` are credential files and are never saved. Other dotfiles and
settings folders are listed but never saved. Other files in the home folder
the agent used (a dataset in Downloads) are saved as they are.
- Never saved: `.env` files, keys, credential stores, tokens, caches and