Skip to content

refactor(tui): approvals as source-agnostic UI state carrying the risk tier - #554

Merged
ajianaz merged 1 commit into
developfrom
refactor/tui-approval-state
Nov 10, 2026
Merged

ajianaz merged 1 commit into
developfrom
refactor/tui-approval-state

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What

Third part of #526 (UI epic #523): a pending approval is modelled as source-agnostic UI state. ApprovalRequest (what the UI shows and decides on, with the Risk tier) and a Pending whose reply is a one-shot closure replace the Sender-based Pending { text, destructive, reply }. Refs #526.

Why

Today the only approval source is the in-process turn thread: Pending held a Sender<Verdict>, and "fail closed" was an accident of dropping that sender. A remote UI (the server's /approvals queue, #200) needs the same UI state with a different way to answer, and the rule that a Destructive call is never offered "allow always" must not be re-implemented in each UI. This is item 4 of the #526 plan.

Changes

  • ApprovalRequest { text, risk }: new reduces the text to one safe line (control characters escaped, as Prompter::ask did), risk() is the real tole_core::tool::Risk, and can_allow_always() is false only for Destructive (the approver never allowlists it): the rule lives in one place for every UI.
  • Pending { request, reply }: the reply is a FnOnce(Verdict) + Send. The verdict is delivered exactly once, and Drop delivers Deny if it was never answered, so "dropped unanswered denies" is now structural (a cancelled turn, a newer request replacing an unanswered one, the UI going away with requests still queued) instead of relying on a dropped channel sender.
  • Prompter::ask(request) blocks for an in-process turn as before. New Prompter::post(request, reply) does not block: a remote source calls it and reply is where the verdict goes (for example the decision POST); it returns false and has already denied if the UI is gone.
  • tole-cli TuiPrompt builds an ApprovalRequest from the tool request (same text, same risk). The transcript still tags ? destructive: / ? write:.
  • CHANGELOG (Changed; breaking for code outside this repo that uses the removed API: Prompter::ask(text, destructive) is now ask(ApprovalRequest) and Pending's fields are private; new public items ApprovalRequest and Prompter::post), docs/tui.md (Architecture: approvals) and docs/epics.md updated in the same PR (AGENTS.md §7); README unaffected.

No behavior change for users: same keys (y / n / Esc), same texts, same fail-closed outcome.

Testing

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo check -p tole-cli --no-default-features, cargo test --workspace (1209 passed: the previous 1203 plus 6)
  • Local cora review --staged: not run (cora is not installed in this environment); the CI Cora Review job is the verdict.
  • One existing assertion adapted, deliberately: a cancelled approval used to leave the test's reply channel with no value (the sender-drop signal); it now receives an explicit Deny, exactly once. Prompter::ask returns Deny either way. Everything else in the 63 prior tole-tui tests and the tui_e2e pty suite passes unchanged.
  • 6 new tests: the request is one safe line carrying its risk; allow-always is offered for ReadOnly/Write and never for Destructive; a remote-style source (post with a closure, never blocking) gets the user's verdict exactly once for y and n and nothing before the answer, with later keys changing nothing; Esc denies and cancels for a remote source too; a destructive request is shown as destructive; and an approval that never gets an answer is denied once whatever ended it (the turn ends, a newer request replaces it, the UI goes away with requests queued, posting to a UI that is already gone).
  • Mutations, each caught: dropping a Pending no longer denies, allow-always offered for Destructive, and post reporting success with the UI gone.

Next in #526

The issue's item 2: move draw and its helpers into a rendering module that only reads App state (a mechanical move; no state changes there). With it the acceptance criteria are covered; I will post the status on the issue.

Related Issues

Refs #526, part of #523. Related: #464, #463, #200.


Generated by Claude Code

…k tier (#526)

ApprovalRequest (sanitized line plus Risk, can_allow_always false for Destructive) and a Pending with a one-shot reply closure replace the Sender-based Pending. Prompter::ask blocks as before; Prompter::post lets a remote source feed the same UI. The verdict is delivered once and a Pending dropped unanswered denies through its Drop.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 0762541 into develop Nov 10, 2026
15 of 16 checks passed
@ajianaz
ajianaz deleted the refactor/tui-approval-state branch November 11, 2026 04:10
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.

2 participants