chore: fmt

This commit is contained in:
Brooklyn Nicholson
2026-04-12 16:33:25 -05:00
parent 4b026d6761
commit e03bef684e
5 changed files with 50 additions and 33 deletions

View File

@@ -455,11 +455,16 @@ export function App({ gw }: { gw: GatewayClient }) {
}) })
}, []) }, [])
const setTrail = (next: string[]) => { turnToolsRef.current = next; return next } const setTrail = (next: string[]) => {
turnToolsRef.current = next
return next
}
const pruneTransient = useCallback(() => { const pruneTransient = useCallback(() => {
setTurnTrail(prev => { setTurnTrail(prev => {
const next = prev.filter(l => !isTransientTrailLine(l)) const next = prev.filter(l => !isTransientTrailLine(l))
return next.length === prev.length ? prev : setTrail(next) return next.length === prev.length ? prev : setTrail(next)
}) })
}, []) }, [])
@@ -480,7 +485,9 @@ export function App({ gw }: { gw: GatewayClient }) {
const answerClarify = useCallback( const answerClarify = useCallback(
(answer: string) => { (answer: string) => {
if (!clarify) return if (!clarify) {
return
}
const label = TOOL_VERBS.clarify ?? 'clarify' const label = TOOL_VERBS.clarify ?? 'clarify'
@@ -491,7 +498,12 @@ export function App({ gw }: { gw: GatewayClient }) {
if (answer) { if (answer) {
persistedToolLabelsRef.current.add(label) persistedToolLabelsRef.current.add(label)
appendMessage({ role: 'system', text: '', kind: 'trail', tools: [buildToolTrailLine('clarify', clarify.question)] }) appendMessage({
role: 'system',
text: '',
kind: 'trail',
tools: [buildToolTrailLine('clarify', clarify.question)]
})
appendMessage({ role: 'user', text: answer }) appendMessage({ role: 'user', text: answer })
} else { } else {
sys('prompt cancelled') sys('prompt cancelled')
@@ -1457,8 +1469,11 @@ export function App({ gw }: { gw: GatewayClient }) {
const wasInterrupted = interruptedRef.current const wasInterrupted = interruptedRef.current
const savedReasoning = reasoningRef.current.trim() const savedReasoning = reasoningRef.current.trim()
const persisted = persistedToolLabelsRef.current const persisted = persistedToolLabelsRef.current
const savedTools = turnToolsRef.current
.filter(l => isToolTrailResultLine(l) && ![...persisted].some(p => sameToolTrailGroup(p, l))) const savedTools = turnToolsRef.current.filter(
l => isToolTrailResultLine(l) && ![...persisted].some(p => sameToolTrailGroup(p, l))
)
const finalText = (p?.rendered ?? p?.text ?? buf.current).trimStart() const finalText = (p?.rendered ?? p?.text ?? buf.current).trimStart()
idle() idle()

View File

@@ -10,11 +10,11 @@ const FOOTNOTE_RE = /^\[\^([^\]]+)\]:\s*(.*)$/
const DEF_RE = /^\s*:\s+(.+)$/ const DEF_RE = /^\s*:\s+(.+)$/
const TABLE_DIVIDER_CELL_RE = /^:?-{3,}:?$/ const TABLE_DIVIDER_CELL_RE = /^:?-{3,}:?$/
const MD_URL_RE = '((?:[^\\s()]|\\([^\\s()]*\\))+?)' const MD_URL_RE = '((?:[^\\s()]|\\([^\\s()]*\\))+?)'
const INLINE_RE =
new RegExp( const INLINE_RE = new RegExp(
`(!\\[(.*?)\\]\\(${MD_URL_RE}\\)|\\[(.+?)\\]\\(${MD_URL_RE}\\)|<((?:https?:\\/\\/|mailto:)[^>\\s]+|[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,})>|~~(.+?)~~|\`([^\\\`]+)\`|\\*\\*(.+?)\\*\\*|__(.+?)__|\\*(.+?)\\*|_(.+?)_|==(.+?)==|\\[\\^([^\\]]+)\\]|\\^([^^\\s][^^]*?)\\^|~([^~\\s][^~]*?)~|(https?:\\/\\/[^\\s<]+))`, `(!\\[(.*?)\\]\\(${MD_URL_RE}\\)|\\[(.+?)\\]\\(${MD_URL_RE}\\)|<((?:https?:\\/\\/|mailto:)[^>\\s]+|[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,})>|~~(.+?)~~|\`([^\\\`]+)\`|\\*\\*(.+?)\\*\\*|__(.+?)__|\\*(.+?)\\*|_(.+?)_|==(.+?)==|\\[\\^([^\\]]+)\\]|\\^([^^\\s][^^]*?)\\^|~([^~\\s][^~]*?)~|(https?:\\/\\/[^\\s<]+))`,
'g' 'g'
) )
type Fence = { type Fence = {
char: '`' | '~' char: '`' | '~'
@@ -171,11 +171,7 @@ function MdInline({ t, text }: { t: Theme; text: string }) {
parts.push(renderAutolink(parts.length, t, url)) parts.push(renderAutolink(parts.length, t, url))
if (tail) { if (tail) {
parts.push( parts.push(<Text key={parts.length}>{tail}</Text>)
<Text key={parts.length}>
{tail}
</Text>
)
} }
} }
@@ -193,16 +189,8 @@ export function Md({ compact, t, text }: { compact?: boolean; t: Theme; text: st
const lines = text.split('\n') const lines = text.split('\n')
const nodes: ReactNode[] = [] const nodes: ReactNode[] = []
let i = 0 let i = 0
let prevKind:
| 'blank' let prevKind: 'blank' | 'code' | 'heading' | 'list' | 'paragraph' | 'quote' | 'rule' | 'table' | null = null
| 'code'
| 'heading'
| 'list'
| 'paragraph'
| 'quote'
| 'rule'
| 'table'
| null = null
const gap = () => { const gap = () => {
if (nodes.length && prevKind !== 'blank') { if (nodes.length && prevKind !== 'blank') {
@@ -400,7 +388,7 @@ export function Md({ compact, t, text }: { compact?: boolean; t: Theme; text: st
nodes.push( nodes.push(
<Text key={`${key}-def-${i}`}> <Text key={`${key}-def-${i}`}>
<Text color={t.color.dim}> · </Text> <Text color={t.color.dim}> · </Text>
<MdInline t={t} text={def[1]!} /> <MdInline t={t} text={def[1]!} />
</Text> </Text>
) )

View File

@@ -2,6 +2,7 @@ import { Box, Text } from '@hermes/ink'
import { useState } from 'react' import { useState } from 'react'
import type { Theme } from '../theme.js' import type { Theme } from '../theme.js'
import { TextInput } from './textInput.js' import { TextInput } from './textInput.js'
export function MaskedPrompt({ export function MaskedPrompt({

View File

@@ -3,6 +3,7 @@ import { useState } from 'react'
import type { Theme } from '../theme.js' import type { Theme } from '../theme.js'
import type { ApprovalReq, ClarifyReq } from '../types.js' import type { ApprovalReq, ClarifyReq } from '../types.js'
import { TextInput } from './textInput.js' import { TextInput } from './textInput.js'
export function ApprovalPrompt({ onChoice, req, t }: { onChoice: (s: string) => void; req: ApprovalReq; t: Theme }) { export function ApprovalPrompt({ onChoice, req, t }: { onChoice: (s: string) => void; req: ApprovalReq; t: Theme }) {
@@ -88,20 +89,31 @@ export function ClarifyPrompt({
useInput((ch, key) => { useInput((ch, key) => {
if (key.escape) { if (key.escape) {
typing && choices.length ? setTyping(false) : onCancel() typing && choices.length ? setTyping(false) : onCancel()
return return
} }
if (typing) return if (typing) {
return
}
if (key.upArrow && sel > 0) setSel(s => s - 1) if (key.upArrow && sel > 0) {
if (key.downArrow && sel < choices.length) setSel(s => s + 1) setSel(s => s - 1)
}
if (key.downArrow && sel < choices.length) {
setSel(s => s + 1)
}
if (key.return) { if (key.return) {
sel === choices.length ? setTyping(true) : choices[sel] && onAnswer(choices[sel]!) sel === choices.length ? setTyping(true) : choices[sel] && onAnswer(choices[sel]!)
} }
const n = parseInt(ch) const n = parseInt(ch)
if (n >= 1 && n <= choices.length) onAnswer(choices[n - 1]!)
if (n >= 1 && n <= choices.length) {
onAnswer(choices[n - 1]!)
}
}) })
if (typing || !choices.length) { if (typing || !choices.length) {
@@ -126,7 +138,9 @@ export function ClarifyPrompt({
{[...choices, 'Other (type your answer)'].map((c, i) => ( {[...choices, 'Other (type your answer)'].map((c, i) => (
<Text key={i}> <Text key={i}>
<Text color={sel === i ? t.color.label : t.color.dim}>{sel === i ? '▸ ' : ' '}</Text> <Text color={sel === i ? t.color.label : t.color.dim}>{sel === i ? '▸ ' : ' '}</Text>
<Text color={sel === i ? t.color.cornsilk : t.color.dim}>{i + 1}. {c}</Text> <Text color={sel === i ? t.color.cornsilk : t.color.dim}>
{i + 1}. {c}
</Text>
</Text> </Text>
))} ))}

View File

@@ -54,8 +54,7 @@ export const buildToolTrailLine = (name: string, context: string, error?: boolea
export const isToolTrailResultLine = (line: string) => line.endsWith(' ✓') || line.endsWith(' ✗') export const isToolTrailResultLine = (line: string) => line.endsWith(' ✓') || line.endsWith(' ✗')
/** Ephemeral status lines that should vanish once the next phase starts. */ /** Ephemeral status lines that should vanish once the next phase starts. */
export const isTransientTrailLine = (line: string) => export const isTransientTrailLine = (line: string) => line.startsWith('drafting ') || line === 'analyzing tool output…'
line.startsWith('drafting ') || line === 'analyzing tool output…'
/** Whether a persisted/activity tool line belongs to the same tool label as a newer line. */ /** Whether a persisted/activity tool line belongs to the same tool label as a newer line. */
export const sameToolTrailGroup = (label: string, entry: string) => export const sameToolTrailGroup = (label: string, entry: string) =>