1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! The modal permission prompt (#3422).
//!
//! Why: a tool call suspended by an `ask` rule is invisible without it — the
//! backend simply stops, and the TUI looks hung until the request times out
//! and is denied. This widget is what turns that stall into a question, and
//! it is the only place the three answers are spelled for the user.
//! What: [`permission_prompt_lines`] turns one
//! [`PendingPermission`](crate::model::PendingPermission) into the rows
//! [`draw_permission_prompt`] renders above the input composer;
//! [`crate::layout::draw`] reserves the rows only while a prompt is open.
//! Nothing here decides anything — the key bindings it advertises are the
//! ones `crate::app::reduce` binds, and the decision itself belongs to the
//! backend (ADR-0063).
//!
//! # Spec References
//! - [`SPEC-TTUI-05~draft`](docs/specs/DOC-50-tcode-tui-claude-code-clone.md#SPEC-TTUI-05~draft) — Slice 9 deliverable (§5, Slice 9): permission prompts.
use Rect;
use ;
use ;
use Paragraph;
use crateReplApp;
use cratePendingPermission;
/// The answer keys, in the order the footer lists them. Kept beside the
/// widget so the advertised bindings and `reduce::permission_answer_for_key`
/// can be compared in one test rather than drifting silently.
const ANSWER_HINTS: & = &;
/// How many rows a prompt occupies: header, subject, rule, answers.
pub const PROMPT_HEIGHT: u16 = 4;
/// The rows [`crate::layout::draw`] must reserve for `app`'s prompt.
///
/// Why: the prompt's height is otherwise fixed by design (see
/// [`permission_prompt_lines`]), but a failed answer adds one retry row —
/// and a layout that reserved [`PROMPT_HEIGHT`] regardless would silently
/// clip exactly the line explaining why the prompt came back (#3422).
/// What: `0` with no prompt open, [`PROMPT_HEIGHT`] normally, one more when
/// [`ReplApp::permission_error`] is set.
/// Test: `tests::prompt_height_grows_by_one_row_for_a_retry_line`.
/// Render the open prompt into `area`.
///
/// Why: a plain `Paragraph` rather than a bordered overlay — the scrollback
/// and input row are borderless too, and a floating box would cost two rows
/// of an already tight layout to say nothing extra.
/// What: draws [`permission_prompt_lines`] for `app.pending_permission`, or
/// nothing at all when no prompt is open.
/// Test: `crate::layout::tests::draw_renders_without_panicking` exercises
/// the `Frame` path; the text itself is covered by the pure-function tests
/// below.
/// The prompt's rows: what is being asked, on what, under which rule, and
/// which key answers how.
///
/// Why: split from [`draw_permission_prompt`] so the wording is unit-testable
/// without a `Frame`, matching [`crate::widgets::tool_card::tool_card_lines`].
/// What: exactly [`PROMPT_HEIGHT`] rows, plus one leading retry row when
/// `error` is `Some` (#3422 — the answer that never reached the backend; see
/// [`crate::event::ReplEvent::PermissionAnswerFailed`]). The subject row
/// renders the producer's already-redacted text verbatim, folded onto one
/// line so a multi-path subject cannot push the input composer off screen;
/// an empty subject (a tool that acts on nothing nameable) still gets its
/// row, so the prompt's height never changes under the REQUEST — only under
/// a failure the operator must see.
/// Test: `tests::prompt_names_the_tool_subject_and_rule`,
/// `tests::prompt_with_an_empty_subject_keeps_its_height`,
/// `tests::prompt_folds_a_multi_line_subject_onto_one_row`,
/// `tests::prompt_shows_the_retry_line_after_a_failed_answer`.
/// Collapse `text` onto one row, joining its non-blank lines with `" · "`.
///
/// Why: a subject can legitimately be several file paths separated by
/// newlines; rendering them as rows would make the prompt's height depend on
/// the request and could push the input composer off a short terminal. It is
/// `pub(crate)` rather than private because the FLAT scrollback line must
/// fold identically — see [`crate::app::reduce`]'s
/// `apply_permission_requested` (#8237).
/// What: splits on `\n`, trims and drops blank lines, joins with `" · "`.
/// Every non-blank source line survives, in order — a raw `\n` inside one
/// ratatui `Span` renders as nothing, so the join separator is what keeps a
/// multi-statement `bash` command readable instead of glued.
/// Test: `tests::prompt_folds_a_multi_line_subject_onto_one_row`,
/// `crate::app::reduce::tests::permission_requested_folds_a_multi_line_subject_in_scrollback`.
pub