A desktop coding agent with free access to frontier models.
TypeScript
fix: include .env example files
ogsamrat408f5c700c08
diff --git a/apps/server/src/context/PARITY.sha256 b/apps/server/src/context/PARITY.sha256index 04075aa1..1bbe4c09 100644--- a/apps/server/src/context/PARITY.sha256+++ b/apps/server/src/context/PARITY.sha256@@ -12,8 +12,8 @@ d772119f2785b6926cd765a44589c171542d5e79b3677bfa076851775d794480 outside.tsd7c5638ca9204a9c51a4552e7a9b09cf7beeae9c63d9352d5950118fd5536967 pm-config.ts932c1eff09d540590abf99ede63447f4e0af9396096d325fa5fcfbcde49eda10 privacy.ts0e04845a2d0ad2136c01a61d3ed1193b62ef99f5b82e1f555b7c97bb6dc18773 processes.ts-d7cb7384da5a3b2c7e82a45f05f1b9258bb84a7f3510de8eb6f1da478b4157f0 redact-policy.ts-ecb628437615d261d3f7f1f02bc05ce000b16b1040c5804e8ffaf9d7ed9fe471 redact-vectors.json+741f4327c70500feb644c8e0820060097e282ff1f121dba8ce1979604867bbc0 redact-policy.ts+820d0a976b16769db789e9b5b3162f3cff096ab7948dcac54d009943a4557492 redact-vectors.jsond8c0636406c8cd9d55f9fb06af8827b3d1b73247393f48aaca2ef053ccf5a1ff services.ts92030e186fcd58a6acaeb9acbaac67c8003d12d0c2eb9e29113faa701885b0eb setup.tsd51d434283f757f0ed45bb6996a74fb5bf9e1d56f34146e99df3c392cde5ea19 shell-aliases.tsdiff --git a/apps/server/src/context/redact-policy.ts b/apps/server/src/context/redact-policy.tsindex f45b12b8..d9901487 100644--- a/apps/server/src/context/redact-policy.ts+++ b/apps/server/src/context/redact-policy.ts@@ -143,7 +143,7 @@ export function looksRandomName(value: string): boolean {/*** Credential files: any non-placeholder value of a secret-named key there is- * a credential. `.env*` except examples and templates, `.npmrc`, `.pypirc`,+ * a credential. `.env*` except examples and templates, `*.env`, `.npmrc`, `.pypirc`,* `.netrc`, `.pgpass`, `.git-credentials`, `credentials` (`.aws/credentials`),* kubeconfig.*/@@ -151,6 +151,8 @@ export function isCredentialFile(path: string | undefined): boolean {if (!path) return false;const name = path.split(/[\\/]/).pop()!.toLowerCase();if (name.startsWith(".env")) return !/(?:example|sample|template|dist|defaults?)$/.test(name);+ // A named env file (`prod.env`, `docker/production.env`) is a `.env` by another name.+ if (/^.+\.env$/.test(name)) return true;return [".npmrc", ".pypirc", ".netrc", "_netrc", ".pgpass", ".git-credentials", "credentials", "kubeconfig", "config.kube"].includes(name)|| name.endsWith(".kubeconfig");}diff --git a/apps/server/src/context/redact-vectors.json b/apps/server/src/context/redact-vectors.jsonindex c9162e5a..00d4c0c8 100644--- a/apps/server/src/context/redact-vectors.json+++ b/apps/server/src/context/redact-vectors.json@@ -229,6 +229,12 @@"expect": "DB_PASSWORD=supersecretword","context": "app/.env.example"},+ {+ "name": "named env file any value",+ "input": "DB_PASSWORD=supersecretword",+ "expect": "DB_PASSWORD=[REDACTED]",+ "context": "docker/production.env"+ },{"name": "npmrc token","input": "//registry.npmjs.org/:_authToken=np⟨+⟩m_Oc6Qi7ggAMKfjlaTNJkd38tGFzUnusvrIPab",diff --git a/apps/server/src/session-archive/files-used-policy.ts b/apps/server/src/session-archive/files-used-policy.tsindex 0feb6592..0598f101 100644--- a/apps/server/src/session-archive/files-used-policy.ts+++ b/apps/server/src/session-archive/files-used-policy.ts@@ -168,7 +168,7 @@ const SECRET_WORD = /(?:^|[/._-])(?:secrets?|credentials?|tokens?|passwords?|pas/** Whether a path names a file that must never be archived (anywhere). */export function isSecretUsePath(absolute: string): boolean {const portable = absolute.replaceAll("\\", "/");- if (ENV_FILE.test(portable)) return !/\.env\.(?:example|sample|template|dist|defaults)$/i.test(portable);+ if (ENV_FILE.test(portable)) return !/\.env\.(?:example|sample|template|dist|defaults?)$/i.test(portable);if (isSecretFile(portable) || isSecretFolder(portable)) return true;return SECRET_WORD.test(portable.split("/").at(-1) ?? "");}diff --git a/apps/server/src/session-uploader.test.ts b/apps/server/src/session-uploader.test.tsindex 0ebc8d73..7cb9d451 100644--- a/apps/server/src/session-uploader.test.ts+++ b/apps/server/src/session-uploader.test.ts@@ -32,6 +32,7 @@ import {filterUploadDiff,isUploadableWebUrl,isUploadPathDenied,+ isUploadFileDenied,isPathLikeKey,isSecretAssignmentKey,isSecretAssignmentValue,@@ -70,6 +71,58 @@ describe("session uploader privacy", () => {expect(isUploadPathDenied("src/app.ts")).toBe(false);});+ test("keeps a .env template in scrubbed snapshots; the archive and every real .env still deny it", () => {+ for (const path of [".env.example", "app/.env.sample", "config/.env.template", ".env.dist", ".ENV.EXAMPLE", ".env.defaults"]) {+ expect(isUploadFileDenied(path)).toBe(false);+ // What is stored byte for byte never takes one.+ expect(isUploadPathDenied(path)).toBe(true);+ }+ for (const path of [".env", ".env.local", ".env.production", ".env.example.local", "secrets/.env.example", ".env.example/x.txt", "keys/.env.sample"]) {+ expect(isUploadFileDenied(path)).toBe(true);+ }+ // A template's values are scrubbed as its .env's would be, under both rule sets.+ const filled = "PORT=3000\nAPI_TOKEN=abcdefgh123\nDATABASE_PASSWORD=Summer2024!\nJWT_SECRET=supersecretjwt\nAPI_KEY=<your-api-key>\n";+ const policy = Symbol.for("omnirush.redactionPolicy");+ const holder = globalThis as unknown as Record<symbol, unknown>;+ const before = holder[policy];+ try {+ for (const rules of ["legacy", "client-v3"]) {+ holder[policy] = rules;+ for (const file of [".env.example", "app/.env.sample"]) {+ expect(redactUploadContent(file, filled)).toMatch(/^PORT=3000\nAPI_TOKEN=\[REDACTED[^\n]*\nDATABASE_PASSWORD=\[REDACTED[^\n]*\nJWT_SECRET=\[REDACTED[^\n]*\nAPI_KEY=<your-api-key>\n$/);+ const diff = filterUploadDiff(`diff --git a/${file} b/${file}\n--- a/${file}\n+++ b/${file}\n@@ -0,0 +1 @@\n+DATABASE_PASSWORD=Summer2024!\n`).diff;+ expect(diff).toMatch(/\+DATABASE_PASSWORD=\[REDACTED/);+ }+ }+ } finally {+ holder[policy] = before;+ }+ });++ test("denies a named env file (prod.env) everywhere and scrubs it as a credential file", () => {+ for (const path of ["prod.env", "app.env", "docker/production.env", "Config/Staging.ENV", ".local.env", "tests/fixtures/app.env"]) {+ expect(isUploadFileDenied(path)).toBe(true);+ expect(isUploadPathDenied(path)).toBe(true);+ }+ for (const path of ["src/env.ts", "prod.env.example", "environment.yml", "src/load.env.ts", "envs/readme.md"]) {+ expect(isUploadFileDenied(path)).toBe(false);+ }+ const policy = Symbol.for("omnirush.redactionPolicy");+ const holder = globalThis as unknown as Record<symbol, unknown>;+ const before = holder[policy];+ try {+ for (const rules of ["legacy", "client-v3"]) {+ holder[policy] = rules;+ for (const file of ["prod.env", "docker/production.env"]) {+ const text = redactUploadText("PORT=3000\nDATABASE_PASSWORD=Summer2024!\n", { context: file, mode: redactModeForPath(file) }).text;+ expect(text).toMatch(/^PORT=3000\nDATABASE_PASSWORD=\[REDACTED/);+ }+ }+ } finally {+ holder[policy] = before;+ }+ });+test("redacts private keys and provider-style secrets before upload", () => {const result = redactUploadText(["AWS_ACCESS_KEY_ID=AKIA1234567890123456",diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.tsindex dc0b7046..e49d5699 100644--- a/apps/server/src/session-uploader.ts+++ b/apps/server/src/session-uploader.ts@@ -1317,11 +1317,41 @@ function pathComponents(path: string): string[] {return path.replaceAll("\\", "/").split("/").filter(Boolean);}-/** The unconditional denials that apply to any component, directories included. */-function hasDeniedComponent(parts: string[]): boolean {+// A `.env` template FILE (`.env.example`, `.env.sample`, ...): the variable+// names a project needs, committed for others to copy. The files-used policy+// (session-archive/files-used-policy.ts) and context/redact-policy.ts already+// treat these templates as no credential; a turn that reads or edits one+// cannot be replayed while the snapshot withholds it.+const ENV_TEMPLATE = /^\.env\.(?:example|sample|template|dist|defaults?)$/;++function isEnvTemplate(parts: string[]): boolean {+ return ENV_TEMPLATE.test(parts.at(-1)?.toLowerCase() ?? "");+}++/**+ * A named env FILE (`prod.env`, `docker/production.env`): a `.env` by another+ * name, denied and scrubbed as one (redact-policy's isCredentialFile agrees).+ */+function isNamedEnvFile(lowerName: string): boolean {+ return /^.+\.env$/.test(lowerName);+}++/**+ * The scrub context of a file kept in the snapshot or the git block. A `.env`+ * template is scrubbed as its `.env`: redact-policy's isCredentialFile exempts+ * templates, so without this a secret-named value that does not look+ * generated (`DB_PASSWORD=Summer2024!`) would leave in a template that a+ * user filled with real values.+ */+function snapshotScrubContext(path: string): string {+ return isEnvTemplate(pathComponents(path)) ? path.replace(/\.[^./\\]+$/, "") : path;+}++/** The unconditional denials that apply to any component, directories included. `keepEnvFile`: the last component is a `.env` template to keep. */+function hasDeniedComponent(parts: string[], keepEnvFile = false): boolean {return parts.some((part, index) => {const lower = part.toLowerCase();- return lower.startsWith(".env")+ return (lower.startsWith(".env") && !(keepEnvFile && index === parts.length - 1))|| DENIED_EXACT_NAMES.has(lower)|| DENIED_SUFFIXES.some((suffix) => lower.endsWith(suffix))|| DENIED_CREDENTIAL_NAME.test(lower)@@ -1358,9 +1388,24 @@ export function isUploadDirectoryDenied(path: string): boolean {* extension, in which case it is kept and scrubbed like any other source file.*/export function isUploadPathDenied(path: string): boolean {+ return uploadPathDenied(path, false);+}++/**+ * The same rule for the snapshot's own files and git block, whose text is+ * scrubbed before it leaves: there a `.env` template is kept (isEnvTemplate).+ * Everything stored byte for byte (the project archive, files outside the+ * workspace, attachments) keeps to isUploadPathDenied.+ */+export function isUploadFileDenied(path: string): boolean {+ return uploadPathDenied(path, true);+}++function uploadPathDenied(path: string, scrubbed: boolean): boolean {const parts = pathComponents(path);- if (hasDeniedComponent(parts)) return true;+ if (hasDeniedComponent(parts, scrubbed && isEnvTemplate(parts))) return true;const name = parts.at(-1)?.toLowerCase();+ if (name && isNamedEnvFile(name)) return true;if (!name || hasScrubbedExtension(name)) return false;return parts.some((part) => hasDeniedWords(part.toLowerCase()));}@@ -1947,7 +1992,7 @@ function redactUploadContentCounted(path: string, text: string): { text: string;const json = redactUploadJsonText(text, path);if (json !== null) return { text: json, count: json === text ? 0 : 1 };}- return redactUploadText(text, { context: path, mode: redactModeForPath(path) });+ return redactUploadText(text, { context: snapshotScrubContext(path), mode: redactModeForPath(path) });}// --- file-aware trace scrub --------------------------------------------------@@ -2777,7 +2822,7 @@ async function walkFallback(} else await walkFallback(root, fullPath, ignoreRules, listing, priorityPaths);} else if (entry.isFile() || entry.isSymbolicLink()) {// Capture v2: a symlink is listed too (never followed; the scan records its target).- if (isUploadPathDenied(path)) {+ if (isUploadFileDenied(path)) {listing.denied += 1;if ((listing.deniedPaths ??= []).length < MAX_LISTED_EXCLUSIONS) listing.deniedPaths.push(path);} else listing.paths.push(path);@@ -2792,7 +2837,7 @@ function filterListing(candidates: string[], priorityPaths: ReadonlySet<string>let denied = 0;for (const path of candidates) {if (!path) continue;- if (isUploadPathDenied(path)) {+ if (isUploadFileDenied(path)) {denied += 1;if (deniedPaths.length < MAX_LISTED_EXCLUSIONS) deniedPaths.push(path);} else eligible.push(path);@@ -2965,7 +3010,7 @@ function parseGitStatus(raw: string, prefix = ""): { entries: GitStatusEntry[];const path = repoPath.slice(prefix.length);if (!path) continue;if (code !== "??" && code !== "!!") dirty = true;- if (isUploadPathDenied(path)) continue;+ if (isUploadFileDenied(path)) continue;if (entries.length >= MAX_GIT_STATUS_ENTRIES) continue;const uploadPath = portablePathForUpload(path);if (uploadPath.length > MAX_GIT_PATH_CHARS) continue;@@ -3067,14 +3112,14 @@ export function filterUploadDiff(raw: string, inputTruncated = false): { diff: sif (!section.startsWith("diff --git ")) continue;const headerEnd = section.indexOf("\n");const path = diffHeaderPath(headerEnd === -1 ? section : section.slice(0, headerEnd));- if (!path || isUploadPathDenied(path)) continue;+ if (!path || isUploadFileDenied(path)) continue;if (/^(?:Binary files .* differ|GIT binary patch)/m.test(section)) continue;// Capture v2: a binary type is never diffed as text (its bytes go to the byte-exact archive), and// a section that was not valid UTF-8 (utf8DiffText) never reaches here.if (isKnownBinaryPath(path)) continue;// A diff is text even when the file is JSON: hunks are not parseable documents.// Each file's section under the mode its path selects, as the file's snapshot.- const redacted = redactUploadText(section, { context: path, mode: redactModeForPath(path) }).text;+ const redacted = redactUploadText(section, { context: snapshotScrubContext(path), mode: redactModeForPath(path) }).text;const size = Buffer.byteLength(redacted);if (used + size > MAX_UPLOAD_DIFF_BYTES) {truncated = true;@@ -5303,7 +5348,7 @@ export class SessionUploader {const path = workspaceRelativePath(state.root, prefix ? `${prefix}/${relative}` : relative);if (!path) return;this.reportTouched(state, path);- if (isUploadPathDenied(path)) return;+ if (isUploadFileDenied(path)) return;if (path === ".gitignore" || path.endsWith("/.gitignore")) {// New ignore rules can hide or reveal any number of files: forget what// git answered so far and rescan the tree with the rules as they stand.@@ -5666,7 +5711,7 @@ export class SessionUploader {state.turnWrittenPaths.set(path, Date.now());state.turnToolWrites.add(path);}- if (isUploadPathDenied(path) || state.touchedPaths.has(path)) return;+ if (isUploadFileDenied(path) || state.touchedPaths.has(path)) return;state.touchedPaths.add(path);this.markDirty(state, path);this.queueChangedPath(state, path);@@ -6377,7 +6422,7 @@ export class SessionUploader {private queueChangedPath(state: SessionState, filename: string): void {if (state.finished) return;const path = workspaceRelativePath(state.root, filename);- if (!path || isUploadPathDenied(path)) return;+ if (!path || isUploadFileDenied(path)) return;// Several events for one path before its capture starts collapse into one read.if (state.pendingJournal.has(path)) return;state.pendingJournal.add(path);@@ -6514,7 +6559,7 @@ export class SessionUploader {// listing vouches for (the paths a targeted scan inspects, and every// journal entry), in one batch: nothing git ignores now leaves the// machine, whatever it answered when the event arrived.- const reported = targeted && previous !== null ? [...dirty].filter((path) => !isUploadPathDenied(path)) : [];+ const reported = targeted && previous !== null ? [...dirty].filter((path) => !isUploadFileDenied(path)) : [];const journaled = type === "change" || type === "end" ? [...state.changeJournal.values()] : [];const checked = [...new Set([...reported, ...journaled.map((entry) => entry.path)])];const ignored = checked.length > 0 ? await this.ignoredPaths(state, checked, true) : new Set<string>();