GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(core): unify filesystem search service (#31566) · moonug/opencode@a0409e6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • bun.lock
  • package.json
  • packages
    • core
      • src
        • filesystem.ts
        • filesystem
          • ripgrep.ts
          • schema.ts
          • search.ts
        • location-layer.ts
        • location-search.ts
        • public
          • opencode.ts
        • ripgrep.ts
        • ripgrep
          • binary.ts
        • tool
          • glob.ts
          • grep.ts
          • read-filesystem.ts
      • test
        • filesystem
          • ripgrep.test.ts
          • search.test.ts
        • location-filesystem.test.ts
        • location-layer.test.ts
        • location-search.test.ts
        • ripgrep.test.ts
        • tool-glob.test.ts
        • tool-grep.test.ts
    • opencode
      • package.json
      • script
        • bench-search.ts
        • build.ts
      • src
        • cli/cmd/debug
          • file.ts
          • ripgrep.ts
        • effect
          • app-runtime.ts
        • project
          • bootstrap.ts
        • server/routes/instance/httpapi
          • groups
            • file.ts
          • handlers
            • file.ts
          • server.ts
        • tool
          • external-directory.ts
          • glob.ts
          • grep.ts
          • read.ts
          • registry.ts
          • skill.ts
      • test
        • control-plane
          • workspace.test.ts
        • plugin
          • workspace-adapter.test.ts
        • server
          • httpapi-instance-context.test.ts
          • httpapi-promptasync-context.test.ts
          • httpapi-session.test.ts
          • httpapi-workspace-routing.test.ts
          • httpapi-workspace.test.ts
        • session
          • prompt.test.ts
          • snapshot-tool-race.test.ts
          • structured-output-integration.test.ts
        • tool
          • glob.test.ts
          • grep.test.ts
          • read.test.ts
          • registry.test.ts
          • skill.test.ts
          • task.test.ts
    • server/src/handlers
      • fs.ts
    • tui/src/component/prompt
      • autocomplete.tsx
  • patches
    • @ff-labs%[email protected]

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bun.lock‎

Copy file name to clipboardExpand all lines: bun.lock
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
"@types/node": "catalog:"
141141
},
142142
"patchedDependencies": {
143+
"@ff-labs/[email protected]": "patches/@ff-labs%[email protected]",
143144
"@npmcli/[email protected]": "patches/@npmcli%[email protected]",
144145
"@silvia-odwyer/[email protected]": "patches/@silvia-odwyer%[email protected]",
145146
"@standard-community/[email protected]": "patches/@standard-community%[email protected]",
Collapse file

‎packages/core/src/filesystem.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/filesystem.ts
+35-94Lines changed: 35 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { Context, Effect, Layer, Option, Schema } from "effect"
66
import { EventV2 } from "./event"
77
import { FSUtil } from "./fs-util"
88
import { Location } from "./location"
9-
import { NonNegativeInt, PositiveInt, RelativePath } from "./schema"
10-
import { Search } from "./filesystem/search"
9+
import { PositiveInt, RelativePath } from "./schema"
10+
import { FileSystemSearch } from "./filesystem/search"
11+
import { Entry, Match } from "./filesystem/schema"
12+
export { Entry, Match, Submatch } from "./filesystem/schema"
1113

1214
export const ReadInput = Schema.Struct({
1315
path: RelativePath,
@@ -28,39 +30,23 @@ export const ListInput = Schema.Struct({
2830
})
2931
export type ListInput = typeof ListInput.Type
3032

31-
export class Entry extends Schema.Class<Entry>("FileSystem.Entry")({
32-
path: RelativePath,
33-
uri: Schema.String,
34-
type: Schema.Literals(["file", "directory"]),
35-
mime: Schema.String,
36-
}) {}
37-
38-
export const FindInput = Schema.Struct({
33+
export class FindInput extends Schema.Class<FindInput>("FileSystem.FindInput")({
3934
query: Schema.String,
4035
type: Schema.Literals(["file", "directory"]).pipe(Schema.optional),
4136
limit: PositiveInt.pipe(Schema.optional),
42-
})
43-
export type FindInput = typeof FindInput.Type
37+
}) {}
4438

45-
export const GrepInput = Schema.Struct({
39+
export class GlobInput extends Schema.Class<GlobInput>("FileSystem.GlobInput")({
4640
pattern: Schema.String,
47-
include: Schema.String.pipe(Schema.optional),
41+
path: RelativePath.pipe(Schema.optional),
4842
limit: PositiveInt.pipe(Schema.optional),
49-
})
50-
export type GrepInput = typeof GrepInput.Type
43+
}) {}
5144

52-
export class GrepMatch extends Schema.Class<GrepMatch>("LocationFileSystem.GrepMatch")({
53-
path: RelativePath,
54-
lines: Schema.String,
55-
line: PositiveInt,
56-
offset: NonNegativeInt,
57-
submatches: Schema.Array(
58-
Schema.Struct({
59-
text: Schema.String,
60-
start: NonNegativeInt,
61-
end: NonNegativeInt,
62-
}),
63-
),
45+
export class GrepInput extends Schema.Class<GrepInput>("FileSystem.GrepInput")({
46+
pattern: Schema.String,
47+
path: RelativePath.pipe(Schema.optional),
48+
include: Schema.String.pipe(Schema.optional),
49+
limit: PositiveInt.pipe(Schema.optional),
6450
}) {}
6551

6652
export const Event = {
@@ -76,17 +62,18 @@ export interface Interface {
7662
readonly read: (input: ReadInput) => Effect.Effect<Content>
7763
readonly list: (input?: ListInput) => Effect.Effect<Entry[]>
7864
readonly find: (input: FindInput) => Effect.Effect<Entry[]>
79-
readonly grep: (input: GrepInput) => Effect.Effect<GrepMatch[]>
65+
readonly glob: (input: GlobInput) => Effect.Effect<readonly Entry[]>
66+
readonly grep: (input: GrepInput) => Effect.Effect<readonly Match[]>
8067
}
8168

8269
export class Service extends Context.Service<Service, Interface>()("@opencode/v2/FileSystem") {}
8370

84-
export const layer = Layer.effect(
71+
const baseLayer = Layer.effect(
8572
Service,
8673
Effect.gen(function* () {
8774
const fs = yield* FSUtil.Service
8875
const location = yield* Location.Service
89-
const search = yield* Search.Service
76+
const search = yield* FileSystemSearch.Service
9077
const root = yield* fs.realPath(location.directory).pipe(Effect.orDie)
9178
const resolve = Effect.fnUntraced(function* (input?: RelativePath) {
9279
const absolute = path.resolve(location.directory, input ?? ".")
@@ -96,22 +83,10 @@ export const layer = Layer.effect(
9683
if (!FSUtil.contains(root, real)) return yield* Effect.die(new Error("Path escapes the location"))
9784
return { absolute, real, directory: location.directory, root }
9885
})
99-
const entry = Effect.fnUntraced(function* (absolute: string, selected = { directory: location.directory, root }) {
100-
const real = yield* fs.realPath(absolute).pipe(Effect.catch(() => Effect.void))
101-
if (!real) return
102-
if (!FSUtil.contains(selected.root, real)) return
103-
const info = yield* fs.stat(real).pipe(Effect.catch(() => Effect.void))
104-
const type = info?.type === "Directory" ? "directory" : info?.type === "File" ? "file" : undefined
105-
if (!type) return
106-
return new Entry({
107-
path: RelativePath.make(path.relative(selected.directory, absolute)),
108-
uri: pathToFileURL(real).href,
109-
type,
110-
mime: type === "directory" ? "application/x-directory" : FSUtil.mimeType(real),
111-
})
112-
})
113-
11486
return Service.of({
87+
find: search.find,
88+
glob: search.glob,
89+
grep: search.grep,
11590
read: Effect.fn("FileSystem.read")(function* (input) {
11691
const target = yield* resolve(input.path)
11792
const info = yield* fs.stat(target.real).pipe(Effect.orDie)
@@ -145,62 +120,28 @@ export const layer = Layer.effect(
145120
if (info.type !== "Directory") return yield* Effect.die(new Error("Path is not a directory"))
146121
return yield* fs.readDirectoryEntries(target.real).pipe(
147122
Effect.orDie,
148-
Effect.flatMap((items) =>
149-
Effect.forEach(items, (item) => entry(path.join(target.absolute, item.name), target), {
150-
concurrency: "unbounded",
151-
}),
152-
),
153123
Effect.map((items) =>
154124
items
155-
.filter((item): item is Entry => item !== undefined)
125+
.flatMap((item) => {
126+
if (item.type !== "file" && item.type !== "directory") return []
127+
const absolute = path.join(target.absolute, item.name)
128+
const relative = path.relative(target.directory, absolute)
129+
return [
130+
new Entry({
131+
path: RelativePath.make(relative + (item.type === "directory" ? path.sep : "")),
132+
type: item.type,
133+
mime: item.type === "directory" ? "application/x-directory" : FSUtil.mimeType(absolute),
134+
}),
135+
]
136+
})
156137
.sort((a, b) => (a.type === b.type ? a.path.localeCompare(b.path) : a.type === "directory" ? -1 : 1)),
157138
),
158139
)
159140
}),
160-
find: Effect.fn("FileSystem.find")(function* (input) {
161-
const found = yield* search
162-
.file({
163-
cwd: location.directory,
164-
query: input.query,
165-
limit: input.limit,
166-
kind: input.type ?? "all",
167-
})
168-
.pipe(Effect.orDie)
169-
return found.map(
170-
(item) =>
171-
new Entry({
172-
path: RelativePath.make(item.path),
173-
uri: pathToFileURL(path.join(location.directory, item.path)).href,
174-
type: item.type,
175-
mime: item.type === "directory" ? "application/x-directory" : FSUtil.mimeType(item.path),
176-
}),
177-
)
178-
}),
179-
grep: Effect.fn("FileSystem.grep")(function* (input) {
180-
return (yield* search
181-
.search({
182-
cwd: location.directory,
183-
pattern: input.pattern,
184-
glob: input.include ? [input.include] : undefined,
185-
limit: input.limit,
186-
})
187-
.pipe(Effect.orDie)).items.map(
188-
(item) =>
189-
new GrepMatch({
190-
path: RelativePath.make(item.path.text),
191-
lines: item.lines.text,
192-
line: item.line_number,
193-
offset: item.absolute_offset,
194-
submatches: item.submatches.map((submatch) => ({
195-
text: submatch.match.text,
196-
start: submatch.start,
197-
end: submatch.end,
198-
})),
199-
}),
200-
)
201-
}),
202141
})
203142
}),
204143
)
205144

145+
export const layer = baseLayer.pipe(Layer.provide(FileSystemSearch.defaultLayer), Layer.provide(FSUtil.defaultLayer))
146+
206147
export const locationLayer = layer

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.