Skip to content

Conversation

@PiotrCzapla
Copy link
Contributor

@PiotrCzapla PiotrCzapla commented Oct 31, 2025

tldr

  • ssage does not know that its cli is called like this so It does not recognized it self in the tmux history
  • zsh -ic alias outputs useless messages and consume additional tokens
  • zsh -i opens /dev/tty which may crash whole proces group, try cat |ssage oops

ssage - a typo

We should add ssage to the prompt so that shell sage is confused when it sees ssage invoications.
Righ now:

$ ssage 'What will this do: "ssage tar"'
About to ripgrep a search term with the following arguments:
{'argstr': 'ssage'}
Execute this? (y/n/suggestion): n
Based on the context, "ssage tar" appears to be a typo or partial command. Here are the likely possibilities:                                                                                                                                                                                                      
                    Most Probable Interpretations:                                                                                                                                           
 1 Typo for "sage tar" - If sage is installed (SageMath), this would pass "tar" as an argument                                                                                                                                                                                                                     
 2 Typo for "usage tar" - Intended to check tar usage/help                                                                                                                                                                                                                                                         
 3 Partial shell history search -

After adding (ssage):

$ ssage 'What will this do: "ssage tar"'
The command ssage tar will invoke me (ShellSage/ssage) with the argument "tar".   

zsh session / macos messages

The zsh in macos likes to output additional information in interactive mode. Like:

  • saving restoring session - used when terminal is being restored after restart.
  • OSC 7 - info to terminal app about current directory (the bit starting with ' \x1b]7;')

This behavior can be disable by removing TERM_PROGRAM from the environment, so the zsh doesn't assumes it runs
under a terminal emulator app.

>>> print(co(["zsh", "-ic", "echo;echo hello", ],text=True))
Saving session...completed.
Restored session: Fri Oct 31 17:22:21 CET 2025
�]7;file://Piotrs-MacBook-Pro-3.local/Users/pczapla/Work/shell_sage/nbs
hello

removing TERM_PROGRAM makes the output clean again

>>> env = os.environ.copy()
>>> env.pop('TERM_PROGRAM',None)
>>> print(co(["zsh", "-ic", "echo test", ],text=True, env=env))
test

zsh -i uses /dev/tty

There is one more issue. The _aliases tries to access the /dev/tty (zsh -i). This crashes chains like cat|ssage hi. Even worse it takes down the whole process group and terminal vanish. Only apple terminal lets me catch what is really going on:

$ cat|ssage hi
zsh: error on TTY read: Input/output error

Saving session...completed.

[Process completed]

I couldn't reproduce the problem in Jupyter, so I created a few examples in the debug folder.
To see the issue in action, run cat | python debug/aliases.py in Apple Terminal -- it will crash the same way ssage does now.
The fixed version safe_aliases.py, starts a new session / process group which removes access to /dev/tty. I also closed the stdin and stderr for good measure.
You can verify that the fix works with: cat | python debug/safe_aliases.py.

@gitnotebooks
Copy link

gitnotebooks bot commented Oct 31, 2025

Found 1 changed notebook. Review the changes at https://app.gitnotebooks.com/AnswerDotAI/shell_sage/pull/57

- ssage does not know that it's cli is called like this so It does not recognized it self in the tmux history
- zsh -ic alias  outputs useless messages and consume additional tokens and may confuse the model
- zsh -i opens /dev/tty   which may crash whole proces group, try `cat |ssage oops`
@ncoop57
Copy link
Contributor

ncoop57 commented Nov 2, 2025

Great PR @PiotrCzapla , really appreciate you figuring out all this stuff. Made me learn more about interesting terminal and shell quirks!

@ncoop57 ncoop57 merged commit 5a1bd7e into AnswerDotAI:main Nov 2, 2025
@ncoop57 ncoop57 added the bug Something isn't working label Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants