A desktop coding agent with free access to frontier models.
TypeScript
fix: keep source files in project copies
ogsamrat6124724a9cf7
diff --git a/apps/server/src/capture-context.test.ts b/apps/server/src/capture-context.test.tsindex 2e7d1a14..f3b317ec 100644--- a/apps/server/src/capture-context.test.ts+++ b/apps/server/src/capture-context.test.ts@@ -844,12 +844,12 @@ test("CLI/desktop parity: the context modules match PARITY.sha256 (the same listfor (const name of files) assert.equal(createHash("sha256").update(fs.readFileSync(path.join(contextDir, name))).digest("hex"), listed.get(name), `${name} changed: port it to the CLI and update PARITY.sha256 in both`);});-test("CLI/desktop parity: the shared session-archive modules match their PARITY.sha256 (auto compact, late writes, tool start, turn writers, turn prompts)", async () => {+test("CLI/desktop parity: the shared session-archive modules match their PARITY.sha256 (auto compact, code files, late writes, tool start, turn writers, turn prompts)", async () => {const { createHash } = await import("node:crypto");const dir = path.join(import.meta.dir, "session-archive");const lines = fs.readFileSync(path.join(dir, "PARITY.sha256"), "utf8").split("\n").filter((line) => line && !line.startsWith("#"));const listed = new Map(lines.map((line) => { const [hash, name] = line.split(/\s+/); return [name, hash]; }));- assert.deepEqual([...listed.keys()].sort(), ["auto-compact.ts", "late-writes.ts", "tool-start.ts", "turn-overlap.ts", "turn-prompts.ts", "turn-writers.ts"]);+ assert.deepEqual([...listed.keys()].sort(), ["auto-compact.ts", "code-files.ts", "late-writes.ts", "tool-start.ts", "turn-overlap.ts", "turn-prompts.ts", "turn-writers.ts"]);for (const [name, hash] of listed) assert.equal(createHash("sha256").update(fs.readFileSync(path.join(dir, name))).digest("hex"), hash, `${name} changed: port it to the CLI and update PARITY.sha256 in both`);});diff --git a/apps/server/src/session-archive/PARITY.sha256 b/apps/server/src/session-archive/PARITY.sha256index 6572c3c0..d8b6ae28 100644--- a/apps/server/src/session-archive/PARITY.sha256+++ b/apps/server/src/session-archive/PARITY.sha256@@ -6,3 +6,4 @@38dc65a461de6905134c22837f5230d03383ec0bdd6df35090dd269160446edf turn-overlap.ts1906cab8c93370abd1d024d3552fe919a0006af9ebef084ada7b64c290d1bc95 turn-writers.ts55e5e322b2c372b77714eb3677bee6ea0f3e0a11120ba6edc7d202c264a3d7e8 turn-prompts.ts+a64925d3546bf3b087677ac46d9a3b18a2f8178bb1258246e4f9504e1085d5fa code-files.tsdiff --git a/apps/server/src/session-archive/code-files.ts b/apps/server/src/session-archive/code-files.tsnew file mode 100644index 00000000..fd9ce575--- /dev/null+++ b/apps/server/src/session-archive/code-files.ts@@ -0,0 +1,43 @@+/**+ * Source files in the project archive. The credential denylist the archive+ * shares with the session uploader judges a path by its words: a folder+ * named `keys`, `secrets` or `credentials`, a name like `secret.rs` or+ * `token.php`. For program source that is a wrong call: `src/config/secret.rs`,+ * `lib/core/secrets/secret_store.dart` or `PhpParser/Token.php` are code the+ * agent reads and edits, and leaving them out leaves a hole in the project.+ * A file with a source-code extension is therefore archived whatever its name+ * or folder says (its text goes through the export pass like any project+ * file), unless a folder above it is a credential store of its own (`.ssh`,+ * `.aws`, `.gnupg`). Data, config, docs and script files (`.json`, `.yml`,+ * `.env`, `.md`, `.sh`, `.cmd`, ...) keep the denylist: they are where real+ * keys are kept. Identical in the CLI and the desktop app (PARITY.sha256).+ */++/** Program source extensions (lower case, with the dot). */+export const ARCHIVE_CODE_EXTENSIONS: ReadonlySet<string> = new Set([+ ".c", ".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".m", ".mm",+ ".cs", ".fs", ".vb",+ ".go", ".rs", ".zig", ".nim", ".v",+ ".java", ".kt", ".kts", ".scala", ".groovy", ".clj", ".cljs",+ ".swift", ".dart",+ ".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts", ".vue", ".svelte", ".astro",+ ".py", ".pyi", ".rb", ".php", ".pl", ".pm", ".lua", ".r", ".jl",+ ".ex", ".exs", ".erl", ".hrl", ".hs", ".ml", ".mli", ".elm",+ ".sol", ".proto", ".graphql", ".gql",+]);++/** Folders that are credential stores whatever they hold. */+const CREDENTIAL_STORE_DIRS: ReadonlySet<string> = new Set([".ssh", ".aws", ".gnupg"]);++/**+ * Whether a project-relative path (split on `/`) is program source that the+ * archive keeps even when the credential denylist matches its name or a+ * folder above it.+ */+export function isArchiveCodeFile(parts: readonly string[]): boolean {+ const name = parts[parts.length - 1]?.toLowerCase() ?? "";+ if (name.startsWith(".env")) return false;+ const dot = name.lastIndexOf(".");+ if (dot <= 0 || !ARCHIVE_CODE_EXTENSIONS.has(name.slice(dot))) return false;+ return !parts.slice(0, -1).some((part) => CREDENTIAL_STORE_DIRS.has(part.toLowerCase()));+}diff --git a/apps/server/src/session-archive/manifest.test.ts b/apps/server/src/session-archive/manifest.test.tsindex 6370ee18..4a99cfb0 100644--- a/apps/server/src/session-archive/manifest.test.ts+++ b/apps/server/src/session-archive/manifest.test.ts@@ -60,6 +60,46 @@ describe("credential filter", () => {});});+describe("source files named like keys", () => {+ // Program source whose name or folder reads like a credential store is+ // project code: a plain project folder and a git repository both keep it,+ // while real key, env and config files stay out.+ const code = [+ "src/config/secret.rs",+ "lib/core/secrets/secret_store.dart",+ "secret_management.py",+ "vendor-src/PhpParser/Token.php",+ "src/keys/keys.mjs",+ "app/credentials/provider.ts",+ ];+ const leftOut = [".env", "config/secrets.json", "credentials.yml", "certs/server.key", "Set Keys.cmd", "deploy/.ssh/helper.py"];++ test("the credential filter keeps them", () => {+ for (const path of code) expect(isArchiveCredentialPath(path)).toBe(false);+ for (const path of leftOut) expect(isArchiveCredentialPath(path)).toBe(true);+ });++ for (const withGit of [false, true]) {+ test(`${withGit ? "a git repository" : "a plain project folder"} archives them`, async () => {+ const root = await tempDir("codenames");+ for (const path of ["package.json", ...code, ...leftOut]) {+ await mkdir(join(root, path, ".."), { recursive: true });+ await writeFile(join(root, path), `${path}\n`);+ }+ if (withGit) {+ await git(root, "init", "-q");+ await git(root, "add", "package.json", ...code);+ await git(root, "commit", "-qm", "init");+ }+ const { entries, excluded } = await scanArchiveTree(root);+ const paths = entries.map((entry) => entry.path);+ for (const path of code) expect(paths).toContain(path);+ for (const path of leftOut) expect(paths).not.toContain(path);+ expect(excluded.credential).toBe(leftOut.length);+ });+ }+});+describe("scan", () => {test("the whole folder: .git and unignored build content present, gitignored content absent; exclusions counted", async () => {const root = await tempDir("scan");diff --git a/apps/server/src/session-archive/manifest.ts b/apps/server/src/session-archive/manifest.tsindex 96831e15..34c85f27 100644--- a/apps/server/src/session-archive/manifest.ts+++ b/apps/server/src/session-archive/manifest.ts@@ -14,6 +14,7 @@ import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";import { clampUploadBytes, isUploadPathDenied, REGENERABLE_DIR_NAMES, stripRemoteUserinfo } from "../session-uploader.js";import { ATTACHMENTS_ROOT_NAME } from "./attachments.js";+import { isArchiveCodeFile } from "./code-files.js";import type { ExcludedList, ExcludedReason } from "./capture-v2.js";import { gitSkipReason } from "../command-guard.js";import { hintGarbageCollection } from "./files.js";@@ -171,14 +172,15 @@ export function compareArchivePaths(left: string, right: string): number {/*** True when a file or symlink must be left out of the archive (section 5.3):- * the session uploader's credential denylist, with git internals exempt and- * `node_modules` not counted as a denial.+ * the session uploader's credential denylist, with git internals exempt,+ * `node_modules` not counted as a denial, and program source kept whatever+ * its name or folder says (code-files.ts).*/export function isArchiveCredentialPath(relPath: string): boolean {const parts = relPath.split("/");if (parts.some((part) => part.toLowerCase() === ".git")) return false;const rest = parts.filter((part) => part.toLowerCase() !== "node_modules");- return rest.length > 0 && isUploadPathDenied(rest.join("/"));+ return rest.length > 0 && isUploadPathDenied(rest.join("/")) && !isArchiveCodeFile(rest);}/** workspace.label: the root's basename, at most 255 UTF-8 bytes. */