catching and explaining tracebacks
This commit is contained in:
parent
87beaf99ea
commit
5162e4e2fd
9 changed files with 36 additions and 83 deletions
|
|
@ -14,6 +14,7 @@ from ..libs.util.telemetry import capture_event
|
|||
from .sdk import ContinueSDK
|
||||
import asyncio
|
||||
from ..libs.util.step_name_to_steps import get_step_from_name
|
||||
from ..libs.util.traceback_parsers import get_python_traceback, get_javascript_traceback
|
||||
|
||||
|
||||
class Autopilot(ContinueBaseModel):
|
||||
|
|
@ -92,12 +93,14 @@ class Autopilot(ContinueBaseModel):
|
|||
# Note that this is being overriden to do nothing in DemoAgent
|
||||
|
||||
async def handle_command_output(self, output: str):
|
||||
is_traceback = False
|
||||
if is_traceback:
|
||||
for tb_step in self.continue_sdk.config.on_traceback:
|
||||
step = get_step_from_name(tb_step.step_name)(
|
||||
output=output, **tb_step.params)
|
||||
await self._run_singular_step(step)
|
||||
get_traceback_funcs = [get_python_traceback, get_javascript_traceback]
|
||||
for get_tb_func in get_traceback_funcs:
|
||||
traceback = get_tb_func(output)
|
||||
if traceback is not None:
|
||||
for tb_step in self.continue_sdk.config.on_traceback:
|
||||
step = get_step_from_name(
|
||||
tb_step.step_name, {"output": output, **tb_step.params})
|
||||
await self._run_singular_step(step)
|
||||
|
||||
_step_depth: int = 0
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from ..recipes.DeployPipelineAirflowRecipe.main import DeployPipelineAirflowReci
|
|||
from ..recipes.AddTransformRecipe.main import AddTransformRecipe
|
||||
from .main import Step, Validator, History, Policy
|
||||
from .observation import Observation, TracebackObservation, UserInputObservation
|
||||
from ..steps.main import EditHighlightedCodeStep, SolveTracebackStep, RunCodeStep, FasterEditHighlightedCodeStep, StarCoderEditHighlightedCodeStep, EmptyStep, SetupContinueWorkspaceStep
|
||||
from ..steps.main import EditHighlightedCodeStep, SolveTracebackStep
|
||||
from ..recipes.WritePytestsRecipe.main import WritePytestsRecipe
|
||||
from ..recipes.ContinueRecipeRecipe.main import ContinueStepStep
|
||||
from ..steps.comment_code import CommentCodeStep
|
||||
|
|
|
|||
|
|
@ -1,24 +1,15 @@
|
|||
from typing import Union
|
||||
from ...models.main import Traceback
|
||||
from boltons import tbutils
|
||||
|
||||
|
||||
def sort_func(items):
|
||||
"""Sort a list of items."""
|
||||
return sorted(items)
|
||||
|
||||
|
||||
def parse_python_traceback(stdout: str) -> Union[Traceback, None]:
|
||||
"""Parse a python traceback from stdout."""
|
||||
|
||||
# Sometimes paths are not quoted, but they need to be
|
||||
if "File \"" not in stdout:
|
||||
stdout = stdout.replace("File ", "File \"").replace(
|
||||
", line ", "\", line ")
|
||||
|
||||
try:
|
||||
tbutil_parsed_exc = tbutils.ParsedException.from_string(stdout)
|
||||
return Traceback.from_tbutil_parsed_exc(tbutil_parsed_exc)
|
||||
|
||||
except Exception:
|
||||
def get_python_traceback(output: str) -> str:
|
||||
if "Traceback (most recent call last):" in output or "SyntaxError" in output:
|
||||
return output
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def get_javascript_traceback(output: str) -> str:
|
||||
lines = output.splitlines()
|
||||
if len(lines) > 0:
|
||||
first_line = lines[0].split(": ")
|
||||
if len(lines) > 1 and len(first_line) > 0 and len(first_line[0]) > 0 and "at" in lines[1].lstrip():
|
||||
return output
|
||||
else:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -35,10 +35,6 @@ class AbstractIdeProtocolServer(ABC):
|
|||
def onAcceptRejectSuggestion(self, suggestionId: str, accepted: bool):
|
||||
"""Called when the user accepts or rejects a suggestion"""
|
||||
|
||||
@abstractmethod
|
||||
def onTraceback(self, traceback: Traceback):
|
||||
"""Called when a traceback is received"""
|
||||
|
||||
@abstractmethod
|
||||
def onFileSystemUpdate(self, update: FileSystemEdit):
|
||||
"""Called when a file system update is received"""
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class SimpleChatStep(Step):
|
|||
name: str = "Chat"
|
||||
|
||||
async def run(self, sdk: ContinueSDK):
|
||||
self.description = f"## {self.user_input}\n\n"
|
||||
self.description = f"```{self.user_input}```\n\n"
|
||||
async for chunk in sdk.models.default.stream_chat(self.user_input, with_history=await sdk.get_chat_context()):
|
||||
self.description += chunk
|
||||
await sdk.update_ui()
|
||||
|
|
|
|||
|
|
@ -332,19 +332,3 @@ class WaitForUserConfirmationStep(Step):
|
|||
self.description = self.prompt
|
||||
resp = await sdk.wait_for_user_input()
|
||||
return TextObservation(text=resp)
|
||||
|
||||
|
||||
def get_python_traceback(output: str) -> str:
|
||||
if "Traceback" in output:
|
||||
return output
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_javascript_traceback(output: str) -> str:
|
||||
lines = output.splitlines("\n")
|
||||
if len(lines) > 0:
|
||||
first_line = lines[0].split(": ")
|
||||
if len(lines) > 1 and len(first_line) > 0 and len(first_line[0]) > 0 and "at" in lines[1].lstrip():
|
||||
return output
|
||||
else:
|
||||
return None
|
||||
|
|
@ -3,7 +3,6 @@ from typing import Coroutine, List, Union
|
|||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..libs.util.traceback_parsers import parse_python_traceback
|
||||
from ..libs.llm import LLM
|
||||
from ..models.main import Traceback, Range
|
||||
from ..models.filesystem_edit import EditDiff, FileEdit
|
||||
|
|
@ -33,28 +32,6 @@ class SetupContinueWorkspaceStep(Step):
|
|||
}"""))
|
||||
|
||||
|
||||
class RunCodeStep(Step):
|
||||
cmd: str
|
||||
|
||||
async def describe(self, models: Models) -> Coroutine[str, None, None]:
|
||||
return f"Ran command: `{self.cmd}`"
|
||||
|
||||
async def run(self, sdk: ContinueSDK) -> Coroutine[Observation, None, None]:
|
||||
result = subprocess.run(
|
||||
self.cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout = result.stdout.decode("utf-8")
|
||||
stderr = result.stderr.decode("utf-8")
|
||||
print(stdout, stderr)
|
||||
|
||||
# If it fails, return the error
|
||||
tb = parse_python_traceback(stdout) or parse_python_traceback(stderr)
|
||||
if tb:
|
||||
return TracebackObservation(traceback=tb)
|
||||
else:
|
||||
self.hide = True
|
||||
return None
|
||||
|
||||
|
||||
class Policy(BaseModel):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ class DefaultOnTracebackStep(Step):
|
|||
hide: bool = True
|
||||
|
||||
async def run(self, sdk: ContinueSDK):
|
||||
sdk.run_step(SimpleChatStep(
|
||||
await sdk.run_step(SimpleChatStep(
|
||||
name="Help With Traceback",
|
||||
user_input=f"""I got the following error, can you please help explain how to fix it?\n\n{self.output}"""))
|
||||
|
|
|
|||
|
|
@ -70,12 +70,13 @@ export class CapturedTerminal {
|
|||
private hasRunCommand: boolean = false;
|
||||
|
||||
private dataEndsInPrompt(strippedData: string): boolean {
|
||||
const lines = this.dataBuffer.split("\n");
|
||||
const lines = strippedData.split("\n");
|
||||
const last_line = lines[lines.length - 1];
|
||||
return (
|
||||
lines.length > 0 &&
|
||||
(lines[lines.length - 1].includes("bash-") ||
|
||||
lines[lines.length - 1].includes(") $ ")) &&
|
||||
lines[lines.length - 1].includes("$")
|
||||
(lines.length > 0 &&
|
||||
(last_line.includes("bash-") || last_line.includes(") $ ")) &&
|
||||
last_line.includes("$")) ||
|
||||
(last_line.includes("]> ") && last_line.includes(") ["))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -127,12 +128,12 @@ export class CapturedTerminal {
|
|||
// Split the output by commands so it can be sent to Continue Server
|
||||
|
||||
const strippedData = stripAnsi(data);
|
||||
this.splitByCommandsBuffer += strippedData;
|
||||
this.splitByCommandsBuffer += data;
|
||||
if (this.dataEndsInPrompt(strippedData)) {
|
||||
if (this.onCommandOutput) {
|
||||
this.onCommandOutput(this.splitByCommandsBuffer);
|
||||
this.onCommandOutput(stripAnsi(this.splitByCommandsBuffer));
|
||||
}
|
||||
this.dataBuffer = "";
|
||||
this.splitByCommandsBuffer = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -166,6 +167,7 @@ export class CapturedTerminal {
|
|||
// Pass data through to terminal
|
||||
this.writeEmitter.fire(data);
|
||||
|
||||
this.splitByCommandsListener(data);
|
||||
for (let listener of this.onDataListeners) {
|
||||
listener(data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue