fix(run): inherit main-session tool permissions for continuation prompts
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import type { BackgroundManager } from "../../features/background-agent"
|
||||
import { log } from "../../shared/logger"
|
||||
import { resolveInheritedPromptTools } from "../../shared"
|
||||
import { HOOK_NAME } from "./hook-name"
|
||||
import { BOULDER_CONTINUATION_PROMPT } from "./system-reminder-templates"
|
||||
import { resolveRecentModelForSession } from "./recent-model-resolver"
|
||||
import { resolveRecentPromptContextForSession } from "./recent-model-resolver"
|
||||
import type { SessionState } from "./types"
|
||||
|
||||
export async function injectBoulderContinuation(input: {
|
||||
@@ -43,13 +44,15 @@ export async function injectBoulderContinuation(input: {
|
||||
try {
|
||||
log(`[${HOOK_NAME}] Injecting boulder continuation`, { sessionID, planName, remaining })
|
||||
|
||||
const model = await resolveRecentModelForSession(ctx, sessionID)
|
||||
const promptContext = await resolveRecentPromptContextForSession(ctx, sessionID)
|
||||
const inheritedTools = resolveInheritedPromptTools(sessionID, promptContext.tools)
|
||||
|
||||
await ctx.client.session.promptAsync({
|
||||
path: { id: sessionID },
|
||||
body: {
|
||||
agent: agent ?? "atlas",
|
||||
...(model !== undefined ? { model } : {}),
|
||||
...(promptContext.model !== undefined ? { model: promptContext.model } : {}),
|
||||
...(inheritedTools ? { tools: inheritedTools } : {}),
|
||||
parts: [{ type: "text", text: prompt }],
|
||||
},
|
||||
query: { directory: ctx.directory },
|
||||
|
||||
@@ -3,28 +3,39 @@ import {
|
||||
findNearestMessageWithFields,
|
||||
findNearestMessageWithFieldsFromSDK,
|
||||
} from "../../features/hook-message-injector"
|
||||
import { getMessageDir, isSqliteBackend, normalizeSDKResponse } from "../../shared"
|
||||
import { getMessageDir, isSqliteBackend, normalizePromptTools, normalizeSDKResponse } from "../../shared"
|
||||
import type { ModelInfo } from "./types"
|
||||
|
||||
export async function resolveRecentModelForSession(
|
||||
type PromptContext = {
|
||||
model?: ModelInfo
|
||||
tools?: Record<string, boolean>
|
||||
}
|
||||
|
||||
export async function resolveRecentPromptContextForSession(
|
||||
ctx: PluginInput,
|
||||
sessionID: string
|
||||
): Promise<ModelInfo | undefined> {
|
||||
): Promise<PromptContext> {
|
||||
try {
|
||||
const messagesResp = await ctx.client.session.messages({ path: { id: sessionID } })
|
||||
const messages = normalizeSDKResponse(messagesResp, [] as Array<{
|
||||
info?: { model?: ModelInfo; modelID?: string; providerID?: string }
|
||||
info?: {
|
||||
model?: ModelInfo
|
||||
modelID?: string
|
||||
providerID?: string
|
||||
tools?: Record<string, boolean | "allow" | "deny" | "ask">
|
||||
}
|
||||
}>)
|
||||
|
||||
for (let i = messages.length - 1; i >= 0; i--) {
|
||||
const info = messages[i].info
|
||||
const model = info?.model
|
||||
const tools = normalizePromptTools(info?.tools)
|
||||
if (model?.providerID && model?.modelID) {
|
||||
return { providerID: model.providerID, modelID: model.modelID }
|
||||
return { model: { providerID: model.providerID, modelID: model.modelID }, tools }
|
||||
}
|
||||
|
||||
if (info?.providerID && info?.modelID) {
|
||||
return { providerID: info.providerID, modelID: info.modelID }
|
||||
return { model: { providerID: info.providerID, modelID: info.modelID }, tools }
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
@@ -39,8 +50,17 @@ export async function resolveRecentModelForSession(
|
||||
currentMessage = messageDir ? findNearestMessageWithFields(messageDir) : null
|
||||
}
|
||||
const model = currentMessage?.model
|
||||
const tools = normalizePromptTools(currentMessage?.tools)
|
||||
if (!model?.providerID || !model?.modelID) {
|
||||
return undefined
|
||||
return { tools }
|
||||
}
|
||||
return { providerID: model.providerID, modelID: model.modelID }
|
||||
return { model: { providerID: model.providerID, modelID: model.modelID }, tools }
|
||||
}
|
||||
|
||||
export async function resolveRecentModelForSession(
|
||||
ctx: PluginInput,
|
||||
sessionID: string
|
||||
): Promise<ModelInfo | undefined> {
|
||||
const context = await resolveRecentPromptContextForSession(ctx, sessionID)
|
||||
return context.model
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user