Skip to content

Commit cade716

Browse files
authored
refactor(core): replace legacy logger with Effect logging (anomalyco#31310)
1 parent 3462525 commit cade716

152 files changed

Lines changed: 697 additions & 2242 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/core/src/effect/logger.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

packages/core/src/effect/observability.ts

Lines changed: 0 additions & 107 deletions
This file was deleted.

packages/core/src/effect/runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Layer, type Context, ManagedRuntime, type Effect } from "effect"
22
import { memoMap } from "./memo-map"
3-
import { Observability } from "./observability"
3+
import { Observability } from "../observability"
44

55
export function makeRuntime<I, S, E>(service: Context.Service<I, S>, layer: Layer.Layer<I, E>) {
66
let rt: ManagedRuntime.ManagedRuntime<I, E> | undefined

packages/core/src/event.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,7 @@ export const layerWith = (options?: LayerOptions) =>
410410
Effect.catchCauseIf(
411411
(cause) => !Cause.hasInterrupts(cause),
412412
(cause) =>
413-
Effect.logError("Event observer failed").pipe(
414-
Effect.annotateLogs({ eventID: event.id, eventType: event.type, kind, cause }),
415-
),
413+
Effect.logError("Event observer failed", { eventID: event.id, eventType: event.type, kind, cause }),
416414
),
417415
)
418416

packages/core/src/filesystem/ripgrep.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner
1010
import { CrossSpawnSpawner } from "../cross-spawn-spawner"
1111
import { Global } from "../global"
1212
import { NonNegativeInt } from "../schema"
13-
import * as Log from "../util/log"
14-
import { sanitizedProcessEnv } from "../util/opencode-process"
1513
import { which } from "../util/which"
1614

17-
const log = Log.create({ service: "ripgrep" })
1815
const VERSION = "15.1.0"
1916
const PLATFORM = {
2017
"arm64-darwin": { platform: "aarch64-apple-darwin", extension: "tar.gz" },
@@ -146,7 +143,9 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/Ri
146143
export const use = serviceUse(Service)
147144

148145
function env() {
149-
const env = sanitizedProcessEnv()
146+
const env = Object.fromEntries(
147+
Object.entries(process.env).filter((entry): entry is [string, string] => entry[1] !== undefined),
148+
)
150149
delete env.RIPGREP_CONFIG_PATH
151150
return env
152151
}
@@ -307,7 +306,7 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | ChildProcessSpa
307306
const url = `https://github.com/BurntSushi/ripgrep/releases/download/${VERSION}/${filename}`
308307
const archive = path.join(Global.Path.bin, filename)
309308

310-
log.info("downloading ripgrep", { url })
309+
yield* Effect.logInfo("downloading ripgrep", { url })
311310
yield* fs.ensureDir(Global.Path.bin).pipe(Effect.orDie)
312311

313312
const bytes = yield* HttpClientRequest.get(url).pipe(
@@ -418,7 +417,7 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | ChildProcessSpa
418417
})
419418

420419
const tree: Interface["tree"] = Effect.fn("Ripgrep.tree")(function* (input: TreeInput) {
421-
log.info("tree", input)
420+
yield* Effect.logInfo("tree", input)
422421
const list = Array.from(yield* files({ cwd: input.cwd, signal: input.signal }).pipe(Stream.runCollect))
423422

424423
interface Node {

packages/core/src/filesystem/search.ts

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import type { PlatformError } from "effect/PlatformError"
44
import { FSUtil } from "../fs-util"
55
import { Glob } from "../util/glob"
66
import { Global } from "../global"
7-
import * as Log from "../util/log"
87
import { serviceUse } from "../effect/service-use"
98
import { makeRuntime } from "../effect/runtime"
109
import { Fff } from "#fff"
1110
import { Ripgrep } from "./ripgrep"
1211

13-
const log = Log.create({ service: "file.search" })
1412
const root = path.join(Global.Path.cache, "fff")
1513

1614
export type Item = Ripgrep.Item
@@ -220,12 +218,14 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service
220218
if (!scanned.ok || !scanned.value) {
221219
yield* fffSync("destroy picker", () => pick.destroy()).pipe(Effect.ignore)
222220
state.pick.delete(dir)
223-
log.warn("fff scan not ready", { dir })
221+
yield* Effect.logWarning("fff scan not ready", { dir })
224222
return yield* Effect.fail(new Error(scanned.ok ? "fff scan timed out" : scanned.error))
225223
}
226224

227225
const git = yield* fffSync("refresh git status", () => pick.refreshGitStatus())
228-
if (!git.ok) log.warn("fff git refresh failed", { dir, error: git.error })
226+
if (!git.ok) {
227+
yield* Effect.logWarning("fff git refresh failed", { dir, error: git.error })
228+
}
229229
})
230230

231231
// Create (or return) the picker for a directory. Creation is synchronous
@@ -244,10 +244,7 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service
244244
if (pending) return yield* Deferred.await(pending)
245245

246246
const available = yield* fffSync("check availability", () => Fff.available()).pipe(
247-
Effect.catch((error) => {
248-
log.warn("fff availability check failed", { error })
249-
return Effect.succeed(false)
250-
}),
247+
Effect.catch((error) => Effect.logWarning("fff availability check failed", { error }).pipe(Effect.as(false))),
251248
)
252249
if (!available) return undefined
253250

@@ -272,7 +269,7 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service
272269
}),
273270
)
274271
if (!made.ok) {
275-
log.warn("fff init failed", { dir, error: made.error })
272+
yield* Effect.logWarning("fff init failed", { dir, error: made.error })
276273
const err = new Error(made.error)
277274
yield* Deferred.fail(gate, err)
278275
return yield* Effect.fail(err)
@@ -355,14 +352,15 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service
355352
pageSize: limit,
356353
}),
357354
).pipe(
358-
Effect.catch((error) => {
359-
log.warn(`fff ${kind} search failed`, { dir, query, error })
360-
return Effect.succeed<Fff.Result<string[]> | undefined>(undefined)
361-
}),
355+
Effect.catch((error) =>
356+
Effect.logWarning(`fff ${kind} search failed`, { dir, query, error }).pipe(
357+
Effect.as<Fff.Result<string[]> | undefined>(undefined),
358+
),
359+
),
362360
)
363361
if (!fffResult) return undefined
364362
if (!fffResult.ok) {
365-
log.warn(`fff ${kind} search failed`, { dir, query, error: fffResult.error })
363+
yield* Effect.logWarning(`fff ${kind} search failed`, { dir, query, error: fffResult.error })
366364
return undefined
367365
}
368366

