Skip to content

feat(hitl): wire up human-in-the-loop approval for system terminal co… - #27

Merged
Nithwin merged 1 commit into
mainfrom
feat/hitl-command
Jul 26, 2026
Merged

feat(hitl): wire up human-in-the-loop approval for system terminal co…#27
Nithwin merged 1 commit into
mainfrom
feat/hitl-command

Conversation

@Nithwin

@Nithwin Nithwin commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Description

This PR implements a critical safety feature: Human-in-the-Loop (HITL) Approval for system terminal commands. Previously, the agent could autonomously execute bash commands via the CommandTool in the background, which posed a security risk.

This update intercepts any run_command tool call, pauses the agent's background goroutine using Go channels, and triggers an interactive confirmation modal in the UI.

Key Changes

  • system/command.go: Upgraded CommandTool to accept an ApprovalCallback func(cmd string) bool. If the user rejects, the tool returns a graceful rejection error to the AI so it can pivot its strategy.
  • defaults/defaults.go: Updated RegisterAll to pass the approval callback to the system tools.
  • chat/messages.go: Introduced ApprovalRequestMsg to bridge the background agent process with the main Bubble Tea event loop.
  • chat/update.go & chat/model.go: Wired up a concurrency-safe channel m.approvalChan. It blocks standard inputs while waiting for the user to press y or n.
  • chat/view.go: Replaces the standard chat input box with a yellow-bordered warning modal displaying the exact bash command waiting for approval.
  • cmd/chat.go: Added headless fallback using fmt.Scanln for standard (y/N) terminal prompts outside the TUI.

Why this is necessary

Provides the "Aider/Claude Code" pair-programming experience. It ensures complete developer control over destructive shell commands (like rm, git push, or npm install) and prevents the LLM from getting stuck in an infinite command-execution loop.

How to Test

  1. Run go run ./cmd/windmist
  2. Ask the agent: "Create a folder called 'test-folder' using terminal commands"
  3. Verify that the UI blocks execution and displays a yellow warning box.
  4. Press n and verify the agent receives the rejection and apologizes.
  5. Press y and verify the command executes successfully.

@Nithwin Nithwin added the enhancement New feature or request label Jul 26, 2026
@Nithwin
Nithwin merged commit 6440491 into main Jul 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant