@@ -84,8 +84,8 @@ class AnalysisToolMetadata(TypedDict, total=False):
84
84
class AnnotateResult (TypedDict , total = False ):
85
85
point : str
86
86
commentText : str | None
87
- annotatedRepo : str
88
- annotatedLocations : list [AnnotatedLocation ]
87
+ annotatedRepo : str | None
88
+ annotatedLocations : list [AnnotatedLocation ] | None
89
89
pointLocation : str | None
90
90
metadata : AnalysisToolMetadata | None
91
91
@@ -97,6 +97,23 @@ def safe_parse_json(text: str) -> dict[str, Any] | None:
97
97
return None
98
98
99
99
100
+ def split_metadata (result ):
101
+ if 'metadata' not in result :
102
+ return {}, result
103
+ metadata = result ['metadata' ]
104
+ data = dict (result )
105
+ del data ['metadata' ]
106
+ return metadata , data
107
+
108
+
109
+ def enhance_prompt (user_message : MessageAction , prefix : str , suffix : str | None = None ):
110
+ if prefix != '' :
111
+ user_message .content = f'{ prefix } \n \n { user_message .content } '
112
+ if suffix is not None :
113
+ user_message .content = f'{ user_message .content } \n \n { suffix } '
114
+ logger .info (f'[REPLAY] Enhanced user prompt:\n { user_message .content } ' )
115
+
116
+
100
117
def handle_replay_observation (
101
118
state : State , observation : ReplayCmdOutputObservation
102
119
) -> AnalysisToolMetadata | None :
@@ -121,11 +138,17 @@ def handle_replay_observation(
121
138
result : AnnotateResult = cast (
122
139
AnnotateResult , safe_parse_json (observation .content )
123
140
)
124
- if result and result .get ('metadata' ):
125
- metadata = result .get ('metadata' )
141
+
142
+ if result and 'metadata' in result :
143
+ metadata , data = split_metadata (result )
144
+ intro = 'This bug had a timetravel debugger recording which has been analyzed. Use the analysis results and the timetravel debugger `inspect-*` tools to find the bug. Once found `submit-hypothesis`, so your results can be used to implement the solution.\n '
145
+ enhance_prompt (
146
+ user_message ,
147
+ intro ,
148
+ f'## Initial Analysis\n { json .dumps (data , indent = 2 )} ' ,
149
+ )
126
150
return metadata
127
151
elif result and result .get ('annotatedRepo' ):
128
- original_prompt = user_message .content
129
152
annotated_repo_path = result .get ('annotatedRepo' , '' )
130
153
comment_text = result .get ('commentText' , '' )
131
154
react_component_name = result .get ('reactComponentName' , '' )
@@ -136,30 +159,25 @@ def handle_replay_observation(
136
159
# TODO: Move this to a prompt template file.
137
160
if comment_text :
138
161
if react_component_name :
139
- enhancement = f'There is a change needed to the { react_component_name } component.\n '
162
+ intro = f'There is a change needed to the { react_component_name } component.\n '
140
163
else :
141
- enhancement = (
142
- f'There is a change needed in { annotated_repo_path } :\n '
143
- )
144
- enhancement += f'{ comment_text } \n \n '
164
+ intro = f'There is a change needed in { annotated_repo_path } :\n '
165
+ intro += f'{ comment_text } \n \n '
145
166
elif console_error :
146
- enhancement = f'There is a change needed in { annotated_repo_path } to fix a console error that has appeared unexpectedly:\n '
147
- enhancement += f'{ console_error } \n \n '
148
-
149
- enhancement += '<IMPORTANT>\n '
150
- enhancement += 'Information about a reproduction of the problem is available in source comments.\n '
151
- enhancement += 'You must search for these comments and use them to get a better understanding of the problem.\n '
152
- enhancement += f'The first reproduction comment to search for is named { start_name } . Start your investigation there.\n '
153
- enhancement += '</IMPORTANT>\n '
154
-
155
- # Enhance:
156
- user_message .content = f'{ enhancement } \n \n { original_prompt } '
157
- # user_message.content = enhancement
158
- logger .info (f'[REPLAY] Enhanced user prompt:\n { user_message .content } ' )
167
+ intro = f'There is a change needed in { annotated_repo_path } to fix a console error that has appeared unexpectedly:\n '
168
+ intro += f'{ console_error } \n \n '
169
+
170
+ intro += '<IMPORTANT>\n '
171
+ intro += 'Information about a reproduction of the problem is available in source comments.\n '
172
+ intro += 'You must search for these comments and use them to get a better understanding of the problem.\n '
173
+ intro += f'The first reproduction comment to search for is named { start_name } . Start your investigation there.\n '
174
+ intro += '</IMPORTANT>\n '
175
+
176
+ enhance_prompt (user_message , intro )
159
177
return None
160
178
else :
161
179
logger .warning (
162
- f'DDBG Replay command did not return an interpretable result . Observed: { str (observation .content )} '
180
+ f'[REPLAY] Replay observation cannot be interpreted . Observed content : { str (observation .content )} '
163
181
)
164
182
165
183
return None
0 commit comments