@@ -4,13 +4,10 @@ import { withTimeout } from '@codebuff/common/util/promise'
44import { CodebuffClient } from '../../sdk/src/client'
55import { withTestRepo } from '../subagents/test-repo-utils'
66
7+ import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
78import type { EvalCommitV2 } from './types'
89
9- export interface AgentStep {
10- response : string
11- toolCalls : any [ ]
12- toolResults : any [ ]
13- }
10+ export type AgentStep = PrintModeEvent
1411
1512export async function runAgentOnCommit ( {
1613 client,
@@ -50,23 +47,6 @@ export async function runAgentOnCommit({
5047 initCommand,
5148 } ,
5249 async ( repoDir ) => {
53- let responseText = ''
54- let toolCalls : any [ ] = [ ]
55- let toolResults : any [ ] = [ ]
56-
57- function flushStep ( ) {
58- if (
59- responseText . length > 0 ||
60- toolCalls . length > 0 ||
61- toolResults . length > 0
62- ) {
63- trace . push ( { response : responseText , toolCalls, toolResults } )
64- responseText = ''
65- toolCalls = [ ]
66- toolResults = [ ]
67- }
68- }
69-
7050 const timeoutMs = 30 * 60 * 1000 // 30 minutes
7151 const result = await withTimeout (
7252 client . run ( {
@@ -75,30 +55,18 @@ export async function runAgentOnCommit({
7555 agentDefinitions : localAgentDefinitions ,
7656 cwd : repoDir ,
7757 handleEvent : ( event ) => {
78- if ( event . type === 'text' ) {
79- if ( toolResults . length > 0 ) {
80- flushStep ( )
81- }
82- responseText += event . text
83- } else if ( event . type === 'tool_call' ) {
84- if ( event . toolName === 'set_messages' ) {
85- return
86- }
87- toolCalls . push ( event )
88- } else if ( event . type === 'tool_result' ) {
89- toolResults . push ( event )
90- } else if ( event . type === 'finish' ) {
91- flushStep ( )
92- } else if ( event . type === 'error' ) {
58+ if ( event . type === 'tool_call' && event . toolName === 'set_messages' ) {
59+ return
60+ }
61+ if ( event . type === 'error' ) {
9362 console . error ( `[${ agentId } ] Error event:` , event . message )
9463 }
64+ trace . push ( event )
9565 } ,
9666 } ) ,
9767 timeoutMs ,
9868 `Agent ${ agentId } timed out after ${ timeoutMs / 1000 } seconds` ,
9969 )
100-
101- flushStep ( )
10270 cost = result . sessionState . mainAgentState . creditsUsed / 100
10371
10472 execSync ( 'git add .' , { cwd : repoDir , stdio : 'ignore' } )
0 commit comments