@@ -8172,6 +8172,155 @@ describe("ClaudeAdapterV2 background wake turns", () => {
81728172 } ) . pipe ( Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
81738173 ) ,
81748174 ) ;
8175+
8176+ describe ( "native goals" , ( ) => {
8177+ const syntheticFrame = ( uuid : string , text : string ) =>
8178+ claudeSdkFrame ( {
8179+ type : "assistant" ,
8180+ message : {
8181+ model : "<synthetic>" ,
8182+ id : uuid ,
8183+ type : "message" ,
8184+ role : "assistant" ,
8185+ content : [ { type : "text" , text } ] ,
8186+ stop_reason : "end_turn" ,
8187+ stop_sequence : null ,
8188+ usage : {
8189+ input_tokens : 0 ,
8190+ output_tokens : 0 ,
8191+ cache_creation_input_tokens : 0 ,
8192+ cache_read_input_tokens : 0 ,
8193+ } ,
8194+ } ,
8195+ parent_tool_use_id : null ,
8196+ uuid,
8197+ session_id : WAKE_NATIVE_SESSION ,
8198+ } ) ;
8199+ const stopHookFeedback = ( uuid : string , condition : string , reason : string ) =>
8200+ claudeSdkFrame ( {
8201+ type : "user" ,
8202+ message : {
8203+ role : "user" ,
8204+ content : [ { type : "text" , text : `Stop hook feedback:\n[${ condition } ]: ${ reason } ` } ] ,
8205+ } ,
8206+ parent_tool_use_id : null ,
8207+ isSynthetic : true ,
8208+ uuid,
8209+ session_id : WAKE_NATIVE_SESSION ,
8210+ } ) ;
8211+ const goalStatuses = ( events : ReadonlyArray < ProviderAdapterV2Event > ) =>
8212+ events . flatMap ( ( event ) =>
8213+ event . type === "provider_thread.updated" && event . providerThread . goal != null
8214+ ? [ event . providerThread . goal ]
8215+ : [ ] ,
8216+ ) ;
8217+
8218+ it . effect ( "tracks a /goal through unmet checks until Claude stops on its own" , ( ) =>
8219+ Effect . gen ( function * ( ) {
8220+ const harness = yield * makeWakeHarness ;
8221+ const condition = "all tests pass" ;
8222+ yield * harness . runtime . startTurn (
8223+ makeClaudeTestTurnInput ( {
8224+ threadId : harness . threadId ,
8225+ providerThread : harness . providerThread ,
8226+ now : yield * DateTime . now ,
8227+ attemptId : RunAttemptId . make ( "goal-attempt" ) ,
8228+ text : `/goal ${ condition } ` ,
8229+ attachments : [ ] ,
8230+ } ) ,
8231+ ) ;
8232+ for ( const frame of [
8233+ syntheticFrame ( "goal-set" , `Goal set: ${ condition } ` ) ,
8234+ makeAssistantTextFrame ( { uuid : "goal-work-1" , text : "Fixing the first test." } ) ,
8235+ stopHookFeedback ( "goal-check-1" , condition , "One test still fails." ) ,
8236+ makeAssistantTextFrame ( { uuid : "goal-work-2" , text : "All tests pass now." } ) ,
8237+ makeResultFrame ( { uuid : "goal-result" , result : "All tests pass now." } ) ,
8238+ ] ) {
8239+ yield * Queue . offer ( harness . sdkMessages , frame ) ;
8240+ }
8241+ const terminal = yield * Queue . take ( harness . terminalReceipts ) ;
8242+ assert . equal ( terminal . status , "completed" ) ;
8243+ assert . deepEqual ( goalStatuses ( harness . events ) , [
8244+ { objective : condition , status : "active" , checks : 0 } ,
8245+ {
8246+ objective : condition ,
8247+ status : "active" ,
8248+ checks : 1 ,
8249+ lastCheck : "One test still fails." ,
8250+ } ,
8251+ { objective : condition , status : "complete" , checks : 1 } ,
8252+ ] ) ;
8253+ } ) . pipe ( Effect . scoped , Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
8254+ ) ;
8255+
8256+ it . effect ( "keeps a goal active when a hook stops the turn before the goal passes" , ( ) =>
8257+ Effect . gen ( function * ( ) {
8258+ const harness = yield * makeWakeHarness ;
8259+ const condition = "the deploy succeeds" ;
8260+ yield * harness . runtime . startTurn (
8261+ makeClaudeTestTurnInput ( {
8262+ threadId : harness . threadId ,
8263+ providerThread : harness . providerThread ,
8264+ now : yield * DateTime . now ,
8265+ attemptId : RunAttemptId . make ( "goal-hook-stop-attempt" ) ,
8266+ text : `/goal ${ condition } ` ,
8267+ attachments : [ ] ,
8268+ } ) ,
8269+ ) ;
8270+ for ( const frame of [
8271+ syntheticFrame ( "goal-hook-set" , `Goal set: ${ condition } ` ) ,
8272+ makeAssistantTextFrame ( { uuid : "goal-hook-work" , text : "Deploying." } ) ,
8273+ makeResultFrame ( {
8274+ uuid : "goal-hook-result" ,
8275+ result : "Deploying." ,
8276+ terminalReason : "hook_stopped" ,
8277+ } ) ,
8278+ ] ) {
8279+ yield * Queue . offer ( harness . sdkMessages , frame ) ;
8280+ }
8281+ yield * Queue . take ( harness . terminalReceipts ) ;
8282+ assert . deepEqual ( goalStatuses ( harness . events ) . at ( - 1 ) , {
8283+ objective : condition ,
8284+ status : "active" ,
8285+ checks : 0 ,
8286+ } ) ;
8287+ } ) . pipe ( Effect . scoped , Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
8288+ ) ;
8289+
8290+ it . effect ( "keeps a goal active after a command turn with no model output" , ( ) =>
8291+ Effect . gen ( function * ( ) {
8292+ const harness = yield * makeWakeHarness ;
8293+ const condition = "the build is green" ;
8294+ yield * harness . runtime . startTurn (
8295+ makeClaudeTestTurnInput ( {
8296+ threadId : harness . threadId ,
8297+ providerThread : {
8298+ ...harness . providerThread ,
8299+ goal : { objective : condition , status : "active" , checks : 2 } ,
8300+ } ,
8301+ now : yield * DateTime . now ,
8302+ attemptId : RunAttemptId . make ( "goal-show-attempt" ) ,
8303+ text : "/goal" ,
8304+ attachments : [ ] ,
8305+ } ) ,
8306+ ) ;
8307+ yield * Queue . offer (
8308+ harness . sdkMessages ,
8309+ syntheticFrame ( "goal-show" , `Goal active: ${ condition } (2 turns)` ) ,
8310+ ) ;
8311+ yield * Queue . offer (
8312+ harness . sdkMessages ,
8313+ makeResultFrame ( { uuid : "goal-show-result" , result : "" , numTurns : 0 } ) ,
8314+ ) ;
8315+ yield * Queue . take ( harness . terminalReceipts ) ;
8316+ assert . deepEqual ( goalStatuses ( harness . events ) . at ( - 1 ) , {
8317+ objective : condition ,
8318+ status : "active" ,
8319+ checks : 2 ,
8320+ } ) ;
8321+ } ) . pipe ( Effect . scoped , Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
8322+ ) ;
8323+ } ) ;
81758324} ) ;
81768325
81778326describe ( "ClaudeAdapterV2 query message stream" , ( ) => {
0 commit comments