Skip to content
Merged
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/responsive-plan-approvals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kilocode/cli": patch
---

Allow plan approval submissions to complete after planning finishes.
42 changes: 20 additions & 22 deletions packages/opencode/src/kilocode/plan-followup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import z from "zod"

const agents = lazy(() => makeRuntime(Agent.Service, Agent.defaultLayer))
const providers = lazy(() => makeRuntime(Provider.Service, Provider.defaultLayer))
const questions = lazy(() => makeRuntime(Question.Service, Question.defaultLayer))
const todo = lazy(() => makeRuntime(Todo.Service, Todo.defaultLayer))
const llm = lazy(() => makeRuntime(LLM.Service, LLM.defaultLayer))
const pending = new Map<SessionID, AbortController>()
Expand All @@ -38,20 +37,6 @@ export const PlanFollowupRuntime = {
model(providerID: ProviderID, modelID: ModelID): Promise<Provider.Model> {
return providers().runPromise((svc) => svc.getModel(providerID, modelID))
},
question: {
ask(input: Parameters<Question.Interface["ask"]>[0]) {
return questions().runPromise((svc) => svc.ask(input))
},
list() {
return questions().runPromise((svc) => svc.list())
},
reject(requestID: Parameters<Question.Interface["reject"]>[0]) {
return questions().runPromise((svc) => svc.reject(requestID))
},
reply(input: Parameters<Question.Interface["reply"]>[0]) {
return questions().runPromise((svc) => svc.reply(input))
},
},
todo: {
get(sessionID: SessionID) {
return todo().runPromise((svc) => svc.get(sessionID))
Expand Down Expand Up @@ -288,8 +273,15 @@ export namespace PlanFollowup {
return msg
}

function prompt(input: { sessionID: SessionID; abort: AbortSignal }) {
const promise = PlanFollowupRuntime.question.ask({
type QuestionRuntime = {
ask: (input: Parameters<Question.Interface["ask"]>[0]) => Promise<ReadonlyArray<Question.Answer>>
list: () => Promise<ReadonlyArray<Question.Request>>
reject: (requestID: Parameters<Question.Interface["reject"]>[0]) => Promise<void>
}

function prompt(input: { sessionID: SessionID; abort: AbortSignal; question: QuestionRuntime }) {
if (input.abort.aborted) return Promise.resolve(undefined)
const promise = input.question.ask({
sessionID: input.sessionID,
questions: [
{
Expand Down Expand Up @@ -323,10 +315,15 @@ export namespace PlanFollowup {
})

const listener = () =>
PlanFollowupRuntime.question.list().then((qs) => {
const match = qs.find((q) => q.sessionID === input.sessionID)
if (match) PlanFollowupRuntime.question.reject(match.id)
})
input.question
.list()
.then((qs) => {
const match = qs.find((q) => q.sessionID === input.sessionID)
return match ? input.question.reject(match.id) : undefined
})
.catch((error) => {
log.warn("failed to reject aborted plan follow-up question", { sessionID: input.sessionID, error })
})
input.abort.addEventListener("abort", listener, { once: true })

return promise
Expand Down Expand Up @@ -478,6 +475,7 @@ export namespace PlanFollowup {
sessionID: SessionID
messages: MessageV2.WithParts[]
abort: AbortSignal
question: QuestionRuntime
}): Promise<"continue" | "break"> {
if (input.abort.aborted) return "break"

Expand All @@ -491,7 +489,7 @@ export namespace PlanFollowup {
const user = latest.find((msg) => msg.info.role === "user")?.info
if (!user || user.role !== "user" || !user.model) return "break"

const answers = await prompt({ sessionID: input.sessionID, abort: input.abort })
const answers = await prompt({ sessionID: input.sessionID, abort: input.abort, question: input.question })
if (!answers) {
Telemetry.trackPlanFollowup(input.sessionID, "dismissed")
return "break"
Expand Down
12 changes: 12 additions & 0 deletions packages/opencode/src/kilocode/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PlanFollowup } from "@/kilocode/plan-followup"
import { KiloSession } from "@/kilocode/session"
import { KiloSessionMessageOrder } from "@/kilocode/session/message-order"
import { Permission } from "@/permission"
import { Question } from "@/question"
import { environmentDetails, type EditorContext } from "@/kilocode/editor-context"
import { Identifier } from "@/id/id"
import { Filesystem } from "@/util/filesystem"
Expand Down Expand Up @@ -48,13 +49,24 @@ export namespace KiloSessionPrompt {
sessionID: SessionID
messages: MessageV2.WithParts[]
abort: AbortSignal
question: Pick<Question.Interface, "ask" | "list" | "reject">
}): Promise<"continue" | "break"> {
if (!shouldAskPlanFollowup({ messages: input.messages, abort: input.abort })) return "break"
const ask = InstanceState.bind(PlanFollowup.ask)
const action = await ask({
sessionID: input.sessionID,
messages: input.messages,
abort: input.abort,
// Keep the request in the listener-local Question service so HTTP replies can resolve it.
question: {
ask: InstanceState.bind((request: Parameters<Question.Interface["ask"]>[0]) =>
Effect.runPromise(input.question.ask(request)),
),
list: InstanceState.bind(() => Effect.runPromise(input.question.list())),
reject: InstanceState.bind((requestID: Parameters<Question.Interface["reject"]>[0]) =>
Effect.runPromise(input.question.reject(requestID)),
),
},
})
return action === "continue" ? "continue" : "break"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
KiloSessionPrompt.shouldAskPlanFollowup({ messages: msgs, abort: AbortSignal.any([]) })
) {
const action = yield* Effect.promise((signal) =>
KiloSessionPrompt.askPlanFollowup({ sessionID, messages: msgs, abort: signal }),
KiloSessionPrompt.askPlanFollowup({ sessionID, messages: msgs, abort: signal, question }),
)
if (action === "continue") continue
yield* slog.info("exiting loop")
Expand All @@ -1561,7 +1561,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
) {
// kilocode_change start - ask follow-up when plan_exit tool was called
const action = yield* Effect.promise((signal) =>
KiloSessionPrompt.askPlanFollowup({ sessionID, messages: msgs, abort: signal }),
KiloSessionPrompt.askPlanFollowup({ sessionID, messages: msgs, abort: signal, question }),
)
if (action === "continue") continue
// kilocode_change end
Expand Down
Loading
Loading