Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions debug/aliases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from subprocess import check_output as co
print(co("uv run python debug/probe_tty.py".split(), text=True ))
aliases = co(["zsh", '-ic', 'alias'], text=True).strip()
print ("Found ", len(aliases.split()), "aliases")
15 changes: 15 additions & 0 deletions debug/probe_tty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os, sys
print("stdin isatty:", sys.stdin.isatty())
print("stdout isatty:", sys.stdout.isatty())
print("stderr isatty:", sys.stderr.isatty())
for fd in (0,1,2):
try:
print(fd, "ttyname:", os.ttyname(fd))
except OSError:
print(fd, "ttyname:", None)
try:
fd = os.open("/dev/tty", os.O_RDWR)
print("can open /dev/tty: YES")
os.close(fd)
except OSError as e:
print("can open /dev/tty: NO ->", e)
7 changes: 7 additions & 0 deletions debug/safe_aliases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from subprocess import check_output as co, DEVNULL

print (co("uv run python debug/probe_tty.py".split(), stderr=DEVNULL, stdin=DEVNULL, text=True, start_new_session=True ))
aliases = co(["zsh", '-ic', 'alias'], text=True,
start_new_session=True # to call setsid() and sever connection to /dev/tty
).strip()
print ("Found ", len(aliases.split()), "aliases")
13 changes: 8 additions & 5 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"from rich.markdown import Markdown\n",
"from shell_sage import __version__\n",
"from shell_sage.config import *\n",
"from subprocess import check_output as co\n",
"from subprocess import check_output as co, DEVNULL\n",
"\n",
"import asyncio,litellm,os,pyperclip,re,subprocess,sys"
]
Expand Down Expand Up @@ -79,7 +79,7 @@
"outputs": [],
"source": [
"#| export\n",
"sp = '''<assistant>You are ShellSage, a command-line teaching assistant created to help users learn and master shell commands and system administration.</assistant>\n",
"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",
"\n",
"<rules>\n",
"- Receive queries that may include file contents or command output as context\n",
Expand Down Expand Up @@ -125,7 +125,7 @@
"outputs": [],
"source": [
"#| export\n",
"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",
"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",
"\n",
"<rules>\n",
"- Respond to queries with a mix of accurate technical information and subtle condescension\n",
Expand Down Expand Up @@ -168,7 +168,7 @@
},
{
"cell_type": "markdown",
"id": "739736b1",
"id": "5855e9b4",
"metadata": {},
"source": [
"## System Environment"
Expand All @@ -183,7 +183,9 @@
"source": [
"#| export\n",
"def _aliases(shell):\n",
" return co([shell, '-ic', 'alias'], text=True).strip()"
" env = os.environ.copy()\n",
" env.pop('TERM_PROGRAM',None)\n",
" return co([shell, '-ic', 'alias'], text=True, stdin=DEVNULL, stderr=DEVNULL, start_new_session=True).strip()"
]
},
{
Expand Down Expand Up @@ -628,6 +630,7 @@
}
],
"source": [
"opts=NS(api_base='', api_key='')\n",
"print(Markdown(get_res(ssage, 'Hi!', opts)))"
]
},
Expand Down
10 changes: 6 additions & 4 deletions shell_sage/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from rich.markdown import Markdown
from . import __version__
from .config import *
from subprocess import check_output as co
from subprocess import check_output as co, DEVNULL

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

Expand All @@ -27,7 +27,7 @@
print = console.print

# %% ../nbs/00_core.ipynb 6
sp = '''<assistant>You are ShellSage, a command-line teaching assistant created to help users learn and master shell commands and system administration.</assistant>
sp = '''<assistant>You are ShellSage (ssage), a command-line teaching assistant created to help users learn and master shell commands and system administration.</assistant>

<rules>
- Receive queries that may include file contents or command output as context
Expand Down Expand Up @@ -65,7 +65,7 @@
</important>'''

# %% ../nbs/00_core.ipynb 7
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>
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>

<rules>
- Respond to queries with a mix of accurate technical information and subtle condescension
Expand Down Expand Up @@ -107,7 +107,9 @@

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

# %% ../nbs/00_core.ipynb 11
def _sys_info():
Expand Down