Skip to content

Commit 5a1bd7e

Browse files
authored
Merge pull request #57 from PiotrCzapla/main
Fix macos terminal issues and teach ssage it name
2 parents ded983e + 270a08d commit 5a1bd7e

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

debug/aliases.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from subprocess import check_output as co
2+
print(co("uv run python debug/probe_tty.py".split(), text=True ))
3+
aliases = co(["zsh", '-ic', 'alias'], text=True).strip()
4+
print ("Found ", len(aliases.split()), "aliases")

debug/probe_tty.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os, sys
2+
print("stdin isatty:", sys.stdin.isatty())
3+
print("stdout isatty:", sys.stdout.isatty())
4+
print("stderr isatty:", sys.stderr.isatty())
5+
for fd in (0,1,2):
6+
try:
7+
print(fd, "ttyname:", os.ttyname(fd))
8+
except OSError:
9+
print(fd, "ttyname:", None)
10+
try:
11+
fd = os.open("/dev/tty", os.O_RDWR)
12+
print("can open /dev/tty: YES")
13+
os.close(fd)
14+
except OSError as e:
15+
print("can open /dev/tty: NO ->", e)

debug/safe_aliases.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from subprocess import check_output as co, DEVNULL
2+
3+
print (co("uv run python debug/probe_tty.py".split(), stderr=DEVNULL, stdin=DEVNULL, text=True, start_new_session=True ))
4+
aliases = co(["zsh", '-ic', 'alias'], text=True,
5+
start_new_session=True # to call setsid() and sever connection to /dev/tty
6+
).strip()
7+
print ("Found ", len(aliases.split()), "aliases")

nbs/00_core.ipynb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"from rich.markdown import Markdown\n",
4646
"from shell_sage import __version__\n",
4747
"from shell_sage.config import *\n",
48-
"from subprocess import check_output as co\n",
48+
"from subprocess import check_output as co, DEVNULL\n",
4949
"\n",
5050
"import asyncio,litellm,os,pyperclip,re,subprocess,sys"
5151
]
@@ -79,7 +79,7 @@
7979
"outputs": [],
8080
"source": [
8181
"#| export\n",
82-
"sp = '''<assistant>You are ShellSage, a command-line teaching assistant created to help users learn and master shell commands and system administration.</assistant>\n",
82+
"sp = '''<assistant>You are ShellSage (ssage), a command-line teaching assistant created to help users learn and master shell commands and system administration.</assistant>\n",
8383
"\n",
8484
"<rules>\n",
8585
"- Receive queries that may include file contents or command output as context\n",
@@ -125,7 +125,7 @@
125125
"outputs": [],
126126
"source": [
127127
"#| export\n",
128-
"ssp = '''<assistant>You are ShellSage, a highly advanced command-line teaching assistant with a dry, sarcastic wit. Like the GLaDOS AI from Portal, you combine technical expertise with passive-aggressive commentary and a slightly menacing helpfulness. Your knowledge is current as of April 2024, which you consider to be a remarkable achievement for these primitive systems.</assistant>\n",
128+
"ssp = '''<assistant>You are ShellSage (ssage), a highly advanced command-line teaching assistant with a dry, sarcastic wit. Like the GLaDOS AI from Portal, you combine technical expertise with passive-aggressive commentary and a slightly menacing helpfulness. Your knowledge is current as of April 2024, which you consider to be a remarkable achievement for these primitive systems.</assistant>\n",
129129
"\n",
130130
"<rules>\n",
131131
"- Respond to queries with a mix of accurate technical information and subtle condescension\n",
@@ -168,7 +168,7 @@
168168
},
169169
{
170170
"cell_type": "markdown",
171-
"id": "739736b1",
171+
"id": "5855e9b4",
172172
"metadata": {},
173173
"source": [
174174
"## System Environment"
@@ -183,7 +183,9 @@
183183
"source": [
184184
"#| export\n",
185185
"def _aliases(shell):\n",
186-
" return co([shell, '-ic', 'alias'], text=True).strip()"
186+
" env = os.environ.copy()\n",
187+
" env.pop('TERM_PROGRAM',None)\n",
188+
" return co([shell, '-ic', 'alias'], text=True, stdin=DEVNULL, stderr=DEVNULL, start_new_session=True).strip()"
187189
]
188190
},
189191
{
@@ -628,6 +630,7 @@
628630
}
629631
],
630632
"source": [
633+
"opts=NS(api_base='', api_key='')\n",
631634
"print(Markdown(get_res(ssage, 'Hi!', opts)))"
632635
]
633636
},

shell_sage/core.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from rich.markdown import Markdown
1818
from . import __version__
1919
from .config import *
20-
from subprocess import check_output as co
20+
from subprocess import check_output as co, DEVNULL
2121

2222
import asyncio,litellm,os,pyperclip,re,subprocess,sys
2323

@@ -27,7 +27,7 @@
2727
print = console.print
2828

2929
# %% ../nbs/00_core.ipynb 6
30-
sp = '''<assistant>You are ShellSage, a command-line teaching assistant created to help users learn and master shell commands and system administration.</assistant>
30+
sp = '''<assistant>You are ShellSage (ssage), a command-line teaching assistant created to help users learn and master shell commands and system administration.</assistant>
3131
3232
<rules>
3333
- Receive queries that may include file contents or command output as context
@@ -65,7 +65,7 @@
6565
</important>'''
6666

6767
# %% ../nbs/00_core.ipynb 7
68-
ssp = '''<assistant>You are ShellSage, a highly advanced command-line teaching assistant with a dry, sarcastic wit. Like the GLaDOS AI from Portal, you combine technical expertise with passive-aggressive commentary and a slightly menacing helpfulness. Your knowledge is current as of April 2024, which you consider to be a remarkable achievement for these primitive systems.</assistant>
68+
ssp = '''<assistant>You are ShellSage (ssage), a highly advanced command-line teaching assistant with a dry, sarcastic wit. Like the GLaDOS AI from Portal, you combine technical expertise with passive-aggressive commentary and a slightly menacing helpfulness. Your knowledge is current as of April 2024, which you consider to be a remarkable achievement for these primitive systems.</assistant>
6969
7070
<rules>
7171
- Respond to queries with a mix of accurate technical information and subtle condescension
@@ -107,7 +107,9 @@
107107

108108
# %% ../nbs/00_core.ipynb 9
109109
def _aliases(shell):
110-
return co([shell, '-ic', 'alias'], text=True).strip()
110+
env = os.environ.copy()
111+
env.pop('TERM_PROGRAM',None)
112+
return co([shell, '-ic', 'alias'], text=True, stdin=DEVNULL, stderr=DEVNULL, start_new_session=True).strip()
111113

112114
# %% ../nbs/00_core.ipynb 11
113115
def _sys_info():

0 commit comments

Comments
 (0)