effect(format): migrate to AppProcess (#27185)

This commit is contained in:
Kit Langton
2026-05-13 11:26:42 -04:00
committed by GitHub
parent 6e25720307
commit 6c7f35b49e

View File

@@ -1,6 +1,6 @@
import { Effect, Layer, Context, Schema } from "effect" import { Effect, Layer, Context, Schema } from "effect"
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process" import { ChildProcess } from "effect/unstable/process"
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner" import { AppProcess } from "@opencode-ai/core/process"
import { InstanceState } from "@/effect/instance-state" import { InstanceState } from "@/effect/instance-state"
import path from "path" import path from "path"
import { mergeDeep } from "remeda" import { mergeDeep } from "remeda"
@@ -29,7 +29,7 @@ export const layer = Layer.effect(
Service, Service,
Effect.gen(function* () { Effect.gen(function* () {
const config = yield* Config.Service const config = yield* Config.Service
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner const appProcess = yield* AppProcess.Service
const state = yield* InstanceState.make( const state = yield* InstanceState.make(
Effect.fn("Format.state")(function* (ctx) { Effect.fn("Format.state")(function* (ctx) {
@@ -81,8 +81,8 @@ export const layer = Layer.effect(
log.info("running", { command: cmd }) log.info("running", { command: cmd })
const replaced = cmd.map((x) => x.replace("$FILE", filepath)) const replaced = cmd.map((x) => x.replace("$FILE", filepath))
const dir = yield* InstanceState.directory const dir = yield* InstanceState.directory
const code = yield* spawner const result = yield* appProcess
.spawn( .run(
ChildProcess.make(replaced[0]!, replaced.slice(1), { ChildProcess.make(replaced[0]!, replaced.slice(1), {
cwd: dir, cwd: dir,
env: item.environment, env: item.environment,
@@ -93,21 +93,20 @@ export const layer = Layer.effect(
}), }),
) )
.pipe( .pipe(
Effect.flatMap((handle) => handle.exitCode), Effect.catch((error) =>
Effect.scoped,
Effect.catch(() =>
Effect.sync(() => { Effect.sync(() => {
log.error("failed to format file", { log.error("failed to format file", {
error: "spawn failed", error: "spawn failed",
command: cmd, command: cmd,
...item.environment, ...item.environment,
file: filepath, file: filepath,
cause: error.message,
}) })
return ChildProcessSpawner.ExitCode(1) return undefined
}), }),
), ),
) )
if (code !== 0) { if (result && result.exitCode !== 0) {
log.error("failed", { log.error("failed", {
command: cmd, command: cmd,
...item.environment, ...item.environment,
@@ -198,9 +197,6 @@ export const layer = Layer.effect(
}), }),
) )
export const defaultLayer = layer.pipe( export const defaultLayer = layer.pipe(Layer.provide(Config.defaultLayer), Layer.provide(AppProcess.defaultLayer))
Layer.provide(Config.defaultLayer),
Layer.provide(CrossSpawnSpawner.defaultLayer),
)
export * as Format from "." export * as Format from "."