Skip to content

Conversation

@GoodluckH
Copy link
Contributor

Issue #, if available:
#1030

Description of changes:

  • Renamed execute_bash tool to execute_shell_commands
  • Fetches all aliases based on Shell type (currently support zsh and bash) from user config files

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@GoodluckH GoodluckH requested a review from a team April 1, 2025 21:40
@GoodluckH GoodluckH linked an issue Apr 1, 2025 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Apr 1, 2025

Codecov Report

❌ Patch coverage is 1.68067% with 117 lines in your changes missing coverage. Please review.
✅ Project coverage is 13.69%. Comparing base (e0f65f3) to head (ecce6f7).
⚠️ Report is 610 commits behind head on main.

Files with missing lines Patch % Lines
...q_cli/src/cli/chat/tools/execute_shell_commands.rs 0.91% 108 Missing ⚠️
crates/q_cli/src/cli/chat/tools/mod.rs 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1043      +/-   ##
==========================================
- Coverage   13.69%   13.69%   -0.01%     
==========================================
  Files        2361     2361              
  Lines      203706   203745      +39     
  Branches   184070   184109      +39     
==========================================
+ Hits        27894    27895       +1     
- Misses     174425   174462      +37     
- Partials     1387     1388       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GoodluckH GoodluckH force-pushed the 1030-feature-request-enable-amazon-q-chat-to-use-users-shell-environment branch from d2b3cb5 to 121d495 Compare April 1, 2025 21:42
@GoodluckH GoodluckH marked this pull request as draft April 1, 2025 22:03
@GoodluckH GoodluckH marked this pull request as ready for review April 1, 2025 23:05
Copy link
Contributor

@mschrage mschrage left a comment

Choose a reason for hiding this comment

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

We should consider launching the process using --login and --interactive to emulate the behavior of the user's shell.

Pros:

  • Will source relevant dotfiles automatically.

Cons:

  • May add additional latency to shell execution as all dotfiles need to be sourced
  • Introduces environment dependency which can result in inconsistent behavior that is difficult to debug.

@GoodluckH
Copy link
Contributor Author

GoodluckH commented Apr 1, 2025

Yes, I initially tried using interactive mode to source config files but it will result in tty suspension error that will kill the Q CLI session.

I'm still investigating how to avoid that.

Screenshot 2025-04-01 at 4 56 42 PM

@mschrage
Copy link
Contributor

mschrage commented Apr 2, 2025

Some interesting discussion here:

This will fix it:

stty -tostop
From the man page:

tostop (-tostop)
Send (do not send) SIGTTOU for background output. This causes background jobs to stop if they attempt terminal output.
This tostop is normally the default setting, as it's usually undesirable to mix the output of

https://stackoverflow.com/questions/24056102/why-do-i-get-suspended-tty-output-in-one-terminal-but-not-in-others

@GoodluckH GoodluckH linked an issue Apr 3, 2025 that may be closed by this pull request
3 tasks
@GoodluckH GoodluckH changed the title feat(chat): support shell aliases in command execution feat(chat): support user shell env in shell command tool Apr 3, 2025
@GoodluckH
Copy link
Contributor Author

Yes I tried all those but didn't work.

Instead, I will launch a PTY.

@GoodluckH GoodluckH requested a review from mschrage April 3, 2025 20:27
@GoodluckH GoodluckH force-pushed the 1030-feature-request-enable-amazon-q-chat-to-use-users-shell-environment branch 3 times, most recently from f3f1d63 to daf2218 Compare April 7, 2025 17:37
@jsamuel1
Copy link
Contributor

jsamuel1 commented Apr 7, 2025

zsh, bash, fish.
What other ones are supported in other parts of q cli?

How will automated tests work for this? Docker based, or can you do it with chroot/mocks?

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a workspace dependency

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make this a workspace dependency and update figterm as well? (figterm already depends on 0.8)

Copy link
Contributor

Choose a reason for hiding this comment

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

nit - move this after all of the imports, it's declaring a new function, also update the name to something more readable preferably, like set_terminal_winsize or something

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the above lines are copied straight from figterm (and they're particularly complicated) I wonder if this could be generalized in a library, e.g. in fig_util

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't work with fish, we'd need to get the current shell and fallback to bash otherwise

also, probably best to use https://github.com/aws/amazon-q-developer-cli/blob/main/crates/fig_util/src/shell.rs#L90

Copy link
Contributor

Choose a reason for hiding this comment

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

This method seems to break our (admittedly already poor support of) interactive commands, e.g. npx create-react-app helloworld

My thought was that we would spawn the child with a pty, and set our terminal to raw mode. This way, we can copy all bytes directly to the child which can then handle sigint etc. which should support more interactive commands.

Copy link
Contributor

Choose a reason for hiding this comment

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

removing stderr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the PTY mode it's hard to differentiate stderr, but we can already infer from status code if the resulting message is error or not. The output of this function is to give some context to the LLM to inform it of the execution result.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was also thinking about how we can handle interactive commands since some (e.g. vim) shouldn't have their stdout returned back to the model, still an open question to solve

@GoodluckH GoodluckH force-pushed the 1030-feature-request-enable-amazon-q-chat-to-use-users-shell-environment branch from daf2218 to ecce6f7 Compare April 9, 2025 00:20
@chaynabors chaynabors requested a review from a team as a code owner June 30, 2025 17:21
@dingfeli dingfeli closed this Oct 17, 2025
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.

Run commands in user's shell environment Q chat requires non obvious interactivity

6 participants