-
Notifications
You must be signed in to change notification settings - Fork 0
feat(interactive): add shell pipe support to REPL mode #25
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: ayeshurun <98805507+ayeshurun@users.noreply.github.com>
…cumentation Co-authored-by: ayeshurun <98805507+ayeshurun@users.noreply.github.com>
| if self._has_pipe(command): | ||
| cli_cmd, shell_cmd = self._split_pipe(command) | ||
| if cli_cmd and shell_cmd: | ||
| output = self._execute_cli_command(cli_cmd) | ||
| if output is not None: | ||
| self._pipe_to_shell(output, shell_cmd) | ||
| return False | ||
| else: | ||
| # Special commands like quit, help, version with pipe - just run the special command | ||
| return self.handle_command(cli_cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot why i need the _execute_cli_command? why can't we just set commnad = cli_cmd and use the rest of the handle_command. and execute the pipe_to_shell at the end if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Refactored in c60e2fa - removed _execute_cli_command entirely and integrated the pipe logic directly into handle_command. Now it extracts the shell command at the start, and only wraps stdout/stderr capture around the command execution when a pipe is present.
| result = subprocess.run( | ||
| shell_command, | ||
| shell=True, | ||
| input=input_data, | ||
| capture_output=True, | ||
| text=True, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot is this secured? the user can run any input we get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is secure in this context. The user is already in an interactive REPL session with full control of their terminal environment - they could simply exit and run any shell command directly. This is the same security model as any shell prompt: the user types commands, and they execute with the user's permissions.
The key distinction is that this input comes directly from the user typing at the interactive prompt, not from external/untrusted sources (like API responses, file contents, or network data). If we were piping data from an untrusted source through a shell command, that would be a security concern - but here the user is explicitly choosing what shell command to run with their own CLI output.
…g into handle_command Co-authored-by: ayeshurun <98805507+ayeshurun@users.noreply.github.com>
📥 Pull Request
✨ Description of new changes
Users can now use shell pipes in interactive mode, matching command-line behavior:
Implementation:
_find_pipe_position()- Locates first unquoted pipe, respecting quotes and escapes_pipe_to_shell()- Pipes captured output through shell command viasubprocess.runls "file|name"won't trigger pipinghandle_command()- captures stdout/stderr only when a pipe is presentTests: 15 new unit tests covering pipe detection, splitting, output capture, and shell execution.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.