Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/subagent-permission-asks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kilocode/cli": patch
---

Fail subagent permission prompts immediately instead of waiting for unavailable user input.
1 change: 1 addition & 0 deletions packages/opencode/src/kilocode/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export namespace KiloSessionPrompt {
...input.request,
ruleset: Permission.merge(agent.permission, guardPermissions({ agent, session })),
hardRuleset: hardPermissions({ agent }),
nonInteractive: agent.mode === "subagent",
})
})

Expand Down
9 changes: 8 additions & 1 deletion packages/opencode/src/permission/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const AskInput = Schema.Struct({
id: Schema.optional(PermissionID),
ruleset: Ruleset,
hardRuleset: Schema.optional(Ruleset), // kilocode_change
nonInteractive: Schema.optional(Schema.Boolean), // kilocode_change
}).annotate({ identifier: "PermissionAskInput" })
export type AskInput = Schema.Schema.Type<typeof AskInput>

Expand Down Expand Up @@ -245,7 +246,7 @@ export const layer = Layer.effect(
const ask = Effect.fn("Permission.ask")(function* (input: AskInput) {
const { approved, pending } = yield* InstanceState.get(state)
// kilocode_change start
const { ruleset, hardRuleset, ...request } = input
const { ruleset, hardRuleset, nonInteractive, ...request } = input
const s = yield* InstanceState.get(state)
const local = s.session[request.sessionID] ?? []
// kilocode_change end
Expand Down Expand Up @@ -276,6 +277,12 @@ export const layer = Layer.effect(

if (!needsAsk) return

// kilocode_change start - subagents cannot answer permission prompts
if (nonInteractive) {
return yield* new DeniedError({ ruleset: subset(request.permission, ruleset) })
}
// kilocode_change end

const id = request.id ?? PermissionID.ascending()
const info: Request = {
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Bus } from "../../src/bus"
import { Command } from "../../src/command"
import { Config } from "../../src/config/config"
import { RuntimeFlags } from "../../src/effect/runtime-flags"
import { KiloSessionPrompt } from "../../src/kilocode/session/prompt"
import { EventV2Bridge } from "../../src/event-v2-bridge"
import { Env } from "../../src/env"
import { Format } from "../../src/format"
Expand Down Expand Up @@ -290,3 +291,38 @@ it.live("active tool calls use permissions changed after model streaming starts"
},
),
)

it.live("subagent permission asks fail instead of waiting for a human reply", () =>
provideTmpdirServer(
Effect.fnUntraced(function* () {
const permission = yield* Permission.Service
const sessions = yield* Session.Service
const chat = yield* sessions.create({ title: "Parent" })
const agent = {
name: "general",
mode: "subagent" as const,
permission: Permission.fromConfig({ bash: "ask" }),
options: {},
}

const err = yield* KiloSessionPrompt.askPermission({
permission,
agents: { get: () => Effect.succeed(agent) },
sessions,
agent,
session: chat,
request: {
sessionID: chat.id,
permission: "bash",
patterns: ["echo 1"],
always: ["echo 1"],
metadata: {},
},
}).pipe(Effect.flip)

expect(err).toBeInstanceOf(Permission.DeniedError)
expect(yield* permission.list()).toEqual([])
}),
{ git: true },
),
)
Loading