Skip to content

feat: interactive permission UI — diff view + arrow-key confirmation for tool calls in ask mode #40

@VforVitorio

Description

@VforVitorio

What problem does this solve?

When the agent is in ask mode and wants to execute a tool call (e.g. write_file, run_shell), the current confirmation flow is basic and doesn't let the user review the proposed changes before approving them.

Proposed solution

Replace the current implicit execution with a rich interactive confirmation UI that lets the user review changes before they are applied.

Diff view (for write_file / file modifications)

Show the proposed change as a unified diff in a styled Rich Panel before the confirmation prompt:

┌─ write_file  src/lmcode/agent/core.py ──────────────────────────────────────┐
│  - old line A                                                                │
│  + new line A (modified)                                                     │
│  + new line B (added)                                                        │
└──────────────────────────────────────────────────────────────────────────────┘

Lines removed in ERROR red, lines added in SUCCESS green — matching the DIFF_ADD/DIFF_REMOVE color aliases already in colors.py.

Confirmation widget

Below the diff, an arrow-key-navigable inline menu styled in ACCENT violet:

  Allow this change?

  ❯ Yes
    No
    Yes — and allow this tool automatically from now on

  ┌──────────────────────────────────────────────────────┐
  │ ...or tell lmcode what to do instead                 │
  └──────────────────────────────────────────────────────┘
  • ↑/↓ arrows navigate the three options.
  • Enter confirms the selected option.
  • Selecting the text box allows the user to type a redirect instruction (e.g. "use a different file name") which is fed back to the model as a new user turn.
  • "Yes — and allow automatically" sets the tool to auto-approve for the rest of the session (equivalent to switching that specific tool to auto mode).

For run_shell

Show the exact command in a styled code block instead of a diff.

Implementation notes:

  • Hook into the _wrap_tool_verbose path — intercept in ask mode before calling the real tool.
  • Use prompt_toolkit for the arrow-key menu (inline, no full-screen).
  • Diff generation: compare existing file content with proposed content using difflib.unified_diff.
  • The "allow automatically" option could set a per-tool flag in Agent (e.g. self._auto_tools: set[str]).

Acceptance criteria:

  • In ask mode, write_file and run_shell calls show the confirmation UI before executing.
  • The diff is syntax-highlighted with correct add/remove colors.
  • Arrow-key navigation works in the VSCode integrated terminal.
  • Auto-allow state persists for the session, resets on /clear.

Alternatives considered

None considered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions