Skip to content

fix(printer, cli): Shade every prompt with the reasoning background - #1140

Open
JeanMertz wants to merge 4 commits into
term/ansi-movefrom
prompt/shading
Open

JeanMertz wants to merge 4 commits into
term/ansi-movefrom
prompt/shading

Conversation

@JeanMertz

Copy link
Copy Markdown
Collaborator

A tool call made from a reasoning block sits inside that block's shading,
and its prompts now do too. The approval prompt and the tool's questions
were already shaded; the inline reply widget, reached by e to edit
arguments or r to skip with a reason, was not, and cut an unshaded hole
in the middle of the block.

The printer knows which background prompts are drawn against, and applies
it to every prompt writer it hands out. Whoever owns the region names it
once and no prompt site has to remember: Printer::set_prompt_background
replaces the copy ToolPrompter was keeping, and the shaded-writer
plumbing that lived beside it in jp_cli is gone. The owned prompt
writer, which is the one the reply widget takes, is covered by the same
code as the borrowed one rather than needing its own.

Closes: T-0fg8cjs
Signed-off-by: Jean Mertz git@jeanmertz.com

Output produced while a prompt is up now waits for the answer instead of
landing in the middle of the question. A tool result arriving from a
parallel tool, a title generator finishing, an MCP server logging to
stderr: each used to print straight over the widget's frame, on a
terminal in raw mode where a line feed no longer returns to column zero.
The same holds while an external `$EDITOR` has the screen.

A handover is bracketed by the guard `suspend_status` and the prompt
writers already take, so the printer now knows exactly when the terminal
is not its own. For that window the worker keeps ordinary output in a
queue and writes it, in the order it was produced, once the terminal
comes back. Handovers nest, and only the outermost hand-back releases
anything: a permission prompt opening the inline reply widget on top of
itself never gives the screen away mid-question.

A print task says who it belongs to, and only a prompt session's own
writes reach a terminal someone else owns. Nothing is dropped: if a run
ends with a widget still holding the terminal, whatever it was holding
back is written on the way out, because that output is the answer the
user asked for and an untidy final frame is the smaller loss.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
`ansi` and `shade` move from `jp_md` to `jp_term`, along with the
region-background types they interpret, which land in a new
`jp_term::background`. Nothing about what they do is markdown: `segments`
tokenizes an escape stream, `AnsiState` tracks what a stream left active,
and `ShadedWriter` keeps a background showing across cursor rewrites and
split escapes. `jp_md` gains a `jp_term` dependency and imports them like
any other consumer.

The move puts them where the printer can reach them. `jp_printer` depends
on `jp_term` and deliberately not on `jp_md`, so shading a prompt meant
either pulling a markdown renderer into the output layer or writing the
state machine a second time.

`DefaultBackground`, `BackgroundFill`, and `line_fill` leave
`jp_md::format` for `jp_term::background`, so the types and the one place
that interprets them travel together. `AnsiState`'s methods widen from
`pub(crate)` to `pub` now that its callers are in another crate.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
A tool call made from a reasoning block sits inside that block's shading,
and its prompts now do too. The approval prompt and the tool's questions
were already shaded; the inline reply widget, reached by `e` to edit
arguments or `r` to skip with a reason, was not, and cut an unshaded hole
in the middle of the block.

The printer knows which background prompts are drawn against, and applies
it to every prompt writer it hands out. Whoever owns the region names it
once and no prompt site has to remember: `Printer::set_prompt_background`
replaces the copy `ToolPrompter` was keeping, and the shaded-writer
plumbing that lived beside it in `jp_cli` is gone. The owned prompt
writer, which is the one the reply widget takes, is covered by the same
code as the borrowed one rather than needing its own.

Closes: T-0fg8cjs
Signed-off-by: Jean Mertz <git@jeanmertz.com>
`T-0fg8cjs` records where the shading landed, why `ansi` and `shade` had
to move crates to get there, and the two things found on the way: the
swallowed flush that made prompt output staircase inside a reasoning
block, and a mock reply widget that wrote nothing to the stream it was
handed.

`T-0fk64t3` records what the move exposed. `jp_term` holds two
implementations of display width that arrived from different directions
and have never been compared, one of which knows about tabs and one of
which does not.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant