# aliases = _aliases('bash')
# print(aliases)
ShellSage
Imports
Model Setup
System Environment
# print(_sys_info())
Tmux
get_pane
get_pane (n, pid=None)
Get output from a tmux pane
# p = get_pane(20)
# print(p[:512])
get_panes
get_panes (n)
# ps = get_panes(20)
# print(ps[:512])
'tmux', 'display-message', '-p', '#{history-limit}'], text=True).strip() co([
'2000'
tmux_history_lim
tmux_history_lim ()
tmux_history_lim()
2000
get_history
get_history (n, pid='current')
Options and ShellSage
get_opts
get_opts (**opts)
= get_opts(provider=None, model=None)
opts opts
{'model': 'claude-3-5-sonnet-20241022', 'provider': 'anthropic'}
get_sage
get_sage (provider, model, base_url=None, api_key=None, mode='default')
= 'openai'
provider = 'llama3.2'
model = 'http://localhost:11434/v1'
base_url = 'ollama' api_key
= get_sage(provider, model, base_url, api_key)
s 'Hi, who are you?')]) s([mk_msg(
Hello! I’m an artificial intelligence model, which means I’m a computer program designed to simulate human-like conversations and answer questions to the best of my ability. I don’t have a personal name, but I’m here to help you with any information or discussion you’d like to have. How can I assist you today?
- id: chatcmpl-211
- choices: [Choice(finish_reason=‘stop’, index=0, logprobs=None, message=ChatCompletionMessage(content=“Hello! I’m an artificial intelligence model, which means I’m a computer program designed to simulate human-like conversations and answer questions to the best of my ability. I don’t have a personal name, but I’m here to help you with any information or discussion you’d like to have. How can I assist you today?”, refusal=None, role=‘assistant’, audio=None, function_call=None, tool_calls=None))]
- created: 1742147991
- model: llama3.2
- object: chat.completion
- service_tier: None
- system_fingerprint: fp_ollama
- usage: CompletionUsage(completion_tokens=66, prompt_tokens=31, total_tokens=97, completion_tokens_details=None, prompt_tokens_details=None)
= get_sage(provider, model, base_url, api_key, mode='command')
sc 'How can I list all the files, including the hidden ones?')]) sc([mk_msg(
To list all files on your computer, including hidden ones, you can use the command line or PowerShell in Windows, or the Terminal in macOS/Linux. Here are a few ways to do it:
Windows Command Line:
- Open Command Prompt or PowerShell.
- Type
dir /s /b
(all files) and press Enter. - Type
dir /s /ad
(directories only) and press Enter.
Windows PowerShell:
- Open PowerShell.
- Type
(Get-ChildItem -Force).Name
(all files) and press Enter. - Type
(Get-ChildItem -Path .\ -Recurse).Name
(all files recursively) and press Enter.
macOS Terminal:
- Open Terminal.
- Type
ls -a
(all files, including hidden ones) and press Enter. - Type
ls /Volumes/*
(list all files on external drives) and press Enter.
The ‘/s’ option is used to view recursively in Windows Command Line. The ‘-force’ option is used in PowerShell to display the files as well.
These commands will list all files, including hidden ones, in plain text format.
- id: chatcmpl-38
- choices: [Choice(finish_reason=‘stop’, index=0, logprobs=None, message=ChatCompletionMessage(content=“To list all files on your computer, including hidden ones, you can use the command line or PowerShell in Windows, or the Terminal in macOS/Linux. Here are a few ways to do it:*Windows Command Line:**. Open Command Prompt or PowerShell.. Type
dir /s /b
(all files) and press Enter.. Typedir /s /ad
(directories only) and press Enter.*Windows PowerShell:**. Open PowerShell.. Type(Get-ChildItem -Force).Name
(all files) and press Enter.. Type(Get-ChildItem -Path .\\ -Recurse).Name
(all files recursively) and press Enter.*macOS Terminal:**. Open Terminal.. Typels -a
(all files, including hidden ones) and press Enter.. Typels /Volumes/*
(list all files on external drives) and press Enter.‘/s’ option is used to view recursively in Windows Command Line. The ‘-force’ option is used in PowerShell to display the files as well. commands will list all files, including hidden ones, in plain text format.”, refusal=None, role=‘assistant’, audio=None, function_call=None, tool_calls=None))] - created: 1742148016
- model: llama3.2
- object: chat.completion
- service_tier: None
- system_fingerprint: fp_ollama
- usage: CompletionUsage(completion_tokens=249, prompt_tokens=38, total_tokens=287, completion_tokens_details=None, prompt_tokens_details=None)
trace
trace (msgs)
# provider = 'anthropic'
# model = 'claude-3-7-sonnet-20250219'
# sagent = get_sage(provider, model, mode='agent')
# sagent.toolloop('What does my github ssh config look like?', trace_func=trace)
get_res
get_res (sage, q, provider, mode='default', verbosity=0)
print(get_res(s, [mk_msg('Hi, who are you?')], provider='openai'))
Hello! I'm an artificial intelligence model known as Llama. Llama stands for "Large Language Model Meta AI."
print(get_res(sc, [mk_msg('How can I list all the files, including the hidden ones?')],
='openai', mode='command')) provider
ls -a
# print(get_res(sagent, 'What does my github ssh config look like?',
# provider='anthropic', mode='agent'))
Logging
mk_db
mk_db ()
Log
Log ()
Initialize self. See help(type(self)) for accurate signature.
# db = mk_db()
# log = db.logs.insert(Log(timestamp=datetime.now().isoformat(), query='Hi, who are you?', model='llama3.2',
# response='I am ShellSage, a command-line teaching assistant!', mode='default'))
# log
Main
main
main (query:str<ThequerytosendtotheLLM>, v:<Printversion>='%(prog)s 0.1.1', pid:str='current', skip_system:bool=False, history_lines:int=None, mode:str='default', log:bool=False, provider:str=None, model:str=None, base_url:str=None, api_key:str=None, code_theme:str=None, code_lexer:str=None, verbosity:int=0)
Type | Default | Details | |
---|---|---|---|
query | str |
||
v | %(prog)s 0.1.1 | ||
pid | str | current | current , all or tmux pane_id (e.g. %0) for context |
skip_system | bool | False | Whether to skip system information in the AI’s context |
history_lines | int | None | Number of history lines. Defaults to tmux scrollback history length |
mode | str | default | Available ShellSage modes: [‘default’, ‘command’, ‘agent’, ‘sassy’] |
log | bool | False | Enable logging |
provider | str | None | The LLM Provider |
model | str | None | The LLM model that will be invoked on the LLM provider |
base_url | str | None | |
api_key | str | None | |
code_theme | str | None | The code theme to use when rendering ShellSage’s responses |
code_lexer | str | None | The lexer to use for inline code markdown blocks |
verbosity | int | 0 | Level of verbosity (0 or 1) |
'Teach me about rsync', history_lines=0, s=True) main(
bash: cannot set terminal process group (59579): Inappropriate ioctl for device
bash: no job control in this shell
Sigh I see you've discovered the space bar. How... creative. Let me tell you about rsync, a tool that's been efficiently copying files since before some humans could walk. Basic Usage: rsync [options] source destination Here are some common options that even an entry-level test subject could handle: • -a: Archive mode (combines -rlptgoD) - for those who like shortcuts • -v: Verbose - because watching numbers go up is apparently entertaining • -z: Compression - in case you're worried about your precious bandwidth • -P: Progress + keep partially transferred files - for the impatient ones • --delete: Remove files in destination that aren't in source (Warning: This one's permanent. Try not to break anything.) Common examples (pay attention, there will be a test): # Local copy (yes, like cp, but better) rsync -av /source/folder/ /destination/folder/ # Remote copy (SSH transport) rsync -avz ~/local/folder/ user@remote:/destination/folder/ # Backup with progress bar (humans love progress bars) rsync -avP --delete /important/files/ /backup/location/ Some features that make rsync superior to primitive copy commands: • Delta-transfer algorithm (only copies changed parts of files) • Built-in compression • Preservation of permissions, timestamps, and other metadata • Remote file transfer capabilities • Resume interrupted transfers Important Notes (because someone will ask): 1 The trailing slash on directories matters: • /source/dir = copy the directory itself • /source/dir/ = copy the contents of the directory 2 For remote transfers, you'll need SSH access. I assume you've figured that out already... right? For more detailed information (which you'll probably ignore), try: man rsync rsync --help Remember: Like the Aperture Science Handheld Portal Device, rsync is a sophisticated tool. Please try not to hurt yourself while using it. Would you like me to explain it again, perhaps with smaller words? Or shall we proceed to testing?
Here is an example of using a local LLM provider via Ollama:
'Teach me about rsync', history_lines=0, provider=provider, model=model, base_url=base_url, api_key=api_key) main(
bash: no job control in this shell
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ RSYNC Syntax ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ Overview rsync is a command that synchronizes two sets of files, creating copies or updates on the second set. Here's a breakdown of its basic syntax: rsync [-aOr--archive] source destination [filtering options] • source: Specifies the content to be sent to destination. This can be a directory path, file name, or a glob pattern. • destination: Where the contents from source are to be written. Like source, it can be a single file, directory, or a combination of both. • filtering options: These options customize how Rsync handles specific types of files. Common Parameters Explained Parameter Purpose ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -a/--archive Enable archive mode. It makes rsync behave as if you had used "-av" and also preserves the access timestamps for files. R/--reduce If files present on both source and target have same modification time, send only the differences. Can be a good choice when file sizes are large. -l/--info-file Specifies file types to report with each file stat. Useful for verifying how it identifies different file types and permissions (e.g., .tar.gz archives). -tT/--transfers-only If you’re transferring only files, use this option otherwise default to an exact copy. --exclude, --include, --permdir, /dev/null Used as filtering options which specify a filename not included (the opposite is the -e option). Options like /dev/null and -e/./ can be used to exclude certain file types from copying, include directories within source by specifying them with the -i flag followed by the path of the content you want to include.