fix: Remove Bash string appearing before commands - brought back on earlier opencode merge

This commit is contained in:
Johnny Amancio
2026-04-17 20:17:57 +02:00
committed by Johnny Eric Amancio
parent 024ad48c50
commit 2172616229
2 changed files with 50 additions and 3 deletions
+3 -3
View File
@@ -280,7 +280,7 @@ async function parse(command: string, ps: boolean) {
return tree.rootNode
}
async function ask(ctx: Tool.Context, scan: Scan) {
async function ask(ctx: Tool.Context, scan: Scan, command: string) {
if (scan.dirs.size > 0) {
const globs = Array.from(scan.dirs).map((dir) => {
if (process.platform === "win32") return Filesystem.normalizePathPattern(path.join(dir, "*"))
@@ -299,7 +299,7 @@ async function ask(ctx: Tool.Context, scan: Scan) {
permission: "bash",
patterns: Array.from(scan.patterns),
always: Array.from(scan.always),
metadata: {},
metadata: { command }, // kilocode_change
})
}
@@ -479,7 +479,7 @@ export const BashTool = Tool.define("bash", async () => {
const root = await parse(params.command, ps)
const scan = await collect(root, cwd, ps, shell)
if (!Instance.containsPath(cwd)) scan.dirs.add(cwd)
await ask(ctx, scan)
await ask(ctx, scan, params.command)
return run(
{
@@ -0,0 +1,47 @@
// regression test for bash permission metadata.command
import { describe, expect, test } from "bun:test"
import { BashTool } from "../../src/tool/bash"
import { Instance } from "../../src/project/instance"
import { tmpdir } from "../fixture/fixture"
import { Shell } from "../../src/shell/shell"
import { SessionID, MessageID } from "../../src/session/schema"
import type { Permission } from "../../src/permission"
Shell.acceptable.reset()
const baseCtx = {
sessionID: SessionID.make("ses_test"),
messageID: MessageID.make(""),
callID: "",
agent: "code",
abort: AbortSignal.any([]),
messages: [],
metadata: () => {},
ask: async () => {},
}
const capture = (requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">>) => ({
...baseCtx,
ask: async (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) => {
requests.push(req)
},
})
describe("bash permission metadata.command", () => {
test("permission prompt shows raw command without tool name prefix", async () => {
await using tmp = await tmpdir()
await Instance.provide({
directory: tmp.path,
fn: async () => {
const bash = await BashTool.init()
const requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">> = []
const command = "echo hello"
await bash.execute({ command, description: "Echo hello" }, capture(requests))
const bashReq = requests.find((r) => r.permission === "bash")
expect(bashReq).toBeDefined()
expect(bashReq!.metadata.command).toBe(command)
},
})
})
})