Skip to content

Commit 6eb5397

Browse files
committed
feat: Use opencode log path
1 parent 690f76e commit 6eb5397

6 files changed

Lines changed: 36 additions & 25 deletions

File tree

bun.lock

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
},
9898
"dependencies": {
9999
"@aws-sdk/client-s3": "3.933.0",
100+
"@ff-labs/fff-bun": "0.6.4",
100101
"@opencode-ai/plugin": "workspace:*",
101102
"@opencode-ai/script": "workspace:*",
102103
"@opencode-ai/sdk": "workspace:*",

packages/opencode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"@clack/prompts": "1.0.0-alpha.1",
103103
"@effect/opentelemetry": "catalog:",
104104
"@effect/platform-node": "catalog:",
105-
"@ff-labs/fff-bun": "0.6.2",
105+
"@ff-labs/fff-bun": "0.6.4",
106106
"@gitlab/opencode-gitlab-auth": "1.3.3",
107107
"@hono/node-server": "1.19.11",
108108
"@hono/node-ws": "1.3.0",

packages/opencode/src/file/fff.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import { Glob } from "../util/glob"
1818
import { Log } from "../util/log"
1919

2020
export namespace Fff {
21-
const log = Log.create({ service: "file.fff" })
22-
2321
export const Match = z.object({
2422
path: z.object({
2523
text: z.string(),
@@ -52,7 +50,7 @@ export namespace Fff {
5250

5351
const root = path.join(Global.Path.cache, "fff")
5452

55-
async function db() {
53+
async function dbs() {
5654
await fs.mkdir(root, { recursive: true })
5755
// fff databases are global across the file system
5856
return {
@@ -71,18 +69,26 @@ export namespace Fff {
7169
if (wait) return wait
7270

7371
const next = (async () => {
74-
const files = await db()
75-
const made = FileFinder.create({
72+
const files = await dbs()
73+
const base = Log.file()
74+
const logfile = path.join(Global.Path.log, base ? "fff-" + path.basename(base) : "fff.log")
75+
const result = FileFinder.create({
76+
aiMode: true,
7677
basePath: dir,
7778
frecencyDbPath: files.frecency,
7879
historyDbPath: files.history,
79-
aiMode: true,
80+
logFilePath: logfile,
81+
logLevel: Log.currentLevel().toLowerCase() as "debug" | "info" | "warn" | "error",
82+
// if there is second project opened within the same sesion - disable
83+
// content mapping, the memory mapping address space is finite, so we
84+
// don't want to blow user's computer (the limit depends on repo size)
85+
cacheBudgetMaxFiles: memo.map.size > 0 ? 0 : undefined,
8086
})
81-
if (!made.ok) throw new Error(made.error)
87+
if (!result.ok) throw new Error(result.error)
8288
// we do not syncrhnously wait for the results here to not block anything
8389
// fff will do the indexing in the background and will automatically
8490
// become available
85-
const pick = made.value
91+
const pick = result.value
8692
memo.map.set(dir, pick)
8793
return pick
8894
})()
@@ -96,8 +102,8 @@ export namespace Fff {
96102
}
97103

98104
export async function files(input: { cwd: string; query: string; page?: number; size?: number; current?: string }) {
99-
const pick = await picker(input.cwd)
100-
const out = pick.fileSearch(input.query, {
105+
const fff = await picker(input.cwd)
106+
const out = fff.fileSearch(input.query, {
101107
pageIndex: input.page ?? 0,
102108
pageSize: input.size ?? 100,
103109
currentFile: input.current,
@@ -107,8 +113,8 @@ export namespace Fff {
107113
}
108114

109115
export async function mixed(input: { cwd: string; query: string; page?: number; size?: number; current?: string }) {
110-
const pick = await picker(input.cwd)
111-
const out = pick.mixedSearch(input.query, {
116+
const fff = await picker(input.cwd)
117+
const out = fff.mixedSearch(input.query, {
112118
pageIndex: input.page ?? 0,
113119
pageSize: input.size ?? 100,
114120
currentFile: input.current,

packages/opencode/src/file/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,8 @@ export const layer = Layer.effect(
650650
const ctx = yield* InstanceState.context
651651
const fast = yield* Effect.promise(() =>
652652
Fff.mixed({
653-
cwd: ctx.directory,
654653
query,
654+
cwd: ctx.directory,
655655
size: limit,
656656
})
657657
.then((out) => {

packages/opencode/src/util/log.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const levelPriority: Record<Level, number> = {
1717
const keep = 10
1818

1919
let level: Level = "INFO"
20+
export function currentLevel() {
21+
return level
22+
}
2023

2124
function shouldLog(input: Level): boolean {
2225
return levelPriority[input] >= levelPriority[level]

0 commit comments

Comments
 (0)