Skip to content

feat: shell command explanation option#173

Merged
tibo-openai merged 11 commits into
openai:mainfrom
binbandit:feat/shell-command-explanation
Apr 17, 2025
Merged

feat: shell command explanation option#173
tibo-openai merged 11 commits into
openai:mainfrom
binbandit:feat/shell-command-explanation

Conversation

@binbandit

@binbandit binbandit commented Apr 17, 2025

Copy link
Copy Markdown
Contributor

Shell Command Explanation Option

Description

This PR adds an option to explain shell commands when the user is prompted to approve them (Fixes #110). When reviewing a shell command, users can now select "Explain this command" to get a detailed explanation of what the command does before deciding whether to approve or reject it.

Changes

  • Added a new "EXPLAIN" option to the ReviewDecision enum
  • Updated the command review UI to include an "Explain this command (x)" option
  • Implemented the logic to send the command to the LLM for explanation using the same model as the agent
  • Added a display for the explanation in the command review UI
  • Updated all relevant components to pass the explanation through the component tree

Benefits

  • Improves user understanding of shell commands before approving them
  • Reduces the risk of approving potentially harmful commands
  • Enhances the educational aspect of the tool, helping users learn about shell commands
  • Maintains the same workflow with minimal UI changes

Testing

  • Manually tested the explanation feature with various shell commands
  • Verified that the explanation is displayed correctly in the UI
  • Confirmed that the user can still approve or reject the command after viewing the explanation

Screenshots

improved_shell_explanation_demo

Additional Notes

The explanation is generated using the same model as the agent, ensuring consistency in the quality and style of explanations.

Signed-off-by: crazywolf132 <crazywolf132@gmail.com>
@tibo-openai

Copy link
Copy Markdown
Collaborator

Could you attach a small video of how it looks like?

@tibo-openai tibo-openai changed the title Shell Command Explanation Option feat: shell command explanation option Apr 17, 2025
@tibo-openai

Copy link
Copy Markdown
Collaborator

Will merge once there is a video attached that demonstrates this in action.

@binbandit

Copy link
Copy Markdown
Contributor Author

Will merge once there is a video attached that demonstrates this in action.

Added a demo

@binbandit

Copy link
Copy Markdown
Contributor Author

This PR fixes a critical issue with the current flow, this PR requires this other PR to be merged too:

#197

@tibo-openai

Copy link
Copy Markdown
Collaborator

Very nice. I will merge this, but in the future we will want to have the acting model explain the command based on the full context instead of delegating the explanation to a separate model. We will land this in a follow-up and will merge this as is as it's clearly useful and it's working well after trying it out locally. Thank you!

@tibo-openai tibo-openai merged commit f3d085a into openai:main Apr 17, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 17, 2025
} catch (e) {
// In practice, there seem to be syntactically valid shell commands that
// shell-quote cannot parse, so we should not reject, but ask the user.
switch (policy) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should have stayed a switch statement because we have ESLint rules set up to ensure switch statements are exhaustive so that if a new variant of the ApprovalPolicy enum is introduced we are forced to address the existing callsites.

};
}

// In 'suggest' mode, all shell commands should require user permission

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The point of isSafeCommand() is to avoid user permission.

Comment thread codex-cli/package.json
"openai": "^4.89.0",
"react": "^18.2.0",
"shell-quote": "^1.8.2",
"strip-ansi": "^7.1.0",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be in devDependencies.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell Command Explanation

3 participants