@@ -3,7 +3,6 @@ import { expect, spyOn } from "bun:test"
33import { Cause , Effect , Exit , Fiber , Layer } from "effect"
44import path from "path"
55import z from "zod"
6- import type { Agent } from "../../src/agent/agent"
76import { Agent as AgentSvc } from "../../src/agent/agent"
87import { Bus } from "../../src/bus"
98import { Command } from "../../src/command"
@@ -35,7 +34,7 @@ import { Log } from "../../src/util/log"
3534import * as CrossSpawnSpawner from "../../src/effect/cross-spawn-spawner"
3635import { provideTmpdirInstance , provideTmpdirServer } from "../fixture/fixture"
3736import { testEffect } from "../lib/effect"
38- import { TestLLMServer } from "../lib/llm-server"
37+ import { reply , TestLLMServer } from "../lib/llm-server"
3938
4039Log . init ( { print : false } )
4140
@@ -453,6 +452,36 @@ it.live("loop continues when finish is tool-calls", () =>
453452 ) ,
454453)
455454
455+ it . live ( "loop continues when finish is stop but assistant has tool parts" , ( ) =>
456+ provideTmpdirServer (
457+ Effect . fnUntraced ( function * ( { llm } ) {
458+ const prompt = yield * SessionPrompt . Service
459+ const sessions = yield * Session . Service
460+ const session = yield * sessions . create ( {
461+ title : "Pinned" ,
462+ permission : [ { permission : "*" , pattern : "*" , action : "allow" } ] ,
463+ } )
464+ yield * prompt . prompt ( {
465+ sessionID : session . id ,
466+ agent : "build" ,
467+ noReply : true ,
468+ parts : [ { type : "text" , text : "hello" } ] ,
469+ } )
470+ yield * llm . push ( reply ( ) . tool ( "first" , { value : "first" } ) . stop ( ) )
471+ yield * llm . text ( "second" )
472+
473+ const result = yield * prompt . loop ( { sessionID : session . id } )
474+ expect ( yield * llm . calls ) . toBe ( 2 )
475+ expect ( result . info . role ) . toBe ( "assistant" )
476+ if ( result . info . role === "assistant" ) {
477+ expect ( result . parts . some ( ( part ) => part . type === "text" && part . text === "second" ) ) . toBe ( true )
478+ expect ( result . info . finish ) . toBe ( "stop" )
479+ }
480+ } ) ,
481+ { git : true , config : providerCfg } ,
482+ ) ,
483+ )
484+
456485it . live ( "failed subtask preserves metadata on error tool state" , ( ) =>
457486 provideTmpdirServer (
458487 Effect . fnUntraced ( function * ( { llm } ) {
0 commit comments