fix: use correct workDir for agentic mode with file inputs#197
fix: use correct workDir for agentic mode with file inputs#197kris-hansen merged 1 commit intomainfrom
Conversation
When agentic loops have file inputs (e.g., from STDIN temp files), the code was falling through to SendPromptWithFile which uses the file's directory as the working directory. For temp files, this meant Claude Code ran in /var/folders/... instead of the project directory. Fix: When in agentic mode with file inputs, read the file content and use SendPromptAgentic with the correct working directory from getEffectiveWorkDir().
PR Analysis
PR Feedback
How to useInstructions
|
| // In agentic mode, read the file content and use SendPromptAgentic | ||
| // This ensures the correct working directory is used instead of the file's temp directory | ||
| if isAgenticMode { | ||
| if claudeCode, ok := configuredProvider.(*models.ClaudeCodeProvider); ok { |
There was a problem hiding this comment.
Consider handling the case where configuredProvider is not of type *models.ClaudeCodeProvider more explicitly, perhaps by logging a warning or error message. This would improve the robustness of the code by making it clear when the expected provider type is not being used. [medium]
| claudeCode.SetDebugFile(debugPath) | ||
| if p.streamLog != nil { | ||
| debugWatcher = NewDebugWatcher(debugPath, p.streamLog) | ||
| debugWatcher.Start() |
There was a problem hiding this comment.
Ensure that the debugWatcher is properly stopped in all code paths, including error handling. This can be done by using a defer statement right after its creation. [important]
| claudeCode.SetWorktree(worktreeName) | ||
| defer claudeCode.ClearWorktree() | ||
| } | ||
| result, err := claudeCode.SendPromptAgentic(modelName, combinedPrompt, |
There was a problem hiding this comment.
Consider using a more descriptive variable name than result for the output of SendPromptAgentic to improve code readability and maintainability. [medium]
| return nil, fmt.Errorf("failed to read file %s: %w", fileInputs[0].Path, err) | ||
| } | ||
| // Combine file content with action | ||
| combinedPrompt := fmt.Sprintf("File: %s\n\n```\n%s\n```\n\nTask: %s", |
There was a problem hiding this comment.
When constructing combinedPrompt, consider using a template or a dedicated function to handle the formatting. This would make the code cleaner and easier to modify if the prompt format needs to change. [medium]
PR Type:
Bug fix
PR Description:
SendPromptAgenticinstead ofSendPromptWithFile.SendPromptWithFilefor non-agentic mode.PR Main Files Walkthrough:
files:
utils/processor/action_handler.go: - Modified the logic to handle file inputs differently based on whether the mode is agentic or not.SendPromptAgenticis used to ensure the correct working directory.SendPromptWithFilefor non-agentic mode.User Description:
Problem
PR #196 fixed the default
runtimeDirwhen not specified, but the issue persisted. Found the real culprit:When agentic loops have file inputs (like STDIN content written to a temp file), the code path was:
/var/folders/.../comanda-stdin-*.txtFileInputSendPromptWithFile(line ~196)SendPromptWithFileusesfilepath.Dir(file.Path)as workDir → temp directoryDebug showed:
Note: "with file" not "agentic prompt" — it was using the wrong code path!
Solution
When in agentic mode with file inputs:
SendPromptAgentic(which usesp.getEffectiveWorkDir())SendPromptWithFileonly for non-agentic modeThis ensures Claude Code runs in the project directory where
allowed_pathsresolve correctly.