| 638 | } |
| 639 | |
| 640 | function scrollBashProgress(p: ToolProps<typeof BashTool>): string { |
| 641 | const out = stripAnsi(p.frame.raw) |
| 642 | const cmd = (p.input.command ?? "").trim() |
| 643 | const fmt = (text: string) => { |
| 644 | const body = text.replace(/^\n+/, "").replace(/\n+$/, "") |
| 645 | return body ? `\n${body}` : "" |
| 646 | } |
| 647 | |
| 648 | if (!cmd) { |
| 649 | return out.replace(/\n+$/, "") |
| 650 | } |
| 651 | |
| 652 | const wdRaw = (p.input.workdir ?? "").trim() |
| 653 | const wd = wdRaw ? toolPath(wdRaw) : "" |
| 654 | const lines = out.split("\n") |
| 655 | const first = (lines[0] || "").trim() |
| 656 | const second = (lines[1] || "").trim() |
| 657 | |
| 658 | if (wd && (first === wd || first === wdRaw) && second === cmd) { |
| 659 | return fmt(lines.slice(2).join("\n")) |
| 660 | } |
| 661 | |
| 662 | if (first === cmd || first === `$ ${cmd}`) { |
| 663 | return fmt(lines.slice(1).join("\n")) |
| 664 | } |
| 665 | |
| 666 | if (wd && (first === `${wd} ${cmd}` || first === `${wdRaw} ${cmd}`)) { |
| 667 | return fmt(lines.slice(1).join("\n")) |
| 668 | } |
| 669 | |
| 670 | return fmt(out) |
| 671 | } |
| 672 | |
| 673 | function scrollBashFinal(p: ToolProps<typeof BashTool>): string { |
| 674 | const code = p.metadata.exit ?? num(p.frame.meta.exitCode) ?? num(p.frame.meta.exit_code) |