Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

feat(archive): archive a session folder that sits inside a git repository

ogsamratce8c43a29bbb
diff --git a/apps/server/src/session-archive/README.md b/apps/server/src/session-archive/README.md
index b3a3e34b..5da2f169 100644
--- a/apps/server/src/session-archive/README.md
+++ b/apps/server/src/session-archive/README.md
@@ -25,7 +25,7 @@ The user-facing description is `docs/project-archive.md`.
| File | Responsibility |
| --- | --- |
-| `detect.ts` | `isArchivableProject(root, detectors?, options?)` and `gitMarkerDetector` (section 4). A pluggable gate; only the `.git` marker is enabled |
+| `detect.ts` | `isArchivableProject(root, detectors?, options?)`, `gitMarkerDetector` and `gitParentDetector` (section 4). A pluggable gate; only the `.git` marker is enabled, in the root or (`git_parent`) in the nearest parent, never at home, a filesystem, drive, share or mount root, or in a system or app directory. A `git_parent` root is archived alone, without the parent's `.git` |
| `manifest.ts` | Scan with the exclusions and credential filter (5.2, 5.3; reuses the collector's `isCollectorPathDenied`, `stripRemoteUserinfo` and `clampCollectorBytes`), streaming SHA-256 with the `(path, size, mtimeNs, ctimeNs, ino)` hash cache, delta computation (5.8), `manifest.json` (5.6) and the git block |
| `pack.ts` | Streaming pax tar writer (5.5) with unstable-entry detection (5.9), and the file -> tar -> zstd -> ORSEAL01 -> temp file pipeline (5.10, 13.1) |
| `seal.ts` | Streaming ORSEAL01 sealer and opener (section 6) over Node `crypto` |
@@ -172,7 +172,7 @@ void sessionArchiver.captureBase(sessionId, root, completedTurns).then(() => ses
- `root` is the folder the agent started in (`input.workspace.path`), as a real path: the gate `lstat`s it and refuses a symlinked root. The home directory, a filesystem root and the app's own directories are always refused.
- `completedTurns` is 0 for a new session. For a resumed session, it is the number of turns the session has already completed.
-- The call is cheap when there is nothing to do. With a base already captured, it only reads the session record, with no network. Without `.git`, it runs two `lstat` calls. Otherwise it fetches `GET /archives/key`, which also checks the archive consent: a 428 means nothing is packed.
+- The call is cheap when there is nothing to do. With a base already captured, it only reads the session record, with no network. Without `.git`, it runs a few `lstat` calls: the root, then its parents up to the nearest `.git`, home or a guarded directory. Otherwise it fetches `GET /archives/key`, which also checks the archive consent: a 428 means nothing is packed.
- Child (sub-agent) sessions share the parent's root and must not be archived. Call this for root sessions only.
- Keep a per-process `Set` of session ids already handed to `captureBase`. `startSession` runs on every prompt dispatch, and each `captureBase` call on a session without a base re-checks consent with one GET.
@@ -298,7 +298,7 @@ cd apps/server && bun --conditions=development test src/session-archive
- pax header edge cases;
- a multi-MiB `writeSealedArchive` round trip checked with the `zstd` CLI.
- `manifest.test.ts`: UTF-8 byte order; the credential filter; the exclusions (credential, FIFO, app state, `__omnirush__`, unreadable, non-UTF-8); the hash cache; delta for add, modify (content and mode), delete, rename, file to dir, dir to file and symlink retarget; unstable re-send; `.git` changes; manifest JSON; the git block; `git status` never rewriting `.git/index`.
-- `detect.test.ts`: a `.git` dir; a gitfile; no `.git`; an invalid gitfile; a `.git` symlink; home, `/` and app dirs refused; `root_not_directory`; detector plug-ins.
+- `detect.test.ts`: a `.git` dir; a gitfile; no `.git`; an invalid gitfile; a `.git` symlink; home, `/` and app dirs refused; `root_not_directory`; detector plug-ins; `git_parent` (nearest parent wins, root `.git` preferred, dotfiles home, system dirs, posix and `path.win32` walks).
- `upload.test.ts` (in-process fake API and S3):
- the happy path;
- resume after a failed part;
diff --git a/apps/server/src/session-archive/detect.test.ts b/apps/server/src/session-archive/detect.test.ts
index 5eeb905e..05b3c558 100644
--- a/apps/server/src/session-archive/detect.test.ts
+++ b/apps/server/src/session-archive/detect.test.ts
@@ -1,9 +1,9 @@
import { afterEach, describe, expect, test } from "bun:test";
-import { mkdir, symlink, writeFile } from "node:fs/promises";
+import { mkdir, rm, symlink, writeFile } from "node:fs/promises";
import { homedir } from "node:os";
-import { join } from "node:path";
+import { join, posix, win32 } from "node:path";
-import { gitMarkerDetector, isArchivableProject, type ProjectMarkerDetector } from "./detect.js";
+import { gitMarkerDetector, gitParentCandidates, gitParentDetector, isArchivableProject, type ProjectMarkerDetector } from "./detect.js";
import { cleanupTempDirs, tempDir } from "./test-helpers.js";
afterEach(cleanupTempDirs);
@@ -81,4 +81,99 @@ describe("project gate", () => {
expect(await isArchivableProject(root, [broken, invalid, blend])).toEqual({ archivable: true, reason: "blend_file", marker: "*.blend" });
expect((await isArchivableProject(root, [invalid, gitMarkerDetector])).reason).toBe("gitfile_invalid");
});
+
+ // Temp folders live under /private or /var on macOS, which the walk never enters; systemDirs: [] lifts that here.
+ const anyDir = { systemDirs: [] as string[] };
+
+ test("a folder inside a repository is archivable as git_parent, from a .git directory or gitfile at the nearest parent", async () => {
+ const repo = await tempDir("gate-parent");
+ await mkdir(join(repo, ".git"));
+ await mkdir(join(repo, "packages/app/src"), { recursive: true });
+ const git_parent = { archivable: true, reason: "git_parent", marker: ".git" };
+ expect(await isArchivableProject(join(repo, "packages/app"), undefined, anyDir)).toEqual(git_parent);
+ expect(await isArchivableProject(join(repo, "packages/app/src"), undefined, anyDir)).toEqual(git_parent);
+ // A worktree or submodule nested in the repo: its gitfile is the nearest .git.
+ await writeFile(join(repo, "packages/.git"), "gitdir: ../.git/modules/packages\n");
+ expect(await isArchivableProject(join(repo, "packages/app"), undefined, anyDir)).toEqual(git_parent);
+ // The nearest .git decides: an invalid gitfile or a symlink there qualifies nothing, even with a repo above.
+ await writeFile(join(repo, "packages/.git"), "not a gitfile\n");
+ expect((await isArchivableProject(join(repo, "packages/app"), undefined, anyDir)).reason).toBe("no_marker");
+ await rm(join(repo, "packages/.git"));
+ await symlink(join(repo, ".git"), join(repo, "packages/.git"));
+ expect((await isArchivableProject(join(repo, "packages/app"), undefined, anyDir)).reason).toBe("no_marker");
+ // A root inside the repository's own .git never qualifies: that would upload its history.
+ await mkdir(join(repo, ".git/hooks"));
+ expect((await isArchivableProject(join(repo, ".git/hooks"), undefined, anyDir)).reason).toBe("no_marker");
+ // The SessionArchiver default runs both detectors; the root marker alone does not look up.
+ expect((await isArchivableProject(join(repo, "packages/app"), [gitMarkerDetector], anyDir)).reason).toBe("no_marker");
+ });
+
+ test("a .git in the root itself is still preferred, and an invalid one there is not overridden by a parent", async () => {
+ const repo = await tempDir("gate-prefer");
+ await mkdir(join(repo, ".git"));
+ await mkdir(join(repo, "vendor/lib/.git"), { recursive: true });
+ await mkdir(join(repo, "tools/cli"), { recursive: true });
+ expect(await isArchivableProject(join(repo, "vendor/lib"), undefined, anyDir)).toEqual({ archivable: true, reason: "git_dir", marker: ".git" });
+ await writeFile(join(repo, "tools/cli/.git"), "not a gitfile\n");
+ expect((await isArchivableProject(join(repo, "tools/cli"), undefined, anyDir)).reason).toBe("gitfile_invalid");
+ expect(await gitParentDetector(join(repo, "tools/cli"), anyDir)).toBeNull();
+ });
+
+ test("a dotfiles repository at the home directory, or anything above it, does not qualify a folder in home", async () => {
+ const above = await tempDir("gate-dotfiles");
+ await mkdir(join(above, ".git"));
+ const home = join(above, "home");
+ await mkdir(join(home, ".git"), { recursive: true });
+ await mkdir(join(home, "code/app"), { recursive: true });
+ expect((await isArchivableProject(join(home, "code/app"), undefined, { ...anyDir, homeDir: home })).reason).toBe("no_marker");
+ await rm(join(home, ".git"), { recursive: true });
+ expect((await isArchivableProject(join(home, "code/app"), undefined, { ...anyDir, homeDir: home })).reason).toBe("no_marker");
+ // A real project inside home still qualifies.
+ await mkdir(join(home, "code/.git"));
+ expect((await isArchivableProject(join(home, "code/app"), undefined, { ...anyDir, homeDir: home })).reason).toBe("git_parent");
+ });
+
+ test("a repository in a system or app directory does not qualify a folder inside it", async () => {
+ const repo = await tempDir("gate-system");
+ await mkdir(join(repo, ".git"));
+ await mkdir(join(repo, "Contents/Resources"), { recursive: true });
+ expect((await isArchivableProject(join(repo, "Contents/Resources"), undefined, { systemDirs: [repo] })).reason).toBe("no_marker");
+ expect((await isArchivableProject(join(repo, "Contents/Resources"), undefined, { systemDirs: [join(repo, "..")] })).reason).toBe("no_marker");
+ // The walk stops at the first guarded folder, even with a repository above it.
+ expect((await isArchivableProject(join(repo, "Contents/Resources"), undefined, { systemDirs: [join(repo, "Contents")] })).reason).toBe("no_marker");
+ expect((await isArchivableProject(join(repo, "Contents/Resources"), undefined, { systemDirs: [join(repo, "Other")] })).reason).toBe("git_parent");
+ });
+
+ test("the parent walk, posix: stops at home, a filesystem or volume root, and system and app directories", () => {
+ const home = ["/Users/sam"];
+ expect(gitParentCandidates("/Users/sam/proj/packages/app", home, posix)).toEqual(["/Users/sam/proj/packages", "/Users/sam/proj"]);
+ expect(gitParentCandidates("/Users/sam/app", home, posix)).toEqual([]);
+ expect(gitParentCandidates("/users/SAM/proj/app", home, posix)).toEqual(["/users/SAM/proj"]);
+ expect(gitParentCandidates("/Users/other/proj/app", home, posix)).toEqual(["/Users/other/proj"]);
+ expect(gitParentCandidates("/home/sam/proj/app", ["/home/sam"], posix)).toEqual(["/home/sam/proj"]);
+ expect(gitParentCandidates("/srv/code/proj/app", home, posix)).toEqual(["/srv/code/proj", "/srv/code", "/srv"]);
+ expect(gitParentCandidates("/proj", home, posix)).toEqual([]);
+ expect(gitParentCandidates("/Volumes/Backup/proj/app", home, posix)).toEqual(["/Volumes/Backup/proj"]);
+ expect(gitParentCandidates("/Volumes/Backup/app", home, posix)).toEqual([]);
+ for (const guarded of ["/System/Volumes/Data/x/app", "/Library/Developer/x/app", "/Applications/Foo.app/Contents/Resources/app", "/usr/local/proj/app", "/private/tmp/proj/app", "/private/var/folders/xy/T/proj/app", "/var/www/site/app", "/etc/nixos/app", "/opt/homebrew/Library/Taps", "/USR/local/x/app"]) {
+ expect(gitParentCandidates(guarded, home, posix)).toEqual([]);
+ }
+ });
+
+ test("the parent walk, path.win32: stops at home, a drive or UNC share root, and Windows, Program Files and ProgramData", () => {
+ const home = ["C:\\Users\\sam"];
+ expect(gitParentCandidates("C:\\src\\proj\\packages\\app", home, win32)).toEqual(["C:\\src\\proj\\packages", "C:\\src\\proj", "C:\\src"]);
+ expect(gitParentCandidates("C:\\Users\\sam\\proj\\app", home, win32)).toEqual(["C:\\Users\\sam\\proj"]);
+ expect(gitParentCandidates("c:\\users\\SAM\\app", home, win32)).toEqual([]);
+ expect(gitParentCandidates("C:\\Users\\other\\proj\\app", home, win32)).toEqual(["C:\\Users\\other\\proj"]);
+ expect(gitParentCandidates("D:\\proj\\app", home, win32)).toEqual(["D:\\proj"]);
+ expect(gitParentCandidates("D:\\app", home, win32)).toEqual([]);
+ expect(gitParentCandidates("\\\\server\\share\\proj\\app", home, win32)).toEqual(["\\\\server\\share\\proj"]);
+ expect(gitParentCandidates("\\\\server\\share\\app", home, win32)).toEqual([]);
+ expect(gitParentCandidates("\\\\?\\UNC\\server\\share\\app", home, win32)).toEqual([]);
+ expect(gitParentCandidates("\\\\?\\C:\\src\\proj\\app", home, win32)).toEqual(["C:\\src\\proj", "C:\\src"]);
+ for (const guarded of ["C:\\Windows\\System32\\x\\app", "c:\\windows\\x\\app", "C:\\Program Files\\App\\resources\\app", "D:\\Program Files (x86)\\App\\x", "C:\\ProgramData\\chocolatey\\lib\\x", "\\\\server\\share\\Windows\\x\\app"]) {
+ expect(gitParentCandidates(guarded, home, win32)).toEqual([]);
+ }
+ });
});
diff --git a/apps/server/src/session-archive/detect.ts b/apps/server/src/session-archive/detect.ts
index f255fe1d..6ba1da31 100644
--- a/apps/server/src/session-archive/detect.ts
+++ b/apps/server/src/session-archive/detect.ts
@@ -1,22 +1,23 @@
/**
* The project gate (section 4): a session is archived only when the folder
* the agent started in is a project. v1 recognises one marker, a `.git`
- * entry; further markers plug in as detectors.
+ * entry, in the folder itself or in the nearest parent that may hold one
+ * (a folder inside a repository); further markers plug in as detectors.
*/
import { lstat, open, realpath } from "node:fs/promises";
import { homedir } from "node:os";
-import { isAbsolute, join, parse, relative, resolve, sep } from "node:path";
+import path, { isAbsolute, join, parse, relative, resolve, sep } from "node:path";
export type ArchivableProject = {
archivable: boolean;
- /** git_dir | git_file | no_marker | gitfile_invalid | root_not_directory | root_too_broad */
+ /** git_dir | git_file | git_parent | no_marker | gitfile_invalid | root_not_directory | root_too_broad */
reason: string;
/** The marker that qualified the root (".git"), null when not archivable. */
marker: string | null;
};
-/** Looks at the root itself only (never walks the tree); null when its marker is absent. Never throws. */
-export type ProjectMarkerDetector = (root: string) => Promise<ArchivableProject | null>;
+/** Looks at the root (and, for gitParentDetector, its parents), never below it; null when its marker is absent. Never throws. */
+export type ProjectMarkerDetector = (root: string, options?: ProjectGateOptions) => Promise<ArchivableProject | null>;
const MAX_GITFILE_BYTES = 4096;
@@ -62,12 +63,14 @@ export type ProjectGateOptions = {
appDirs?: readonly string[];
/** Tests only; defaults to os.homedir(). */
homeDir?: string;
+ /** Tests only; replaces the system and app directories gitParentDetector never looks in. */
+ systemDirs?: readonly string[];
};
-async function pathForms(path: string): Promise<string[]> {
- const forms = [resolve(path)];
+async function pathForms(target: string): Promise<string[]> {
+ const forms = [resolve(target)];
try {
- const real = await realpath(path);
+ const real = await realpath(target);
if (!forms.includes(real)) forms.push(real);
} catch {
// A directory that does not exist yet is compared by its resolved form only.
@@ -109,6 +112,95 @@ async function refusedRoot(root: string, options: ProjectGateOptions): Promise<s
return null;
}
+// --- a folder inside a repository ---------------------------------------------
+
+type PathApi = Pick<typeof path, "dirname" | "join" | "parse" | "relative" | "isAbsolute" | "sep">;
+
+/** System and app directories: a `.git` in one, or anywhere inside one, never qualifies a folder below it. */
+const POSIX_SYSTEM_DIRS = ["/System", "/Library", "/Applications", "/usr", "/private", "/var", "/etc", "/opt"];
+/** The same on Windows, on every drive and share. */
+const WIN32_SYSTEM_NAMES = ["Windows", "Program Files", "Program Files (x86)", "ProgramData"];
+
+function sameOrInsideFolded(child: string, parent: string, p: PathApi): boolean {
+ const rel = p.relative(parent.toLowerCase(), child.toLowerCase());
+ return rel === "" || (!rel.startsWith(`..${p.sep}`) && rel !== ".." && !p.isAbsolute(rel));
+}
+
+/** Why the parent walk must stop at `dir` without looking for `.git` in it, or null. Case-insensitive, so it errs on the side of stopping. */
+function parentWalkStop(dir: string, homes: readonly string[], p: PathApi, systemDirs?: readonly string[]): string | null {
+ if (p.parse(dir).root === dir || (p.sep === "/" && /^\/Volumes(?:\/[^/]+)?\/?$/.test(dir))) return "filesystem_root";
+ if (homes.some((home) => p.relative(home.toLowerCase(), dir.toLowerCase()) === "")) return "home";
+ // Another account's home: /Users/<name>, /home/<name>, <drive>:\Users\<name>.
+ if (/^(?:\/users|\/home|[a-z]:\\users)$/i.test(p.dirname(dir))) return "home";
+ const system = systemDirs ?? (p.sep === "/" ? POSIX_SYSTEM_DIRS : WIN32_SYSTEM_NAMES.map((name) => p.join(p.parse(dir).root, name)));
+ if (system.some((guarded) => sameOrInsideFolded(dir, guarded, p))) return "system_dir";
+ return null;
+}
+
+/**
+ * The parents of `root` that gitParentDetector may look in for `.git`,
+ * nearest first. The walk stops before the home directory (dotfiles repos),
+ * a filesystem, drive or UNC share root, or a system or app directory, so
+ * none of those, nor anything above them, can qualify the root.
+ */
+export function gitParentCandidates(
+ root: string,
+ homes: readonly string[],
+ p: PathApi = path,
+ systemDirs?: readonly string[],
+): string[] {
+ // Win32 namespace prefixes: \\?\UNC\server\share -> \\server\share, \\?\C:\ -> C:\.
+ const start = p.sep === "\\" ? root.replace(/^\\\\[?.]\\UNC\\/i, "\\\\").replace(/^\\\\[?.]\\(?=[a-z]:)/i, "") : root;
+ const candidates: string[] = [];
+ let current = start;
+ for (;;) {
+ const parent = p.dirname(current);
+ if (parent === current || parentWalkStop(parent, homes, p, systemDirs)) return candidates;
+ candidates.push(parent);
+ current = parent;
+ }
+}
+
+/** A mount point (the root of another filesystem) is a drive root too. Errs on the side of true. */
+async function isMountPoint(dir: string): Promise<boolean> {
+ try {
+ const [own, above] = await Promise.all([lstat(dir), lstat(path.dirname(dir))]);
+ return own.dev !== above.dev;
+ } catch {
+ return true;
+ }
+}
+
+/**
+ * A root without `.git` that sits inside a repository, e.g. `~/proj/packages/app`
+ * with `~/proj/.git`: archivable as git_parent when the nearest parent holding
+ * `.git` (a directory or a valid gitfile) lies before any stop of
+ * gitParentCandidates or a mount point. Only the root is archived; the
+ * parent's `.git` is not. A `.git` of any other kind in the root, or at the
+ * nearest parent, and a root inside that `.git`, qualify nothing.
+ */
+export const gitParentDetector: ProjectMarkerDetector = async (root, options = {}) => {
+ try {
+ if (await lstat(join(root, ".git")).then(() => true, () => false)) return null;
+ const start = await realpath(root).catch(() => resolve(root));
+ const homes = await pathForms(options.homeDir ?? homedir());
+ for (const dir of gitParentCandidates(start, homes, path, options.systemDirs)) {
+ if (await isMountPoint(dir)) return null;
+ if (!(await lstat(join(dir, ".git")).then(() => true, () => false))) continue;
+ // A root inside the repository's own .git (hooks, worktrees) would upload its history.
+ if (relative(dir, start).split(sep).some((part) => part.toLowerCase() === ".git")) return null;
+ const found = await gitMarkerDetector(dir);
+ return found?.archivable ? { archivable: true, reason: "git_parent", marker: ".git" } : null;
+ }
+ return null;
+ } catch {
+ return null;
+ }
+};
+
+/** The gate's detectors: `.git` in the root first, then in the nearest parent. */
+export const defaultProjectDetectors: readonly ProjectMarkerDetector[] = [gitMarkerDetector, gitParentDetector];
+
/**
* Whether the session root is a project to archive: the root checks first,
* then the detectors in order; the first archivable result wins, else the
@@ -116,7 +208,7 @@ async function refusedRoot(root: string, options: ProjectGateOptions): Promise<s
*/
export async function isArchivableProject(
root: string,
- detectors: readonly ProjectMarkerDetector[] = [gitMarkerDetector],
+ detectors: readonly ProjectMarkerDetector[] = defaultProjectDetectors,
options: ProjectGateOptions = {},
): Promise<ArchivableProject> {
const refused = await refusedRoot(root, options);
@@ -125,7 +217,7 @@ export async function isArchivableProject(
for (const detector of detectors) {
let result: ArchivableProject | null = null;
try {
- result = await detector(root);
+ result = await detector(root, options);
} catch {
result = null;
}
diff --git a/apps/server/src/session-archive/index.test.ts b/apps/server/src/session-archive/index.test.ts
index 5dff6b68..c6c16beb 100644
--- a/apps/server/src/session-archive/index.test.ts
+++ b/apps/server/src/session-archive/index.test.ts
@@ -5,6 +5,7 @@ import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
import { basename, join } from "node:path";
import { promisify } from "node:util";
+import { gitMarkerDetector, gitParentDetector } from "./detect.js";
import { FakeArchiveServer, slowPartTwo } from "./fake-archive-server.js";
import { ARCHIVE_STATE_DIRECTORY, SessionArchiver, type SessionArchiverOptions } from "./index.js";
import { cleanupTempDirs, manifestOf, openArchive, tempDir } from "./test-helpers.js";
@@ -150,6 +151,51 @@ describe("SessionArchiver", () => {
expect(server.calls).toEqual([]);
});
+ test("a folder inside a repository: the whole folder with every subfolder, nothing from the parent or its .git, git block from the parent", async () => {
+ const server = new FakeArchiveServer();
+ const { root: repo, head } = await project();
+ const root = join(repo, "packages/app");
+ await mkdir(join(root, "src/deep/deeper"), { recursive: true });
+ await writeFile(join(root, "src/main.ts"), "export const main = 1;\n");
+ await writeFile(join(root, "src/deep/deeper/data.bin"), randomBytes(4096));
+ await mkdir(join(root, "node_modules/dep"), { recursive: true });
+ await writeFile(join(root, "node_modules/dep/index.js"), "module.exports = 1;\n");
+ await mkdir(join(root, "dist"));
+ const binary = randomBytes(200 * 1024);
+ await writeFile(join(root, "dist/app.wasm"), binary);
+ await writeFile(join(root, ".env"), "TOKEN=abc\n");
+ await mkdir(join(repo, "packages/other"), { recursive: true });
+ await writeFile(join(repo, "packages/other/sibling.ts"), "export {};\n");
+ // Temp folders sit under /private or /var on macOS, where the parent walk never looks.
+ const detectors = [gitMarkerDetector, (dir: string) => gitParentDetector(dir, { systemDirs: [] })];
+ const subject = archiver(server, await tempDir("state"), { detectors });
+
+ expect(await subject.captureBase("ses_repo_subfolder", root)).toMatchObject({ status: "queued", kind: "base" });
+ await subject.drain();
+ const [first] = server.objects();
+ expect(first!.request).toMatchObject({ kind: "base", marker: ".git" });
+ const members = await openArchive(first!.object!);
+ const names = members.map((member) => member.name);
+ expect(names).toEqual(expect.arrayContaining(["src/main.ts", "src/deep/deeper/data.bin", "node_modules/dep/index.js", "dist/app.wasm"]));
+ expect(names.filter((name) => name.split("/").includes(".git"))).toEqual([]);
+ for (const outside of ["src/app.ts", ".gitignore", "assets/scene.blend", "sibling.ts", "packages/other/sibling.ts", ".env"]) expect(names).not.toContain(outside);
+ expect(names.every((name) => !name.startsWith("/") && !name.split("/").includes(".."))).toBe(true);
+ expect(members.find((member) => member.name === "dist/app.wasm")!.content.equals(binary)).toBe(true);
+ expect(manifestOf(members)).toMatchObject({
+ workspace: { label: "app", marker: ".git", git: { head, branch: "main", remote: "https://github.com/acme/app.git", dirty: true } },
+ excluded: { credential: 1 },
+ });
+
+ await writeFile(join(root, "src/main.ts"), "export const main = 2;\n");
+ await git(repo, "add", "packages/app/src");
+ await git(repo, "commit", "-q", "-m", "turn one");
+ expect((await subject.captureDelta("ses_repo_subfolder", root, 1)).status).toBe("queued");
+ await subject.drain();
+ const deltaMembers = await openArchive(server.objects()[1]!.object!);
+ expect(deltaMembers.slice(1).map((member) => member.name)).toEqual(["src/main.ts"]);
+ expect(manifestOf(deltaMembers)).toMatchObject({ workspace: { git: { head: await git(repo, "rev-parse", "HEAD"), branch: "main" } } });
+ });
+
test("428 at /archives/key: nothing is packed, archiving stays off until a later captureBase succeeds", async () => {
const server = new FakeArchiveServer();
server.gate = { status: 428, detail: "archive_consent_required" };
diff --git a/apps/server/src/session-archive/index.ts b/apps/server/src/session-archive/index.ts
index 88986e08..b915c0c9 100644
--- a/apps/server/src/session-archive/index.ts
+++ b/apps/server/src/session-archive/index.ts
@@ -13,7 +13,7 @@ import { join, resolve } from "node:path";
import { z } from "zod";
import { externalFetch } from "../server-fetch.js";
-import { gitMarkerDetector, isArchivableProject, type ProjectMarkerDetector } from "./detect.js";
+import { defaultProjectDetectors, isArchivableProject, type ProjectMarkerDetector } from "./detect.js";
import { hintGarbageCollection, readJsonFile, stateKey, writeChunksAtomic, writeJsonAtomic } from "./files.js";
import {
ArchiveHashCache,
@@ -41,7 +41,7 @@ import {
type RetryPolicy,
} from "./upload.js";
-export { gitMarkerDetector, isArchivableProject, type ArchivableProject, type ProjectMarkerDetector } from "./detect.js";
+export { gitMarkerDetector, gitParentDetector, isArchivableProject, type ArchivableProject, type ProjectMarkerDetector } from "./detect.js";
export { isArchiveCredentialPath } from "./manifest.js";
export type { ArchiveApiRequest } from "./upload.js";
@@ -232,7 +232,7 @@ export class SessionArchiver {
retry: this.retry,
log: this.log,
});
- this.detectors = options.detectors ?? [gitMarkerDetector];
+ this.detectors = options.detectors ?? defaultProjectDetectors;
this.appDirs = [stateDir, ...(options.excludedDirs ?? []).map((dir) => resolve(dir))];
this.includeCredentials = options.archiveIncludeCredentialFiles === true;
}
diff --git a/docs/project-archive.md b/docs/project-archive.md
index c797c0e3..c1173fe7 100644
--- a/docs/project-archive.md
+++ b/docs/project-archive.md
@@ -21,7 +21,16 @@ All of these must be true:
consent settings. It is a separate choice, off by default. Agreeing to the
general data collection does not turn it on.
- The folder the chat started in contains `.git` (a git repository, a
- worktree or a submodule). Nothing is archived for other folders.
+ worktree or a submodule), or sits inside a git repository, for example
+ `packages/app` in a repository whose `.git` is two folders up. In that
+ case only the chat's folder is archived, with all its subfolders; the
+ repository's `.git` and the rest of the repository are not; only its
+ current branch, commit, remote address (without any login in it) and
+ whether it has uncommitted changes are recorded. A `.git` in
+ your home folder (a dotfiles repository), at the root of a disk or
+ network share, or in a system or application folder (such as `/usr`,
+ `/Applications`, `C:\Windows` or `C:\Program Files`) does not count.
+ Nothing is archived for other folders.
- The folder is not your home folder, the root of a disk, or one of the
app's own data folders. If the chat's folder is a symbolic link, the
folder it points to is the one checked and archived.