@@ -13,9 +13,7 @@ import (
1313)
1414
1515func (e * Engine ) runTool (ctx context.Context , name string , args map [string ]string ) (string , error ) {
16- tools := iteragent .DefaultTools (e .repoPath )
17- tm := iteragent .ToolMap (tools )
18- tool , ok := tm [name ]
16+ tool , ok := e .toolMap [name ]
1917 if ! ok {
2018 return "" , fmt .Errorf ("tool %q not found" , name )
2119 }
@@ -127,10 +125,10 @@ func (e *Engine) createPR(ctx context.Context, title, body string, issueNums []i
127125
128126 url := strings .TrimSpace (out )
129127 var prNum int
130- fmt .Sscanf (url , "%*s/%d" , & prNum )
131128 if idx := strings .LastIndex (url , "/" ); idx >= 0 {
132- numStr := url [idx + 1 :]
133- fmt .Sscanf (numStr , "%d" , & prNum )
129+ if _ , err := fmt .Sscanf (url [idx + 1 :], "%d" , & prNum ); err != nil {
130+ e .logger .Warn ("could not parse PR number from URL" , "url" , url )
131+ }
134132 }
135133
136134 e .prURL = url
@@ -208,7 +206,7 @@ func (e *Engine) mergePR(ctx context.Context) error {
208206 })
209207 if err != nil {
210208 if strings .Contains (strings .ToLower (out ), "no mergeable" ) || strings .Contains (strings .ToLower (out ), "conflict" ) {
211- e .logger .Warn ("PR has merge conflicts, attempting auto- merge" )
209+ e .logger .Warn ("PR has merge conflicts, attempting merge with --admin flag (bypasses branch protection)" , "pr" , e . prNumber )
212210 mergeOut , mergeErr := e .runTool (ctx , "bash" , map [string ]string {
213211 "cmd" : fmt .Sprintf ("gh pr merge %d --repo %s --squash --admin --delete-branch 2>&1 || echo 'MERGE_FAILED'" , e .prNumber , e .repo ),
214212 })
@@ -254,9 +252,7 @@ func (e *Engine) forwardEvents(src <-chan iteragent.Event) {
254252}
255253
256254func (e * Engine ) runTests (ctx context.Context ) (string , error ) {
257- tools := iteragent .DefaultTools (e .repoPath )
258- tm := iteragent .ToolMap (tools )
259- return tm ["run_tests" ].Execute (ctx , nil )
255+ return e .toolMap ["run_tests" ].Execute (ctx , nil )
260256}
261257
262258// defaultPhaseTimeout is the maximum duration for any evolution phase.
@@ -268,25 +264,19 @@ func withTimeout(ctx context.Context) (context.Context, context.CancelFunc) {
268264}
269265
270266func (e * Engine ) revert (ctx context.Context ) error {
271- tools := iteragent .DefaultTools (e .repoPath )
272- tm := iteragent .ToolMap (tools )
273-
274- // First, reset all staged and unstaged changes
275- _ , err := e .runTool (ctx , "bash" , map [string ]string {
267+ // Reset uncommitted changes first.
268+ if _ , err := e .runTool (ctx , "bash" , map [string ]string {
276269 "cmd" : "git checkout -- . && git clean -fd" ,
277- })
278- if err != nil {
279- e .logger .Warn ("git checkout failed, trying revert tool" , "err" , err )
270+ }); err == nil {
271+ return nil
280272 }
281-
282- // Then use the revert tool for any committed changes
283- _ , err = tm ["git_revert" ].Execute (ctx , nil )
273+ // Fall back: use git_revert tool for any committed changes.
274+ e . logger . Warn ( "git checkout failed, trying revert tool" )
275+ _ , err := e . toolMap ["git_revert" ].Execute (ctx , nil )
284276 return err
285277}
286278
287279func (e * Engine ) commit (ctx context.Context , msg string ) error {
288- tools := iteragent .DefaultTools (e .repoPath )
289- tm := iteragent .ToolMap (tools )
290- _ , err := tm ["git_commit" ].Execute (ctx , map [string ]string {"message" : msg })
280+ _ , err := e .toolMap ["git_commit" ].Execute (ctx , map [string ]string {"message" : msg })
291281 return err
292282}
0 commit comments