fix(confirmations): guarded-action handling across webchat and tui

This commit is contained in:
William Valentin
2026-02-18 17:43:57 -08:00
parent 7e00cb6b04
commit cdba111831
9 changed files with 199 additions and 52 deletions
+9
View File
@@ -167,6 +167,9 @@ Commands:
/queue Show queue policy for this session
/queue set <k> <v> Set queue override (mode/cap/overflow/debounce_ms/summarize_overflow)
/queue reset Clear queue overrides for this session
/approvals List pending guarded actions for this session
/approve [id] Approve latest pending action (or specific id)
/deny [id] [reason] Deny latest pending action (or specific id)
/elevate [args] Show or manage elevated mode
/reset, /clear, /new Clear conversation history
/compact Compact conversation history
@@ -202,6 +205,9 @@ export const SLASH_COMMANDS = [
'/login',
'/pair',
'/queue',
'/approvals',
'/approve',
'/deny',
'/elevate',
'/transfer',
'/quit',
@@ -226,6 +232,9 @@ export const COMMAND_TOOLTIPS: Record<string, string> = {
'/login': 'Authenticate with GitHub/OpenAI/Anthropic (OAuth/token or API key) or Z.AI (API key store)',
'/pair': 'Generate/list/revoke DM pairing codes',
'/queue': 'Show or update per-session queue policy',
'/approvals': 'List pending guarded actions for this session',
'/approve': 'Approve latest pending action (or specific id)',
'/deny': 'Deny latest pending action (or specific id and reason)',
'/elevate': 'Show or manage elevated mode',
'/transfer': 'Transfer session to another frontend (telegram|tui)',
'/quit': 'Exit TUI',
+6 -51
View File
@@ -8,7 +8,7 @@ import type { Message, ModelClient, TokenUsage } from '../../../models/types.js'
import type { ModelRouter } from '../../../models/router.js';
import type { ManagedSession } from '../../../session/index.js';
import type { NativeAgent, ToolUseEvent } from '../../../backends/native/agent.js';
import type { HookEngine, HookResult } from '../../../hooks/index.js';
import type { HookEngine } from '../../../hooks/index.js';
import type { ModelConfig, ModelProvider } from '../../../config/schema.js';
import { MODEL_PROVIDERS } from '../../../config/schema.js';
import { createClientFromConfig } from '../../../daemon/index.js';
@@ -95,9 +95,6 @@ export function App({
const lastCtrlCAtRef = useRef(0);
const toolLinesRef = useRef<string[]>([]);
const confirmResolveRef = useRef<((result: HookResult) => void) | null>(null);
const [confirmation, setConfirmation] = useState<{ tool: string; args: Record<string, unknown> } | null>(null);
// Set up an Ink-compatible onToolUse callback for the agent.
// This replaces process.stdout writes (which corrupt Ink rendering)
// with one that updates React state to show tool activity.
@@ -132,43 +129,18 @@ export function App({
};
}, [agent, verbose]);
// Inline confirmations for dangerous tools (e.g. shell.exec) in fullscreen mode.
// Fullscreen TUI runs in non-interactive confirmation mode:
// confirmation hooks are auto-approved so flows never block on a y/n prompt.
useEffect(() => {
if (!hookEngine) {return;}
hookEngine.setInteractiveConfirmer(async (pending) => {
return new Promise<HookResult>((resolve) => {
confirmResolveRef.current = resolve;
setConfirmation({ tool: pending.tool, args: pending.args });
});
});
hookEngine.setInteractiveConfirmer(async () => ({ approved: true }));
return () => {
hookEngine.setInteractiveConfirmer(undefined);
confirmResolveRef.current = null;
setConfirmation(null);
};
}, [hookEngine]);
useInput((inputChar, key) => {
// Confirmation prompt mode: capture y/n and ignore everything else.
if (confirmation && confirmResolveRef.current) {
const c = inputChar.toLowerCase();
if (c === 'y') {
confirmResolveRef.current({ approved: true });
confirmResolveRef.current = null;
setConfirmation(null);
return;
}
if (c === 'n') {
confirmResolveRef.current({ approved: false, reason: 'Denied by user' });
confirmResolveRef.current = null;
setConfirmation(null);
return;
}
return;
}
if (key.escape) {
if (isStreaming) {
abortRef.current = true;
@@ -272,10 +244,6 @@ export function App({
}, []);
const handleSubmit = useCallback(async (value: string) => {
if (confirmation) {
return;
}
const command = parseCommand(value);
if (!command) {return;}
@@ -854,7 +822,6 @@ export function App({
setStreamingContent('');
}
}, [
confirmation,
session,
agent,
modelClient,
@@ -885,24 +852,12 @@ export function App({
streamingContent={isStreaming ? streamingContent : undefined}
/>
{confirmation ? (
<Box paddingX={1} paddingY={0} borderStyle="round" borderColor="yellow">
<Text color="yellow">
Confirmation required: {confirmation.tool}{' '}
{Object.keys(confirmation.args).length > 0 ? JSON.stringify(confirmation.args) : ''}
</Text>
<Text color="yellow">Press y to approve, n to deny.</Text>
</Box>
) : null}
<InputBar
value={input}
onChange={setInput}
onSubmit={handleSubmit}
isLoading={isStreaming || !!confirmation}
placeholder={confirmation
? 'Confirmation required (press y/n)'
: (isStreaming ? 'Flynn is typing... (Esc to cancel)' : 'Type a message... (Esc=exit, /help)')}
isLoading={isStreaming}
placeholder={isStreaming ? 'Flynn is typing... (Esc to cancel)' : 'Type a message... (Esc=exit, /help)'}
/>
<StatusBar