@@ -1228,6 +1228,24 @@ function summarizeToolRequest(toolName: string, input: Record<string, unknown>):
12281228 return `${ toolName } : ${ serialized . slice ( 0 , 397 ) } ...` ;
12291229}
12301230
1231+ /**
1232+ * The advisor is a server-side tool: Claude consults a second model mid-turn.
1233+ * It arrives as a `server_tool_use` block named `advisor` and its result comes
1234+ * back in the assistant stream, never as a `tool_result` user message.
1235+ */
1236+ function isAdvisorToolName ( toolName : string ) : boolean {
1237+ return toolName . toLowerCase ( ) === "advisor" ;
1238+ }
1239+
1240+ /** The advisor result block, which closes the advisor tool item it names. */
1241+ function isAdvisorResultBlock ( block : unknown ) : block is { readonly tool_use_id ?: unknown } {
1242+ return (
1243+ typeof block === "object" &&
1244+ block !== null &&
1245+ ( block as { readonly type ?: unknown } ) . type === "advisor_tool_result"
1246+ ) ;
1247+ }
1248+
12311249function titleForTool ( itemType : CanonicalItemType ) : string {
12321250 switch ( itemType ) {
12331251 case "command_execution" :
@@ -2471,11 +2489,14 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
24712489 // Drop only the subagent's narration (text/thinking); tool_use blocks
24722490 // and their input_json_delta frames must flow so attributed tool items
24732491 // keep their inputs (review finding: dropping deltas emptied inputs).
2492+ // The advisor result block flows for the same reason: it is what closes
2493+ // the subagent's advisor tool item.
24742494 const dropStart =
24752495 event . type === "content_block_start" &&
24762496 event . content_block . type !== "tool_use" &&
24772497 event . content_block . type !== "server_tool_use" &&
2478- event . content_block . type !== "mcp_tool_use" ;
2498+ event . content_block . type !== "mcp_tool_use" &&
2499+ ! isAdvisorResultBlock ( event . content_block ) ;
24792500 const dropDelta =
24802501 event . type === "content_block_delta" &&
24812502 ( event . delta . type === "text_delta" || event . delta . type === "thinking_delta" ) ;
@@ -2668,6 +2689,59 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
26682689 } ) ;
26692690 return ;
26702691 }
2692+ // The advisor's result closes the tool block that started it. It never
2693+ // arrives as a `tool_result` user message, so without this the item
2694+ // spins until the turn's end-of-result sweep completes it.
2695+ if ( isAdvisorResultBlock ( block ) ) {
2696+ const advisorToolUseId =
2697+ typeof block . tool_use_id === "string" ? block . tool_use_id : undefined ;
2698+ const advisorEntry = advisorToolUseId
2699+ ? Array . from ( context . inFlightTools . entries ( ) ) . find (
2700+ ( [ , inFlight ] ) => inFlight . itemId === advisorToolUseId ,
2701+ )
2702+ : undefined ;
2703+ if ( ! advisorEntry ) {
2704+ return ;
2705+ }
2706+ const [ advisorIndex , advisorTool ] = advisorEntry ;
2707+ context . inFlightTools . delete ( advisorIndex ) ;
2708+ const advisorStamp = yield * makeEventStamp ( ) ;
2709+ yield * offerRuntimeEvent ( {
2710+ type : "item.completed" ,
2711+ eventId : advisorStamp . eventId ,
2712+ provider : PROVIDER ,
2713+ createdAt : advisorStamp . createdAt ,
2714+ threadId : context . session . threadId ,
2715+ ...( context . turnState ? { turnId : asCanonicalTurnId ( context . turnState . turnId ) } : { } ) ,
2716+ itemId : asRuntimeItemId ( advisorTool . itemId ) ,
2717+ payload : {
2718+ itemType : advisorTool . itemType ,
2719+ status : "completed" ,
2720+ title : advisorTool . title ,
2721+ ...( advisorTool . detail ? { detail : advisorTool . detail } : { } ) ,
2722+ ...( advisorTool . agentId ? { agentId : advisorTool . agentId } : { } ) ,
2723+ ...( advisorTool . parentToolUseId
2724+ ? { parentToolUseId : advisorTool . parentToolUseId }
2725+ : { } ) ,
2726+ // The advisor's advice is returned encrypted, so there is no result
2727+ // text to carry: the item records that the consult happened.
2728+ data : {
2729+ toolName : advisorTool . toolName ,
2730+ input : advisorTool . input ,
2731+ } ,
2732+ } ,
2733+ providerRefs : nativeProviderRefs ( context , {
2734+ providerItemId : advisorTool . itemId ,
2735+ } ) ,
2736+ raw : {
2737+ source : "claude.sdk.message" ,
2738+ method : "claude/stream_event/content_block_start" ,
2739+ payload : message ,
2740+ } ,
2741+ } ) ;
2742+ return ;
2743+ }
2744+
26712745 if (
26722746 block . type !== "tool_use" &&
26732747 block . type !== "server_tool_use" &&
@@ -2683,7 +2757,10 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
26832757 : { } ;
26842758 const itemType = classifyToolItemType ( toolName , toolInput ) ;
26852759 const itemId = block . id ;
2686- const detail = summarizeToolRequest ( toolName , toolInput ) ;
2760+ // The advisor takes no arguments, so the generic input summary reads
2761+ // "advisor: {}". Its title carries the meaning instead.
2762+ const isAdvisor = isAdvisorToolName ( toolName ) ;
2763+ const detail = isAdvisor ? undefined : summarizeToolRequest ( toolName , toolInput ) ;
26872764 const inputFingerprint =
26882765 Object . keys ( toolInput ) . length > 0 ? toolInputFingerprint ( toolInput ) : undefined ;
26892766
@@ -2699,8 +2776,8 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
26992776 itemId,
27002777 itemType,
27012778 toolName,
2702- title : titleForTool ( itemType ) ,
2703- detail,
2779+ title : isAdvisor ? "Advisor consult" : titleForTool ( itemType ) ,
2780+ ... ( detail ? { detail } : { } ) ,
27042781 input : toolInput ,
27052782 partialInputJson : "" ,
27062783 ...( inputFingerprint ? { lastEmittedInputFingerprint : inputFingerprint } : { } ) ,
@@ -4357,6 +4434,10 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
43574434 ...( claudeSettings . autoCompactWindow
43584435 ? { autoCompactWindow : Number ( claudeSettings . autoCompactWindow ) }
43594436 : { } ) ,
4437+ // Settings key, not the `--advisor` flag: the flag aborts session start
4438+ // when the advisor cannot advise the thread model, while this path logs
4439+ // and runs the turn without an advisor.
4440+ ...( claudeSettings . advisorModel ? { advisorModel : claudeSettings . advisorModel } : { } ) ,
43604441 } ;
43614442 const mcpSession = McpProviderSession . readMcpProviderSession ( input . threadId ) ;
43624443 // The attachments dir grant lets the agent Read/copy pasted images at
0 commit comments