URIError: URI malformed in cellMarker when rendering markdown tables with special characters
Description
prime-agent crashes with URIError: URI malformed when rendering a markdown table whose cell content contains lone surrogates or other characters that encodeURIComponent cannot handle.
Stack trace
```
URIError: URI malformed
at encodeURIComponent (
Root cause
In cellMarker:
```js function cellMarker(kind, row, column, segment2, content) { const encodedContent = content === void 0 ? "" : `:${encodeURIComponent(content)}`; // ... } ```
encodeURIComponent throws on strings with lone surrogates (e.g. U+D800–U+DFFF). Agent output can contain such characters (e.g. binary data snippets, malformed unicode from tool output, certain emoji sequences).
Suggested fix
Wrap in try/catch and sanitize lone surrogates:
```js function cellMarker(kind, row, column, segment2, content) { let encodedContent; if (content === void 0) { encodedContent = ""; } else { try { encodedContent = `:${encodeURIComponent(content)}`; } catch { encodedContent = `:${encodeURIComponent(String(content).replace(/[\uD800-\uDFFF]/g, "\uFFFD"))}`; } } return `${TABLE_MARKER_PREFIX}${kind}:${row}:${column}:${segment2}${encodedContent}\x07`; } ```
Reproduction
- Have an agent produce a markdown table with content containing lone surrogates or malformed unicode
- The TUI crashes immediately when trying to render it
Version
prime-agent 0.9.1, Node.js v24.11.1
Workaround
Patching the dist bundle directly with the suggested fix above.
Hi @vichaunter, thanks for your interest!
This project requires that issue reporters are vouched, and you are not in the list of vouched users.
This issue will be closed automatically. See https://github.com/PrimeIntellect-ai/prime-agent/blob/main/CONTRIBUTING.md for more details.