Skip to content

Propagate --explain flag into interactive mode#30

Merged
kriserickson merged 6 commits intoadd-explainfrom
copilot/sub-pr-27-again
Mar 2, 2026
Merged

Propagate --explain flag into interactive mode#30
kriserickson merged 6 commits intoadd-explainfrom
copilot/sub-pr-27-again

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

--explain was wired up for single-shot mode but silently ignored in interactive mode: interactive.Run had no explain parameter, replBuildSystemPrompt hardcoded false, and handleResponse passed false to executor.Run.

Changes

  • internal/interactive/repl.go: Add explain bool to Run, replBuildSystemPrompt, and handleResponse; thread it through to llm.BuildSystemPrompt and executor.Run
  • cmd/root.go: Pass explainFlag to interactiveRun in the interactive branch
  • Tests: Update all stubs and call sites to match new signatures; add TestRunRoot_InteractiveMode_ExplainFlag to verify explainFlag is forwarded correctly (both true and false) to interactiveRun; add TestRun_ExplainFlagPropagated to verify explain=true reaches both replBuildSystemPrompt and replHandleResponse inside the REPL loop
// Before
replBuildSystemPrompt = func(osName, shellName, shellVersion, cwd string) string {
    return llm.BuildSystemPrompt(osName, shellName, shellVersion, cwd, false) // hardcoded
}
return executor.Run(resp.Commands, cfg, shellInfo, false) // hardcoded

// After
replBuildSystemPrompt = func(osName, shellName, shellVersion, cwd string, explain bool) string {
    return llm.BuildSystemPrompt(osName, shellName, shellVersion, cwd, explain)
}
return executor.Run(resp.Commands, cfg, shellInfo, explain)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: kriserickson <325934+kriserickson@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on adding explain flag for interactive mode Propagate --explain flag into interactive mode Mar 1, 2026
@kriserickson kriserickson marked this pull request as ready for review March 1, 2026 20:28
Copilot AI review requested due to automatic review settings March 1, 2026 20:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes interactive mode ignoring the --explain flag by threading the flag through the interactive REPL entrypoint and down into system-prompt construction and command execution, matching single-shot behavior.

Changes:

  • Add an explain bool parameter to interactive.Run, replBuildSystemPrompt, and handleResponse, and pass it through to llm.BuildSystemPrompt and executor.Run.
  • Update the interactive branch in cmd/root.go to pass explainFlag into interactiveRun.
  • Update impacted tests/stubs to match the new function signatures.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/interactive/repl.go Threads explain through the interactive REPL prompt builder and response handling into executor.Run.
cmd/root.go Forwards the Cobra --explain flag into interactive mode via interactiveRun(..., explainFlag).
internal/interactive/repl_test.go Updates handleResponse callsites to include the new explain argument.
internal/interactive/repl_run_test.go Updates REPL hook stubs to match new signatures (prompt builder / response handler).
cmd/root_test.go Updates interactive-mode stubs for interactiveRun to accept the new explain argument.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 103 to 107
var capturedCmds interactive.BuiltinCommands
interactiveRun = func(_ string, cmds interactive.BuiltinCommands, _ *config.Config, _ llm.Client, _ shell.Info) error {
interactiveRun = func(_ string, cmds interactive.BuiltinCommands, _ *config.Config, _ llm.Client, _ shell.Info, _ bool) error {
capturedCmds = cmds
return nil
}
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interactive mode tests stub interactiveRun but never assert that the new explain flag is forwarded. Add/extend a test to set explainFlag=true before runRoot and verify the stub receives explain=true (and similarly verify false by default) so this regression can’t reappear.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TestRunRoot_InteractiveMode_ExplainFlag in commit 8818e5a. It calls runRoot with explainFlag=false and verifies the stub receives false, then again with explainFlag=true and verifies it receives true.

Comment on lines 200 to 204
var promptArgs []string
replBuildSystemPrompt = func(osName, shellName, shellVersion, cwd string) string {
replBuildSystemPrompt = func(osName, shellName, shellVersion, cwd string, explain bool) string {
promptArgs = []string{osName, shellName, shellVersion, cwd}
return "system-prompt"
}
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test updates the replBuildSystemPrompt signature to accept explain, but it still always calls Run(..., false) and doesn’t assert what explain value was passed into the prompt builder/response handler. Add a case that runs with explain=true and asserts the captured explain argument(s) so interactive mode explain propagation is covered.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TestRun_ExplainFlagPropagated in commit 8818e5a. It calls Run(..., true) and asserts that both replBuildSystemPrompt and replHandleResponse receive explain=true.

kriserickson and others added 2 commits March 1, 2026 16:28
- Implement ValidatePath function to ensure paths are within the current working directory and do not match blocked patterns.
- Create tests for ValidatePath covering valid paths, paths outside CWD, blocked patterns, and allowed files.
- Introduce tools for listing directories, reading files, and checking commands with safety checks.
- Add tests for tool execution, including handling of blocked files and large files.
- Implement environment variable filtering to redact sensitive information.
- Enhance command help functionality with fallbacks for Unix systems.
- Add comprehensive tests for all new functionalities to ensure reliability and security.
@kriserickson
Copy link
Owner

@copilot fix the tests for this biuld.

Co-authored-by: kriserickson <325934+kriserickson@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 2, 2026

@copilot fix the tests for this biuld.

Done in commit 8818e5a. Added the two tests requested by the reviewer to assert explain flag propagation into interactive mode.

@kriserickson kriserickson merged commit 69850da into add-explain Mar 2, 2026
3 checks passed
@kriserickson kriserickson deleted the copilot/sub-pr-27-again branch March 2, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants