fix(opencode): answer subagent permissions in run (#43675)
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
5e75e5e990
commit
08faeb3893
@@ -696,9 +696,14 @@ export const RunCommand = effectCmd({
|
|||||||
// created, and replies issued from inside the loop must use that client.
|
// created, and replies issued from inside the loop must use that client.
|
||||||
async function loop(client: OpencodeClient, events: Awaited<ReturnType<typeof sdk.event.subscribe>>) {
|
async function loop(client: OpencodeClient, events: Awaited<ReturnType<typeof sdk.event.subscribe>>) {
|
||||||
const toggles = new Map<string, boolean>()
|
const toggles = new Map<string, boolean>()
|
||||||
|
const sessions = new Set([sessionID])
|
||||||
let error: string | undefined
|
let error: string | undefined
|
||||||
|
|
||||||
for await (const event of events.stream) {
|
for await (const event of events.stream) {
|
||||||
|
if (event.type === "session.created" && event.properties.info.parentID) {
|
||||||
|
if (sessions.has(event.properties.info.parentID)) sessions.add(event.properties.info.id)
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
event.type === "message.updated" &&
|
event.type === "message.updated" &&
|
||||||
event.properties.sessionID === sessionID &&
|
event.properties.sessionID === sessionID &&
|
||||||
@@ -795,7 +800,7 @@ export const RunCommand = effectCmd({
|
|||||||
|
|
||||||
if (event.type === "permission.asked") {
|
if (event.type === "permission.asked") {
|
||||||
const permission = event.properties
|
const permission = event.properties
|
||||||
if (permission.sessionID !== sessionID) continue
|
if (!sessions.has(permission.sessionID)) continue
|
||||||
|
|
||||||
if (auto) {
|
if (auto) {
|
||||||
await client.permission.reply({
|
await client.permission.reply({
|
||||||
|
|||||||
@@ -277,6 +277,50 @@ describe("opencode run (non-interactive subprocess)", () => {
|
|||||||
60_000,
|
60_000,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cliIt.concurrent(
|
||||||
|
"answers requested permissions from subagents",
|
||||||
|
({ llm, opencode }) =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
yield* llm.tool("task", {
|
||||||
|
description: "Run a command",
|
||||||
|
prompt: "Run the requested command",
|
||||||
|
subagent_type: "general",
|
||||||
|
})
|
||||||
|
yield* llm.tool("bash", { command: "printf child", description: "Print from the child" })
|
||||||
|
yield* llm.text("child finished")
|
||||||
|
yield* llm.text("parent finished")
|
||||||
|
|
||||||
|
const result = yield* opencode.run("delegate a command", {
|
||||||
|
permission: { bash: "ask" },
|
||||||
|
extraArgs: ["--dangerously-skip-permissions"],
|
||||||
|
timeoutMs: 10_000,
|
||||||
|
})
|
||||||
|
|
||||||
|
opencode.expectExit(result, 0)
|
||||||
|
expect(result.stdout).toContain("parent finished")
|
||||||
|
|
||||||
|
yield* llm.reset
|
||||||
|
yield* llm.tool("task", {
|
||||||
|
description: "Run a command",
|
||||||
|
prompt: "Run the requested command",
|
||||||
|
subagent_type: "general",
|
||||||
|
})
|
||||||
|
yield* llm.tool("bash", { command: "printf child", description: "Print from the child" })
|
||||||
|
yield* llm.text("child continued")
|
||||||
|
yield* llm.text("parent continued")
|
||||||
|
|
||||||
|
const rejected = yield* opencode.run("delegate a rejected command", {
|
||||||
|
permission: { bash: "ask" },
|
||||||
|
timeoutMs: 10_000,
|
||||||
|
})
|
||||||
|
|
||||||
|
opencode.expectExit(rejected, 0)
|
||||||
|
expect(rejected.stderr).toContain("permission requested: bash")
|
||||||
|
expect(rejected.stdout).toContain("child continued")
|
||||||
|
}),
|
||||||
|
30_000,
|
||||||
|
)
|
||||||
|
|
||||||
cliIt.live(
|
cliIt.live(
|
||||||
"attach mode sends client-local file contents without a shared path",
|
"attach mode sends client-local file contents without a shared path",
|
||||||
({ home, llm, opencode }) =>
|
({ home, llm, opencode }) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user