From c326dc779777b70a7db194a5b9a40cabee76747d Mon Sep 17 00:00:00 2001 From: Arun Sasidharan <7837006+esoxjem@users.noreply.github.com> Date: Sat, 31 Oct 2026 12:07:40 +0000 Subject: [PATCH 1/9] fix(web): copy ignored folders to another machine --- .../src/workspace/WorkspaceEntries.test.ts | 38 ++- apps/server/src/workspace/WorkspaceEntries.ts | 16 +- .../components/AddProjectToMachineDialog.tsx | 39 +-- apps/web/src/lib/addProjectToMachine.ts | 23 +- .../src/lib/readProjectFilesToCopy.test.ts | 230 ++++++++++++++++++ apps/web/src/lib/readProjectFilesToCopy.ts | 79 ++++++ packages/contracts/src/project.ts | 4 +- 7 files changed, 374 insertions(+), 55 deletions(-) create mode 100644 apps/web/src/lib/readProjectFilesToCopy.test.ts create mode 100644 apps/web/src/lib/readProjectFilesToCopy.ts diff --git a/apps/server/src/workspace/WorkspaceEntries.test.ts b/apps/server/src/workspace/WorkspaceEntries.test.ts index 2453f0c528f57..483d08e60873e 100644 --- a/apps/server/src/workspace/WorkspaceEntries.test.ts +++ b/apps/server/src/workspace/WorkspaceEntries.test.ts @@ -414,24 +414,44 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => { }); describe("listIgnoredFiles", () => { - it.effect("lists ignored files with sizes and skips wholly ignored folders", () => + it.effect("keeps directory entries out of legacy file-only requests", () => Effect.gen(function* () { const cwd = yield* makeTempDir({ git: true }); - yield* writeTextFile(cwd, ".gitignore", "node_modules/\n.env*\n"); + yield* writeTextFile(cwd, ".gitignore", ".agents/\n.env\n"); + yield* writeTextFile(cwd, ".env", "A=1"); + yield* writeTextFile(cwd, ".agents/skills/example/SKILL.md", "# Example skill\n"); + + const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; + expect(yield* workspaceEntries.listIgnoredFiles({ cwd })).toEqual({ + files: [{ path: ".env", byteLength: 3 }], + truncated: false, + }); + }), + ); + + it.effect("lists ignored files with sizes and selectable folders without scanning them", () => + Effect.gen(function* () { + const cwd = yield* makeTempDir({ git: true }); + yield* writeTextFile(cwd, ".gitignore", "node_modules/\n.env*\n.agents/\n"); yield* writeTextFile(cwd, ".env", "A=1"); yield* writeTextFile(cwd, "apps/web/index.ts", "y"); yield* git(cwd, ["add", "apps/web/index.ts"]); yield* writeTextFile(cwd, "apps/web/.env.local", "B=22"); yield* writeTextFile(cwd, "node_modules/pkg/index.js", "x"); + yield* writeTextFile(cwd, ".agents/skills/example/SKILL.md", "# Example skill\n"); const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; - expect(yield* workspaceEntries.listIgnoredFiles({ cwd })).toEqual({ - files: [ - { path: ".env", byteLength: 3 }, - { path: "apps/web/.env.local", byteLength: 4 }, - ], - truncated: false, - }); + expect(yield* workspaceEntries.listIgnoredFiles({ cwd, includeDirectories: true })).toEqual( + { + files: [ + { path: ".agents/", byteLength: 0 }, + { path: ".env", byteLength: 3 }, + { path: "apps/web/.env.local", byteLength: 4 }, + { path: "node_modules/", byteLength: 0 }, + ], + truncated: false, + }, + ); }), ); diff --git a/apps/server/src/workspace/WorkspaceEntries.ts b/apps/server/src/workspace/WorkspaceEntries.ts index 738268f95558b..15a5d5da385b0 100644 --- a/apps/server/src/workspace/WorkspaceEntries.ts +++ b/apps/server/src/workspace/WorkspaceEntries.ts @@ -118,7 +118,6 @@ export class WorkspaceEntries extends Context.Service< } >()("t3/workspace/WorkspaceEntries") {} -/** Ignored files offered for copying; more than this is a build folder, not config. */ const IGNORED_FILES_LIMIT = 200; /** Paths sent to one `git check-ignore` call when labelling a folder's children. */ @@ -604,8 +603,7 @@ export const make = Effect.gen(function* () { "WorkspaceEntries.listIgnoredFiles", )(function* (input) { const normalizedCwd = yield* normalizeWorkspaceRoot(input.cwd); - // `--directory` reports a folder holding nothing but ignored files as one - // `name/` entry, which is how `node_modules` and build output drop out. + // Keep ignored folders collapsed so opening the picker never scans their contents. const result = yield* vcsProcess .run({ operation: "WorkspaceEntries.listIgnoredFiles", @@ -633,16 +631,20 @@ export const make = Effect.gen(function* () { const paths = result.stdout .split("\0") .filter( - (entry) => entry.length > 0 && !entry.endsWith("/") && entry.toLowerCase().includes(query), + (entry) => + entry.length > 0 && + (input.includeDirectories === true || !entry.endsWith("/")) && + entry.toLowerCase().includes(query), ) .toSorted(); const files = yield* Effect.promise(() => Promise.all( paths.slice(0, IGNORED_FILES_LIMIT).map(async (relativePath) => { // lstat: a symlink usually points outside the workspace, where reads refuse to go. - const stat = await NodeFSP.lstat(path.join(normalizedCwd, relativePath)).catch( - () => null, - ); + const stat = await NodeFSP.lstat( + path.join(normalizedCwd, relativePath.replace(/\/$/, "")), + ).catch(() => null); + if (stat?.isDirectory()) return { path: relativePath, byteLength: 0 }; return stat?.isFile() ? { path: relativePath, byteLength: stat.size } : null; }), ), diff --git a/apps/web/src/components/AddProjectToMachineDialog.tsx b/apps/web/src/components/AddProjectToMachineDialog.tsx index 0982ab1e1ccab..504cac57e5de0 100644 --- a/apps/web/src/components/AddProjectToMachineDialog.tsx +++ b/apps/web/src/components/AddProjectToMachineDialog.tsx @@ -135,7 +135,7 @@ function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRe project && canListFiles ? projectEnvironment.listIgnoredFiles({ environmentId: project.environmentId, - input: { cwd: project.workspaceRoot }, + input: { cwd: project.workspaceRoot, includeDirectories: true }, }) : null, ); @@ -146,7 +146,7 @@ function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRe project && searching ? projectEnvironment.listIgnoredFiles({ environmentId: project.environmentId, - input: { cwd: project.workspaceRoot, query: sentFileQuery }, + input: { cwd: project.workspaceRoot, query: sentFileQuery, includeDirectories: true }, }) : null, ); @@ -158,10 +158,9 @@ function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRe const copyable = files.filter((file) => file.byteLength <= COPYABLE_FILE_MAX_BYTES); const allCopyableSelected = copyable.every((file) => selectedFiles.has(file.path)); const atSelectionLimit = selectedFiles.size >= COPIED_FILES_MAX_COUNT; - const selectedBytes = [...selectedFiles.values()].reduce( - (total, file) => total + file.byteLength, - 0, - ); + const selectedBytes = [...selectedFiles.values()].some((file) => file.path.endsWith("/")) + ? null + : [...selectedFiles.values()].reduce((total, file) => total + file.byteLength, 0); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); @@ -292,7 +291,7 @@ function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRe {selectedFiles.size === 0 ? gt("no files") - : gt("{count, plural, one {+ {count} file} other {+ {count} files}}", { + : gt("{count, plural, one {+ {count} item} other {+ {count} items}}", { count: selectedFiles.size, })} @@ -378,7 +377,7 @@ function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRe
{copyable.length > 0 ? ( <> @@ -387,7 +386,9 @@ function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRe selected: selectedFiles.size, total: allIgnoredFiles.data?.files.length ?? 0, })} - {selectedBytes > 0 ? ` · ${formatBytes(selectedBytes)}` : ""} + {selectedBytes !== null && selectedBytes > 0 + ? ` · ${formatBytes(selectedBytes)}` + : ""}