feat(hitl): wire up human-in-the-loop approval for system terminal co… - #27
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
CommandToolin the background, which posed a security risk.This update intercepts any
run_commandtool call, pauses the agent's background goroutine using Go channels, and triggers an interactive confirmation modal in the UI.Key Changes
system/command.go: UpgradedCommandToolto accept anApprovalCallback 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: UpdatedRegisterAllto pass the approval callback to the system tools.chat/messages.go: IntroducedApprovalRequestMsgto bridge the background agent process with the main Bubble Tea event loop.chat/update.go&chat/model.go: Wired up a concurrency-safe channelm.approvalChan. It blocks standard inputs while waiting for the user to pressyorn.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 usingfmt.Scanlnfor 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, ornpm install) and prevents the LLM from getting stuck in an infinite command-execution loop.How to Test
go run ./cmd/windmistnand verify the agent receives the rejection and apologizes.yand verify the command executes successfully.