Append finalized history. Accepts either a Block (preferred — keeps the source so resize can re-render at the new width) or a pre-rendered list[str] (legacy: wrapped as a 'plain' block, which can reflow only through _fit_rows — no un-rendering of width-baked structures). For
(self, content)
| 3631 | self._invalidate_ptk() |
| 3632 | |
| 3633 | def commit(self, content) -> None: |
| 3634 | """Append finalized history. Accepts either a Block (preferred — keeps |
| 3635 | the source so resize can re-render at the new width) or a pre-rendered |
| 3636 | list[str] (legacy: wrapped as a 'plain' block, which can reflow only |
| 3637 | through _fit_rows — no un-rendering of width-baked structures). For |
| 3638 | assistant blocks, _tool_base is anchored to the cumulative tool count |
| 3639 | of prior blocks so chip tids continue the global sequence and stay |
| 3640 | stable across resize repaints.""" |
| 3641 | w = _term()[0] |
| 3642 | if isinstance(content, Block): |
| 3643 | blk = content |
| 3644 | if blk.kind == 'assistant': |
| 3645 | self._tool_base = sum(b.tool_n for b in self._blocks) |
| 3646 | self._blocks.append(blk) |
| 3647 | self._cap_blocks() |
| 3648 | lines = self._render_block(blk, w) |
| 3649 | if blk.kind == 'assistant': |
| 3650 | self._tool_base += blk.tool_n # advance for next message |
| 3651 | else: |
| 3652 | blk = Block('plain', '\n'.join(content)) |
| 3653 | self._blocks.append(blk) |
| 3654 | self._cap_blocks() |
| 3655 | lines = list(content) |
| 3656 | self._emit_lines(lines, w) |
| 3657 | |
| 3658 | def _cap_blocks(self) -> None: |
| 3659 | if len(self._blocks) > 4000: |
no test coverage detected