From 7f392ba6178ac1be6f2b6385293a61586cd98a87 Mon Sep 17 00:00:00 2001 From: Ben Fairless Date: Mon, 14 Sep 2026 08:07:05 +0800 Subject: [PATCH] fix(core): break filesystem/search import cycle filesystem.ts and filesystem/search.ts import each other, and filesystem.ts dereferences the other module at evaluation time in a top-level deps array. search.ts never needs it that early: its only runtime uses are FileSystem.Entry.make and FileSystem.Match.make, and its three remaining uses are type positions. Entry and Match already live in @opencode-ai/schema/filesystem, which filesystem.ts imports them from and re-exports. Import them from there directly, and make the remaining FileSystem import type-only so it is erased. That removes the runtime edge back to filesystem.ts, so the cycle is gone and module evaluation order no longer matters. With the cycle present, a bundler that emits search.ts after filesystem.ts leaves FileSystemSearch.node undefined in that deps array, and the layer graph then fails on first use with "TypeError: undefined is not an object (evaluating 'a.name')". Bun 1.4.2 does exactly that, reported as oven-sh/bun#42664. Closes #48876 Assisted-by: Claude Code:claude-opus-5 --- packages/core/src/filesystem/search.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/core/src/filesystem/search.ts b/packages/core/src/filesystem/search.ts index c7738388bcc0..03ca875e5ba7 100644 --- a/packages/core/src/filesystem/search.ts +++ b/packages/core/src/filesystem/search.ts @@ -5,7 +5,8 @@ import path from "path" import { Context, Effect, Layer, Scope } from "effect" import { Fff } from "#fff" import fuzzysort from "fuzzysort" -import { FileSystem } from "../filesystem" +import type { FileSystem } from "../filesystem" +import { Entry, Match } from "@opencode-ai/schema/filesystem" import { FSUtil } from "../fs-util" import { Location } from "../location" import { Ripgrep } from "../ripgrep" @@ -61,7 +62,7 @@ export const ripgrepLayer = Layer.effect( .pipe( Effect.map((result) => result.map((entry) => - FileSystem.Entry.make({ + Entry.make({ ...entry, path: RelativePath.make(path.relative(location.directory, path.resolve(cwd, entry.path))), }), @@ -86,9 +87,9 @@ export const ripgrepLayer = Layer.effect( .pipe( Effect.map((result) => result.map((match) => - FileSystem.Match.make({ + Match.make({ ...match, - entry: FileSystem.Entry.make({ + entry: Entry.make({ ...match.entry, path: RelativePath.make(path.relative(location.directory, path.resolve(cwd, match.entry.path))), }), @@ -109,7 +110,7 @@ export const ripgrepLayer = Layer.effect( return fuzzysort.go(input.query, items, { limit: input.limit ?? 50 }).map((item) => { const relative = item.target const type = relative.endsWith(path.sep) ? ("directory" as const) : ("file" as const) - return FileSystem.Entry.make({ + return Entry.make({ path: RelativePath.make(relative), type, }) @@ -154,7 +155,7 @@ export const fffLayer = Layer.effect( }) if (!found.ok) throw found.error return found.value.items.map((item) => - FileSystem.Entry.make({ + Entry.make({ path: RelativePath.make(item.relativePath.replaceAll("\\", "/")), type: "file", }), @@ -172,8 +173,8 @@ export const fffLayer = Layer.effect( if (!found.ok) throw found.error return found.value.items.map((match) => { const bytes = Buffer.from(match.lineContent) - return FileSystem.Match.make({ - entry: FileSystem.Entry.make({ + return Match.make({ + entry: Entry.make({ path: RelativePath.make(match.relativePath.replaceAll("\\", "/")), type: "file", }), @@ -222,7 +223,7 @@ export const fffLayer = Layer.effect( .sort((a, b) => b.score - a.score || a.path.length - b.path.length) .map((item) => { const relative = item.path.replaceAll("\\", "/").replace(/\/$/, "") - return FileSystem.Entry.make({ + return Entry.make({ path: RelativePath.make(relative + (item.type === "directory" ? path.sep : "")), type: item.type, })