@@ -48,6 +48,7 @@ import * as TestClock from "effect/testing/TestClock";
4848import { Tool } from "effect/ai" ;
4949import { formatClaudeResumeCompactionQuestion } from "@t3tools/shared/claudeCompaction" ;
5050import { HostProcessPlatform } from "@t3tools/shared/hostProcess" ;
51+ import { getModelSelectionStringOptionValue } from "@t3tools/shared/model" ;
5152import { SpawnExecutableResolution } from "@t3tools/shared/shell" ;
5253
5354import { attachmentRelativePath } from "../../attachmentStore.ts" ;
@@ -7810,25 +7811,249 @@ describe("ClaudeAdapterV2 background wake turns", () => {
78107811 ) ;
78117812 yield * Queue . take ( harness . terminalReceipts ) ;
78127813 const subagents = harness . events . filter ( ( event ) => event . type === "subagent.updated" ) ;
7814+ // Aliases and dated ids are recorded as the catalog slug.
7815+ const observedSlug = "claude-haiku-4-5" ;
78137816 const initialModel =
78147817 source === "observed-before"
7815- ? observedModel
7818+ ? observedSlug
78167819 : source === "inherit"
78177820 ? parentModel
78187821 : source === "unknown"
78197822 ? null
7820- : "haiku" ;
7823+ : "claude- haiku-5-5 " ;
78217824 assert . equal ( subagents [ 0 ] ?. subagent . model , initialModel ) ;
78227825 assert . equal (
78237826 subagents . at ( - 1 ) ?. subagent . model ,
7824- source . startsWith ( "observed" ) ? observedModel : initialModel ,
7827+ source . startsWith ( "observed" ) ? observedSlug : initialModel ,
78257828 ) ;
78267829 const child = harness . events . find ( ( event ) => event . type === "app_thread.created" ) ;
78277830 assert . equal ( child ?. appThread . modelSelection ?. model , initialModel ?? parentModel ) ;
78287831 } ) . pipe ( Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
78297832 ) ,
78307833 ) ;
78317834
7835+ it . effect . each ( [
7836+ { requested : undefined , expected : "max" } ,
7837+ { requested : "low" , expected : "low" } ,
7838+ ] ) ( "records the effort a subagent runs at (Agent effort $requested)" , ( { requested, expected } ) =>
7839+ Effect . scoped (
7840+ Effect . gen ( function * ( ) {
7841+ const harness = yield * makeWakeHarness ;
7842+ const now = yield * DateTime . now ;
7843+ const toolUseId = "toolu-subagent-effort" ;
7844+ const parentSelection = {
7845+ instanceId : CLAUDE_TEST_MODEL_SELECTION . instanceId ,
7846+ model : "claude-opus-4-6" ,
7847+ options : [
7848+ { id : "effort" , value : "max" } ,
7849+ { id : "fastMode" , value : false } ,
7850+ ] ,
7851+ } satisfies ModelSelection ;
7852+ yield * harness . runtime . startTurn (
7853+ makeClaudeTestTurnInput ( {
7854+ threadId : harness . threadId ,
7855+ providerThread : harness . providerThread ,
7856+ now,
7857+ attemptId : RunAttemptId . make ( "attempt-subagent-effort" ) ,
7858+ text : "Spawn a subagent." ,
7859+ attachments : [ ] ,
7860+ modelSelection : parentSelection ,
7861+ } ) ,
7862+ ) ;
7863+ for ( const frame of [
7864+ claudeSdkFrame ( {
7865+ type : "assistant" ,
7866+ parent_tool_use_id : null ,
7867+ message : {
7868+ model : parentSelection . model ,
7869+ id : "msg_subagent_effort_launch" ,
7870+ type : "message" ,
7871+ role : "assistant" ,
7872+ content : [
7873+ {
7874+ type : "tool_use" ,
7875+ id : toolUseId ,
7876+ name : "Agent" ,
7877+ input : {
7878+ description : "Research" ,
7879+ subagent_type : "general-purpose" ,
7880+ model : "opus" ,
7881+ ...( requested === undefined ? { } : { effort : requested } ) ,
7882+ prompt : "Research the topic." ,
7883+ } ,
7884+ } ,
7885+ ] ,
7886+ } ,
7887+ uuid : "00000000-0000-4000-8000-000000000211" ,
7888+ session_id : WAKE_NATIVE_SESSION ,
7889+ } ) ,
7890+ claudeSdkFrame ( {
7891+ type : "system" ,
7892+ subtype : "task_started" ,
7893+ task_id : "task-subagent-effort" ,
7894+ tool_use_id : toolUseId ,
7895+ description : "Research" ,
7896+ task_type : "local_agent" ,
7897+ uuid : "00000000-0000-4000-8000-000000000212" ,
7898+ session_id : WAKE_NATIVE_SESSION ,
7899+ } ) ,
7900+ // The reply names the model the alias resolved to.
7901+ claudeSdkFrame ( {
7902+ type : "assistant" ,
7903+ parent_tool_use_id : toolUseId ,
7904+ message : {
7905+ model : "claude-opus-5-5" ,
7906+ id : "msg_subagent_effort_observed" ,
7907+ type : "message" ,
7908+ role : "assistant" ,
7909+ content : [ { type : "text" , text : "Researching." } ] ,
7910+ } ,
7911+ uuid : "00000000-0000-4000-8000-000000000213" ,
7912+ session_id : WAKE_NATIVE_SESSION ,
7913+ } ) ,
7914+ makeResultFrame ( {
7915+ uuid : "00000000-0000-4000-8000-000000000214" ,
7916+ result : "Spawned the subagent." ,
7917+ } ) ,
7918+ ] ) {
7919+ yield * Queue . offer ( harness . sdkMessages , frame ) ;
7920+ }
7921+ yield * Queue . take ( harness . terminalReceipts ) ;
7922+
7923+ // The alias is stored as its slug, so the reply is no model change,
7924+ // and the parent's fast mode stays with the parent.
7925+ const subagentSelection = {
7926+ instanceId : parentSelection . instanceId ,
7927+ model : "claude-opus-5-5" ,
7928+ options : [ { id : "effort" , value : expected } ] ,
7929+ } ;
7930+ const child = harness . events . find ( ( event ) => event . type === "app_thread.created" ) ;
7931+ assert . deepEqual ( child ?. appThread . modelSelection , subagentSelection ) ;
7932+ const subagents = harness . events . filter ( ( event ) => event . type === "subagent.updated" ) ;
7933+ assert . deepEqual (
7934+ subagents . map ( ( event ) => event . subagent . modelSelection ) ,
7935+ subagents . map ( ( ) => subagentSelection ) ,
7936+ ) ;
7937+ } ) . pipe ( Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
7938+ ) ,
7939+ ) ;
7940+
7941+ it . effect ( "gives a nested subagent its own effort, else the one its owner runs at" , ( ) =>
7942+ Effect . scoped (
7943+ Effect . gen ( function * ( ) {
7944+ const OUTER_TOOL_USE_ID = "toolu-effort-outer" ;
7945+ const INHERITING_TOOL_USE_ID = "toolu-effort-nested-inheriting" ;
7946+ const OVERRIDING_TOOL_USE_ID = "toolu-effort-nested-overriding" ;
7947+ const harness = yield * makeWakeHarness ;
7948+ const now = yield * DateTime . now ;
7949+ const parentSelection = {
7950+ instanceId : CLAUDE_TEST_MODEL_SELECTION . instanceId ,
7951+ model : "claude-opus-4-6" ,
7952+ options : [ { id : "effort" , value : "high" } ] ,
7953+ } satisfies ModelSelection ;
7954+ yield * harness . runtime . startTurn (
7955+ makeClaudeTestTurnInput ( {
7956+ threadId : harness . threadId ,
7957+ providerThread : harness . providerThread ,
7958+ now,
7959+ attemptId : RunAttemptId . make ( "attempt-subagent-nested-effort" ) ,
7960+ text : "Spawn a subagent that spawns two more." ,
7961+ attachments : [ ] ,
7962+ modelSelection : parentSelection ,
7963+ } ) ,
7964+ ) ;
7965+ const agentCall = ( id : string , effort ?: string ) => ( {
7966+ type : "tool_use" as const ,
7967+ id,
7968+ name : "Agent" ,
7969+ input : {
7970+ description : id ,
7971+ subagent_type : "general-purpose" ,
7972+ ...( effort === undefined ? { } : { effort } ) ,
7973+ prompt : "Check one thing." ,
7974+ } ,
7975+ } ) ;
7976+ const taskStarted = ( id : string , uuid : string ) =>
7977+ claudeSdkFrame ( {
7978+ type : "system" ,
7979+ subtype : "task_started" ,
7980+ task_id : `task-${ id } ` ,
7981+ tool_use_id : id ,
7982+ description : id ,
7983+ task_type : "local_agent" ,
7984+ uuid,
7985+ session_id : WAKE_NATIVE_SESSION ,
7986+ } ) ;
7987+ for ( const frame of [
7988+ claudeSdkFrame ( {
7989+ type : "assistant" ,
7990+ parent_tool_use_id : null ,
7991+ message : {
7992+ model : parentSelection . model ,
7993+ id : "msg_nested_effort_outer_launch" ,
7994+ type : "message" ,
7995+ role : "assistant" ,
7996+ content : [ agentCall ( OUTER_TOOL_USE_ID , "low" ) ] ,
7997+ } ,
7998+ uuid : "00000000-0000-4000-8000-000000000221" ,
7999+ session_id : WAKE_NATIVE_SESSION ,
8000+ } ) ,
8001+ taskStarted ( OUTER_TOOL_USE_ID , "00000000-0000-4000-8000-000000000222" ) ,
8002+ // The outer subagent's own Agent calls arrive in its snapshot.
8003+ claudeSdkFrame ( {
8004+ type : "assistant" ,
8005+ parent_tool_use_id : OUTER_TOOL_USE_ID ,
8006+ message : {
8007+ model : parentSelection . model ,
8008+ id : "msg_nested_effort_inner_launch" ,
8009+ type : "message" ,
8010+ role : "assistant" ,
8011+ content : [
8012+ agentCall ( INHERITING_TOOL_USE_ID ) ,
8013+ agentCall ( OVERRIDING_TOOL_USE_ID , "max" ) ,
8014+ ] ,
8015+ } ,
8016+ uuid : "00000000-0000-4000-8000-000000000223" ,
8017+ session_id : WAKE_NATIVE_SESSION ,
8018+ } ) ,
8019+ taskStarted ( INHERITING_TOOL_USE_ID , "00000000-0000-4000-8000-000000000224" ) ,
8020+ taskStarted ( OVERRIDING_TOOL_USE_ID , "00000000-0000-4000-8000-000000000225" ) ,
8021+ makeResultFrame ( {
8022+ uuid : "00000000-0000-4000-8000-000000000226" ,
8023+ result : "Spawned the subagents." ,
8024+ } ) ,
8025+ ] ) {
8026+ yield * Queue . offer ( harness . sdkMessages , frame ) ;
8027+ }
8028+ yield * Queue . take ( harness . terminalReceipts ) ;
8029+
8030+ const efforts = new Map (
8031+ harness . events . flatMap ( ( event ) =>
8032+ event . type === "subagent.updated"
8033+ ? [
8034+ [
8035+ event . subagent . nativeTaskRef ?. nativeId ,
8036+ getModelSelectionStringOptionValue ( event . subagent . modelSelection , "effort" ) ,
8037+ ] as const ,
8038+ ]
8039+ : [ ] ,
8040+ ) ,
8041+ ) ;
8042+ assert . deepEqual ( Object . fromEntries ( efforts ) , {
8043+ [ `task-${ OUTER_TOOL_USE_ID } ` ] : "low" ,
8044+ [ `task-${ INHERITING_TOOL_USE_ID } ` ] : "low" ,
8045+ [ `task-${ OVERRIDING_TOOL_USE_ID } ` ] : "max" ,
8046+ } ) ;
8047+ const childEfforts = harness . events . flatMap ( ( event ) =>
8048+ event . type === "app_thread.created" && event . appThread . id !== harness . threadId
8049+ ? [ getModelSelectionStringOptionValue ( event . appThread . modelSelection , "effort" ) ]
8050+ : [ ] ,
8051+ ) ;
8052+ assert . deepEqual ( childEfforts , [ "low" , "low" , "max" ] ) ;
8053+ } ) . pipe ( Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
8054+ ) ,
8055+ ) ;
8056+
78328057 it . effect ( "extracts text from direct content-block subagent results" , ( ) =>
78338058 Effect . scoped (
78348059 Effect . gen ( function * ( ) {
0 commit comments