chore: fmt

This commit is contained in:
Brooklyn Nicholson 2026-04-09 14:17:45 -05:00
parent 00e1d42b9e
commit 17f13013eb
2 changed files with 206 additions and 74 deletions

View file

@ -13,7 +13,7 @@ import { MessageLine } from './components/messageLine.js'
import { ApprovalPrompt, ClarifyPrompt } from './components/prompts.js'
import { QueuedMessages } from './components/queuedMessages.js'
import { SessionPicker } from './components/sessionPicker.js'
import { TextInput } from './components/textInput.js'
import { type PasteEvent, TextInput } from './components/textInput.js'
import { Thinking } from './components/thinking.js'
import { HOTKEYS, INTERPOLATION_RE, PLACEHOLDERS, TOOL_VERBS, ZERO } from './constants.js'
import { type GatewayClient, type GatewayEvent } from './gatewayClient.js'
@ -229,18 +229,24 @@ export function App({ gw }: { gw: GatewayClient }) {
const [cols, setCols] = useState(stdout?.columns ?? 80)
useEffect(() => {
if (!stdout) {return}
if (!stdout) {
return
}
const sync = () => setCols(stdout.columns ?? 80)
stdout.on('resize', sync)
// Enable bracketed paste so image-only clipboard paste reaches the app
if (stdout.isTTY) {stdout.write('\x1b[?2004h')}
if (stdout.isTTY) {
stdout.write('\x1b[?2004h')
}
return () => {
stdout.off('resize', sync)
if (stdout.isTTY) {stdout.write('\x1b[?2004l')}
if (stdout.isTTY) {
stdout.write('\x1b[?2004l')
}
}
}, [stdout])
@ -513,14 +519,20 @@ export function App({ gw }: { gw: GatewayClient }) {
)
const handleTextPaste = useCallback(
({ bracketed, cursor, hotkey, text, value }: import('./components/textInput.js').PasteEvent) => {
if (hotkey) { void paste(false);
({ bracketed, cursor, hotkey, text, value }: PasteEvent) => {
if (hotkey) {
void paste(false)
return null }
return null
}
if (bracketed) {void paste(true)}
if (bracketed) {
void paste(true)
}
if (!text) {return null}
if (!text) {
return null
}
const lineCount = text.split('\n').length
@ -770,23 +782,38 @@ export function App({ gw }: { gw: GatewayClient }) {
// ── Input handling ───────────────────────────────────────────────
const ctrl = (key: { ctrl: boolean }, ch: string, target: string) =>
key.ctrl && ch.toLowerCase() === target
const ctrl = (key: { ctrl: boolean }, ch: string, target: string) => key.ctrl && ch.toLowerCase() === target
useInput((ch, key) => {
if (isBlocked) {
if (pasteReview) {
if (key.return) { setPasteReview(null); dispatchSubmission(pasteReview.text, true) }
else if (key.escape || ctrl(key, ch, 'c')) { setPasteReview(null); setStatus('ready') }
if (key.return) {
setPasteReview(null)
dispatchSubmission(pasteReview.text, true)
} else if (key.escape || ctrl(key, ch, 'c')) {
setPasteReview(null)
setStatus('ready')
}
return
}
if (ctrl(key, ch, 'c')) {
if (approval) { gw.request('approval.respond', { choice: 'deny', session_id: sid }).catch(() => {}); setApproval(null); sys('denied') }
else if (sudo) { gw.request('sudo.respond', { request_id: sudo.requestId, password: '' }).catch(() => {}); setSudo(null); sys('sudo cancelled') }
else if (secret) { gw.request('secret.respond', { request_id: secret.requestId, value: '' }).catch(() => {}); setSecret(null); sys('secret entry cancelled') }
else if (picker) {setPicker(false)}
if (approval) {
gw.request('approval.respond', { choice: 'deny', session_id: sid }).catch(() => {})
setApproval(null)
sys('denied')
} else if (sudo) {
gw.request('sudo.respond', { request_id: sudo.requestId, password: '' }).catch(() => {})
setSudo(null)
sys('sudo cancelled')
} else if (secret) {
gw.request('secret.respond', { request_id: secret.requestId, value: '' }).catch(() => {})
setSecret(null)
sys('secret entry cancelled')
} else if (picker) {
setPicker(false)
}
} else if (key.escape && picker) {
setPicker(false)
}
@ -803,7 +830,9 @@ export function App({ gw }: { gw: GatewayClient }) {
if (!inputBuf.length && key.tab && completions.length) {
const row = completions[compIdx]
if (row) {setInput(input.slice(0, compReplace) + row.text)}
if (row) {
setInput(input.slice(0, compReplace) + row.text)
}
return
}
@ -811,12 +840,19 @@ export function App({ gw }: { gw: GatewayClient }) {
if (key.upArrow && !inputBuf.length) {
if (queueRef.current.length) {
const idx = queueEditIdx === null ? 0 : (queueEditIdx + 1) % queueRef.current.length
setQueueEdit(idx); setHistoryIdx(null); setInput(queueRef.current[idx] ?? '')
setQueueEdit(idx)
setHistoryIdx(null)
setInput(queueRef.current[idx] ?? '')
} else if (historyRef.current.length) {
const idx = historyIdx === null ? historyRef.current.length - 1 : Math.max(0, historyIdx - 1)
if (historyIdx === null) {historyDraftRef.current = input}
setHistoryIdx(idx); setQueueEdit(null); setInput(historyRef.current[idx] ?? '')
if (historyIdx === null) {
historyDraftRef.current = input
}
setHistoryIdx(idx)
setQueueEdit(null)
setInput(historyRef.current[idx] ?? '')
}
return
@ -824,16 +860,24 @@ export function App({ gw }: { gw: GatewayClient }) {
if (key.downArrow && !inputBuf.length) {
if (queueRef.current.length) {
const idx = queueEditIdx === null
? queueRef.current.length - 1
: (queueEditIdx - 1 + queueRef.current.length) % queueRef.current.length
const idx =
queueEditIdx === null
? queueRef.current.length - 1
: (queueEditIdx - 1 + queueRef.current.length) % queueRef.current.length
setQueueEdit(idx); setHistoryIdx(null); setInput(queueRef.current[idx] ?? '')
setQueueEdit(idx)
setHistoryIdx(null)
setInput(queueRef.current[idx] ?? '')
} else if (historyIdx !== null) {
const next = historyIdx + 1
if (next >= historyRef.current.length) { setHistoryIdx(null); setInput(historyDraftRef.current) }
else { setHistoryIdx(next); setInput(historyRef.current[next] ?? '') }
if (next >= historyRef.current.length) {
setHistoryIdx(null)
setInput(historyDraftRef.current)
} else {
setHistoryIdx(next)
setInput(historyRef.current[next] ?? '')
}
}
return
@ -846,10 +890,20 @@ export function App({ gw }: { gw: GatewayClient }) {
const partial = (streaming || buf.current).trimStart()
partial ? appendMessage({ role: 'assistant', text: partial + '\n\n*[interrupted]*' }) : sys('interrupted')
idle(); setReasoning(''); setActivity([]); turnToolsRef.current = []; setStatus('interrupted')
idle()
setReasoning('')
setActivity([])
turnToolsRef.current = []
setStatus('interrupted')
if (statusTimerRef.current) {clearTimeout(statusTimerRef.current)}
statusTimerRef.current = setTimeout(() => { statusTimerRef.current = null; setStatus('ready') }, 1500)
if (statusTimerRef.current) {
clearTimeout(statusTimerRef.current)
}
statusTimerRef.current = setTimeout(() => {
statusTimerRef.current = null
setStatus('ready')
}, 1500)
} else if (input || inputBuf.length) {
clearIn()
} else {
@ -859,13 +913,20 @@ export function App({ gw }: { gw: GatewayClient }) {
return
}
if (ctrl(key, ch, 'd')) {return die()}
if (ctrl(key, ch, 'd')) {
return die()
}
if (ctrl(key, ch, 'l')) { setStatus('forging session…'); newSession();
if (ctrl(key, ch, 'l')) {
setStatus('forging session…')
newSession()
return }
return
}
if (ctrl(key, ch, 'g')) {return openEditor()}
if (ctrl(key, ch, 'g')) {
return openEditor()
}
})
// ── Gateway events ───────────────────────────────────────────────