fix(run): inherit main-session tool permissions for continuation prompts

This commit is contained in:
YeonGyu-Kim
2026-02-18 18:02:42 +09:00
parent 7622eddb0d
commit 096db59399
17 changed files with 297 additions and 28 deletions
@@ -8,6 +8,7 @@ type MessageInfo = {
model?: { providerID: string; modelID: string }
providerID?: string
modelID?: string
tools?: Record<string, boolean | "allow" | "deny" | "ask">
}
type MessagePart = {
@@ -40,6 +41,20 @@ export function getMessageInfo(value: unknown): MessageInfo | undefined {
model,
providerID: typeof info.providerID === "string" ? info.providerID : undefined,
modelID: typeof info.modelID === "string" ? info.modelID : undefined,
tools: isRecord(info.tools)
? Object.entries(info.tools).reduce<Record<string, boolean | "allow" | "deny" | "ask">>((acc, [key, value]) => {
if (
value === true ||
value === false ||
value === "allow" ||
value === "deny" ||
value === "ask"
) {
acc[key] = value
}
return acc
}, {})
: undefined,
}
}
@@ -1,6 +1,7 @@
import type { BackgroundManager } from "../../features/background-agent"
import { getMainSessionID, getSessionAgent } from "../../features/claude-code-session-state"
import { log } from "../../shared/logger"
import { resolveInheritedPromptTools } from "../../shared"
import {
buildReminder,
extractMessages,
@@ -29,6 +30,7 @@ type BabysitterContext = {
parts: Array<{ type: "text"; text: string }>
agent?: string
model?: { providerID: string; modelID: string }
tools?: Record<string, boolean>
}
query?: { directory?: string }
}) => Promise<unknown>
@@ -38,6 +40,7 @@ type BabysitterContext = {
parts: Array<{ type: "text"; text: string }>
agent?: string
model?: { providerID: string; modelID: string }
tools?: Record<string, boolean>
}
query?: { directory?: string }
}) => Promise<unknown>
@@ -54,9 +57,10 @@ type BabysitterOptions = {
async function resolveMainSessionTarget(
ctx: BabysitterContext,
sessionID: string
): Promise<{ agent?: string; model?: { providerID: string; modelID: string } }> {
): Promise<{ agent?: string; model?: { providerID: string; modelID: string }; tools?: Record<string, boolean> }> {
let agent = getSessionAgent(sessionID)
let model: { providerID: string; modelID: string } | undefined
let tools: Record<string, boolean> | undefined
try {
const messagesResp = await ctx.client.session.messages({
@@ -68,6 +72,7 @@ async function resolveMainSessionTarget(
if (info?.agent || info?.model || (info?.providerID && info?.modelID)) {
agent = agent ?? info?.agent
model = info?.model ?? (info?.providerID && info?.modelID ? { providerID: info.providerID, modelID: info.modelID } : undefined)
tools = resolveInheritedPromptTools(sessionID, info?.tools) ?? tools
break
}
}
@@ -75,7 +80,7 @@ async function resolveMainSessionTarget(
log(`[${HOOK_NAME}] Failed to resolve main session agent`, { sessionID, error: String(error) })
}
return { agent, model }
return { agent, model, tools: resolveInheritedPromptTools(sessionID, tools) }
}
async function getThinkingSummary(ctx: BabysitterContext, sessionID: string): Promise<string | null> {
@@ -144,7 +149,7 @@ export function createUnstableAgentBabysitterHook(ctx: BabysitterContext, option
const summary = task.sessionID ? await getThinkingSummary(ctx, task.sessionID) : null
const reminder = buildReminder(task, summary, idleMs)
const { agent, model } = await resolveMainSessionTarget(ctx, mainSessionID)
const { agent, model, tools } = await resolveMainSessionTarget(ctx, mainSessionID)
try {
await ctx.client.session.promptAsync({
@@ -152,6 +157,7 @@ export function createUnstableAgentBabysitterHook(ctx: BabysitterContext, option
body: {
...(agent ? { agent } : {}),
...(model ? { model } : {}),
...(tools ? { tools } : {}),
parts: [{ type: "text", text: reminder }],
},
query: { directory: ctx.directory },