From 033e0d18a713675f55e855626604b0735a24e365 Mon Sep 17 00:00:00 2001 From: tstachl Date: Wed, 16 Sep 2026 10:47:22 +0300 Subject: [PATCH] fix(core): break filesystem/search runtime import cycle packages/core/src/filesystem.ts captures FileSystemSearch.node in its layer deps at module scope, while filesystem/search.ts imports ../filesystem at runtime. When the bundle evaluates search.ts first, FileSystemSearch.node is still undefined, so every prompt dies in the layer-tree walk (recur -> resolve -> node.name on undefined) and surfaces as 'Unexpected server error'. Make the search.ts import type-only and take the Entry/Match values straight from @opencode-ai/schema/filesystem (the same objects core re-exports), removing the runtime edge. --- packages/core/src/filesystem/search.ts | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/core/src/filesystem/search.ts b/packages/core/src/filesystem/search.ts index c7738388bcc0..875d0e0d8ab5 100644 --- a/packages/core/src/filesystem/search.ts +++ b/packages/core/src/filesystem/search.ts @@ -5,7 +5,11 @@ import path from "path" import { Context, Effect, Layer, Scope } from "effect" import { Fff } from "#fff" import fuzzysort from "fuzzysort" -import { FileSystem } from "../filesystem" +// NOTE: type-only import to avoid a runtime import cycle with +// ../filesystem (which depends on FileSystemSearch.node at module +// scope). Value uses go through @opencode-ai/schema/filesystem directly. +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" @@ -13,9 +17,9 @@ import { RelativePath } from "../schema" import { Flag } from "../flag/flag" export interface Interface { - readonly find: (input: FileSystem.FindInput) => Effect.Effect - readonly glob: (input: FileSystem.GlobInput) => Effect.Effect - readonly grep: (input: FileSystem.GrepInput) => Effect.Effect + readonly find: (input: FileSystem.FindInput) => Effect.Effect + readonly glob: (input: FileSystem.GlobInput) => Effect.Effect + readonly grep: (input: FileSystem.GrepInput) => Effect.Effect } export class Service extends Context.Service()("@opencode/v2/FileSystem/Search") {} @@ -61,7 +65,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 +90,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 +113,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 +158,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 +176,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 +226,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, })