Skip to content

The open-source app everyone uses to manage agents at work

[codex] fix worktree dev dependency ergonomics (#3743)

Dottac1a02497b0a5
diff --git a/scripts/ensure-workspace-package-links.ts b/scripts/ensure-workspace-package-links.ts
index 17a9990945..8e26d521a3 100644
--- a/scripts/ensure-workspace-package-links.ts
+++ b/scripts/ensure-workspace-package-links.ts
@@ -1,6 +1,6 @@
#!/usr/bin/env -S node --import tsx
import fs from "node:fs/promises";
-import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync } from "node:fs";
+import { existsSync, readdirSync, readFileSync, realpathSync } from "node:fs";
import path from "node:path";
import { repoRoot } from "./dev-service-profile.ts";
@@ -43,20 +43,6 @@ function discoverWorkspacePackagePaths(rootDir: string): Map<string, string> {
return packagePaths;
}
-function isLinkedGitWorktreeCheckout(rootDir: string) {
- const gitMetadataPath = path.join(rootDir, ".git");
- if (!existsSync(gitMetadataPath)) return false;
-
- const stat = lstatSync(gitMetadataPath);
- if (!stat.isFile()) return false;
-
- return readFileSync(gitMetadataPath, "utf8").trimStart().startsWith("gitdir:");
-}
-
-if (!isLinkedGitWorktreeCheckout(repoRoot)) {
- process.exit(0);
-}
-
const workspacePackagePaths = discoverWorkspacePackagePaths(repoRoot);
const workspaceDirs = Array.from(
new Set(
@@ -67,6 +53,11 @@ const workspaceDirs = Array.from(
).sort();
function findWorkspaceLinkMismatches(workspaceDir: string): WorkspaceLinkMismatch[] {
+ const nodeModulesDir = path.join(repoRoot, workspaceDir, "node_modules");
+ if (!existsSync(nodeModulesDir)) {
+ return [];
+ }
+
const packageJson = readJsonFile(path.join(repoRoot, workspaceDir, "package.json"));
const dependencies = {
...(packageJson.dependencies as Record<string, unknown> | undefined),
diff --git a/server/src/__tests__/app-vite-dev-routing.test.ts b/server/src/__tests__/app-vite-dev-routing.test.ts
new file mode 100644
index 0000000000..cc13ec837e
--- /dev/null
+++ b/server/src/__tests__/app-vite-dev-routing.test.ts
@@ -0,0 +1,27 @@
+import { describe, expect, it } from "vitest";
+import type { Request } from "express";
+import { shouldServeViteDevHtml } from "../app.js";
+
+function createRequest(path: string, acceptsResult: string | false): Request {
+ return {
+ path,
+ accepts: () => acceptsResult,
+ } as unknown as Request;
+}
+
+describe("shouldServeViteDevHtml", () => {
+ it("serves HTML shell for document requests", () => {
+ expect(shouldServeViteDevHtml(createRequest("/", "html"))).toBe(true);
+ expect(shouldServeViteDevHtml(createRequest("/issues/abc", "html"))).toBe(true);
+ });
+
+ it("skips public assets even when the client accepts */*", () => {
+ expect(shouldServeViteDevHtml(createRequest("/sw.js", "html"))).toBe(false);
+ expect(shouldServeViteDevHtml(createRequest("/site.webmanifest", "html"))).toBe(false);
+ });
+
+ it("skips vite asset requests", () => {
+ expect(shouldServeViteDevHtml(createRequest("/@vite/client", "html"))).toBe(false);
+ expect(shouldServeViteDevHtml(createRequest("/src/main.tsx", "html"))).toBe(false);
+ });
+});
diff --git a/server/src/__tests__/http-log-policy.test.ts b/server/src/__tests__/http-log-policy.test.ts
index 5f21836ade..ec140c3e87 100644
--- a/server/src/__tests__/http-log-policy.test.ts
+++ b/server/src/__tests__/http-log-policy.test.ts
@@ -56,6 +56,7 @@ describe("shouldSilenceHttpSuccessLog", () => {
expect(shouldSilenceHttpSuccessLog("GET", "/@fs/Users/dotta/paperclip/ui/src/main.tsx", 200)).toBe(true);
expect(shouldSilenceHttpSuccessLog("GET", "/src/App.tsx?t=123", 200)).toBe(true);
expect(shouldSilenceHttpSuccessLog("GET", "/site.webmanifest", 200)).toBe(true);
+ expect(shouldSilenceHttpSuccessLog("GET", "/sw.js", 200)).toBe(true);
});
it("keeps normal successful application requests", () => {
diff --git a/server/src/app.ts b/server/src/app.ts
index 9f9c9ccfe3..c60de55526 100644
--- a/server/src/app.ts
+++ b/server/src/app.ts
@@ -70,6 +70,7 @@ const VITE_DEV_STATIC_PATHS = new Set([
"/favicon.ico",
"/favicon.svg",
"/site.webmanifest",
+ "/sw.js",
]);
export function resolveViteHmrPort(serverPort: number): number {
@@ -79,7 +80,7 @@ export function resolveViteHmrPort(serverPort: number): number {
return Math.max(1_024, serverPort - 10_000);
}
-function shouldServeViteDevHtml(req: ExpressRequest): boolean {
+export function shouldServeViteDevHtml(req: ExpressRequest): boolean {
const pathname = req.path;
if (VITE_DEV_STATIC_PATHS.has(pathname)) return false;
if (VITE_DEV_ASSET_PREFIXES.some((prefix) => pathname.startsWith(prefix))) return false;
@@ -347,6 +348,7 @@ export async function createApp(
if (opts.uiMode === "vite-dev") {
const uiRoot = path.resolve(__dirname, "../../ui");
+ const publicUiRoot = path.resolve(uiRoot, "public");
const hmrPort = resolveViteHmrPort(opts.serverPort);
const { createServer: createViteServer } = await import("vite");
const vite = await createViteServer({
@@ -369,6 +371,9 @@ export async function createApp(
});
const renderViteHtml = viteHtmlRenderer;
+ if (fs.existsSync(publicUiRoot)) {
+ app.use(express.static(publicUiRoot, { index: false }));
+ }
app.get(/.*/, async (req, res, next) => {
if (!shouldServeViteDevHtml(req)) {
next();
diff --git a/server/src/middleware/http-log-policy.ts b/server/src/middleware/http-log-policy.ts
index fee44fee1a..d652ee38d0 100644
--- a/server/src/middleware/http-log-policy.ts
+++ b/server/src/middleware/http-log-policy.ts
@@ -25,6 +25,7 @@ const SILENCED_SUCCESS_STATIC_PREFIXES = [
const SILENCED_SUCCESS_STATIC_PATHS = new Set([
"/favicon.ico",
"/site.webmanifest",
+ "/sw.js",
]);
function normalizePath(url: string): string {
diff --git a/ui/src/lib/vite-watch.test.ts b/ui/src/lib/vite-watch.test.ts
new file mode 100644
index 0000000000..c4b456b62a
--- /dev/null
+++ b/ui/src/lib/vite-watch.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from "vitest";
+import { createUiDevWatchOptions, shouldIgnoreUiDevWatchPath } from "./vite-watch";
+
+describe("shouldIgnoreUiDevWatchPath", () => {
+ it("ignores test-only files and folders", () => {
+ expect(shouldIgnoreUiDevWatchPath("/repo/ui/src/components/IssuesList.test.tsx")).toBe(true);
+ expect(shouldIgnoreUiDevWatchPath("/repo/ui/src/lib/issue-tree.spec.ts")).toBe(true);
+ expect(shouldIgnoreUiDevWatchPath("/repo/ui/src/__tests__/helpers.ts")).toBe(true);
+ expect(shouldIgnoreUiDevWatchPath("/repo/ui/tests/helpers.ts")).toBe(true);
+ });
+
+ it("keeps runtime source files watchable", () => {
+ expect(shouldIgnoreUiDevWatchPath("/repo/ui/src/components/IssuesList.tsx")).toBe(false);
+ expect(shouldIgnoreUiDevWatchPath("/repo/ui/src/pages/IssueDetail.tsx")).toBe(false);
+ });
+});
+
+describe("createUiDevWatchOptions", () => {
+ it("preserves the WSL /mnt polling fallback", () => {
+ expect(createUiDevWatchOptions("/mnt/c/paperclip")).toMatchObject({
+ usePolling: true,
+ interval: 1000,
+ });
+ });
+
+ it("always includes the ignored-path predicate", () => {
+ expect(createUiDevWatchOptions("/Users/dotta/paperclip")).toHaveProperty("ignored");
+ });
+});
diff --git a/ui/src/lib/vite-watch.ts b/ui/src/lib/vite-watch.ts
new file mode 100644
index 0000000000..f5792a2e19
--- /dev/null
+++ b/ui/src/lib/vite-watch.ts
@@ -0,0 +1,29 @@
+const TEST_DIRECTORY_NAMES = new Set([
+ "__tests__",
+ "_tests",
+ "test",
+ "tests",
+]);
+
+const TEST_FILE_BASENAME_RE = /\.(test|spec)\.[^/]+$/i;
+
+export function shouldIgnoreUiDevWatchPath(watchedPath: string): boolean {
+ const normalizedPath = String(watchedPath).replaceAll("\\", "/");
+ if (normalizedPath.length === 0) return false;
+
+ const segments = normalizedPath.split("/");
+ const basename = segments.at(-1) ?? normalizedPath;
+
+ return segments.some((segment) => TEST_DIRECTORY_NAMES.has(segment))
+ || TEST_FILE_BASENAME_RE.test(basename);
+}
+
+export function createUiDevWatchOptions(currentWorkingDirectory: string) {
+ return {
+ ignored: shouldIgnoreUiDevWatchPath,
+ // WSL2 /mnt/ drives don't support inotify — fall back to polling so HMR works.
+ ...(currentWorkingDirectory.startsWith("/mnt/")
+ ? { usePolling: true, interval: 1000 }
+ : {}),
+ };
+}
diff --git a/ui/vite.config.ts b/ui/vite.config.ts
index a680f60730..27f481a401 100644
--- a/ui/vite.config.ts
+++ b/ui/vite.config.ts
@@ -2,6 +2,7 @@ import path from "path";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
+import { createUiDevWatchOptions } from "./src/lib/vite-watch";
export default defineConfig(({ mode }) => ({
plugins: [react(), tailwindcss()],
@@ -23,8 +24,7 @@ export default defineConfig(({ mode }) => ({
},
server: {
port: 5173,
- // WSL2 /mnt/ drives don't support inotify — fall back to polling so HMR works
- watch: process.cwd().startsWith("/mnt/") ? { usePolling: true, interval: 1000 } : undefined,
+ watch: createUiDevWatchOptions(process.cwd()),
proxy: {
"/api": {
target: "http://localhost:3100",