feat: store tool restrictions in session-tools-store at prompt-send sites
Call setSessionTools(sessionID, tools) before every prompt dispatch so the tools object is captured and available for later retrieval when background tasks complete.
This commit is contained in:
parent
936b51de79
commit
f20e1aa0d0
@ -1,5 +1,6 @@
|
|||||||
import type { BackgroundTask, ResumeInput } from "../types"
|
import type { BackgroundTask, ResumeInput } from "../types"
|
||||||
import { log, getAgentToolRestrictions } from "../../../shared"
|
import { log, getAgentToolRestrictions } from "../../../shared"
|
||||||
|
import { setSessionTools } from "../../../shared/session-tools-store"
|
||||||
import type { SpawnerContext } from "./spawner-context"
|
import type { SpawnerContext } from "./spawner-context"
|
||||||
import { subagentSessions } from "../../claude-code-session-state"
|
import { subagentSessions } from "../../claude-code-session-state"
|
||||||
import { getTaskToastManager } from "../../task-toast-manager"
|
import { getTaskToastManager } from "../../task-toast-manager"
|
||||||
@ -35,6 +36,9 @@ export async function resumeTask(
|
|||||||
task.parentMessageID = input.parentMessageID
|
task.parentMessageID = input.parentMessageID
|
||||||
task.parentModel = input.parentModel
|
task.parentModel = input.parentModel
|
||||||
task.parentAgent = input.parentAgent
|
task.parentAgent = input.parentAgent
|
||||||
|
if (input.parentTools) {
|
||||||
|
task.parentTools = input.parentTools
|
||||||
|
}
|
||||||
task.startedAt = new Date()
|
task.startedAt = new Date()
|
||||||
|
|
||||||
task.progress = {
|
task.progress = {
|
||||||
@ -75,12 +79,16 @@ export async function resumeTask(
|
|||||||
agent: task.agent,
|
agent: task.agent,
|
||||||
...(resumeModel ? { model: resumeModel } : {}),
|
...(resumeModel ? { model: resumeModel } : {}),
|
||||||
...(resumeVariant ? { variant: resumeVariant } : {}),
|
...(resumeVariant ? { variant: resumeVariant } : {}),
|
||||||
tools: {
|
tools: (() => {
|
||||||
|
const tools = {
|
||||||
...getAgentToolRestrictions(task.agent),
|
...getAgentToolRestrictions(task.agent),
|
||||||
task: false,
|
task: false,
|
||||||
call_omo_agent: true,
|
call_omo_agent: true,
|
||||||
question: false,
|
question: false,
|
||||||
},
|
}
|
||||||
|
setSessionTools(task.sessionID!, tools)
|
||||||
|
return tools
|
||||||
|
})(),
|
||||||
parts: [{ type: "text", text: input.prompt }],
|
parts: [{ type: "text", text: input.prompt }],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import type { QueueItem } from "../constants"
|
import type { QueueItem } from "../constants"
|
||||||
import { log, getAgentToolRestrictions, promptWithModelSuggestionRetry } from "../../../shared"
|
import { log, getAgentToolRestrictions, promptWithModelSuggestionRetry } from "../../../shared"
|
||||||
|
import { setSessionTools } from "../../../shared/session-tools-store"
|
||||||
import { subagentSessions } from "../../claude-code-session-state"
|
import { subagentSessions } from "../../claude-code-session-state"
|
||||||
import { getTaskToastManager } from "../../task-toast-manager"
|
import { getTaskToastManager } from "../../task-toast-manager"
|
||||||
import { createBackgroundSession } from "./background-session-creator"
|
import { createBackgroundSession } from "./background-session-creator"
|
||||||
@ -79,12 +80,16 @@ export async function startTask(item: QueueItem, ctx: SpawnerContext): Promise<v
|
|||||||
...(launchModel ? { model: launchModel } : {}),
|
...(launchModel ? { model: launchModel } : {}),
|
||||||
...(launchVariant ? { variant: launchVariant } : {}),
|
...(launchVariant ? { variant: launchVariant } : {}),
|
||||||
system: input.skillContent,
|
system: input.skillContent,
|
||||||
tools: {
|
tools: (() => {
|
||||||
|
const tools = {
|
||||||
...getAgentToolRestrictions(input.agent),
|
...getAgentToolRestrictions(input.agent),
|
||||||
task: false,
|
task: false,
|
||||||
call_omo_agent: true,
|
call_omo_agent: true,
|
||||||
question: false,
|
question: false,
|
||||||
},
|
}
|
||||||
|
setSessionTools(sessionID, tools)
|
||||||
|
return tools
|
||||||
|
})(),
|
||||||
parts: [{ type: "text", text: input.prompt }],
|
parts: [{ type: "text", text: input.prompt }],
|
||||||
},
|
},
|
||||||
}).catch((error: unknown) => {
|
}).catch((error: unknown) => {
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import { promptWithModelSuggestionRetry } from "../../shared/model-suggestion-re
|
|||||||
import { findNearestMessageWithFields } from "../../features/hook-message-injector"
|
import { findNearestMessageWithFields } from "../../features/hook-message-injector"
|
||||||
import { formatDuration } from "./time-formatter"
|
import { formatDuration } from "./time-formatter"
|
||||||
import { syncContinuationDeps, type SyncContinuationDeps } from "./sync-continuation-deps"
|
import { syncContinuationDeps, type SyncContinuationDeps } from "./sync-continuation-deps"
|
||||||
|
import { setSessionTools } from "../../shared/session-tools-store"
|
||||||
|
|
||||||
export async function executeSyncContinuation(
|
export async function executeSyncContinuation(
|
||||||
args: DelegateTaskArgs,
|
args: DelegateTaskArgs,
|
||||||
@ -77,6 +78,13 @@ export async function executeSyncContinuation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const allowTask = isPlanFamily(resumeAgent)
|
const allowTask = isPlanFamily(resumeAgent)
|
||||||
|
const tools = {
|
||||||
|
...(resumeAgent ? getAgentToolRestrictions(resumeAgent) : {}),
|
||||||
|
task: allowTask,
|
||||||
|
call_omo_agent: true,
|
||||||
|
question: false,
|
||||||
|
}
|
||||||
|
setSessionTools(args.session_id!, tools)
|
||||||
|
|
||||||
await promptWithModelSuggestionRetry(client, {
|
await promptWithModelSuggestionRetry(client, {
|
||||||
path: { id: args.session_id! },
|
path: { id: args.session_id! },
|
||||||
@ -84,12 +92,7 @@ export async function executeSyncContinuation(
|
|||||||
...(resumeAgent !== undefined ? { agent: resumeAgent } : {}),
|
...(resumeAgent !== undefined ? { agent: resumeAgent } : {}),
|
||||||
...(resumeModel !== undefined ? { model: resumeModel } : {}),
|
...(resumeModel !== undefined ? { model: resumeModel } : {}),
|
||||||
...(resumeVariant !== undefined ? { variant: resumeVariant } : {}),
|
...(resumeVariant !== undefined ? { variant: resumeVariant } : {}),
|
||||||
tools: {
|
tools,
|
||||||
...(resumeAgent ? getAgentToolRestrictions(resumeAgent) : {}),
|
|
||||||
task: allowTask,
|
|
||||||
call_omo_agent: true, // Intentionally overrides restrictions - continuation context needs delegation capability even for restricted agents
|
|
||||||
question: false,
|
|
||||||
},
|
|
||||||
parts: [{ type: "text", text: args.prompt }],
|
parts: [{ type: "text", text: args.prompt }],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { isPlanFamily } from "./constants"
|
|||||||
import { promptWithModelSuggestionRetry } from "../../shared/model-suggestion-retry"
|
import { promptWithModelSuggestionRetry } from "../../shared/model-suggestion-retry"
|
||||||
import { formatDetailedError } from "./error-formatting"
|
import { formatDetailedError } from "./error-formatting"
|
||||||
import { getAgentToolRestrictions } from "../../shared/agent-tool-restrictions"
|
import { getAgentToolRestrictions } from "../../shared/agent-tool-restrictions"
|
||||||
|
import { setSessionTools } from "../../shared/session-tools-store"
|
||||||
|
|
||||||
export async function sendSyncPrompt(
|
export async function sendSyncPrompt(
|
||||||
client: OpencodeClient,
|
client: OpencodeClient,
|
||||||
@ -18,17 +19,19 @@ export async function sendSyncPrompt(
|
|||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const allowTask = isPlanFamily(input.agentToUse)
|
const allowTask = isPlanFamily(input.agentToUse)
|
||||||
|
const tools = {
|
||||||
|
task: allowTask,
|
||||||
|
call_omo_agent: true,
|
||||||
|
question: false,
|
||||||
|
...getAgentToolRestrictions(input.agentToUse),
|
||||||
|
}
|
||||||
|
setSessionTools(input.sessionID, tools)
|
||||||
await promptWithModelSuggestionRetry(client, {
|
await promptWithModelSuggestionRetry(client, {
|
||||||
path: { id: input.sessionID },
|
path: { id: input.sessionID },
|
||||||
body: {
|
body: {
|
||||||
agent: input.agentToUse,
|
agent: input.agentToUse,
|
||||||
system: input.systemContent,
|
system: input.systemContent,
|
||||||
tools: {
|
tools,
|
||||||
task: allowTask,
|
|
||||||
call_omo_agent: true,
|
|
||||||
question: false,
|
|
||||||
...getAgentToolRestrictions(input.agentToUse),
|
|
||||||
},
|
|
||||||
parts: [{ type: "text", text: input.args.prompt }],
|
parts: [{ type: "text", text: input.args.prompt }],
|
||||||
...(input.categoryModel ? { model: { providerID: input.categoryModel.providerID, modelID: input.categoryModel.modelID } } : {}),
|
...(input.categoryModel ? { model: { providerID: input.categoryModel.providerID, modelID: input.categoryModel.modelID } } : {}),
|
||||||
...(input.categoryModel?.variant ? { variant: input.categoryModel.variant } : {}),
|
...(input.categoryModel?.variant ? { variant: input.categoryModel.variant } : {}),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user