Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions packages/core/src/filesystem/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import path from "path"
import { Context, Effect, Layer, Scope } from "effect"
import { Fff } from "#fff"
import fuzzysort from "fuzzysort"
import { FileSystem } from "../filesystem"
import { Entry, FindInput, Match } from "@pentestcode/schema/filesystem"
import type { GlobInput, GrepInput } from "../filesystem"
import { FSUtil } from "../fs-util"
import { Location } from "../location"
import { Ripgrep } from "../ripgrep"
import { RelativePath } from "../schema"
import { Flag } from "../flag/flag"

export interface Interface {
readonly find: (input: FileSystem.FindInput) => Effect.Effect<FileSystem.Entry[]>
readonly glob: (input: FileSystem.GlobInput) => Effect.Effect<readonly FileSystem.Entry[]>
readonly grep: (input: FileSystem.GrepInput) => Effect.Effect<readonly FileSystem.Match[]>
readonly find: (input: FindInput) => Effect.Effect<Entry[]>
readonly glob: (input: GlobInput) => Effect.Effect<readonly Entry[]>
readonly grep: (input: GrepInput) => Effect.Effect<readonly Match[]>
}

export class Service extends Context.Service<Service, Interface>()("@pentestcode/v2/FileSystem/Search") {}
Expand Down Expand Up @@ -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))),
}),
Expand All @@ -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))),
}),
Expand All @@ -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,
})
Expand Down Expand Up @@ -152,7 +153,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",
}),
Expand All @@ -170,8 +171,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",
}),
Expand Down Expand Up @@ -220,7 +221,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,
})
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/session/llm/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export const prepare = Effect.fn("LLMRequestPrep.prepare")(function* (input: Pre
...(input.model.providerID.startsWith("opencode")
? {
...(opencodeProjectID ? { "x-pentestcode-project": opencodeProjectID } : {}),
"x-opencode-session": input.sessionID,
"x-pentestcode-session": input.sessionID,
"x-pentestcode-request": input.user.id,
"x-pentestcode-client": input.flags.client,
Expand Down