Skip to content

Commit 59d0868

Browse files
chore: generate
1 parent f7514d9 commit 59d0868

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

packages/opencode/src/tool/bash.ts

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ function prefix(text: string) {
182182
return text.slice(0, match.index)
183183
}
184184

185-
186185
function pathArgs(list: Part[], ps: boolean) {
187186
if (!ps) {
188187
return list
@@ -210,7 +209,6 @@ function pathArgs(list: Part[], ps: boolean) {
210209
return out
211210
}
212211

213-
214212
function preview(text: string) {
215213
if (text.length <= MAX_METADATA_LENGTH) return text
216214
return text.slice(0, MAX_METADATA_LENGTH) + "\n\n..."
@@ -249,7 +247,6 @@ const ask = Effect.fn("BashTool.ask")(function* (ctx: Tool.Context, scan: Scan)
249247
)
250248
})
251249

252-
253250
function cmd(shell: string, name: string, command: string, cwd: string, env: NodeJS.ProcessEnv) {
254251
if (process.platform === "win32" && PS.has(name)) {
255252
return ChildProcess.make(shell, ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", command], {
@@ -269,7 +266,6 @@ function cmd(shell: string, name: string, command: string, cwd: string, env: Nod
269266
})
270267
}
271268

272-
273269
const parser = lazy(async () => {
274270
const { Parser } = await import("web-tree-sitter")
275271
const { default: treeWasm } = await import("web-tree-sitter/tree-sitter.wasm" as string, {
@@ -306,9 +302,9 @@ export const BashTool = Tool.defineEffect(
306302
const plugin = yield* Plugin.Service
307303

308304
const cygpath = Effect.fn("BashTool.cygpath")(function* (shell: string, text: string) {
309-
const lines = yield* spawner.lines(
310-
ChildProcess.make(shell, ["-lc", 'cygpath -w -- "$1"', "_", text]),
311-
).pipe(Effect.catch(() => Effect.succeed([] as string[])))
305+
const lines = yield* spawner
306+
.lines(ChildProcess.make(shell, ["-lc", 'cygpath -w -- "$1"', "_", text]))
307+
.pipe(Effect.catch(() => Effect.succeed([] as string[])))
312308
const file = lines[0]?.trim()
313309
if (!file) return
314310
return AppFileSystem.normalizePath(file)
@@ -366,7 +362,11 @@ export const BashTool = Tool.defineEffect(
366362
})
367363

368364
const shellEnv = Effect.fn("BashTool.shellEnv")(function* (ctx: Tool.Context, cwd: string) {
369-
const extra = yield* plugin.trigger("shell.env", { cwd, sessionID: ctx.sessionID, callID: ctx.callID }, { env: {} })
365+
const extra = yield* plugin.trigger(
366+
"shell.env",
367+
{ cwd, sessionID: ctx.sessionID, callID: ctx.callID },
368+
{ env: {} },
369+
)
370370
return {
371371
...process.env,
372372
...extra.env,
@@ -477,31 +477,34 @@ export const BashTool = Tool.defineEffect(
477477
.replaceAll("${maxLines}", String(Truncate.MAX_LINES))
478478
.replaceAll("${maxBytes}", String(Truncate.MAX_BYTES)),
479479
parameters: Parameters,
480-
execute: (params: z.infer<typeof Parameters>, ctx: Tool.Context) =>
481-
Effect.gen(function* () {
482-
const cwd = params.workdir
483-
? yield* resolvePath(params.workdir, Instance.directory, shell)
484-
: Instance.directory
485-
if (params.timeout !== undefined && params.timeout < 0) {
486-
throw new Error(`Invalid timeout value: ${params.timeout}. Timeout must be a positive number.`)
487-
}
488-
const timeout = params.timeout ?? DEFAULT_TIMEOUT
489-
const ps = PS.has(name)
490-
const root = yield* parse(params.command, ps)
491-
const scan = yield* collect(root, cwd, ps, shell)
492-
if (!Instance.containsPath(cwd)) scan.dirs.add(cwd)
493-
yield* ask(ctx, scan)
494-
495-
return yield* run({
496-
shell,
497-
name,
498-
command: params.command,
499-
cwd,
500-
env: yield* shellEnv(ctx, cwd),
501-
timeout,
502-
description: params.description,
503-
}, ctx)
504-
}).pipe(Effect.orDie, Effect.runPromise),
480+
execute: (params: z.infer<typeof Parameters>, ctx: Tool.Context) =>
481+
Effect.gen(function* () {
482+
const cwd = params.workdir
483+
? yield* resolvePath(params.workdir, Instance.directory, shell)
484+
: Instance.directory
485+
if (params.timeout !== undefined && params.timeout < 0) {
486+
throw new Error(`Invalid timeout value: ${params.timeout}. Timeout must be a positive number.`)
487+
}
488+
const timeout = params.timeout ?? DEFAULT_TIMEOUT
489+
const ps = PS.has(name)
490+
const root = yield* parse(params.command, ps)
491+
const scan = yield* collect(root, cwd, ps, shell)
492+
if (!Instance.containsPath(cwd)) scan.dirs.add(cwd)
493+
yield* ask(ctx, scan)
494+
495+
return yield* run(
496+
{
497+
shell,
498+
name,
499+
command: params.command,
500+
cwd,
501+
env: yield* shellEnv(ctx, cwd),
502+
timeout,
503+
description: params.description,
504+
},
505+
ctx,
506+
)
507+
}).pipe(Effect.orDie, Effect.runPromise),
505508
}
506509
}
507510
}),

packages/opencode/test/tool/bash.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ const runtime = ManagedRuntime.make(
1919
)
2020

2121
function initBash() {
22-
return runtime.runPromise(
23-
BashTool.pipe(Effect.flatMap((info) => Effect.promise(() => info.init()))),
24-
)
22+
return runtime.runPromise(BashTool.pipe(Effect.flatMap((info) => Effect.promise(() => info.init()))))
2523
}
2624

2725
const ctx = {

0 commit comments

Comments
 (0)