Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Enhance /run Command to Support Piping Content into the Session #2740

Open
lockmeister opened this issue Jan 1, 2025 · 4 comments

Comments

@lockmeister
Copy link

Description:
The existing /run command in Aider allows users to execute shell commands. However, it could be
enhanced to directly pipe the output of those commands into the interactive session for further
interaction.

Proposed Solution:
Modify the /run command to include an option or syntax that pipes the output of the executed
command into the session. For example:

/run cat blah.txt --pipe

or

/run echo "This is some text" --pipe

This would inject the output of the command into the session as if it were typed directly by the
user.

Use Case:

• Dynamically inject file content or command output into the session for analysis or modification.
• Streamline workflows where dynamic content needs to be included without leaving the interactive
session.

Example Workflow:

1 Start an interactive Aider session:

aider                                                                                          

2 Inside the Aider prompt, use the /run command to pipe content:

/run cat requirements.txt --pipe                                                               

This would inject the contents of requirements.txt into the session for further interaction.

Benefits:

• Leverages existing functionality (/run) to avoid introducing new commands.
• Improves efficiency for users who rely on dynamic content.
• Better integration with command-line workflows without leaving the interactive session.

Aider version: 0.70.0
Python version: 3.12.3
Platform: Linux-6.8.0-51-generic-x86_64-with-glibc2.39
Python implementation: CPython
Virtual environment: Yes
OS: Linux 6.8.0-51-generic (64bit)
Git version: git version 2.43.0

@lockmeister
Copy link
Author

lockmeister commented Jan 1, 2025

I know that the /run command already offers to add command output to the chat.

For example,
/run cat .aider.chat.history.md | llm "summarise this" works, leveraging https://datasette.io/tools/llm

however it would still be useful to be able to insert the output of commands into arbitrary parts of an aider prompt
rather than just the chat history.

@lockmeister
Copy link
Author

/run echo "explain all these files: $(ls)"

^^This is the sort of thing I want to be able to do, but all this does is add the output to the chat, not execute it as a prompt

@lockmeister
Copy link
Author

lockmeister commented Jan 1, 2025

Related; this could be useful

Tool Reference Injection: Use a special syntax (e.g., @tool, or !bash_command) to reference external tools like
MCP tools and inject their output into the prompt.

@mcp fetch-context --file=blah.txt

This could also be activated when using --watch-files in another editor, to achieve more capable and enriched results.

E.g. in VSCode, while aider is being used in --watch-files mode:

# insert a summary of @mcp fetch-context --file=blah.txt here AI!

# insert a bullet point list of the main problems we've had !tail -n 50 debug.log AI!

@lockmeister
Copy link
Author

Description: Allow users to dynamically insert evaluated output into their prompts using shell-like syntax (e.g.,
$(cat file.txt) or $(git branch --show-current)). This would enable real-time context integration, such as file
contents, Git status, or environment variables, directly into their instructions to the LLM.

Example:

Fix the bug in $(cat bug_report.txt). The current branch is $(git branch --show-current).

→ Becomes:

Fix the bug in NullPointerException in line 42. The current branch is main.

Implementation:

1 Parse User Input: Identify $(...) patterns using regex.
2 Evaluate Commands: Use subprocess.run to execute commands and capture output.
3 Replace Commands: Insert evaluated output into the prompt.
4 Security: Sanitize input and whitelist safe commands (e.g., cat, pwd, git).
5 Integration: Add this functionality to Aider’s input handling in io.py.

Benefits:

• Dynamic Context: Insert real-time information into prompts.
• Flexibility: Supports file content, Git status, environment variables, etc.
• Seamless Workflow: Fits naturally into Aider’s conversational interface.

Challenges:

• Security: Prevent command injection and ensure safe execution.
• Complexity: Handle multi-line output and special characters.
• User Education: Provide clear documentation and examples.

Next Steps:

1 Implement and test the feature in io.py.
2 Add documentation and examples for users.
3 Consider a whitelist of safe commands for enhanced security.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
This feature would make Aider even more powerful by allowing users to incorporate dynamic, real-time context into
their prompts.

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

No branches or pull requests

1 participant