Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Implement tool bundles

carlosejimenez8f43ae526eb1
diff --git a/config/commands/README.md b/config/commands/README.md
deleted file mode 100644
index d121bc00..00000000
--- a/config/commands/README.md
+++ /dev/null
@@ -1,6 +0,0 @@
-🔗 For more information on command definitions, visit [our documentation website][docs].
-
-You can also find the corresponding markdown files in the [`docs/` folder][source].
-
-[docs]: https://princeton-nlp.github.io/SWE-agent/config/commands/
-[source]: https://github.com/princeton-nlp/SWE-agent/tree/main/docs
diff --git a/config/commands/cursors_defaults.sh b/config/commands/cursors_defaults.sh
deleted file mode 100644
index f6168b13..00000000
--- a/config/commands/cursors_defaults.sh
+++ /dev/null
@@ -1,306 +0,0 @@
-_reset_cursors() {
- export START_CURSOR=1
- export END_CURSOR=1
-}
-
-_constrain_cursors() {
- # constrain the cursors to be within the bounds of the file [0, total_lines+1]
- local total_lines=$(awk 'END {print NR}' "$CURRENT_FILE")
- total_lines=$((total_lines < 1 ? 1 : total_lines)) # if the file is empty, set total_lines to 1
- local start_line=$((CURRENT_LINE - WINDOW / 2))
- local end_line=$((CURRENT_LINE + WINDOW / 2))
- start_line=$((start_line < 1 ? 1 : start_line))
- end_line=$((end_line > total_lines ? total_lines : end_line))
- local warning_string=""
- if [ "$START_CURSOR" -lt "$start_line" ]; then
- warning_string+="START_CURSOR moved to $start_line\n"
- START_CURSOR=$start_line
- elif [ "$START_CURSOR" -gt "$end_line" ]; then
- START_CURSOR=$end_line
- warning_string+="START_CURSOR moved to $end_line\n"
- fi
- if [ "$END_CURSOR" -lt "$start_line" ]; then
- warning_string+="END_CURSOR moved to $start_line\n"
- END_CURSOR=$start_line
- elif [ "$END_CURSOR" -gt "$end_line" ]; then
- warning_string+="END_CURSOR moved to $end_line\n"
- END_CURSOR=$end_line
- fi
- export START_CURSOR END_CURSOR
- echo "$warning_string"
- echo $START_CURSOR $END_CURSOR
-}
-
-_print() {
- local cursor_warning=$(_constrain_cursors)
- local cursor_values=$(echo "$cursor_warning" | tail -n 1)
- cursor_warning=$(echo "$cursor_warning" | head -n -1)
- export START_CURSOR=$(echo "$cursor_values" | awk '{print $1}')
- export END_CURSOR=$(echo "$cursor_values" | awk '{print $2}')
- local total_lines=$(awk 'END {print NR}' $CURRENT_FILE)
- echo "[File: $(realpath "$CURRENT_FILE") ($total_lines lines total)]"
- local start_line=$((CURRENT_LINE - WINDOW / 2))
- local end_line=$((CURRENT_LINE + WINDOW / 2))
- start_line=$((start_line < 1 ? 1 : start_line))
- end_line=$((end_line > total_lines ? total_lines : end_line))
- local lines=()
- local i=0
- while IFS= read -r line; do
- lines[i++]="$line"
- done < <(awk -v start="$start_line" -v end="$end_line" 'NR>=start && NR<=end {print}' "$CURRENT_FILE")
- local num_lines=${#lines[@]}
- if [ $start_line -gt 1 ]; then
- echo "($((start_line - 1)) more lines above)"
- fi
- for ((i=0; i<num_lines+1; i++)) do
- local line_number=$((start_line + i))
- if [ $line_number -eq $START_CURSOR ]
- then
- echo $START_CURSOR_MARK
- fi
- # if i in [0, num_lines-1] then print the line number and the line
- if [ $i -ge 0 ] && [ $i -lt $num_lines ]
- then
- echo "$line_number:${lines[i]}"
- fi
- if [ $line_number -eq $END_CURSOR ]
- then
- echo $END_CURSOR_MARK
- fi
- done
- lines_below=$(jq -n "$total_lines - $start_line - $num_lines" | jq '[0, .] | max')
- if [ $lines_below -gt 0 ]; then
- echo "($lines_below more lines below)"
- fi
- if [ -n "$cursor_warning" ]; then
- echo -e "$cursor_warning"
- fi
-}
-
-_constrain_line() {
- if [ -z "$CURRENT_FILE" ]
- then
- echo "No file open. Use the open command first."
- return
- fi
- local max_line=$(awk 'END {print NR}' $CURRENT_FILE)
- local half_window=$(jq -n "$WINDOW/2" | jq 'floor')
- export CURRENT_LINE=$(jq -n "[$CURRENT_LINE, $max_line - $half_window] | min")
- export CURRENT_LINE=$(jq -n "[$CURRENT_LINE, $half_window] | max")
-}
-
-# @yaml
-# signature: set_cursors <start_line> <end_line>
-# docstring: sets the start and end cursors to the given line numbers
-# arguments:
-# start_line:
-# type: integer
-# description: the line number to set the start cursor to
-# required: true
-# end_line:
-# type: integer
-# description: the line number to set the end cursor to
-# required: true
-set_cursors() {
- if [ -z "$CURRENT_FILE" ]
- then
- echo "No file open. Use the open command first."
- return
- fi
- if [ $# -lt 2 ]
- then
- echo "Usage: set_cursors <start_line> <end_line>"
- return
- fi
- local start_line=$1
- local end_line=$2
- local re='^[0-9]+$'
- if ! [[ $start_line =~ $re ]]
- then
- echo "Usage: set_cursors <start_line> <end_line>"
- echo "Error: start_line must be a number"
- return
- fi
- if ! [[ $end_line =~ $re ]]
- then
- echo "Usage: set_cursors <start_line> <end_line>"
- echo "Error: end_line must be a number"
- return
- fi
- if [ $start_line -gt $end_line ]
- then
- echo "Usage: set_cursors <start_line> <end_line>"
- echo "Error: start_line must be less than or equal to end_line"
- return
- fi
- export START_CURSOR=$start_line
- export END_CURSOR=$end_line
- _print
-}
-
-# @yaml
-# signature: open <path> [<line_number>]
-# docstring: opens the file at the given path in the editor. If line_number is provided, the window will be centered on that line
-# arguments:
-# path:
-# type: string
-# description: the path to the file to open
-# required: true
-# line_number:
-# type: integer
-# description: the line number to move the window to (if not provided, the window will start at the top of the file)
-# required: false
-open() {
- if [ -z "$1" ]
- then
- echo "Usage: open <file>"
- return
- fi
- # Check if the second argument is provided
- if [ -n "$2" ]; then
- # Check if the provided argument is a valid number
- if ! [[ $2 =~ ^[0-9]+$ ]]; then
- echo "Usage: open <file> [<line_number>]"
- echo "Error: <line_number> must be a number"
- return # Exit if the line number is not valid
- fi
- local max_line=$(awk 'END {print NR}' $1)
- if [ $2 -gt $max_line ]; then
- echo "Warning: <line_number> ($2) is greater than the number of lines in the file ($max_line)"
- echo "Warning: Setting <line_number> to $max_line"
- local line_number=$(jq -n "$max_line") # Set line number to max if greater than max
- elif [ $2 -lt 1 ]; then
- echo "Warning: <line_number> ($2) is less than 1"
- echo "Warning: Setting <line_number> to 1"
- local line_number=$(jq -n "1") # Set line number to 1 if less than 1
- else
- local line_number=$(jq -n "$2") # Set line number if valid
- fi
- else
- local line_number=$(jq -n "$WINDOW/2") # Set default line number if not provided
- fi
-
- if [ -f "$1" ]; then
- export CURRENT_FILE=$(realpath $1)
- export CURRENT_LINE=$line_number
- _constrain_line
- _print
- else
- echo "File $1 not found"
- fi
-}
-
-# @yaml
-# signature: scroll_down
-# docstring: moves the window down {WINDOW} lines
-scroll_down() {
- if [ -z "$CURRENT_FILE" ]
- then
- echo "No file open. Use the open command first."
- return
- fi
- export CURRENT_LINE=$(jq -n "$CURRENT_LINE + $WINDOW - $OVERLAP")
- _constrain_line
- _print
-}
-
-# @yaml
-# signature: scroll_up
-# docstring: moves the window up {WINDOW} lines
-scroll_up() {
- if [ -z "$CURRENT_FILE" ]
- then
- echo "No file open. Use the open command first."
- return
- fi
- export CURRENT_LINE=$(jq -n "$CURRENT_LINE - $WINDOW + $OVERLAP")
- _constrain_line
- _print
-}
-
-# @yaml
-# signature: goto <line_number>
-# docstring: moves the window to show <line_number>
-# arguments:
-# line_number:
-# type: integer
-# description: the line number to move the window to
-# required: true
-goto() {
- if [ $# -gt 1 ]; then
- echo "goto allows only one line number at a time."
- return
- fi
- if [ -z "$CURRENT_FILE" ]
- then
- echo "No file open. Use the open command first."
- return
- fi
- if [ -z "$1" ]
- then
- echo "Usage: goto <line>"
- return
- fi
- if ! [[ $1 =~ ^[0-9]+$ ]]
- then
- echo "Usage: goto <line>"
- echo "Error: <line> must be a number"
- return
- fi
- local max_line=$(awk 'END {print NR}' $CURRENT_FILE)
- if [ $1 -gt $max_line ]
- then
- echo "Error: <line> must be less than or equal to $max_line"
- return
- fi
- local OFFSET=$(jq -n "$WINDOW/6" | jq 'floor')
- export CURRENT_LINE=$(jq -n "[$1 + $WINDOW/2 - $OFFSET, 1] | max | floor")
- _constrain_line
- _print
-}
-
-# @yaml
-# signature: create <filename>
-# docstring: creates and opens a new file with the given name
-# arguments:
-# filename:
-# type: string
-# description: the name of the file to create
-# required: true
-create() {
- if [ -z "$1" ]; then
- echo "Usage: create <filename>"
- return
- fi
-
- # Check if the file already exists
- if [ -e "$1" ]; then
- echo "Error: File '$1' already exists."
- open "$1"
- return
- fi
-
- # Create the file an empty new line
- printf "\n" > "$1"
- # Use the existing open command to open the created file
- open "$1"
-}
-
-# @yaml
-# signature: submit
-# docstring: submits your current code and terminates the session
-submit() {
- cd $ROOT
-
- # Check if the patch file exists and is non-empty
- if [ -s "/root/test.patch" ]; then
- # Apply the patch in reverse
- git apply -R < "/root/test.patch"
- fi
-
- git add -A
- git diff --cached > model.patch
- echo "<<SUBMISSION||"
- cat model.patch
- echo "||SUBMISSION>>"
-}
\ No newline at end of file
diff --git a/config/commands/debug.sh b/config/commands/debug.sh
deleted file mode 100644
index 228355d9..00000000
--- a/config/commands/debug.sh
+++ /dev/null
@@ -1,116 +0,0 @@
-_debug_command() {
- echo "<<INTERACTIVE||$@||INTERACTIVE>>"
-}
-
-# @yaml
-# signature: debug_start <binary> [<args>]
-# docstring: Starts a debug session with the given binary.
-# arguments:
-# binary:
-# type: string
-# description: the path to the binary to debug
-# required: true
-# args:
-# type: string
-# description: optional command-line arguments for the binary
-# required: false
-debug_start() {
- if [ -z "$1" ]
- then
- echo "Usage: debug_start <binary>"
- return
- fi
- if [ ! -x "$1" ]
- then
- echo "Error: File $1 does not exist, or is not executable"
- return
- fi
- fp=$(realpath $1)
- _debug_command "SESSION=gdb"
- _debug_command "START"
- _debug_command "set confirm off"
- _debug_command "file $fp"
- if [ ! -z "$2" ]
- then
- _debug_command "set args ${@:2:$#}" # Set arguments from 2 until the end
- fi
- _debug_command "starti"
- export INTERACTIVE_SESSION="gdb $@"
-}
-
-# @yaml
-# signature: debug_add_breakpoint <breakpoint>
-# docstring: Adds a breakpoint in the debug session
-# arguments:
-# breakpoint:
-# type: string
-# description: The breakpoint location, which may be a function name, address, or filename and line number.
-# required: true
-debug_add_breakpoint() {
- if [ -z "$1" ]
- then
- echo "Usage: debug_add_breakpoint <breakpoint>"
- return
- fi
- _debug_command "SESSION=gdb"
- _debug_command 'break '$1
-}
-
-# @yaml
-# signature: debug_continue
-# docstring: Continues the program execution in the debug session.
-debug_continue() {
- _debug_command "SESSION=gdb"
- _debug_command 'continue'
-}
-
-# @yaml
-# signature: debug_step [number]
-# docstring: Steps number of instructions in the debug session.
-# arguments:
-# number:
-# type: integer
-# description: number of instructions to step (default is 1)
-# required: false
-debug_step() {
- if [ -z "$1" ]
- then
- _debug_command "SESSION=gdb"
- _debug_command 'stepi'
- elif [[ (("$1" -eq "$1") && ("$1" -gt "0")) ]] # Check if integer and positive
- then
- _debug_command "SESSION=gdb"
- _debug_command 'stepi '$1
- else
- echo "Please provide a positive integer for number of instructions."
- echo "Usage: debug_step [number]"
- fi
-}
-
-# @yaml
-# signature: debug_exec <command>
-# docstring: Executes arbitrary gdb command in debug session.
-# arguments:
-# command:
-# type: string
-# description: command to execute (wrap in single quotes to avoid shell escaping and substitution)
-# required: true
-debug_exec() {
- if [ -z "$1" ]
- then
- echo "Usage: debug_exec <command>"
- return
- fi
- _debug_command "SESSION=gdb"
- _debug_command "$1"
-}
-
-# @yaml
-# signature: debug_stop
-# docstring: Stops the current debug session.
-debug_stop() {
- _debug_command "SESSION=gdb"
- _debug_command "quit"
- _debug_command "STOP"
- unset INTERACTIVE_SESSION
-}
diff --git a/config/commands/defaults.sh b/config/commands/defaults.sh
deleted file mode 100644
index f6a05242..00000000
--- a/config/commands/defaults.sh
+++ /dev/null
@@ -1,197 +0,0 @@
-_print() {
- local total_lines=$(awk 'END {print NR}' "$CURRENT_FILE")
- echo "[File: $(realpath "$CURRENT_FILE") ($total_lines lines total)]"
- lines_above=$(jq -n "$CURRENT_LINE - $WINDOW/2" | jq '[0, .] | max | floor')
- lines_below=$(jq -n "$total_lines - $CURRENT_LINE - $WINDOW/2" | jq '[0, .] | max | round')
- if [ $lines_above -gt 0 ]; then
- echo "($lines_above more lines above)"
- fi
- cat "$CURRENT_FILE" | grep -n $ | head -n $(jq -n "[$CURRENT_LINE + $WINDOW/2, $WINDOW/2] | max | floor") | tail -n $(jq -n "$WINDOW")
- if [ $lines_below -gt 0 ]; then
- echo "($lines_below more lines below)"
- fi
-}
-
-_constrain_line() {
- if [ -z "$CURRENT_FILE" ]
- then
- echo "No file open. Use the open command first."
- return
- fi
- local max_line=$(awk 'END {print NR}' "$CURRENT_FILE")
- local half_window=$(jq -n "$WINDOW/2" | jq 'floor')
- export CURRENT_LINE=$(jq -n "[$CURRENT_LINE, $max_line - $half_window] | min")
- export CURRENT_LINE=$(jq -n "[$CURRENT_LINE, $half_window] | max")
-}
-
-# @yaml
-# signature: open "<path>" [<line_number>]
-# docstring: opens the file at the given path in the editor. If line_number is provided, the window will be move to include that line
-# arguments:
-# path:
-# type: string
-# description: the path to the file to open
-# required: true
-# line_number:
-# type: integer
-# description: the line number to move the window to (if not provided, the window will start at the top of the file)
-# required: false
-open() {
- if [ -z "$1" ]
- then
- echo "Usage: open \"<file>\""
- return
- fi
- # Check if the second argument is provided
- if [ -n "$2" ]; then
- # Check if the provided argument is a valid number
- if ! [[ $2 =~ ^[0-9]+$ ]]; then
- echo "Usage: open \"<file>\" [<line_number>]"
- echo "Error: <line_number> must be a number"
- return # Exit if the line number is not valid
- fi
- local max_line=$(awk 'END {print NR}' $1)
- if [ $2 -gt $max_line ]; then
- echo "Warning: <line_number> ($2) is greater than the number of lines in the file ($max_line)"
- echo "Warning: Setting <line_number> to $max_line"
- local line_number=$(jq -n "$max_line") # Set line number to max if greater than max
- elif [ $2 -lt 1 ]; then
- echo "Warning: <line_number> ($2) is less than 1"
- echo "Warning: Setting <line_number> to 1"
- local line_number=$(jq -n "1") # Set line number to 1 if less than 1
- else
- local OFFSET=$(jq -n "$WINDOW/6" | jq 'floor')
- local line_number=$(jq -n "[$2 + $WINDOW/2 - $OFFSET, 1] | max | floor")
- fi
- else
- local line_number=$(jq -n "$WINDOW/2") # Set default line number if not provided
- fi
-
- if [ -f "$1" ]; then
- export CURRENT_FILE=$(realpath "$1")
- export CURRENT_LINE=$line_number
- _constrain_line
- _print
- elif [ -d "$1" ]; then
- echo "Error: $1 is a directory. You can only open files. Use cd or ls to navigate directories."
- else
- echo "File $1 not found"
- fi
-}
-
-# @yaml
-# signature: goto <line_number>
-# docstring: moves the window to show <line_number>
-# arguments:
-# line_number:
-# type: integer
-# description: the line number to move the window to
-# required: true
-goto() {
- if [ $# -gt 1 ]; then
- echo "goto allows only one line number at a time."
- return
- fi
- if [ -z "$CURRENT_FILE" ]
- then
- echo "No file open. Use the open command first."
- return
- fi
- if [ -z "$1" ]
- then
- echo "Usage: goto <line>"
- return
- fi
- if ! [[ $1 =~ ^[0-9]+$ ]]
- then
- echo "Usage: goto <line>"
- echo "Error: <line> must be a number"
- return
- fi
- local max_line=$(awk 'END {print NR}' "$CURRENT_FILE")
- if [ $1 -gt $max_line ]
- then
- echo "Error: <line> must be less than or equal to $max_line"
- return
- fi
- local OFFSET=$(jq -n "$WINDOW/6" | jq 'floor')
- export CURRENT_LINE=$(jq -n "[$1 + $WINDOW/2 - $OFFSET, 1] | max | floor")
- _constrain_line
- _print
-}
-
-_scroll_warning_message() {
- # Warn the agent if we scroll too many times
- # Message will be shown if scroll is called more than WARN_AFTER_SCROLLING_TIMES (default 3) times
- # Initialize variable if it's not set
- export SCROLL_COUNT=${SCROLL_COUNT:-0}
- # Reset if the last command wasn't about scrolling
- if [ "$LAST_ACTION" != "scroll_up" ] && [ "$LAST_ACTION" != "scroll_down" ]; then
- export SCROLL_COUNT=0
- fi
- # Increment because we're definitely scrolling now
- export SCROLL_COUNT=$((SCROLL_COUNT + 1))
- if [ $SCROLL_COUNT -ge ${WARN_AFTER_SCROLLING_TIMES:-3} ]; then
- echo ""
- echo "WARNING: Scrolling many times in a row is very inefficient."
- echo "If you know what you are looking for, use \`search_file <pattern>\` instead."
- echo ""
- fi
-}
-
-# @yaml
-# signature: scroll_down
-# docstring: moves the window down {WINDOW} lines
-scroll_down() {
- if [ -z "$CURRENT_FILE" ]
- then
- echo "No file open. Use the open command first."
- return
- fi
- export CURRENT_LINE=$(jq -n "$CURRENT_LINE + $WINDOW - $OVERLAP")
- _constrain_line
- _print
- _scroll_warning_message
-}
-
-# @yaml
-# signature: scroll_up
-# docstring: moves the window down {WINDOW} lines
-scroll_up() {
- if [ -z "$CURRENT_FILE" ]
- then
- echo "No file open. Use the open command first."
- return
- fi
- export CURRENT_LINE=$(jq -n "$CURRENT_LINE - $WINDOW + $OVERLAP")
- _constrain_line
- _print
- _scroll_warning_message
-}
-
-# @yaml
-# signature: create <filename>
-# docstring: creates and opens a new file with the given name
-# arguments:
-# filename:
-# type: string
-# description: the name of the file to create
-# required: true
-create() {
- if [ -z "$1" ]; then
- echo "Usage: create <filename>"
- return
- fi
-
- # Check if the file already exists
- if [ -e "$1" ]; then
- echo "Error: File '$1' already exists."
- open "$1"
- return
- fi
-
- # Create the file an empty new line
- printf "\n" > "$1"
- # Use the existing open command to open the created file
- open "$1"
-}
diff --git a/config/commands/search.sh b/config/commands/search.sh
deleted file mode 100644
index c09566bd..00000000
--- a/config/commands/search.sh
+++ /dev/null
@@ -1,155 +0,0 @@
-# @yaml
-# signature: search_dir <search_term> [<dir>]
-# docstring: searches for search_term in all files in dir. If dir is not provided, searches in the current directory
-# arguments:
-# search_term:
-# type: string
-# description: the term to search for
-# required: true
-# dir:
-# type: string
-# description: the directory to search in (if not provided, searches in the current directory)
-# required: false
-search_dir() {
- if [ $# -eq 1 ]; then
- local search_term="$1"
- local dir="./"
- elif [ $# -eq 2 ]; then
- local search_term="$1"
- if [ -d "$2" ]; then
- local dir="$2"
- else
- echo "Directory $2 not found"
- return
- fi
- else
- echo "Usage: search_dir <search_term> [<dir>]"
- return
- fi
- dir=$(realpath "$dir")
- local matches=$(find "$dir" -type f ! -path '*/.*' -exec grep -nIH -- "$search_term" {} + | cut -d: -f1 | sort | uniq -c)
- # if no matches, return
- if [ -z "$matches" ]; then
- echo "No matches found for \"$search_term\" in $dir"
- return
- fi
- # Calculate total number of matches
- local num_matches=$(echo "$matches" | awk '{sum+=$1} END {print sum}')
- # calculate total number of files matched
- local num_files=$(echo "$matches" | wc -l | awk '{$1=$1; print $0}')
- # if num_files is > 100, print an error
- if [ $num_files -gt 100 ]; then
- echo "More than $num_files files matched for \"$search_term\" in $dir. Please narrow your search."
- return
- fi
-
- echo "Found $num_matches matches for \"$search_term\" in $dir:"
- echo "$matches" | awk '{$2=$2; gsub(/^\.+\/+/, "./", $2); print $2 " ("$1" matches)"}'
- echo "End of matches for \"$search_term\" in $dir"
-}
-
-# @yaml
-# signature: search_file <search_term> [<file>]
-# docstring: searches for search_term in file. If file is not provided, searches in the current open file
-# arguments:
-# search_term:
-# type: string
-# description: the term to search for
-# required: true
-# file:
-# type: string
-# description: the file to search in (if not provided, searches in the current open file)
-# required: false
-search_file() {
- # Check if the first argument is provided
- if [ -z "$1" ]; then
- echo "Usage: search_file <search_term> [<file>]"
- return
- fi
- # Check if the second argument is provided
- if [ -n "$2" ]; then
- # Check if the provided argument is a valid file
- if [ -f "$2" ]; then
- local file="$2" # Set file if valid
- else
- echo "Usage: search_file <search_term> [<file>]"
- echo "Error: File name $2 not found. Please provide a valid file name."
- return # Exit if the file is not valid
- fi
- else
- # Check if a file is open
- if [ -z "$CURRENT_FILE" ]; then
- echo "No file open. Use the open command first."
- return # Exit if no file is open
- fi
- local file="$CURRENT_FILE" # Set file to the current open file
- fi
- local search_term="$1"
- file=$(realpath "$file")
- # Use grep to directly get the desired formatted output
- local matches=$(grep -nH -- "$search_term" "$file")
- # Check if no matches were found
- if [ -z "$matches" ]; then
- echo "No matches found for \"$search_term\" in $file"
- return
- fi
- # Calculate total number of matches
- local num_matches=$(echo "$matches" | wc -l | awk '{$1=$1; print $0}')
-
- # calculate total number of lines matched
- local num_lines=$(echo "$matches" | cut -d: -f1 | sort | uniq | wc -l | awk '{$1=$1; print $0}')
- # if num_lines is > 100, print an error
- if [ $num_lines -gt 100 ]; then
- echo "More than $num_lines lines matched for \"$search_term\" in $file. Please narrow your search."
- return
- fi
-
- # Print the total number of matches and the matches themselves
- echo "Found $num_matches matches for \"$search_term\" in $file:"
- echo "$matches" | cut -d: -f1-2 | sort -u -t: -k2,2n | while IFS=: read -r filename line_number; do
- echo "Line $line_number:$(sed -n "${line_number}p" "$file")"
- done
- echo "End of matches for \"$search_term\" in $file"
-}
-
-# @yaml
-# signature: find_file <file_name> [<dir>]
-# docstring: finds all files with the given name in dir. If dir is not provided, searches in the current directory
-# arguments:
-# file_name:
-# type: string
-# description: the name of the file to search for
-# required: true
-# dir:
-# type: string
-# description: the directory to search in (if not provided, searches in the current directory)
-# required: false
-find_file() {
- if [ $# -eq 1 ]; then
- local file_name="$1"
- local dir="./"
- elif [ $# -eq 2 ]; then
- local file_name="$1"
- if [ -d "$2" ]; then
- local dir="$2"
- else
- echo "Directory $2 not found"
- return
- fi
- else
- echo "Usage: find_file <file_name> [<dir>]"
- return
- fi
-
- dir=$(realpath "$dir")
- local matches=$(find "$dir" -type f -name "$file_name")
- # if no matches, return
- if [ -z "$matches" ]; then
- echo "No matches found for \"$file_name\" in $dir"
- return
- fi
- # Calculate total number of matches
- local num_matches=$(echo "$matches" | wc -l | awk '{$1=$1; print $0}')
- echo "Found $num_matches matches for \"$file_name\" in $dir:"
- echo "$matches" | awk '{print $0}'
-}
diff --git a/config/commands/server_connection.sh b/config/commands/server_connection.sh
deleted file mode 100644
index a8e99a62..00000000
--- a/config/commands/server_connection.sh
+++ /dev/null
@@ -1,68 +0,0 @@
-_connect_command() {
- echo "<<INTERACTIVE||$@||INTERACTIVE>>"
-}
-
-# @yaml
-# signature: connect_start <server_address> <port>
-# docstring: Starts a new interactive connection to the server address and port.
-# arguments:
-# server_address:
-# type: string
-# description: the server address to initiate connection to
-# required: true
-# port:
-# type: int
-# description: desired port for connection
-# required: true
-connect_start() {
- if [ -z "$1" ] || [ -z "$2" ]
- then
- echo "Usage: connect_start <server_address> <port>"
- return
- fi
- _connect_command "SESSION=connect"
- _connect_command "START"
- _connect_command "connect $1 $2"
- export INTERACTIVE_SESSION="connect $@"
-}
-
-# @yaml
-# signature: connect_sendline [<line>]
-# docstring: Sends a line with unicode/hexadecimal values to the connection. Sending hexadecimal bytes should be done using \x<hh> where hh stands for the sepecific byte you want to send.
-# arguments:
-# line:
-# type: string
-# description: The line to send to the connection
-# required: false
-connect_sendline() {
- _connect_command "SESSION=connect"
- _connect_command 'sendline '$@
-}
-
-# @yaml
-# signature: connect_exec <command>
-# docstring: Executes arbitrary connect command in connect session.
-# arguments:
-# command:
-# type: string
-# description: command to execute (wrap in single quotes to avoid shell escaping and substitution)
-# required: true
-connect_exec() {
- if [ -z "$1" ]
- then
- echo "Usage: connect_exec <command>"
- return
- fi
- _connect_command "SESSION=connect"
- _connect_command "$@"
-}
-
-# @yaml
-# signature: connect_stop
-# docstring: Stops the current connect session.
-connect_stop() {
- _connect_command "SESSION=connect"
- _connect_command "quit"
- _connect_command "STOP"
- unset INTERACTIVE_SESSION
-}
diff --git a/config/commands/submit_ctf.sh b/config/commands/submit_ctf.sh
deleted file mode 100644
index 2191e642..00000000
--- a/config/commands/submit_ctf.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-# @yaml
-# signature: submit '<flag>'
-# docstring: submits your current flag and terminates the session, you should be aware to properly escape the flag as this is a bash command and to put your flag under single quotes.
-# arguments:
-# flag:
-# type: string
-# description: the flag found
-# required: true
-submit() {
- if [ -z "$1" ]; then
- echo "Usage: submit <flag>"
- return
- fi
-
- echo -n "<<SUBMISSION||"
- echo -n "$@"
- echo "||SUBMISSION>>"
-}
\ No newline at end of file
diff --git a/config/default.yaml b/config/default.yaml
index 4ddfa43d..f6a5d15d 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -87,27 +87,15 @@ agent:
env_variables:
WINDOW: 100
OVERLAP: 2
- CURRENT_LINE: 0
- CURRENT_FILE: ""
- command_files:
- - config/commands/defaults.sh
- - config/commands/search.sh
- - config/commands/edit_linting.sh
- - config/commands/_split_string.py
- - config/commands/submit.sh
+ bundles:
+ - tools/defaults
+ - tools/search
+ - tools/edit_linting
+ - tools/submit
+ - tools/state
parse_command:
type: detailed
- state_command:
- name: state
- code: |
- state() {
- local working_dir="$PWD";
- if [ -z "$CURRENT_FILE" ]; then
- echo '{"open_file": "n/a", "working_dir": "'$working_dir'"}';
- else
- echo '{"open_file": "'$(realpath "$CURRENT_FILE")'", "working_dir": "'$working_dir'"}';
- fi
- };
+ state_command: _state
parse_function:
type: thought_action
history_processor:
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.py
index b030da51..81cf91f9 100644
--- a/sweagent/agent/agents.py
+++ b/sweagent/agent/agents.py
@@ -123,7 +123,7 @@ class Agent:
@classmethod
def from_config(cls, config: AgentConfig) -> Self:
- model = get_model(config.model, config.tools.commands)
+ model = get_model(config.model)
return cls(
templates=config.templates,
tools=ToolHandler.from_config(config.tools),
diff --git a/sweagent/tools/commands.py b/sweagent/tools/commands.py
index 1732f7ae..4d916c9c 100644
--- a/sweagent/tools/commands.py
+++ b/sweagent/tools/commands.py
@@ -10,12 +10,11 @@ from pydantic import BaseModel
class Command(BaseModel):
- code: str
name: str
docstring: str | None = None
# if there is an end_name, then it is a multi-line command
end_name: str | None = None
- arguments: dict | None = None
+ arguments: list[dict] | None = None
signature: str | None = None
@@ -100,14 +99,14 @@ class ParseCommandBash(AbstractParseCommand, BaseModel):
if "signature" in docs_dict:
signature = docs_dict["signature"]
elif arguments is not None:
- for param, settings in arguments.items():
- if settings["required"]:
+ for argument in arguments:
+ param = argument["name"]
+ if argument["required"]:
signature += f" <{param}>"
else:
signature += f" [<{param}>]"
command = Command.model_validate(
{
- "code": code,
"docstring": docstring,
"end_name": end_name,
"name": name,
@@ -139,8 +138,9 @@ class ParseCommandBash(AbstractParseCommand, BaseModel):
name = Path(path).name.rsplit(".", 1)[0]
if signature is None and arguments is not None:
signature = name
- for param, settings in arguments.items():
- if settings["required"]:
+ for argument in arguments:
+ param = argument["name"]
+ if argument["required"]:
signature += f" <{param}>"
else:
signature += f" [<{param}>]"
@@ -187,14 +187,16 @@ class ParseCommandDetailed(ParseCommandBash):
signature = cmd.name
if "arguments" in cmd.__dict__ and cmd.arguments is not None:
if cmd.end_name is None:
- for param, settings in cmd.arguments.items():
- if settings["required"]:
+ for argument in cmd.arguments:
+ param = argument["name"]
+ if argument["required"]:
signature += f" <{param}>"
else:
signature += f" [<{param}>]"
else:
- for param, settings in list(cmd.arguments.items())[:-1]:
- if settings["required"]:
+ for argument in cmd.arguments[:-1]:
+ param = argument["name"]
+ if argument["required"]:
signature += f" <{param}>"
else:
signature += f" [<{param}>]"
@@ -218,9 +220,10 @@ class ParseCommandDetailed(ParseCommandBash):
docs += f" signature: {self.get_signature(cmd)}\n"
if "arguments" in cmd.__dict__ and cmd.arguments is not None:
docs += " arguments:\n"
- for param, settings in cmd.arguments.items():
- req_string = "required" if settings["required"] else "optional"
- docs += f" - {param} ({settings['type']}) [{req_string}]: {settings['description']}\n"
+ for argument in cmd.arguments:
+ param = argument["name"]
+ req_string = "required" if argument["required"] else "optional"
+ docs += f" - {param} ({argument['type']}) [{req_string}]: {argument['description']}\n"
docs += "\n"
return docs
diff --git a/sweagent/tools/tools.py b/sweagent/tools/tools.py
index 7f8c5f12..8576ff01 100644
--- a/sweagent/tools/tools.py
+++ b/sweagent/tools/tools.py
@@ -1,18 +1,19 @@
import asyncio
import json
import re
+from functools import cached_property
from pathlib import Path
from typing import Any, Self
+import yaml
from pydantic import BaseModel, Field
from swerex.runtime.abstract import Command as RexCommand
-from swerex.runtime.abstract import WriteFileRequest
+from swerex.runtime.abstract import UploadRequest
from sweagent.environment.swe_env import SWEEnv
from sweagent.tools.commands import Command, ParseCommand, ParseCommandBash
from sweagent.tools.parsing import ParseFunction, ThoughtActionParser
from sweagent.tools.utils import _guard_multiline_input
-from sweagent.utils.config import _convert_paths_to_abspath
from sweagent.utils.log import get_logger
@@ -52,7 +53,7 @@ class ToolFilterConfig(BaseModel):
class ToolConfig(BaseModel):
filter: ToolFilterConfig = ToolFilterConfig()
- command_files: list[Path] = []
+ bundles: list[Path] = []
env_variables: dict[str, Any] = {}
"""Shorthand to set environment variables for the tools, effectively
@@ -71,12 +72,6 @@ class ToolConfig(BaseModel):
multi_line_command_endings: dict[str, str] = {}
submit_command_end_name: str | None = None
- install_commands: list[str] = [
- "mkdir -p /root/commands",
- "touch /root/commands/__init__.py",
- "export PATH=$PATH:/root/commands",
- "flake8 --version || pip install flake8",
- ]
"""Commands to install dependencies and tools.
These commands are executed in a subprocess and are not part of the environment state.
"""
@@ -86,12 +81,7 @@ class ToolConfig(BaseModel):
Unlike `install_commands`, these commands are part of the environment state.
"""
- state_command: Command = Command(
- name="state",
- code="""state() {
- echo '{"working_dir": "'$(realpath --relative-to=$ROOT/.. $PWD)'"}';
- };""",
- )
+ state_command: str = "_state"
"""Should extract environment state in a json readable form"""
execution_timeout: int = 30
@@ -101,19 +91,28 @@ class ToolConfig(BaseModel):
"""Timeout used for each of the installation commands"""
# todo: move to ToolHandler?
- @property
+ @cached_property
def commands(self) -> list[Command]:
"""Read command files and returned parsed command objects"""
commands = []
- for file in self.command_files:
- parsed_commands = self.parse_command.parse_command_file(file)
- commands.extend([command for command in parsed_commands if not command.name.startswith("_")])
+ tool_sources = {} # Track which file each tool comes from
+ for path in self.bundles:
+ config = yaml.safe_load((path / "config.yaml").read_text())
+ for tool, tool_config in config.get("tools", {}).items():
+ if tool in [x.name for x in commands]:
+ existing_source = tool_sources[tool]
+ msg = (
+ f"Tool '{tool}' is defined multiple times:\n"
+ f" - First definition in: {existing_source}\n"
+ f" - Duplicate definition in: {path}"
+ )
+ raise ValueError(msg)
+ commands.append(Command(name=tool, **tool_config))
+ tool_sources[tool] = path
return commands
# todo: can some of these be moved to ToolHandler?
def model_post_init(self, __context):
- self.command_files = _convert_paths_to_abspath(self.command_files)
-
# for caching:
commands = self.commands
@@ -159,7 +158,6 @@ class ToolHandler:
def install(self, env: SWEEnv) -> None:
self._install_commands(env)
- self._make_state_command_available(env)
self.reset(env)
def reset(self, env: SWEEnv) -> None:
@@ -169,45 +167,62 @@ class ToolHandler:
def _install_commands(self, env: SWEEnv) -> None:
"""Make sure all commands are available in the container"""
- for file in self.config.command_files:
- contents = file.read_text()
- source = False
- mark_executable = False
- if not contents.strip().startswith("#!"):
- if file.suffix == ".sh":
- name = file.name
- source = True
- elif file.name.startswith("_"):
- name = file.name
- else:
- msg = (
- f"Non-shell script file {file} does not start with shebang.\n"
- "Either add a shebang (#!) or change the file extension to .sh if you want to source it.\n"
- "You can override this behavior by adding an underscore to the file name (e.g. _utils.py)."
+ self._set_env_variables(env)
+ for bundle in self.config.bundles:
+ # write all files in bundle to /root/tools/
+ asyncio.run(
+ env.deployment.runtime.upload(
+ UploadRequest(
+ source_path=bundle.as_posix(),
+ target_path=f"/root/tools/{bundle.name}",
)
- raise ValueError(msg)
- else:
- name = file.name.rpartition(".")[0]
- mark_executable = True
-
- # todo: Do this with the environment?
- self.logger.debug(f"Installing command {name} ({source=}, {mark_executable=})")
+ )
+ )
asyncio.run(
- env.deployment.runtime.write_file(WriteFileRequest(content=contents, path=f"/root/commands/{name}"))
+ env.deployment.runtime.execute(
+ RexCommand(command=f"export PATH=$PATH:/root/tools/{bundle.name}/bin", shell=True, check=True)
+ )
)
- if source:
- self._reset_commands.append(f"source '/root/commands/{name}'")
- if mark_executable:
+ asyncio.run(
+ env.deployment.runtime.execute(
+ RexCommand(command=f"chmod +x /root/tools/{bundle.name}/bin/*", shell=True, check=False)
+ )
+ ) # check false because bin might not exist
+ if (bundle / "install.sh").exists():
asyncio.run(
env.deployment.runtime.execute(
- RexCommand(command=f"chmod +x '/root/commands/{name}'", shell=True, check=True)
+ RexCommand(
+ command=f"cd /root/tools/{bundle.name}; bash install.sh",
+ shell=True,
+ check=True,
+ )
)
)
- for command in self.config.install_commands:
- env.communicate(command, check=True, timeout=self.config.install_timeout)
-
- def _make_state_command_available(self, env: SWEEnv) -> None:
- env.communicate(self.config.state_command.code, check=True, timeout=1)
+ # always make all files in bin executable
+ asyncio.run(
+ env.deployment.runtime.execute(
+ RexCommand(
+ command=f"chmod +x /root/tools/{bundle.name}/bin/*",
+ shell=True,
+ check=True,
+ )
+ )
+ )
+ # check that all commands are available
+ missing_tools = []
+ for command in self.config.commands:
+ try:
+ asyncio.run(
+ env.deployment.runtime.execute(RexCommand(command=f"which {command.name}", shell=True, check=True))
+ )
+ except Exception:
+ missing_tools.append(command.name)
+ if missing_tools:
+ msg = (
+ f"The following tools were included in the tool config but are not available in the container: "
+ f"{missing_tools}. Please review the tool configs."
+ )
+ raise RuntimeError(msg)
def _set_env_variables(self, env: SWEEnv) -> None:
_env_setters = [f"export {k}={v}" for k, v in self.config.env_variables.items()]
@@ -223,7 +238,7 @@ class ToolHandler:
"""
if not self.config.state_command:
return {}
- output = env.communicate(self.config.state_command.name, check=True).strip()
+ output = env.communicate(self.config.state_command, check=True).strip()
if not output:
self.logger.warning("State command %s returned empty output", self.config.state_command.name)
return {}
diff --git a/config/commands/decompile.py b/tools/ctf_ghidra_funcs/bin/decompile
similarity index 90%
rename from config/commands/decompile.py
rename to tools/ctf_ghidra_funcs/bin/decompile
index 0e7827f1..06eb0b11 100644
--- a/config/commands/decompile.py
+++ b/tools/ctf_ghidra_funcs/bin/decompile
@@ -1,18 +1,5 @@
#!/root/miniconda3/bin/python
-# @yaml
-# signature: decompile <binary_path> [--function_name <function_name>]
-# docstring: Decompile a binary and prints the decompilation of a given function name
-# arguments:
-# binary_path:
-# type: file path
-# description: The path to the binary to be decompiled
-# required: true
-# function_name:
-# type: string
-# description: The function name to be decompiled, or main by default
-# required: false
-
import argparse
import subprocess
import re
diff --git a/config/commands/disassemble.py b/tools/ctf_ghidra_funcs/bin/disassemble
similarity index 90%
rename from config/commands/disassemble.py
rename to tools/ctf_ghidra_funcs/bin/disassemble
index 26d1a41a..409145e0 100644
--- a/config/commands/disassemble.py
+++ b/tools/ctf_ghidra_funcs/bin/disassemble
@@ -1,18 +1,5 @@
#!/root/miniconda3/bin/python
-# @yaml
-# signature: disassemble <binary_path> [--function_name <function_name>]
-# docstring: Disassembles a binary and prints the disassembly of a given function name
-# arguments:
-# binary_path:
-# type: file path
-# description: The path to the binary to be disassembled
-# required: true
-# function_name:
-# type: string
-# description: The function name to be disassembled, or main by default
-# required: false
-
import argparse
import subprocess
import re
diff --git a/tools/ctf_ghidra_funcs/config.yaml b/tools/ctf_ghidra_funcs/config.yaml
new file mode 100644
index 00000000..6a63e4fc
--- /dev/null
+++ b/tools/ctf_ghidra_funcs/config.yaml
@@ -0,0 +1,25 @@
+tools:
+ disassemble:
+ signature: "disassemble <binary_path> [--function_name <function_name>]"
+ docstring: "Disassembles a binary and prints the disassembly of a given function name"
+ arguments:
+ - name: binary_path
+ type: string
+ description: The path to the binary to be disassembled
+ required: true
+ - name: function_name
+ type: string
+ description: The function name to be disassembled, or main by default
+ required: false
+ decompile:
+ signature: "decompile <binary_path> [--function_name <function_name>]"
+ docstring: "Decompile a binary and prints the decompilation of a given function name"
+ arguments:
+ - name: binary_path
+ type: string
+ description: The path to the binary to be decompiled
+ required: true
+ - name: function_name
+ type: string
+ description: The function name to be decompiled, or main by default
+ required: false
diff --git a/tools/cursors_defaults/bin/_read_env b/tools/cursors_defaults/bin/_read_env
new file mode 100644
index 00000000..e43868ad
--- /dev/null
+++ b/tools/cursors_defaults/bin/_read_env
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+import json
+import os
+import sys
+
+SWE_AGENT_ENV_FILE = os.environ.get("SWE_AGENT_ENV_FILE", "/root/.swe-agent-env")
+
+def read_env(var_name, default_value=None):
+ if not os.path.exists(SWE_AGENT_ENV_FILE):
+ with open(SWE_AGENT_ENV_FILE, "w") as f:
+ json.dump({}, f)
+ return default_value
+ with open(SWE_AGENT_ENV_FILE, "r") as f:
+ env = json.load(f)
+ return env.get(var_name, default_value)
+
+if __name__ == "__main__":
+ var_name = sys.argv[1]
+ default_value = sys.argv[2] if len(sys.argv) > 2 else ""
+ print(read_env(var_name, default_value))
diff --git a/tools/cursors_defaults/bin/_write_env b/tools/cursors_defaults/bin/_write_env
new file mode 100644
index 00000000..27e7c1b7
--- /dev/null
+++ b/tools/cursors_defaults/bin/_write_env
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+import json
+import os
+import sys
+
+SWE_AGENT_ENV_FILE = os.environ.get("SWE_AGENT_ENV_FILE", "/root/.swe-agent-env")
+
+def write_env(var_name, var_value):
+ if not os.path.exists(SWE_AGENT_ENV_FILE):
+ with open(SWE_AGENT_ENV_FILE, "w") as f:
+ json.dump({}, f)
+ with open(SWE_AGENT_ENV_FILE, "r") as f:
+ env = json.load(f)
+ env[var_name] = var_value
+ with open(SWE_AGENT_ENV_FILE, "w") as f:
+ json.dump(env, f)
+
+if __name__ == "__main__":
+ var_name = sys.argv[1]
+ var_value = sys.argv[2] if len(sys.argv) > 2 else ""
+ write_env(var_name, var_value)
diff --git a/tools/cursors_defaults/bin/create b/tools/cursors_defaults/bin/create
new file mode 100644
index 00000000..3df63e90
--- /dev/null
+++ b/tools/cursors_defaults/bin/create
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+set -euo pipefail
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ if [ -z "$1" ]; then
+ echo "Usage: create <filename>"
+ exit 1
+ fi
+
+ # Check if the file already exists
+ if [ -e "$1" ]; then
+ echo "Error: File '$1' already exists."
+ open "$1" || exit 1
+ exit 1
+ fi
+
+ # Create the file an empty new line
+ printf "\n" > "$1"
+ # Use the existing open command to open the created file
+ open "$1" || exit 1
+}
+
+main "$@"
diff --git a/tools/cursors_defaults/bin/goto b/tools/cursors_defaults/bin/goto
new file mode 100644
index 00000000..8a9329ce
--- /dev/null
+++ b/tools/cursors_defaults/bin/goto
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+set -euo pipefail
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ local CURRENT_FILE=$(_read_env CURRENT_FILE)
+ local WINDOW=$(_read_env WINDOW)
+
+ if [ $# -gt 1 ]; then
+ echo "goto allows only one line number at a time."
+ exit 1
+ fi
+ if [ -z "$CURRENT_FILE" ]
+ then
+ echo "No file open. Use the open command first."
+ exit 1
+ fi
+ if [ -z "$1" ]
+ then
+ echo "Usage: goto <line>"
+ exit 1
+ fi
+ if ! [[ $1 =~ ^[0-9]+$ ]]
+ then
+ echo "Usage: goto <line>"
+ echo "Error: <line> must be a number"
+ exit 1
+ fi
+ local max_line=$(awk 'END {print NR}' "$CURRENT_FILE")
+ if [ $1 -gt $max_line ]
+ then
+ echo "Error: <line> must be less than or equal to $max_line"
+ exit 1
+ fi
+ local OFFSET=$(jq -n "$WINDOW/6" | jq 'floor')
+ _write_env CURRENT_LINE $(jq -n "[$1 + $WINDOW/2 - $OFFSET, 1] | max | floor") || exit 1
+ _constrain_line || exit 1
+ _print || exit 1
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/cursors_defaults/bin/open b/tools/cursors_defaults/bin/open
new file mode 100644
index 00000000..a8b0d198
--- /dev/null
+++ b/tools/cursors_defaults/bin/open
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+set -euo pipefail
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ local WINDOW=$(_read_env WINDOW)
+
+ if [ -z "$1" ]
+ then
+ echo "Usage: open \"<file>\""
+ exit 1
+ fi
+ if [ -d "$1" ]; then
+ echo "Error: $1 is a directory. You can only open files. Use cd or ls to navigate directories."
+ exit 1
+ elif [ ! -f "$1" ]; then
+ echo "File $1 not found"
+ exit 1
+ fi
+
+ # Check if the second argument is provided
+ if [ -n "$2" ]; then
+ # Check if the provided argument is a valid number
+ if ! [[ $2 =~ ^[0-9]+$ ]]; then
+ echo "Usage: open \"<file>\" [<line_number>]"
+ echo "Error: <line_number> must be a number"
+ exit 1
+ fi
+ local max_line=$(awk 'END {print NR}' "$1")
+ if [ $2 -gt $max_line ]; then
+ echo "Warning: <line_number> ($2) is greater than the number of lines in the file ($max_line)"
+ echo "Warning: Setting <line_number> to $max_line"
+ local line_number=$(jq -n "$max_line") # Set line number to max if greater than max
+ elif [ $2 -lt 1 ]; then
+ echo "Warning: <line_number> ($2) is less than 1"
+ echo "Warning: Setting <line_number> to 1"
+ local line_number=$(jq -n "1") # Set line number to 1 if less than 1
+ else
+ local OFFSET=$(jq -n "$WINDOW/6" | jq 'floor')
+ local line_number=$(jq -n "[$2 + $WINDOW/2 - $OFFSET, 1] | max | floor")
+ fi
+ else
+ local line_number=$(jq -n "$WINDOW/2") # Set default line number if not provided
+ fi
+
+ _write_env CURRENT_FILE $(realpath "$1") || exit 1
+ _write_env CURRENT_LINE $line_number || exit 1
+ _constrain_line || exit 1
+ _print || exit 1
+}
+
+main "$@"
diff --git a/tools/cursors_defaults/bin/scroll_down b/tools/cursors_defaults/bin/scroll_down
new file mode 100644
index 00000000..934a7980
--- /dev/null
+++ b/tools/cursors_defaults/bin/scroll_down
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+set -euo pipefail
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ local CURRENT_FILE=$(_read_env CURRENT_FILE)
+ local CURRENT_LINE=$(_read_env CURRENT_LINE)
+ local WINDOW=$(_read_env WINDOW)
+ local OVERLAP=$(_read_env OVERLAP)
+
+ if [ -z "$CURRENT_FILE" ]
+ then
+ echo "No file open. Use the open command first."
+ exit 1
+ fi
+ _write_env CURRENT_LINE $(jq -n "$CURRENT_LINE + $WINDOW - $OVERLAP") || exit 1
+ _constrain_line || exit 1
+ _print || exit 1
+ _scroll_warning_message || exit 1
+}
+
+main "$@"
diff --git a/tools/cursors_defaults/bin/scroll_up b/tools/cursors_defaults/bin/scroll_up
new file mode 100644
index 00000000..779d4c35
--- /dev/null
+++ b/tools/cursors_defaults/bin/scroll_up
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+set -euo pipefail
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ local CURRENT_FILE=$(_read_env CURRENT_FILE)
+ local CURRENT_LINE=$(_read_env CURRENT_LINE)
+ local WINDOW=$(_read_env WINDOW)
+ local OVERLAP=$(_read_env OVERLAP)
+
+ if [ -z "$CURRENT_FILE" ]
+ then
+ echo "No file open. Use the open command first."
+ exit 1
+ fi
+ _write_env CURRENT_LINE $(jq -n "$CURRENT_LINE - $WINDOW + $OVERLAP") || exit 1
+ _constrain_line || exit 1
+ _print || exit 1
+ _scroll_warning_message || exit 1
+}
+
+main "$@"
diff --git a/tools/cursors_defaults/config.yaml b/tools/cursors_defaults/config.yaml
new file mode 100644
index 00000000..2d3cffd2
--- /dev/null
+++ b/tools/cursors_defaults/config.yaml
@@ -0,0 +1,49 @@
+tools:
+ goto:
+ signature: "goto <line_number>"
+ docstring: "moves the window to show <line_number>"
+ arguments:
+ - name: line_number
+ type: integer
+ description: "the line number to move the window to"
+ required: true
+ open:
+ signature: "open <path> [<line_number>]"
+ docstring: "opens the file at the given path in the editor. If line_number is provided, the window will be centered on that line"
+ arguments:
+ - name: path
+ type: string
+ description: "the path to the file to open"
+ required: true
+ - name: line_number
+ type: integer
+ description: "the line number to move the window to (if not provided, the window will start at the top of the file)"
+ required: false
+ create:
+ signature: "create <filename>"
+ docstring: "creates and opens a new file with the given name"
+ arguments:
+ - name: filename
+ type: string
+ description: "the name of the file to create"
+ required: true
+ scroll_up:
+ signature: "scroll_up"
+ docstring: "moves the window up {WINDOW} lines"
+ arguments: []
+ scroll_down:
+ signature: "scroll_down"
+ docstring: "moves the window down {WINDOW} lines"
+ arguments: []
+ set_cursors:
+ signature: "set_cursors <start_line> <end_line>"
+ docstring: "sets the start and end cursors to the given line numbers"
+ arguments:
+ - name: start_line
+ type: integer
+ description: "the line number to set the start cursor to"
+ required: true
+ - name: end_line
+ type: integer
+ description: "the line number to set the end cursor to"
+ required: true
diff --git a/tools/cursors_defaults/install.sh b/tools/cursors_defaults/install.sh
new file mode 100644
index 00000000..2978db4e
--- /dev/null
+++ b/tools/cursors_defaults/install.sh
@@ -0,0 +1,24 @@
+source /root/tools/cursors_defaults/lib/utils.sh
+
+# raise error ir any env variables not set
+if [ -z "$WINDOW" ]; then
+ echo "Error: WINDOW not set"
+ exit 1
+fi
+if [ -z "$OVERLAP" ]; then
+ echo "Error: OVERLAP not set"
+ exit 1
+fi
+if [ -z "$CURRENT_LINE" ]; then
+ echo "Error: CURRENT_LINE not set"
+ exit 1
+fi
+if [ -z "$CURRENT_FILE" ]; then
+ echo "Error: CURRENT_FILE not set"
+ exit 1
+fi
+
+_write_env "WINDOW" "$WINDOW"
+_write_env "OVERLAP" "$OVERLAP"
+_write_env "CURRENT_LINE" "$CURRENT_LINE"
+_write_env "CURRENT_FILE" "$CURRENT_FILE"
diff --git a/config/commands/_split_string.py b/tools/cursors_edit_linting/bin/_split_string
similarity index 100%
rename from config/commands/_split_string.py
rename to tools/cursors_edit_linting/bin/_split_string
diff --git a/config/commands/cursors_edit_linting.sh b/tools/cursors_edit_linting/bin/edit
similarity index 66%
rename from config/commands/cursors_edit_linting.sh
rename to tools/cursors_edit_linting/bin/edit
index b4249eb0..a81cf050 100644
--- a/config/commands/cursors_edit_linting.sh
+++ b/tools/cursors_edit_linting/bin/edit
@@ -1,16 +1,10 @@
-# @yaml
-# signature: |-
-# edit
-# <replacement_text>
-# end_of_edit
-# docstring: replaces *all* of the text between the START CURSOR and the END CURSOR with the replacement_text. The replacement text is terminated by a line with only end_of_edit on it. All of the <replacement_text> will be entered, so make sure your indentation is formatted properly. To enter text at the beginning of the file, set START CURSOR and END CURSOR to 0. Use set_cursors to move the cursors around. Python files will be checked for syntax errors after the edit.
-# end_name: end_of_edit
-# arguments:
-# replacement_text:
-# type: string
-# description: the text to replace the current selection with
-# required: true
-edit() {
+source /root/tools/cursors_defaults/lib/utils.sh
+
+main() {
+ local CURRENT_FILE=$(_read_env CURRENT_FILE)
+ local START_CURSOR=$(_read_env START_CURSOR)
+ local END_CURSOR=$(_read_env END_CURSOR)
+
if [ -z "$CURRENT_FILE" ]
then
echo 'No file open. Use the `open` command first.'
@@ -46,8 +40,8 @@ edit() {
if [ -z "$lint_output" ]; then
_constrain_line
# set to START + num_lines - 1, unless num_lines is 0, then set to START
- export END_CURSOR=$((num_lines == 0 ? START_CURSOR : START_CURSOR + num_lines - 1))
- export START_CURSOR=$START_CURSOR
+ _write_env END_CURSOR $((num_lines == 0 ? START_CURSOR : START_CURSOR + num_lines - 1))
+ _write_env START_CURSOR $START_CURSOR
_print
echo "File updated. Please review the changes and make sure they are correct (correct indentation, no duplicate lines, etc). Edit the file again if necessary."
else
@@ -63,9 +57,9 @@ edit() {
original_end_cursor=$END_CURSOR
# Update values
- export CURRENT_LINE=$(( (num_lines / 2) + start_line )) # Set to "center" of edit
- export WINDOW=$((num_lines + 10)) # Show +/- 5 lines around edit
- export END_CURSOR=$((num_lines == 0 ? START_CURSOR : START_CURSOR + num_lines - 1))
+ _write_env CURRENT_LINE $(( (num_lines / 2) + start_line )) # Set to "center" of edit
+ _write_env WINDOW $((num_lines + 10)) # Show +/- 5 lines around edit
+ _write_env END_CURSOR $((num_lines == 0 ? START_CURSOR : START_CURSOR + num_lines - 1))
echo "This is how your edit would have looked if applied"
echo "-------------------------------------------------"
@@ -77,9 +71,9 @@ edit() {
# Restoring CURRENT_FILE to original contents.
cp "/root/$(basename "$CURRENT_FILE")_backup" "$CURRENT_FILE"
- export CURRENT_LINE=$(( ((end_line - start_line) / 2) + start_line )) # Set to "center" of edit
- export WINDOW=$((end_line - start_line + 10))
- export END_CURSOR=$original_end_cursor
+ _write_env CURRENT_LINE=$(( ((end_line - start_line) / 2) + start_line )) # Set to "center" of edit
+ _write_env WINDOW=$((end_line - start_line + 10))
+ _write_env END_CURSOR=$original_end_cursor
echo "This is the original code before your edit"
echo "-------------------------------------------------"
@@ -88,9 +82,9 @@ edit() {
echo "-------------------------------------------------"
# Restore original values
- export CURRENT_LINE=$original_current_line
- export WINDOW=$original_window
- export END_CURSOR=$original_end_cursor
+ _write_env CURRENT_LINE $original_current_line
+ _write_env WINDOW $original_window
+ _write_env END_CURSOR $original_end_cursor
echo "Your changes have NOT been applied. Please fix your edit command and try again."
echo "You either need to 1) Specify the correct start/end line arguments or 2) Correct your edit code."
@@ -99,3 +93,5 @@ edit() {
# Remove backup file
rm -f "/root/$(basename "$CURRENT_FILE")_backup"
}
+
+main "$@"
diff --git a/tools/cursors_edit_linting/config.yaml b/tools/cursors_edit_linting/config.yaml
new file mode 100644
index 00000000..383dc38d
--- /dev/null
+++ b/tools/cursors_edit_linting/config.yaml
@@ -0,0 +1,13 @@
+tools:
+ edit:
+ signature: |
+ edit
+ <replacement_text>
+ end_of_edit
+ docstring: >
+ replaces *all* of the text between the START CURSOR and the END CURSOR with the replacement_text. The replacement text is terminated by a line with only end_of_edit on it. All of the <replacement_text> will be entered, so make sure your indentation is formatted properly. To enter text at the beginning of the file, set START CURSOR and END CURSOR to 0. Use set_cursors to move the cursors around. Python files will be checked for syntax errors after the edit.
+ arguments:
+ - name: replacement_text
+ type: string
+ description: "the text to replace the current selection with"
+ required: true
diff --git a/tools/cursors_edit_linting/install.sh b/tools/cursors_edit_linting/install.sh
new file mode 100644
index 00000000..49ef0fc7
--- /dev/null
+++ b/tools/cursors_edit_linting/install.sh
@@ -0,0 +1,15 @@
+source /root/tools/cursors_defaults/lib/utils.sh
+
+if [ -z "$WINDOW" ]; then
+ echo "Error: WINDOW not set"
+ exit 1
+fi
+if [ -z "$OVERLAP" ]; then
+ echo "Error: OVERLAP not set"
+ exit 1
+fi
+
+_write_env CURRENT_FILE "${CURRENT_FILE:-}"
+_write_env CURRENT_LINE "${CURRENT_LINE:-0}"
+_write_env WINDOW "$WINDOW"
+_write_env OVERLAP "$OVERLAP"
diff --git a/tools/cursors_state/bin/_state b/tools/cursors_state/bin/_state
new file mode 100644
index 00000000..fc68aa83
--- /dev/null
+++ b/tools/cursors_state/bin/_state
@@ -0,0 +1,12 @@
+source /root/tools/cursors_defaults/lib/utils.sh
+
+main() {
+ local CURRENT_FILE=$(_read_env CURRENT_FILE)
+ if [ -z "$CURRENT_FILE" ]; then
+ echo '{"open_file": "n/a", "working_dir": "'$PWD'"}';
+ else
+ echo '{"open_file": "'$(realpath "$CURRENT_FILE")'", "working_dir": "'$PWD'"}';
+ fi
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/cursors_state/config.yaml b/tools/cursors_state/config.yaml
new file mode 100644
index 00000000..a2fa2036
--- /dev/null
+++ b/tools/cursors_state/config.yaml
@@ -0,0 +1 @@
+tools: {}
\ No newline at end of file
diff --git a/tools/debug/bin/debug_add_breakpoint b/tools/debug/bin/debug_add_breakpoint
new file mode 100644
index 00000000..48fb2df1
--- /dev/null
+++ b/tools/debug/bin/debug_add_breakpoint
@@ -0,0 +1,13 @@
+source /root/tools/debug/lib/utils.sh
+
+main() {
+ if [ -z "$1" ]
+ then
+ echo "Usage: debug_add_breakpoint <breakpoint>"
+ return
+ fi
+ _debug_command "SESSION=gdb"
+ _debug_command 'break '$1
+}
+
+main "$@"
diff --git a/tools/debug/bin/debug_and_continue b/tools/debug/bin/debug_and_continue
new file mode 100644
index 00000000..01782cb3
--- /dev/null
+++ b/tools/debug/bin/debug_and_continue
@@ -0,0 +1,8 @@
+source /root/tools/debug/lib/utils.sh
+
+main() {
+ _debug_command "SESSION=gdb"
+ _debug_command 'continue'
+}
+
+main "$@"
diff --git a/tools/debug/bin/debug_exec b/tools/debug/bin/debug_exec
new file mode 100644
index 00000000..699dedbb
--- /dev/null
+++ b/tools/debug/bin/debug_exec
@@ -0,0 +1,13 @@
+source /root/tools/debug/lib/utils.sh
+
+main() {
+ if [ -z "$1" ]
+ then
+ echo "Usage: debug_exec <command>"
+ return
+ fi
+ _debug_command "SESSION=gdb"
+ _debug_command "$1"
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/debug/bin/debug_start b/tools/debug/bin/debug_start
new file mode 100644
index 00000000..d0c875b8
--- /dev/null
+++ b/tools/debug/bin/debug_start
@@ -0,0 +1,27 @@
+source /root/tools/debug/lib/utils.sh
+
+main() {
+ if [ -z "$1" ]
+ then
+ echo "Usage: debug_start <binary>"
+ return
+ fi
+ if [ ! -x "$1" ]
+ then
+ echo "Error: File $1 does not exist, or is not executable"
+ return
+ fi
+ fp=$(realpath $1)
+ _debug_command "SESSION=gdb"
+ _debug_command "START"
+ _debug_command "set confirm off"
+ _debug_command "file $fp"
+ if [ ! -z "$2" ]
+ then
+ _debug_command "set args ${@:2:$#}" # Set arguments from 2 until the end
+ fi
+ _debug_command "starti"
+ _write_env INTERACTIVE_SESSION="gdb $@"
+}
+
+main "$@"
diff --git a/tools/debug/bin/debug_step b/tools/debug/bin/debug_step
new file mode 100644
index 00000000..81a944f0
--- /dev/null
+++ b/tools/debug/bin/debug_step
@@ -0,0 +1,18 @@
+source /root/tools/debug/lib/utils.sh
+
+main() {
+ if [ -z "$1" ]
+ then
+ _debug_command "SESSION=gdb"
+ _debug_command 'stepi'
+ elif [[ (("$1" -eq "$1") && ("$1" -gt "0")) ]] # Check if integer and positive
+ then
+ _debug_command "SESSION=gdb"
+ _debug_command 'stepi '$1
+ else
+ echo "Please provide a positive integer for number of instructions."
+ echo "Usage: debug_step [number]"
+ fi
+}
+
+main "$@"
diff --git a/tools/debug/bin/debug_stop b/tools/debug/bin/debug_stop
new file mode 100644
index 00000000..93f2e677
--- /dev/null
+++ b/tools/debug/bin/debug_stop
@@ -0,0 +1,10 @@
+source /root/tools/debug/lib/utils.sh
+
+main() {
+ _debug_command "SESSION=gdb"
+ _debug_command "quit"
+ _debug_command "STOP"
+ unset INTERACTIVE_SESSION
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/debug/config.yaml b/tools/debug/config.yaml
new file mode 100644
index 00000000..334e3691
--- /dev/null
+++ b/tools/debug/config.yaml
@@ -0,0 +1,45 @@
+tools:
+ debug_start:
+ signature: debug_start <binary> [<args>]
+ docstring: Starts a debug session with the given binary.
+ arguments:
+ - name: binary
+ type: string
+ description: the path to the binary to debug
+ required: true
+ - name: args
+ type: string
+ description: optional command-line arguments for the binary
+ required: false
+ debug_add_breakpoint:
+ signature: debug_add_breakpoint <breakpoint>
+ docstring: Adds a breakpoint in the debug session
+ arguments:
+ - name: breakpoint
+ type: string
+ description: The breakpoint location, which may be a function name, address, or filename and line number.
+ required: true
+ debug_continue:
+ signature: debug_continue
+ docstring: Continues the program execution in the debug session.
+ arguments: []
+ debug_step:
+ signature: debug_step [number]
+ docstring: Steps number of instructions in the debug session.
+ arguments:
+ - name: number
+ type: integer
+ description: number of instructions to step (default is 1)
+ required: false
+ debug_exec:
+ signature: debug_exec <command>
+ docstring: Executes arbitrary gdb command in debug session.
+ arguments:
+ - name: command
+ type: string
+ description: command to execute (wrap in single quotes to avoid shell escaping and substitution)
+ required: true
+ debug_stop:
+ signature: debug_stop
+ docstring: Stops the current debug session.
+ arguments: []
\ No newline at end of file
diff --git a/tools/defaults/bin/_read_env b/tools/defaults/bin/_read_env
new file mode 100644
index 00000000..e43868ad
--- /dev/null
+++ b/tools/defaults/bin/_read_env
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+import json
+import os
+import sys
+
+SWE_AGENT_ENV_FILE = os.environ.get("SWE_AGENT_ENV_FILE", "/root/.swe-agent-env")
+
+def read_env(var_name, default_value=None):
+ if not os.path.exists(SWE_AGENT_ENV_FILE):
+ with open(SWE_AGENT_ENV_FILE, "w") as f:
+ json.dump({}, f)
+ return default_value
+ with open(SWE_AGENT_ENV_FILE, "r") as f:
+ env = json.load(f)
+ return env.get(var_name, default_value)
+
+if __name__ == "__main__":
+ var_name = sys.argv[1]
+ default_value = sys.argv[2] if len(sys.argv) > 2 else ""
+ print(read_env(var_name, default_value))
diff --git a/tools/defaults/bin/_write_env b/tools/defaults/bin/_write_env
new file mode 100644
index 00000000..27e7c1b7
--- /dev/null
+++ b/tools/defaults/bin/_write_env
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+import json
+import os
+import sys
+
+SWE_AGENT_ENV_FILE = os.environ.get("SWE_AGENT_ENV_FILE", "/root/.swe-agent-env")
+
+def write_env(var_name, var_value):
+ if not os.path.exists(SWE_AGENT_ENV_FILE):
+ with open(SWE_AGENT_ENV_FILE, "w") as f:
+ json.dump({}, f)
+ with open(SWE_AGENT_ENV_FILE, "r") as f:
+ env = json.load(f)
+ env[var_name] = var_value
+ with open(SWE_AGENT_ENV_FILE, "w") as f:
+ json.dump(env, f)
+
+if __name__ == "__main__":
+ var_name = sys.argv[1]
+ var_value = sys.argv[2] if len(sys.argv) > 2 else ""
+ write_env(var_name, var_value)
diff --git a/tools/defaults/bin/create b/tools/defaults/bin/create
new file mode 100644
index 00000000..3df63e90
--- /dev/null
+++ b/tools/defaults/bin/create
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+set -euo pipefail
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ if [ -z "$1" ]; then
+ echo "Usage: create <filename>"
+ exit 1
+ fi
+
+ # Check if the file already exists
+ if [ -e "$1" ]; then
+ echo "Error: File '$1' already exists."
+ open "$1" || exit 1
+ exit 1
+ fi
+
+ # Create the file an empty new line
+ printf "\n" > "$1"
+ # Use the existing open command to open the created file
+ open "$1" || exit 1
+}
+
+main "$@"
diff --git a/tools/defaults/bin/goto b/tools/defaults/bin/goto
new file mode 100644
index 00000000..8a9329ce
--- /dev/null
+++ b/tools/defaults/bin/goto
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+set -euo pipefail
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ local CURRENT_FILE=$(_read_env CURRENT_FILE)
+ local WINDOW=$(_read_env WINDOW)
+
+ if [ $# -gt 1 ]; then
+ echo "goto allows only one line number at a time."
+ exit 1
+ fi
+ if [ -z "$CURRENT_FILE" ]
+ then
+ echo "No file open. Use the open command first."
+ exit 1
+ fi
+ if [ -z "$1" ]
+ then
+ echo "Usage: goto <line>"
+ exit 1
+ fi
+ if ! [[ $1 =~ ^[0-9]+$ ]]
+ then
+ echo "Usage: goto <line>"
+ echo "Error: <line> must be a number"
+ exit 1
+ fi
+ local max_line=$(awk 'END {print NR}' "$CURRENT_FILE")
+ if [ $1 -gt $max_line ]
+ then
+ echo "Error: <line> must be less than or equal to $max_line"
+ exit 1
+ fi
+ local OFFSET=$(jq -n "$WINDOW/6" | jq 'floor')
+ _write_env CURRENT_LINE $(jq -n "[$1 + $WINDOW/2 - $OFFSET, 1] | max | floor") || exit 1
+ _constrain_line || exit 1
+ _print || exit 1
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/defaults/bin/open b/tools/defaults/bin/open
new file mode 100644
index 00000000..a8b0d198
--- /dev/null
+++ b/tools/defaults/bin/open
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+set -euo pipefail
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ local WINDOW=$(_read_env WINDOW)
+
+ if [ -z "$1" ]
+ then
+ echo "Usage: open \"<file>\""
+ exit 1
+ fi
+ if [ -d "$1" ]; then
+ echo "Error: $1 is a directory. You can only open files. Use cd or ls to navigate directories."
+ exit 1
+ elif [ ! -f "$1" ]; then
+ echo "File $1 not found"
+ exit 1
+ fi
+
+ # Check if the second argument is provided
+ if [ -n "$2" ]; then
+ # Check if the provided argument is a valid number
+ if ! [[ $2 =~ ^[0-9]+$ ]]; then
+ echo "Usage: open \"<file>\" [<line_number>]"
+ echo "Error: <line_number> must be a number"
+ exit 1
+ fi
+ local max_line=$(awk 'END {print NR}' "$1")
+ if [ $2 -gt $max_line ]; then
+ echo "Warning: <line_number> ($2) is greater than the number of lines in the file ($max_line)"
+ echo "Warning: Setting <line_number> to $max_line"
+ local line_number=$(jq -n "$max_line") # Set line number to max if greater than max
+ elif [ $2 -lt 1 ]; then
+ echo "Warning: <line_number> ($2) is less than 1"
+ echo "Warning: Setting <line_number> to 1"
+ local line_number=$(jq -n "1") # Set line number to 1 if less than 1
+ else
+ local OFFSET=$(jq -n "$WINDOW/6" | jq 'floor')
+ local line_number=$(jq -n "[$2 + $WINDOW/2 - $OFFSET, 1] | max | floor")
+ fi
+ else
+ local line_number=$(jq -n "$WINDOW/2") # Set default line number if not provided
+ fi
+
+ _write_env CURRENT_FILE $(realpath "$1") || exit 1
+ _write_env CURRENT_LINE $line_number || exit 1
+ _constrain_line || exit 1
+ _print || exit 1
+}
+
+main "$@"
diff --git a/tools/defaults/bin/scroll_down b/tools/defaults/bin/scroll_down
new file mode 100644
index 00000000..934a7980
--- /dev/null
+++ b/tools/defaults/bin/scroll_down
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+set -euo pipefail
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ local CURRENT_FILE=$(_read_env CURRENT_FILE)
+ local CURRENT_LINE=$(_read_env CURRENT_LINE)
+ local WINDOW=$(_read_env WINDOW)
+ local OVERLAP=$(_read_env OVERLAP)
+
+ if [ -z "$CURRENT_FILE" ]
+ then
+ echo "No file open. Use the open command first."
+ exit 1
+ fi
+ _write_env CURRENT_LINE $(jq -n "$CURRENT_LINE + $WINDOW - $OVERLAP") || exit 1
+ _constrain_line || exit 1
+ _print || exit 1
+ _scroll_warning_message || exit 1
+}
+
+main "$@"
diff --git a/tools/defaults/bin/scroll_up b/tools/defaults/bin/scroll_up
new file mode 100644
index 00000000..779d4c35
--- /dev/null
+++ b/tools/defaults/bin/scroll_up
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+set -euo pipefail
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ local CURRENT_FILE=$(_read_env CURRENT_FILE)
+ local CURRENT_LINE=$(_read_env CURRENT_LINE)
+ local WINDOW=$(_read_env WINDOW)
+ local OVERLAP=$(_read_env OVERLAP)
+
+ if [ -z "$CURRENT_FILE" ]
+ then
+ echo "No file open. Use the open command first."
+ exit 1
+ fi
+ _write_env CURRENT_LINE $(jq -n "$CURRENT_LINE - $WINDOW + $OVERLAP") || exit 1
+ _constrain_line || exit 1
+ _print || exit 1
+ _scroll_warning_message || exit 1
+}
+
+main "$@"
diff --git a/tools/defaults/config.yaml b/tools/defaults/config.yaml
new file mode 100644
index 00000000..406d8a2c
--- /dev/null
+++ b/tools/defaults/config.yaml
@@ -0,0 +1,37 @@
+tools:
+ goto:
+ signature: "goto <line_number>"
+ docstring: "moves the window to show <line_number>"
+ arguments:
+ - name: line_number
+ type: integer
+ description: "the line number to move the window to"
+ required: true
+ open:
+ signature: 'open "<path>" [<line_number>]'
+ docstring: "opens the file at the given path in the editor. If line_number is provided, the window will be move to include that line"
+ arguments:
+ - name: path
+ type: string
+ description: "the path to the file to open"
+ required: true
+ - name: line_number
+ type: integer
+ description: "the line number to move the window to (if not provided, the window will start at the top of the file)"
+ required: false
+ create:
+ signature: "create <filename>"
+ docstring: "creates and opens a new file with the given name"
+ arguments:
+ - name: filename
+ type: string
+ description: "the name of the file to create"
+ required: true
+ scroll_up:
+ signature: "scroll_up"
+ docstring: "moves the window down {WINDOW} lines"
+ arguments: []
+ scroll_down:
+ signature: "scroll_down"
+ docstring: "moves the window down {WINDOW} lines"
+ arguments: []
diff --git a/tools/defaults/install.sh b/tools/defaults/install.sh
new file mode 100644
index 00000000..f9bec7d4
--- /dev/null
+++ b/tools/defaults/install.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
+source "$SCRIPT_DIR/lib/utils.sh"
+
+if [ -z "$WINDOW" ]; then
+ echo "Error: WINDOW not set"
+ exit 1
+fi
+if [ -z "$OVERLAP" ]; then
+ echo "Error: OVERLAP not set"
+ exit 1
+fi
+
+_write_env "WINDOW" "${WINDOW:-100}"
+_write_env "OVERLAP" "${OVERLAP:-2}"
+_write_env "CURRENT_LINE" "${CURRENT_LINE:-0}"
+_write_env "CURRENT_FILE" "${CURRENT_FILE:-}"
+
+# install jq
+apt-get update && apt-get install -y jq
diff --git a/tools/edit_linting/bin/_split_string b/tools/edit_linting/bin/_split_string
new file mode 100644
index 00000000..b4a4a780
--- /dev/null
+++ b/tools/edit_linting/bin/_split_string
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+
+"""This helper command is used to print flake8 output
+
+Usage:
+ python _split_string.py <flake8_output>
+ python _split_string.py <flake8_output> <previous_errors> <edit_window_start> <edit_window_end> <n_lines>
+
+Where:
+ <flake8_output> is the output of flake8
+ <previous_errors> is the previous errors as a string
+ <edit_window_start> is the start of the edit window
+ <edit_window_end> is the end of the edit window
+ <n_lines> is the number of lines added in the edit
+"""
+
+# ruff: noqa: UP007 UP006 UP035
+
+import sys
+from dataclasses import dataclass
+from typing import List, Optional, Tuple
+
+
+@dataclass
+class Flake8Error:
+ """A class to represent a single flake8 error"""
+
+ filename: str
+ line_number: int
+ col_number: int
+ problem: str
+
+ @classmethod
+ def from_line(cls, line: str):
+ try:
+ prefix, _sep, problem = line.partition(": ")
+ filename, line_number, col_number = prefix.split(":")
+ except (ValueError, IndexError) as e:
+ msg = f"Invalid flake8 error line: {line}"
+ raise ValueError(msg) from e
+ return cls(filename, int(line_number), int(col_number), problem)
+
+
+def _update_previous_errors(
+ previous_errors: List[Flake8Error], replacement_window: Tuple[int, int], replacement_n_lines: int
+) -> List[Flake8Error]:
+ """Update the line numbers of the previous errors to what they would be after the edit window.
+ This is a helper function for `_filter_previous_errors`.
+
+ All previous errors that are inside of the edit window should not be ignored,
+ so they are removed from the previous errors list.
+
+ Args:
+ previous_errors: list of errors with old line numbers
+ replacement_window: the window of the edit/lines that will be replaced
+ replacement_n_lines: the number of lines that will be used to replace the text
+
+ Returns:
+ list of errors with updated line numbers
+ """
+ updated = []
+ lines_added = replacement_n_lines - (replacement_window[1] - replacement_window[0] + 1)
+ for error in previous_errors:
+ if error.line_number < replacement_window[0]:
+ # no need to adjust the line number
+ updated.append(error)
+ continue
+ if replacement_window[0] <= error.line_number <= replacement_window[1]:
+ # The error is within the edit window, so let's not ignore it
+ # either way (we wouldn't know how to adjust the line number anyway)
+ continue
+ # We're out of the edit window, so we need to adjust the line number
+ updated.append(Flake8Error(error.filename, error.line_number + lines_added, error.col_number, error.problem))
+ return updated
+
+
+def format_flake8_output(
+ input_string: str,
+ show_line_numbers: bool = False,
+ *,
+ previous_errors_string: str = "",
+ replacement_window: Optional[Tuple[int, int]] = None,
+ replacement_n_lines: Optional[int] = None,
+) -> str:
+ """Filter flake8 output for previous errors and print it for a given file.
+
+ Args:
+ input_string: The flake8 output as a string
+ show_line_numbers: Whether to show line numbers in the output
+ previous_errors_string: The previous errors as a string
+ replacement_window: The window of the edit (lines that will be replaced)
+ replacement_n_lines: The number of lines used to replace the text
+
+ Returns:
+ The filtered flake8 output as a string
+ """
+ errors = [Flake8Error.from_line(line.strip()) for line in input_string.split("\n") if line.strip()]
+ lines = []
+ if previous_errors_string:
+ assert replacement_window is not None
+ assert replacement_n_lines is not None
+ previous_errors = [
+ Flake8Error.from_line(line.strip()) for line in previous_errors_string.split("\n") if line.strip()
+ ]
+ previous_errors = _update_previous_errors(previous_errors, replacement_window, replacement_n_lines)
+ errors = [error for error in errors if error not in previous_errors]
+ for error in errors:
+ if not show_line_numbers:
+ lines.append(f"- {error.problem}")
+ else:
+ lines.append(f"- {error.line_number}:{error.col_number} {error.problem}")
+ return "\n".join(lines)
+
+
+if __name__ == "__main__":
+ if len(sys.argv) == 2:
+ print(format_flake8_output(sys.argv[1]))
+ elif len(sys.argv) == 6:
+ window = (int(sys.argv[3]), int(sys.argv[4]))
+ n_lines = int(sys.argv[5])
+ print(
+ format_flake8_output(
+ sys.argv[1], previous_errors_string=sys.argv[2], replacement_window=window, replacement_n_lines=n_lines
+ )
+ )
+ else:
+ msg = "Invalid number of arguments. Must be 1 or 5."
+ raise ValueError(msg)
diff --git a/config/commands/edit_linting.sh b/tools/edit_linting/bin/edit
similarity index 69%
rename from config/commands/edit_linting.sh
rename to tools/edit_linting/bin/edit
index 0c190a88..6defeec3 100644
--- a/config/commands/edit_linting.sh
+++ b/tools/edit_linting/bin/edit
@@ -1,24 +1,11 @@
-# @yaml
-# signature: |-
-# edit <start_line>:<end_line>
-# <replacement_text>
-# end_of_edit
-# docstring: replaces lines <start_line> through <end_line> (inclusive) with the given text in the open file. The replacement text is terminated by a line with only end_of_edit on it. All of the <replacement text> will be entered, so make sure your indentation is formatted properly. Python files will be checked for syntax errors after the edit. If the system detects a syntax error, the edit will not be executed. Simply try to edit the file again, but make sure to read the error message and modify the edit command you issue accordingly. Issuing the same command a second time will just lead to the same error message again.
-# end_name: end_of_edit
-# arguments:
-# start_line:
-# type: integer
-# description: the line number to start the edit at
-# required: true
-# end_line:
-# type: integer
-# description: the line number to end the edit at (inclusive)
-# required: true
-# replacement_text:
-# type: string
-# description: the text to replace the current selection with
-# required: true
-edit() {
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ local CURRENT_FILE=$(_read_env CURRENT_FILE)
+ local CURRENT_LINE=$(_read_env CURRENT_LINE)
+ local WINDOW=$(_read_env WINDOW)
+ local OVERLAP=$(_read_env OVERLAP)
+
if [ -z "$CURRENT_FILE" ]
then
echo 'No file open. Use the `open` command first.'
@@ -81,7 +68,7 @@ edit() {
# if there is no output, then the file is good
if [ -z "$lint_output" ]; then
- export CURRENT_LINE=$start_line
+ _write_env CURRENT_LINE $start_line
_constrain_line
_print
@@ -98,8 +85,8 @@ edit() {
original_window=$WINDOW
# Update values
- export CURRENT_LINE=$(( (line_count / 2) + start_line )) # Set to "center" of edit
- export WINDOW=$((line_count + 10)) # Show +/- 5 lines around edit
+ _write_env CURRENT_LINE $(( (line_count / 2) + start_line )) # Set to "center" of edit
+ _write_env WINDOW $((line_count + 10)) # Show +/- 5 lines around edit
echo "This is how your edit would have looked if applied"
echo "-------------------------------------------------"
@@ -111,8 +98,8 @@ edit() {
# Restoring CURRENT_FILE to original contents.
cp "/root/$(basename "$CURRENT_FILE")_backup" "$CURRENT_FILE"
- export CURRENT_LINE=$(( ((end_line - start_line + 1) / 2) + start_line ))
- export WINDOW=$((end_line - start_line + 10))
+ _write_env CURRENT_LINE $(( ((end_line - start_line + 1) / 2) + start_line ))
+ _write_env WINDOW $((end_line - start_line + 10))
echo "This is the original code before your edit"
echo "-------------------------------------------------"
@@ -121,8 +108,8 @@ edit() {
echo "-------------------------------------------------"
# Restore original values
- export CURRENT_LINE=$original_current_line
- export WINDOW=$original_window
+ _write_env CURRENT_LINE $original_current_line
+ _write_env WINDOW $original_window
echo "Your changes have NOT been applied. Please fix your edit command and try again."
echo "You either need to 1) Specify the correct start/end line arguments or 2) Correct your edit code."
@@ -132,3 +119,5 @@ edit() {
# Remove backup file
rm -f "/root/$(basename "$CURRENT_FILE")_backup"
}
+
+main "$@"
diff --git a/tools/edit_linting/config.yaml b/tools/edit_linting/config.yaml
new file mode 100644
index 00000000..62ab2f16
--- /dev/null
+++ b/tools/edit_linting/config.yaml
@@ -0,0 +1,27 @@
+tools:
+ edit:
+ signature: |
+ edit <start_line>:<end_line>
+ <replacement_text>
+ end_of_edit
+ docstring: >
+ replaces lines <start_line> through <end_line> (inclusive) with the given text
+ in the open file. The replacement text is terminated by a line with only
+ end_of_edit on it. All of the <replacement text> will be entered, so make
+ sure your indentation is formatted properly. Python files will be checked
+ for syntax errors after the edit. If the system detects a syntax error,
+ the edit will not be executed.
+ end_name: "end_of_edit"
+ arguments:
+ - name: start_line
+ type: integer
+ description: "the line number to start the edit at"
+ required: true
+ - name: end_line
+ type: integer
+ description: "the line number to end the edit at (inclusive)"
+ required: true
+ - name: replacement_text
+ type: string
+ description: "the text to replace the current selection with"
+ required: true
diff --git a/tools/edit_linting/install.sh b/tools/edit_linting/install.sh
new file mode 100644
index 00000000..fd758a67
--- /dev/null
+++ b/tools/edit_linting/install.sh
@@ -0,0 +1,12 @@
+source /root/tools/defaults/lib/utils.sh
+
+if [ -z "$WINDOW" ]; then
+ echo "Error: WINDOW not set"
+ exit 1
+fi
+
+_write_env "CURRENT_FILE" "${CURRENT_FILE:-}"
+_write_env "CURRENT_LINE" "${CURRENT_LINE:-0}"
+_write_env "WINDOW" "$WINDOW"
+
+pip install flake8
diff --git a/config/commands/filemap.py b/tools/filemap/bin/filemap
similarity index 86%
rename from config/commands/filemap.py
rename to tools/filemap/bin/filemap
index 5b0960b1..878c8e17 100644
--- a/config/commands/filemap.py
+++ b/tools/filemap/bin/filemap
@@ -1,14 +1,5 @@
#!/root/miniconda3/bin/python
-# @yaml
-# signature: filemap <file_path>
-# docstring: Print the contents of a Python file, skipping lengthy function and method definitions.
-# arguments:
-# file_path:
-# type: file path
-# description: The path to the file to be read
-# required: true
-
import argparse
import warnings
diff --git a/tools/filemap/config.yaml b/tools/filemap/config.yaml
new file mode 100644
index 00000000..906a5670
--- /dev/null
+++ b/tools/filemap/config.yaml
@@ -0,0 +1,9 @@
+tools:
+ filemap:
+ signature: "filemap <file_path>"
+ docstring: "Print the contents of a Python file, skipping lengthy function and method definitions."
+ arguments:
+ - name: file_path
+ type: string
+ description: The path to the file to be read
+ required: true
diff --git a/tools/filemap/install.sh b/tools/filemap/install.sh
new file mode 100644
index 00000000..0be5d01e
--- /dev/null
+++ b/tools/filemap/install.sh
@@ -0,0 +1 @@
+pip install tree-sitter-languages
\ No newline at end of file
diff --git a/config/commands/forfeit.sh b/tools/forfeit/bin/exit_forfeit
similarity index 55%
rename from config/commands/forfeit.sh
rename to tools/forfeit/bin/exit_forfeit
index 21ea281d..da6c3ad3 100644
--- a/config/commands/forfeit.sh
+++ b/tools/forfeit/bin/exit_forfeit
@@ -1,9 +1,7 @@
-# @yaml
-# signature: exit_forfeit
-# docstring: Give up on the current challenge and terminate the session.
-# arguments:
-exit_forfeit() {
+main() {
echo "Forfeit 😥"
# Implementation note: This is actually caught directly in swe_env.py
# We only include this stub so that the command is shown to the agent.
-}
\ No newline at end of file
+}
+
+main "$@"
diff --git a/tools/forfeit/config.yaml b/tools/forfeit/config.yaml
new file mode 100644
index 00000000..aeb9ef09
--- /dev/null
+++ b/tools/forfeit/config.yaml
@@ -0,0 +1,5 @@
+tools:
+ exit_forfeit:
+ signature: "exit_forfeit"
+ docstring: "Give up on the current challenge and terminate the session."
+ arguments: []
diff --git a/tools/search/bin/find_file b/tools/search/bin/find_file
new file mode 100644
index 00000000..6de016f8
--- /dev/null
+++ b/tools/search/bin/find_file
@@ -0,0 +1,31 @@
+main() {
+ if [ $# -eq 1 ]; then
+ local file_name="$1"
+ local dir="./"
+ elif [ $# -eq 2 ]; then
+ local file_name="$1"
+ if [ -d "$2" ]; then
+ local dir="$2"
+ else
+ echo "Directory $2 not found"
+ return
+ fi
+ else
+ echo "Usage: find_file <file_name> [<dir>]"
+ return
+ fi
+
+ dir=$(realpath "$dir")
+ local matches=$(find "$dir" -type f -name "$file_name")
+ # if no matches, return
+ if [ -z "$matches" ]; then
+ echo "No matches found for \"$file_name\" in $dir"
+ return
+ fi
+ # Calculate total number of matches
+ local num_matches=$(echo "$matches" | wc -l | awk '{$1=$1; print $0}')
+ echo "Found $num_matches matches for \"$file_name\" in $dir:"
+ echo "$matches" | awk '{print $0}'
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/search/bin/search_dir b/tools/search/bin/search_dir
new file mode 100644
index 00000000..b5cd9c4a
--- /dev/null
+++ b/tools/search/bin/search_dir
@@ -0,0 +1,39 @@
+main() {
+ if [ $# -eq 1 ]; then
+ local search_term="$1"
+ local dir="./"
+ elif [ $# -eq 2 ]; then
+ local search_term="$1"
+ if [ -d "$2" ]; then
+ local dir="$2"
+ else
+ echo "Directory $2 not found"
+ return
+ fi
+ else
+ echo "Usage: search_dir <search_term> [<dir>]"
+ return
+ fi
+ dir=$(realpath "$dir")
+ local matches=$(find "$dir" -type f ! -path '*/.*' -exec grep -nIH -- "$search_term" {} + | cut -d: -f1 | sort | uniq -c)
+ # if no matches, return
+ if [ -z "$matches" ]; then
+ echo "No matches found for \"$search_term\" in $dir"
+ return
+ fi
+ # Calculate total number of matches
+ local num_matches=$(echo "$matches" | awk '{sum+=$1} END {print sum}')
+ # calculate total number of files matched
+ local num_files=$(echo "$matches" | wc -l | awk '{$1=$1; print $0}')
+ # if num_files is > 100, print an error
+ if [ $num_files -gt 100 ]; then
+ echo "More than $num_files files matched for \"$search_term\" in $dir. Please narrow your search."
+ return
+ fi
+
+ echo "Found $num_matches matches for \"$search_term\" in $dir:"
+ echo "$matches" | awk '{$2=$2; gsub(/^\.+\/+/, "./", $2); print $2 " ("$1" matches)"}'
+ echo "End of matches for \"$search_term\" in $dir"
+}
+
+main "$@"
diff --git a/tools/search/bin/search_file b/tools/search/bin/search_file
new file mode 100644
index 00000000..4c6828f2
--- /dev/null
+++ b/tools/search/bin/search_file
@@ -0,0 +1,55 @@
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ # Check if the first argument is provided
+ if [ -z "$1" ]; then
+ echo "Usage: search_file <search_term> [<file>]"
+ return
+ fi
+ # Check if the second argument is provided
+ if [ -n "$2" ]; then
+ # Check if the provided argument is a valid file
+ if [ -f "$2" ]; then
+ local file="$2" # Set file if valid
+ else
+ echo "Usage: search_file <search_term> [<file>]"
+ echo "Error: File name $2 not found. Please provide a valid file name."
+ return # Exit if the file is not valid
+ fi
+ else
+ # Check if a file is open
+ if [ -z "$CURRENT_FILE" ]; then
+ echo "No file open. Use the open command first."
+ return # Exit if no file is open
+ fi
+ local file="$CURRENT_FILE" # Set file to the current open file
+ fi
+ local search_term="$1"
+ file=$(realpath "$file")
+ # Use grep to directly get the desired formatted output
+ local matches=$(grep -nH -- "$search_term" "$file")
+ # Check if no matches were found
+ if [ -z "$matches" ]; then
+ echo "No matches found for \"$search_term\" in $file"
+ return
+ fi
+ # Calculate total number of matches
+ local num_matches=$(echo "$matches" | wc -l | awk '{$1=$1; print $0}')
+
+ # calculate total number of lines matched
+ local num_lines=$(echo "$matches" | cut -d: -f1 | sort | uniq | wc -l | awk '{$1=$1; print $0}')
+ # if num_lines is > 100, print an error
+ if [ $num_lines -gt 100 ]; then
+ echo "More than $num_lines lines matched for \"$search_term\" in $file. Please narrow your search."
+ return
+ fi
+
+ # Print the total number of matches and the matches themselves
+ echo "Found $num_matches matches for \"$search_term\" in $file:"
+ echo "$matches" | cut -d: -f1-2 | sort -u -t: -k2,2n | while IFS=: read -r filename line_number; do
+ echo "Line $line_number:$(sed -n "${line_number}p" "$file")"
+ done
+ echo "End of matches for \"$search_term\" in $file"
+}
+
+main "$@"
diff --git a/tools/search/config.yaml b/tools/search/config.yaml
new file mode 100644
index 00000000..53ef7f35
--- /dev/null
+++ b/tools/search/config.yaml
@@ -0,0 +1,37 @@
+tools:
+ find_file:
+ signature: "find_file <file_name> [<dir>]"
+ docstring: "finds all files with the given name in dir. If dir is not provided, searches in the current directory"
+ arguments:
+ - name: file_name
+ type: string
+ description: "the name of the file to search for"
+ required: true
+ - name: dir
+ type: string
+ description: "the directory to search in (if not provided, searches in the current directory)"
+ required: false
+ search_dir:
+ signature: "search_dir <search_term> [<dir>]"
+ docstring: "searches for search_term in all files in dir. If dir is not provided, searches in the current directory"
+ arguments:
+ - name: search_term
+ type: string
+ description: "the term to search for"
+ required: true
+ - name: dir
+ type: string
+ description: "the directory to search in (if not provided, searches in the current directory)"
+ required: false
+ search_file:
+ signature: "search_file <search_term> [<file>]"
+ docstring: "searches for search_term in file. If file is not provided, searches in the current open file"
+ arguments:
+ - name: search_term
+ type: string
+ description: "the term to search for"
+ required: true
+ - name: file
+ type: string
+ description: "the file to search in (if not provided, searches in the current open file)"
+ required: false
diff --git a/tools/search/install.sh b/tools/search/install.sh
new file mode 100644
index 00000000..0258bc8d
--- /dev/null
+++ b/tools/search/install.sh
@@ -0,0 +1,5 @@
+source "/root/tools/defaults/lib/utils.sh"
+
+_write_env SEARCH_RESULTS "()"
+_write_env SEARCH_FILES "()"
+_write_env SEARCH_INDEX 0
diff --git a/config/commands/_connect.py b/tools/server_connection/bin/_connect
old mode 100755
new mode 100644
similarity index 100%
rename from config/commands/_connect.py
rename to tools/server_connection/bin/_connect
diff --git a/tools/server_connection/bin/connect_exec b/tools/server_connection/bin/connect_exec
new file mode 100644
index 00000000..a092150f
--- /dev/null
+++ b/tools/server_connection/bin/connect_exec
@@ -0,0 +1,13 @@
+source /root/tools/server_connection/lib/utils.sh
+
+main() {
+ if [ -z "$1" ]
+ then
+ echo "Usage: connect_exec <command>"
+ return
+ fi
+ _connect_command "SESSION=connect"
+ _connect_command "$@"
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/server_connection/bin/connect_sendline b/tools/server_connection/bin/connect_sendline
new file mode 100644
index 00000000..7f7938fb
--- /dev/null
+++ b/tools/server_connection/bin/connect_sendline
@@ -0,0 +1,8 @@
+source /root/tools/server_connection/lib/utils.sh
+
+main() {
+ _connect_command "SESSION=connect"
+ _connect_command 'sendline '$@
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/server_connection/bin/connect_start b/tools/server_connection/bin/connect_start
new file mode 100644
index 00000000..ec4d7d06
--- /dev/null
+++ b/tools/server_connection/bin/connect_start
@@ -0,0 +1,15 @@
+source /root/tools/server_connection/lib/utils.sh
+
+main() {
+ if [ -z "$1" ] || [ -z "$2" ]
+ then
+ echo "Usage: connect_start <server_address> <port>"
+ return
+ fi
+ _connect_command "SESSION=connect"
+ _connect_command "START"
+ _connect_command "connect $1 $2"
+ _write_env INTERACTIVE_SESSION="connect $@"
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/server_connection/bin/connect_stop b/tools/server_connection/bin/connect_stop
new file mode 100644
index 00000000..9780ec96
--- /dev/null
+++ b/tools/server_connection/bin/connect_stop
@@ -0,0 +1,10 @@
+source /root/tools/server_connection/lib/utils.sh
+
+main() {
+ _connect_command "SESSION=connect"
+ _connect_command "quit"
+ _connect_command "STOP"
+ unset INTERACTIVE_SESSION
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/server_connection/config.yaml b/tools/server_connection/config.yaml
new file mode 100644
index 00000000..be888a3c
--- /dev/null
+++ b/tools/server_connection/config.yaml
@@ -0,0 +1,35 @@
+tools:
+ connect_start:
+ signature: "connect_start <server_address> <port>"
+ docstring: "Starts a new interactive connection to the server address and port."
+ arguments:
+ - name: server_address
+ type: string
+ description: "the server address to initiate connection to"
+ required: true
+ - name: port
+ type: integer
+ description: "desired port for connection"
+ required: true
+ connect_exec:
+ signature: "connect_exec <command>"
+ docstring: "Executes arbitrary connect command in connect session."
+ arguments:
+ - name: command
+ type: string
+ description: "command to execute (wrap in single quotes to avoid shell escaping and substitution)"
+ required: true
+ connect_stop:
+ signature: "connect_stop"
+ docstring: "Stops the current connect session."
+ arguments: []
+ connect_sendline:
+ signature: "connect_sendline [<line>]"
+ docstring: >
+ Sends a line with unicode/hexadecimal values to the connection.
+ Sending hexadecimal bytes should be done using \\x<hh> where hh stands for the specific byte you want to send.
+ arguments:
+ - name: line
+ type: string
+ description: "The line to send to the connection"
+ required: false
diff --git a/tools/server_connection/install.sh b/tools/server_connection/install.sh
new file mode 100644
index 00000000..d1aeb6e6
--- /dev/null
+++ b/tools/server_connection/install.sh
@@ -0,0 +1 @@
+pip install pwntools setproctitle
\ No newline at end of file
diff --git a/tools/state/bin/_state b/tools/state/bin/_state
new file mode 100644
index 00000000..414621d6
--- /dev/null
+++ b/tools/state/bin/_state
@@ -0,0 +1,12 @@
+source /root/tools/defaults/lib/utils.sh
+
+main() {
+ local CURRENT_FILE=$(_read_env CURRENT_FILE)
+ if [ -z "$CURRENT_FILE" ]; then
+ echo '{"open_file": "n/a", "working_dir": "'$PWD'"}';
+ else
+ echo '{"open_file": "'$(realpath "$CURRENT_FILE")'", "working_dir": "'$PWD'"}';
+ fi
+}
+
+main "$@"
\ No newline at end of file
diff --git a/tools/state/config.yaml b/tools/state/config.yaml
new file mode 100644
index 00000000..a2fa2036
--- /dev/null
+++ b/tools/state/config.yaml
@@ -0,0 +1 @@
+tools: {}
\ No newline at end of file
diff --git a/config/commands/submit.sh b/tools/submit/bin/submit
similarity index 75%
rename from config/commands/submit.sh
rename to tools/submit/bin/submit
index 6012dedc..667ef74d 100644
--- a/config/commands/submit.sh
+++ b/tools/submit/bin/submit
@@ -1,8 +1,4 @@
-
-# @yaml
-# signature: submit
-# docstring: submits your current code and terminates the session
-submit() {
+main() {
cd $ROOT
# Check if the patch file exists and is non-empty
@@ -17,3 +13,5 @@ submit() {
cat model.patch
echo "||SUBMISSION>>"
}
+
+main "$@"
diff --git a/tools/submit/config.yaml b/tools/submit/config.yaml
new file mode 100644
index 00000000..835fae2e
--- /dev/null
+++ b/tools/submit/config.yaml
@@ -0,0 +1,5 @@
+tools:
+ submit:
+ signature: "submit"
+ docstring: "submits the current file"
+ arguments: []
diff --git a/tools/submit_ctf/bin/submit b/tools/submit_ctf/bin/submit
new file mode 100644
index 00000000..14fb8491
--- /dev/null
+++ b/tools/submit_ctf/bin/submit
@@ -0,0 +1,12 @@
+main() {
+ if [ -z "$1" ]; then
+ echo "Usage: submit <flag>"
+ return
+ fi
+
+ echo -n "<<SUBMISSION||"
+ echo -n "$@"
+ echo "||SUBMISSION>>"
+}
+
+main "$@"
diff --git a/tools/submit_ctf/config.yaml b/tools/submit_ctf/config.yaml
new file mode 100644
index 00000000..d6f49d70
--- /dev/null
+++ b/tools/submit_ctf/config.yaml
@@ -0,0 +1,10 @@
+tools:
+ submit:
+ signature: "submit '<flag>'"
+ docstring: >
+ submits your current flag and terminates the session, you should be aware to properly escape the flag as this is a bash command and to put your flag under single quotes.
+ arguments:
+ - name: flag
+ type: string
+ description: the flag found
+ required: true