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]

Web: Add step index and scroll to it

Kilian Lieret10f1127e1c1a
diff --git a/sweagent/web/server.py b/sweagent/web/server.py
index 9c4e3735..3868aa56 100644
--- a/sweagent/web/server.py
+++ b/sweagent/web/server.py
@@ -84,7 +84,7 @@ class AgentUpdateHook(AgentHook):
def on_sub_action_started(self, *, sub_action: dict):
msg = f"```bash\n{sub_action['action']}\n```"
self._sub_action = sub_action["action"].strip()
- self._wu.up_env(message=msg, title=f"Action (step {self._thought_idx})", thought_idx=self._thought_idx)
+ self._wu.up_env(message=msg, title=f"Action", thought_idx=self._thought_idx)
def on_sub_action_executed(self, *, obs: str, done: bool):
language = ""
diff --git a/sweagent/web/static/scripts/mainscript.js b/sweagent/web/static/scripts/mainscript.js
index d95fe268..9a3dab2d 100644
--- a/sweagent/web/static/scripts/mainscript.js
+++ b/sweagent/web/static/scripts/mainscript.js
@@ -1,11 +1,17 @@
-function addMessageToFeed(feedID, title, text, format) {
+function addMessageToFeed(feedID, title, text, format, step) {
console.log("in addMessageToFeed");
+ let classes = "message"
+ if (step !== null) {
+ classes += " step" + step;
+ title += " (step " + step + ")";
+
+ }
const $feed = $(feedID);
- const $messageBlock = $('<div>', { class: 'message' });
+ const $messageBlock = $('<div>', { class: classes});
if (title) {
- $('<h4>', { text: title }).appendTo($messageBlock);
+ $('<h4>', { text: title}).appendTo($messageBlock);
}
let $messageText;
@@ -22,11 +28,37 @@ function addMessageToFeed(feedID, title, text, format) {
$feed.scrollTop($feed.prop("scrollHeight")); // jQuery method to scroll to the bottom
}
+function highlightStep(step) {
+ // Highlight all actions, thoughts, etc. of one specific step
+ $('.message').removeClass('highlight');
+ $(`.message.step${step}`).addClass('highlight');
+}
+
+function removeAllMessagesFromFeed(feedID) {
+ const $feed = $(feedID);
+ $feed.find('.message').remove();
+}
+
document.addEventListener('DOMContentLoaded', function() {
const socket = io();
socket.on('update', function(data) {
feed = '#' + data["feed"] + "Feed";
- addMessageToFeed(feed, data["title"], data["message"], data["format"]);
+ addMessageToFeed(feed, data["title"], data["message"], data["format"], data["thought_idx"]);
});
-});
\ No newline at end of file
+});
+
+
+function findFirstMessageForStep(feedName, step) {
+ // Find the first element with class 'message' and 'stepX' within the specified feed
+ const selector = `#${feedName} .message.step${step}`;
+ return $(selector).first();
+}
+
+
+function scrollToFirstMessageForStep(feedName, step) {
+ const $message = findFirstMessageForStep(feedName, step);
+ const $container = $(`#${feedName}`);
+ const scrollTo = $message.offset().top - $container.offset().top + $container.scrollTop();
+ $container.animate({ scrollTop: scrollTo }, 'slow');
+}
\ No newline at end of file
diff --git a/sweagent/web/static/styles/mainpage.css b/sweagent/web/static/styles/mainpage.css
index be2ac3b7..d623683b 100644
--- a/sweagent/web/static/styles/mainpage.css
+++ b/sweagent/web/static/styles/mainpage.css
@@ -21,4 +21,8 @@
border: 1px solid #ccc;
padding: 10px;
border-radius: 5px;
+}
+
+.highlight {
+ background-color: #eac2c2;
}
\ No newline at end of file
diff --git a/sweagent/web/templates/index.html b/sweagent/web/templates/index.html
index 282a4283..732e6196 100644
--- a/sweagent/web/templates/index.html
+++ b/sweagent/web/templates/index.html
@@ -11,6 +11,8 @@
$(document).ready(function() {
$('#dataForm').on('submit', function(event) {
event.preventDefault();
+ removeAllMessagesFromFeed("#agentFeed");
+ removeAllMessagesFromFeed("#envFeed");
const dataPath = $('#data_path').val();
const testRun = $('#test_run').is(':checked');
$.get(`/run`, { data_path: dataPath, test_run: testRun }, function(response) {
@@ -19,6 +21,25 @@
console.error('Error:', error);
});
});
+
+ // Hovering over a message in the feed highlights the corresponding step
+ // and scrolls to the right place
+ $(document).on('mouseenter', '[class*=step]', function() {
+ // Extract the step number from the class name
+ const stepNumber = $(this).attr('class').match(/step(\d+)/)[1];
+ if (stepNumber) {
+ highlightStep(stepNumber);
+
+ if ($(this).closest('.envFeed').length > 0) {
+ console.log("In agent feed");
+ scrollToFirstMessageForStep("agentFeed", stepNumber);
+ }
+ else {
+ console.log("In env feed");
+ scrollToFirstMessageForStep("envFeed", stepNumber);
+ }
+ }
+ });
});
</script>
</head>
@@ -35,10 +56,10 @@
<div id="update"></div>
<h2>Trajectory</h2>
<div id="container">
- <div id="agentFeed">
+ <div id="agentFeed" class="agentFeed">
<h3>Agent Feed</h3>
</div>
- <div id="envFeed">
+ <div id="envFeed" class="envFeed">
<h3>Environment Feed</h3>
</div>
</div>