Skip to content
Open
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
12 changes: 11 additions & 1 deletion packages/opencode/src/tool/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Question } from "../question"
import { Session } from "../session"
import { MessageV2 } from "../session/message-v2"
import { Provider } from "../provider"
import { Agent } from "../agent/agent"
import { Instance } from "../project/instance"
import { type SessionID, MessageID, PartID } from "../session/schema"
import ENTER_DESCRIPTION from "./plan-enter.txt"
Expand Down Expand Up @@ -104,6 +105,7 @@ export const PlanExitTool = Tool.define(
const session = yield* Session.Service
const question = yield* Question.Service
const provider = yield* Provider.Service
const agents = yield* Agent.Service

return {
description: EXIT_DESCRIPTION,
Expand Down Expand Up @@ -148,7 +150,15 @@ export const PlanExitTool = Tool.define(
}
}

const model = getLastModel(ctx.sessionID) ?? (yield* provider.defaultModel())
// Resolve model from build agent config first, then fall back to last session model
const buildAgent = yield* agents.get("build").pipe(Effect.catch(() => Effect.succeed(undefined)))
const agentModel = buildAgent?.modelRef
? yield* provider.resolveModelRef(buildAgent.modelRef).pipe(
Effect.map((m) => ({ providerID: m.providerID, modelID: m.id })),
Effect.catch(() => Effect.succeed(undefined)),
)
: buildAgent?.model ?? undefined
const model = agentModel ?? getLastModel(ctx.sessionID) ?? (yield* provider.defaultModel())

const msg: MessageV2.User = {
id: MessageID.ascending(),
Expand Down