@@ -393,14 +391,15 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service
393391
timeBudgetMs: 1_500,
394392
}),
395393
).pipe(
396-
Effect.catch((error) => {
397-
log.warn("fff grep failed", { dir, pattern: input.pattern, error })
398-
return Effect.succeed<Fff.Result<Fff.Grep> | undefined>(undefined)
399-
}),
394+
Effect.catch((error) =>
395+
Effect.logWarning("fff grep failed", { dir, pattern: input.pattern, error }).pipe(
396+
Effect.as<Fff.Result<Fff.Grep> | undefined>(undefined),
397+
),
398+
),
400399
)
401400
if (!fffGrep) return yield* rip(input)
402401
if (!fffGrep.ok) {
403-
log.warn("fff grep failed", { dir, pattern: input.pattern, error: fffGrep.error })
402+
yield* Effect.logWarning("fff grep failed", { dir, pattern: input.pattern, error: fffGrep.error })
404403
return yield* rip(input)
405404
}
406405

@@ -432,10 +431,11 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service
432431
pageSize: limit,
433432
}),
434433
).pipe(
435-
Effect.catch((error) => {
436-
log.warn("fff glob failed", { dir, pattern: input.pattern, error })
437-
return Effect.succeed<Fff.Result<Fff.Search> | undefined>(undefined)
438-
}),
434+
Effect.catch((error) =>
435+
Effect.logWarning("fff glob failed", { dir, pattern: input.pattern, error }).pipe(
436+
Effect.as<Fff.Result<Fff.Search> | undefined>(undefined),
437+
),
438+
),
439439
)
440440

441441
if (fffGlob?.ok) {
@@ -453,7 +453,7 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service
453453
truncated: fffGlob.value.totalMatched > rows.length,
454454
}
455455
} else if (fffGlob) {
456-
log.warn("fff glob failed", { dir, pattern: input.pattern, error: fffGlob.error })
456+
yield* Effect.logWarning("fff glob failed", { dir, pattern: input.pattern, error: fffGlob.error })
457457
// fall through to the fallback
458458
}
459459
}
@@ -500,13 +500,16 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service
500500
if (!entry) return
501501

502502
const out = yield* fffSync("track query", () => entry.pick.trackQuery(row.text, file)).pipe(
503-
Effect.catch((error) => {
504-
log.warn("fff track query failed", { dir: row.dir, query: row.text, file, error })
505-
return Effect.succeed<Fff.Result<boolean> | undefined>(undefined)
506-
}),
503+
Effect.catch((error) =>
504+
Effect.logWarning("fff track query failed", { dir: row.dir, query: row.text, file, error }).pipe(
505+
Effect.as<Fff.Result<boolean> | undefined>(undefined),
506+
),
507+
),
507508
)
508509
if (!out) return
509-
if (!out.ok) log.warn("fff track query failed", { dir: row.dir, query: row.text, file, error: out.error })
510+
if (!out.ok) {
511+
yield* Effect.logWarning("fff track query failed", { dir: row.dir, query: row.text, file, error: out.error })
512+
}
510513
})
511514

512515
return Service.of({ files, tree, search, file, glob, open, warm, release })

0 commit comments

Comments
 (0)