You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
b.WriteString("Basic standard library packages available (don't use the `os`, `ioutil, `net`, `exec` package instead use methods provided below). Timeout enforced.\n")
168
168
b.WriteString("Every program **must** declare `package main`, define `func main()`, and print results (e.g., via `fmt.Println`) so the orchestrator receives the output.\n\n")
169
169
b.WriteString("Try to reduce the output of shell programs by e.g. only searching and outputting errors.\n\n")
170
-
b.WriteString("Don't use this tool calls for just outputing the summary text at the end.")
171
-
b.WriteString("Seven custom functions are automatically available in your code:\n\n")
170
+
b.WriteString("Output is limited to 4096 lines. When truncated, consider parsing specific parts with Go (e.g., only output lines around error messages).\n\n")
171
+
b.WriteString("Don't use this tool calls for just outputing the summary text at the end.\n\n")
172
+
b.WriteString("# Previous Execution State\n\n")
173
+
b.WriteString("Three global variables are automatically available that preserve output from the previous sandbox execution:\n")
174
+
b.WriteString("- `last_exit_code` (int): Exit code from the last sandbox run (0 on first run)\n")
175
+
b.WriteString("- `last_stdout` (string): Standard output from the last sandbox run (empty on first run)\n")
176
+
b.WriteString("- `last_stderr` (string): Standard error from the last sandbox run (empty on first run)\n\n")
177
+
b.WriteString("These variables are useful when output is truncated and you want to process specific parts in subsequent runs.\n")
178
+
b.WriteString("Example:\n")
179
+
b.WriteString("```go\n")
180
+
b.WriteString("package main\n\n")
181
+
b.WriteString("import (\n")
182
+
b.WriteString(" \"fmt\"\n")
183
+
b.WriteString(" \"strings\"\n")
184
+
b.WriteString(")\n\n")
185
+
b.WriteString("func main() {\n")
186
+
b.WriteString(" if last_exit_code != 0 {\n")
187
+
b.WriteString(" fmt.Printf(\"Previous run failed with exit code %d\\n\", last_exit_code)\n")
188
+
b.WriteString(" // Parse errors from last_stderr\n")
189
+
b.WriteString(" for _, line := range strings.Split(last_stderr, \"\\n\") {\n")
190
+
b.WriteString(" if strings.Contains(line, \"error\") {\n")
191
+
b.WriteString(" fmt.Println(line)\n")
192
+
b.WriteString(" }\n")
193
+
b.WriteString(" }\n")
194
+
b.WriteString(" } else if len(last_stdout) > 0 {\n")
// Count the last line if it doesn't end with newline
213
+
iflen(text) >0&&text[len(text)-1] !='\n' {
214
+
lineCount++
215
+
}
216
+
217
+
// If under the limit, return as-is
218
+
iflineCount<=maxLines {
219
+
returntext, ""
220
+
}
221
+
222
+
// Find the truncation point (end of maxLines-th line)
223
+
currentLine:=0
224
+
truncIndex:=len(text) // default to end of string
225
+
fori, char:=rangetext {
226
+
ifchar=='\n' {
227
+
currentLine++
228
+
ifcurrentLine>=maxLines {
229
+
truncIndex=i
230
+
break
231
+
}
232
+
}
233
+
}
234
+
235
+
// If we didn't find enough newlines, truncate at maxLines character count
236
+
ifcurrentLine<maxLines {
237
+
truncIndex=len(text)
238
+
}
239
+
240
+
truncated:=text[:truncIndex]
241
+
truncationMsg:=fmt.Sprintf("\n\n[Output truncated: showed %d of %d lines. The full output is preserved in last_stdout/last_stderr variables for the next sandbox execution. Consider parsing specific parts with Go to reduce output.]", maxLines, lineCount)
0 commit comments