Repository: ErikBjare/gptme
File: gptme/tools/tmux.py (Python)

Code before:
> System:
{ToolUse("output", [], "Server is running on localhost:5600").to_output()}

> User: Stop the dev server
> Assistant: I'll send 'Ctrl+C' to the pane to stop the server:
{ToolUse("tmux", [], "send_keys 0 C-c").to_output(tool_format)}
> System: Sent 'C-c' to pane 0

#### Get info from ncurses applications

> User: start top and give me a summary
> Assistant: Sure! Let's start the top command in a tmux session:
{ToolUse("tmux", [], "new_session 'top'").to_output(tool_format)}
> System: Running `top` in session 1.
{ToolUse("output", [], "(output from top shown here)").to_output()}
> Assistant: The load is...

#### Send keys to a session

> User: start ipython
> Assistant: Let's start an ipython session:
{ToolUse("tmux", [], "new_session 'ipython'").to_output(tool_format)}
> System: Running `ipython` in session 2.
{ToolUse("output", [], "(output from ipython shown here)").to_output()}
> User: Run 'print("Hello, world!")' in the ipython session
{ToolUse("tmux", [], 'send_keys 2 print("Hello, world!") Enter').to_output(tool_format)}

#### Background process

> User: Start the dev server
> Assistant: Certainly! To start the dev server we should use the tmux tool to run it in a tmux session:
{ToolUse("tmux", [], "new_session 'npm run dev'").to_output(tool_format)}

#### Listing active sessions

> User: List all active tmux sessions
{ToolUse("tmux", [], "list_sessions").to_output(tool_format)}
> System: Active tmux sessions [0]

#### Ending a session

> User: I changed my mind
> Assistant: No problem! Let's kill the session and start over:
> Assistant:
{ToolUse("tmux", [], "kill_session gptme_0").to_output(tool_format)}
> System: Killed tmux session with ID 0
"""
    # we want to skip the last two examples in prompting
    return "####".join(all_examples.split("####")[:-2])



Review comment (suggestion):
```suggestion
{ToolUse("tmux", [], "new_session 'ipython'").to_output(tool_format)}
> System: Running `ipython` in session gptme_2.
{ToolUse("output", [], "(output from ipython shown here)").to_output()}
> User: Run 'print("Hello, world!")' in the ipython session
{ToolUse("tmux", [], 'send_keys gptme_2 print("Hello, world!") Enter').to_output(tool_format)}
```

Code after:
{ToolUse("tmux", [], "inspect_pane gptme_1").to_output(tool_format)}
> System:
{ToolUse("output", [], "Server is running on localhost:5600").to_output()}

> User: Stop the dev server
> Assistant: I'll send 'Ctrl+C' to the pane to stop the server:
{ToolUse("tmux", [], "send_keys 0 C-c").to_output(tool_format)}
> System: Sent 'C-c' to pane 0

#### Get info from ncurses applications

> User: start top and give me a summary
> Assistant: Sure! Let's start the top command in a tmux session:
{ToolUse("tmux", [], "new_session 'top'").to_output(tool_format)}
> System: Running `top` in session gptme_1.
{ToolUse("output", [], "(output from top shown here)").to_output()}
> Assistant: The load is...

#### Send keys to a session

> User: start ipython
> Assistant: Let's start an ipython session:
{ToolUse("tmux", [], "new_session 'ipython'").to_output(tool_format)}
> System: Running `ipython` in session 2.
{ToolUse("output", [], "(output from ipython shown here)").to_output()}
> User: Run 'print("Hello, world!")' in the ipython session
{ToolUse("tmux", [], f'send_keys 2 {escaped_hello_world} Enter').to_output(tool_format)}

#### Listing active sessions

> User: List all active tmux sessions
{ToolUse("tmux", [], "list_sessions").to_output(tool_format)}
> System: Active tmux sessions ['0', 'gptme_1']

#### Ending a session

> User: I changed my mind
> Assistant: No problem! Let's kill the session and start over:
> Assistant:
{ToolUse("tmux", [], "kill_session gptme_1").to_output(tool_format)}
> System: Killed tmux session with ID gptme_1
"""
    # we want to skip the last two examples in prompting
    return "####".join(all_examples.split("####")[:-2])


tool = ToolSpec(
    name="tmux",
    desc="Executes shell commands in a tmux session",
    instructions=instructions,
    examples=examples,