mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
**Problem.** A line of many `>` characters makes `marked` produce one nested blockquote token per `>`. The blockquote branch of `Markdown.renderToken` renders its children at `Math.max(1, width - 2)` columns, then wraps each child line again at that width and adds a `│ ` prefix. Once the nesting uses up the width (about 39 levels at 80 columns), the width stays clamped at 1. From then on, each child line (`│ x`, 3 columns wide) is wrapped into about 3 lines at every further level, so the output roughly triples per level. At 80 columns: - 50 levels: 4096 lines, about 30 s to render; - 55 levels: `push(...lines)` exceeds the JavaScript argument limit and throws `RangeError: Maximum call stack size exceeded`, which crashes pi. Reopening the session crashes it again. **Fix.** - When there is no room left for another border (`width < 3`), the blockquote branch now renders its child tokens at the same width without adding a border and without wrapping them again. - Child lines are appended with a loop instead of a spread `push`. Quotes that fit in the width render exactly as before. **Testing.** - Added a regression test in `packages/tui/test/markdown.test.ts`: 60 nested `>` rendered at width 80 give one line that keeps the content. Without the fix the test fails with the RangeError; with it, all 92 tests in that file pass (`node --test test/markdown.test.ts`). - `npm run check` passes. - Reproduction script rendering `">".repeat(n) + "x"` at width 80: - before: 50 levels gave 4096 lines in 29.5 s, and 55 or 60 levels threw a RangeError; - after: 40, 50, 60 and 200 levels each give 1 line in about 10 ms. **Not covered.** A run of about 2000 `>` still overflows the stack inside `marked`'s own lexer, before pi's renderer runs. That is a separate limit and is not changed here. Fixes #11272 Requested by @davidbrai Co-authored-by: triagent <triagent@localhost> |
||
|---|---|---|
| .. | ||
| agent | ||
| ai | ||
| chord | ||
| codemode | ||
| coding-agent | ||
| durable | ||
| env | ||
| evals | ||
| mcp | ||
| telemetry | ||
| tui | ||