refactor(flags): move bash timeout to runtime flags (#27607)
This commit is contained in:
@@ -2,6 +2,11 @@ import { Config, ConfigProvider, Context, Effect, Layer } from "effect"
|
||||
import { ConfigService } from "@/effect/config-service"
|
||||
|
||||
const bool = (name: string) => Config.boolean(name).pipe(Config.withDefault(false))
|
||||
const positiveInteger = (name: string) =>
|
||||
Config.number(name).pipe(
|
||||
Config.map((value) => (Number.isInteger(value) && value > 0 ? value : undefined)),
|
||||
Config.orElse(() => Config.succeed(undefined)),
|
||||
)
|
||||
const experimental = bool("OPENCODE_EXPERIMENTAL")
|
||||
const enabledByExperimental = (name: string) =>
|
||||
Config.all({ experimental, enabled: bool(name) }).pipe(Config.map((flags) => flags.experimental || flags.enabled))
|
||||
@@ -30,6 +35,7 @@ export class Service extends ConfigService.Service<Service>()("@opencode/Runtime
|
||||
experimentalPlanMode: enabledByExperimental("OPENCODE_EXPERIMENTAL_PLAN_MODE"),
|
||||
experimentalEventSystem: enabledByExperimental("OPENCODE_EXPERIMENTAL_EVENT_SYSTEM"),
|
||||
experimentalWorkspaces: enabledByExperimental("OPENCODE_EXPERIMENTAL_WORKSPACES"),
|
||||
bashDefaultTimeoutMs: positiveInteger("OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS"),
|
||||
client: Config.string("OPENCODE_CLIENT").pipe(Config.withDefault("cli")),
|
||||
}) {}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import { Language, type Node } from "web-tree-sitter"
|
||||
import { AppFileSystem } from "@opencode-ai/core/filesystem"
|
||||
import { fileURLToPath } from "url"
|
||||
import { Config } from "@/config/config"
|
||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||
import { RuntimeFlags } from "@/effect/runtime-flags"
|
||||
import { Shell } from "@/shell/shell"
|
||||
import { ShellID } from "./shell/id"
|
||||
|
||||
@@ -26,7 +26,6 @@ import { BashArity } from "@/permission/arity"
|
||||
export { Parameters } from "./shell/prompt"
|
||||
|
||||
const MAX_METADATA_LENGTH = 30_000
|
||||
const DEFAULT_TIMEOUT = Flag.OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS || 2 * 60 * 1000
|
||||
const CWD = new Set(["cd", "chdir", "popd", "pushd", "push-location", "set-location"])
|
||||
const FILES = new Set([
|
||||
...CWD,
|
||||
@@ -340,6 +339,8 @@ export const ShellTool = Tool.define(
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const trunc = yield* Truncate.Service
|
||||
const plugin = yield* Plugin.Service
|
||||
const flags = yield* RuntimeFlags.Service
|
||||
const defaultTimeout = flags.bashDefaultTimeoutMs ?? 2 * 60 * 1000
|
||||
|
||||
const cygpath = Effect.fn("ShellTool.cygpath")(function* (shell: string, text: string) {
|
||||
const lines = yield* spawner
|
||||
@@ -615,7 +616,7 @@ export const ShellTool = Tool.define(
|
||||
if (params.timeout !== undefined && params.timeout < 0) {
|
||||
throw new Error(`Invalid timeout value: ${params.timeout}. Timeout must be a positive number.`)
|
||||
}
|
||||
const timeout = params.timeout ?? DEFAULT_TIMEOUT
|
||||
const timeout = params.timeout ?? defaultTimeout
|
||||
const ps = Shell.ps(shell)
|
||||
yield* Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
|
||||
Reference in New Issue
Block a user