@@ -12,6 +12,7 @@ import {
1212 type InProcessAcpConnection ,
1313} from "../adapters/acp-connection" ;
1414import { selectRecentTurns } from "../adapters/claude/session/jsonl-hydration" ;
15+ import { RESEARCH_BACKGROUND_TOOLS } from "../adapters/claude/tools" ;
1516import { PostHogAPIClient } from "../posthog-api" ;
1617import {
1718 type ConversationTurn ,
@@ -633,18 +634,24 @@ export class AgentServer {
633634 this . detectedPrUrl = prUrl ;
634635 }
635636
637+ const claudeCodeOptions : Record < string , unknown > = { } ;
638+ if ( this . config . claudeCode ?. plugins ?. length ) {
639+ claudeCodeOptions . plugins = this . config . claudeCode . plugins ;
640+ }
641+ if ( this . config . toolsPreset === "research_background_agent" ) {
642+ claudeCodeOptions . tools = RESEARCH_BACKGROUND_TOOLS ;
643+ }
644+
636645 const sessionResponse = await clientConnection . newSession ( {
637646 cwd : this . config . repositoryPath ?? "/tmp/workspace" ,
638647 mcpServers : this . config . mcpServers ?? [ ] ,
639648 _meta : {
640649 sessionId : payload . run_id ,
641650 taskRunId : payload . run_id ,
642651 systemPrompt : this . buildSessionSystemPrompt ( prUrl ) ,
643- ...( this . config . claudeCode ?. plugins ?. length && {
652+ ...( Object . keys ( claudeCodeOptions ) . length > 0 && {
644653 claudeCode : {
645- options : {
646- plugins : this . config . claudeCode . plugins ,
647- } ,
654+ options : claudeCodeOptions ,
648655 } ,
649656 } ) ,
650657 } ,
@@ -1095,6 +1102,27 @@ Important:
10951102 options : params . options ,
10961103 } ) ;
10971104
1105+ // Defense-in-depth: deny tools not in the restricted allowlist
1106+ if ( this . config . toolsPreset === "research_background_agent" ) {
1107+ const meta = params . toolCall ?. _meta as
1108+ | Record < string , unknown >
1109+ | undefined ;
1110+ const toolName =
1111+ ( meta ?. codeToolKind as string ) ?? ( meta ?. toolName as string ) ;
1112+ if ( toolName && ! RESEARCH_BACKGROUND_TOOLS . includes ( toolName ) ) {
1113+ this . logger . warn (
1114+ "Denied restricted tool in research_background_agent mode" ,
1115+ { toolName } ,
1116+ ) ;
1117+ return {
1118+ outcome : { outcome : "cancelled" as const } ,
1119+ _meta : {
1120+ message : `Tool "${ toolName } " is not available in research mode. You can only use read, search, and planning tools.` ,
1121+ } ,
1122+ } ;
1123+ }
1124+ }
1125+
10981126 const allowOption = params . options . find (
10991127 ( o ) => o . kind === "allow_once" || o . kind === "allow_always" ,
11001128 ) ;
0 commit comments