formatCommandOutput formats command output handling timeout, cancellation, and errors.
(timeoutCtx, ctx context.Context, err error, rawOutput string, timeout time.Duration)
| 563 | |
| 564 | // formatCommandOutput formats command output handling timeout, cancellation, and errors. |
| 565 | func formatCommandOutput(timeoutCtx, ctx context.Context, err error, rawOutput string, timeout time.Duration) string { |
| 566 | var output string |
| 567 | if timeoutCtx.Err() != nil { |
| 568 | if ctx.Err() != nil { |
| 569 | output = "Command cancelled" |
| 570 | } else { |
| 571 | output = fmt.Sprintf("Command timed out after %v\nOutput: %s", timeout, rawOutput) |
| 572 | } |
| 573 | } else { |
| 574 | output = rawOutput |
| 575 | if err != nil { |
| 576 | output = fmt.Sprintf("Error executing command: %s\nOutput: %s", err, output) |
| 577 | } |
| 578 | } |
| 579 | return cmp.Or(strings.TrimSpace(output), "<no output>") |
| 580 | } |
| 581 | |
| 582 | func (t *ToolSet) Instructions() string { |
| 583 | return `## Shell Tools |