mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
Merge remote-tracking branch 'origin/main' into brennanb2025/mobile-folder-create-worktree
# Conflicts: # mobile/src/i18n/locales/en.json
This commit is contained in:
@@ -307,6 +307,27 @@
|
||||
"dynamic": false,
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"filePath": "mobile/src/terminal/session/MobileSessionLatchKeys.tsx",
|
||||
"kind": "object-property:label",
|
||||
"text": "Shift",
|
||||
"dynamic": false,
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"filePath": "mobile/src/terminal/session/MobileSessionLatchKeys.tsx",
|
||||
"kind": "object-property:label",
|
||||
"text": "Ctrl",
|
||||
"dynamic": false,
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"filePath": "mobile/src/terminal/session/MobileSessionLatchKeys.tsx",
|
||||
"kind": "object-property:label",
|
||||
"text": "Alt",
|
||||
"dynamic": false,
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"filePath": "mobile/src/tasks/mobile-smart-source-modes.ts",
|
||||
"kind": "object-property:label",
|
||||
|
||||
@@ -41,6 +41,9 @@ export const customKeyModalStyles = themedStyleSheet(() => ({
|
||||
borderRadius: radii.surface,
|
||||
overflow: 'hidden'
|
||||
},
|
||||
smartRailGroup: {
|
||||
marginTop: spacing.md
|
||||
},
|
||||
shortcutForm: {
|
||||
paddingTop: spacing.sm
|
||||
},
|
||||
|
||||
@@ -19,6 +19,7 @@ import { useMobileTranslation } from '../i18n/use-mobile-translation'
|
||||
import { MobileSwitch } from './MobileSwitch'
|
||||
import { ListGroup, ListRow } from './list/ListGroup'
|
||||
import { FieldTextInput } from './composer-input/FieldTextInput'
|
||||
import { SmartRailRow } from './SmartRailRow'
|
||||
|
||||
type Step = 'choose-type' | 'shortcut-combo' | 'special-keys' | 'text-macro'
|
||||
|
||||
@@ -62,9 +63,11 @@ type Props = {
|
||||
onClose: () => void
|
||||
onKeysChanged: (keys: CustomKey[]) => void
|
||||
onManageShortcuts?: () => void
|
||||
smartRail?: { enabled: boolean; onChange: (enabled: boolean) => void }
|
||||
}
|
||||
|
||||
export function CustomKeyModal({ visible, onClose, onKeysChanged, onManageShortcuts }: Props) {
|
||||
export function CustomKeyModal(props: Props) {
|
||||
const { visible, onClose, onKeysChanged, onManageShortcuts, smartRail } = props
|
||||
useMobileColorScheme()
|
||||
const t = useMobileTranslation()
|
||||
const [step, setStep] = useState<Step>('choose-type')
|
||||
@@ -235,6 +238,11 @@ export function CustomKeyModal({ visible, onClose, onKeysChanged, onManageShortc
|
||||
) : null}
|
||||
</ListGroup>
|
||||
)}
|
||||
{step === 'choose-type' && smartRail ? (
|
||||
<ListGroup style={styles.smartRailGroup}>
|
||||
<SmartRailRow {...smartRail} />
|
||||
</ListGroup>
|
||||
) : null}
|
||||
|
||||
{step === 'shortcut-combo' && (
|
||||
<View style={styles.shortcutForm}>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ListRow } from './list/ListGroup'
|
||||
import { MobileSwitch } from './MobileSwitch'
|
||||
import { useMobileTranslation } from '../i18n/use-mobile-translation'
|
||||
|
||||
/** The Smart rail setting: keys for what the terminal's agent is doing, at the front of the key row. */
|
||||
export function SmartRailRow({
|
||||
enabled,
|
||||
onChange
|
||||
}: {
|
||||
enabled: boolean
|
||||
onChange: (enabled: boolean) => void
|
||||
}): React.JSX.Element {
|
||||
const t = useMobileTranslation()
|
||||
const title = t('components.smartRailRow.title', 'Smart rail')
|
||||
return (
|
||||
<ListRow
|
||||
title={title}
|
||||
subtitle={t('components.smartRailRow.subtitle', 'Shows keys for what your agent is doing')}
|
||||
accessory={
|
||||
<MobileSwitch accessibilityLabel={title} value={enabled} onValueChange={onChange} />
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
setTerminalAccessoryBuiltInVisible
|
||||
} from '../terminal/terminal-accessory-layout'
|
||||
import { MobileSwitch } from './MobileSwitch'
|
||||
import { SmartRailRow } from './SmartRailRow'
|
||||
|
||||
// Absolutely positioned DragReorderList rows require one fixed height per section.
|
||||
const REORDER_ROW_HEIGHT = 56
|
||||
@@ -148,10 +149,13 @@ export function TerminalShortcutSettings({
|
||||
[persistLayout]
|
||||
)
|
||||
|
||||
// Resetting the keys leaves the Smart rail setting alone.
|
||||
const resetBuiltInKeys = useCallback(() => {
|
||||
const next = defaultLayout()
|
||||
setShortcutLayout(next)
|
||||
persistLayout(next)
|
||||
setShortcutLayout((current) => {
|
||||
const next = { ...defaultLayout(), smartRail: current.smartRail }
|
||||
persistLayout(next)
|
||||
return next
|
||||
})
|
||||
}, [defaultLayout, persistLayout])
|
||||
|
||||
const reorderCustomKeys = useCallback(
|
||||
@@ -182,6 +186,18 @@ export function TerminalShortcutSettings({
|
||||
|
||||
return (
|
||||
<>
|
||||
<SettingsSection>
|
||||
<SmartRailRow
|
||||
enabled={shortcutLayout.smartRail === true}
|
||||
onChange={(enabled) =>
|
||||
setShortcutLayout((current) => {
|
||||
const next = { ...current, smartRail: enabled }
|
||||
persistLayout(next)
|
||||
return next
|
||||
})
|
||||
}
|
||||
/>
|
||||
</SettingsSection>
|
||||
{hasPad ? (
|
||||
<SettingsSection
|
||||
title={t('components.terminalShortcutSettings.directionPad', 'DIRECTION PAD')}
|
||||
|
||||
@@ -1484,6 +1484,10 @@
|
||||
"uncertainFolderCreate": "This worktree may have been created. Check the folder before creating another.",
|
||||
"uncertainCreate": "This workspace may have been created. Check your workspaces before creating another.",
|
||||
"folderCreateBusy": "A worktree in this repository is still being created or checked. It shows in the folder once it lands."
|
||||
},
|
||||
"smartRailRow": {
|
||||
"title": "Smart rail",
|
||||
"subtitle": "Shows keys for what your agent is doing"
|
||||
}
|
||||
},
|
||||
"pullRequest": {
|
||||
@@ -2892,6 +2896,25 @@
|
||||
},
|
||||
"usePrTextAction": {
|
||||
"updateFailed": "Failed to update pull request."
|
||||
},
|
||||
"smartKeys": {
|
||||
"always": "Always",
|
||||
"answer": "Answer",
|
||||
"background": "Background",
|
||||
"cancel": "Cancel",
|
||||
"confirm": "Confirm",
|
||||
"edit": "Edit",
|
||||
"history": "History",
|
||||
"keyLabel": "{{word}}, sends {{combo}}",
|
||||
"mode": "Mode",
|
||||
"no": "No",
|
||||
"queue": "Queue",
|
||||
"reject": "Reject",
|
||||
"rewind": "Rewind",
|
||||
"sendNow": "Send now",
|
||||
"skip": "Skip",
|
||||
"stop": "Stop",
|
||||
"yes": "Yes"
|
||||
}
|
||||
},
|
||||
"chat": {
|
||||
|
||||
@@ -60,7 +60,6 @@ export function MobileSessionCommandDock({ controller }: { controller: MobileSes
|
||||
<View style={dockStyles.inputBar}>
|
||||
<LiveInputField
|
||||
controller={controller}
|
||||
keysInRail={rail.keysInRail}
|
||||
trailing={
|
||||
<MobileTerminalLiveInputStatus
|
||||
dictation={dictation}
|
||||
@@ -95,11 +94,9 @@ export function MobileSessionCommandDock({ controller }: { controller: MobileSes
|
||||
// Only this field reads the typed text, so a keystroke re-renders it and not the dock or session.
|
||||
function LiveInputField({
|
||||
controller,
|
||||
keysInRail,
|
||||
trailing
|
||||
}: {
|
||||
controller: MobileSessionController
|
||||
keysInRail: boolean
|
||||
trailing: ReactNode
|
||||
}) {
|
||||
const t = useMobileTranslation()
|
||||
@@ -124,11 +121,8 @@ function LiveInputField({
|
||||
trailing={trailing}
|
||||
value={text}
|
||||
onChange={(event) => {
|
||||
// A ctrl/alt/shift held on the Duo rail turns the next typed letter into a combo, while the rail shows it.
|
||||
if (
|
||||
!keysInRail ||
|
||||
!dockKeys.interceptTypedCharacter(text, event.nativeEvent.text, liveInputRef)
|
||||
) {
|
||||
// A held Shift, Ctrl or Alt on the key row or the Duo rail turns the next typed letter into a combo.
|
||||
if (!dockKeys.interceptTypedCharacter(text, event.nativeEvent.text, liveInputRef)) {
|
||||
handleLiveInputChange(event)
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -77,6 +77,8 @@ export function MobileSessionSheets({ controller }: { controller: MobileSessionC
|
||||
confirmDiscardMarkdown,
|
||||
handleDeleteCustomKey,
|
||||
handleManageShortcuts,
|
||||
smartRailEnabled,
|
||||
handleSmartRailChange,
|
||||
handleClearTerminal,
|
||||
handleCreateTerminal,
|
||||
launchQuickCommand,
|
||||
@@ -363,6 +365,7 @@ export function MobileSessionSheets({ controller }: { controller: MobileSessionC
|
||||
onClose={() => setShowCustomKeyModal(false)}
|
||||
onKeysChanged={setCustomKeys}
|
||||
onManageShortcuts={handleManageShortcuts}
|
||||
smartRail={{ enabled: smartRailEnabled, onChange: handleSmartRailChange }}
|
||||
/>
|
||||
<MobileDictationSetupSheet
|
||||
visible={showDictationSetup}
|
||||
|
||||
@@ -5,7 +5,10 @@ import { useEffect, useRef, useCallback, useState } from 'react'
|
||||
import { AppState, type AppStateStatus, Platform } from 'react-native'
|
||||
import { useFocusEffect } from 'expo-router'
|
||||
import { loadHosts } from '../transport/hosts/host-store'
|
||||
import { loadTerminalAccessoryLayout } from '../terminal/terminal-accessory-layout'
|
||||
import {
|
||||
loadTerminalAccessoryLayout,
|
||||
saveTerminalSmartRail
|
||||
} from '../terminal/terminal-accessory-layout'
|
||||
import {
|
||||
recoverActiveTerminalAfterForeground,
|
||||
shouldRecoverTerminalOnAppStateChange
|
||||
@@ -25,6 +28,7 @@ export function useMobileSessionLifecycle(scope: MobileSessionTabReconciliationM
|
||||
setCustomKeys,
|
||||
setVisibleBuiltInIds,
|
||||
setDirectionPadEnabled,
|
||||
setSmartRailEnabled,
|
||||
setHostEndpoint,
|
||||
setHostName,
|
||||
connStateRef,
|
||||
@@ -101,6 +105,7 @@ export function useMobileSessionLifecycle(scope: MobileSessionTabReconciliationM
|
||||
if (layout) {
|
||||
setVisibleBuiltInIds(layout.visibleBuiltInIds)
|
||||
setDirectionPadEnabled(layout.directionPadEnabled !== false)
|
||||
setSmartRailEnabled(layout.smartRail === true)
|
||||
}
|
||||
setAccessoryLayoutLoaded(true)
|
||||
}
|
||||
@@ -112,6 +117,19 @@ export function useMobileSessionLifecycle(scope: MobileSessionTabReconciliationM
|
||||
}
|
||||
}, [padAvailable, shellStorage])
|
||||
|
||||
const handleSmartRailChange = useCallback(
|
||||
(enabled: boolean) => {
|
||||
// A read that started before the toggle must not flip it back.
|
||||
layoutReadRevisionRef.current += 1
|
||||
setSmartRailEnabled(enabled)
|
||||
saveTerminalSmartRail(enabled, padAvailable).catch((error: unknown) => {
|
||||
console.warn('[terminal-keys] the store would not take the Smart rail setting', error)
|
||||
setSmartRailEnabled(!enabled)
|
||||
})
|
||||
},
|
||||
[padAvailable]
|
||||
)
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
const releaseKeys = refreshCustomKeys()
|
||||
@@ -195,6 +213,7 @@ export function useMobileSessionLifecycle(scope: MobileSessionTabReconciliationM
|
||||
}, [connState, scheduleDelayedAction, subscribeToTerminal, terminalResume, unsubscribeTerminal])
|
||||
return {
|
||||
accessoryPreferencesReady: customKeysLoaded && accessoryLayoutLoaded,
|
||||
handleSmartRailChange,
|
||||
pendingForegroundRecoveryRef
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ export function useMobileSessionScreenState(scope: MobileSessionFoundationModel)
|
||||
const [renameTarget, setRenameTarget] = useState<Terminal | null>(null)
|
||||
const [customKeys, setCustomKeys] = useState<CustomKey[]>([])
|
||||
const [directionPadEnabled, setDirectionPadEnabled] = useState(true)
|
||||
const [smartRailEnabled, setSmartRailEnabled] = useState(false)
|
||||
const [visibleBuiltInIds, setVisibleBuiltInIds] = useState<string[]>(
|
||||
getDefaultTerminalAccessoryBuiltInIds
|
||||
)
|
||||
@@ -182,6 +183,8 @@ export function useMobileSessionScreenState(scope: MobileSessionFoundationModel)
|
||||
setCustomKeys,
|
||||
directionPadEnabled,
|
||||
setDirectionPadEnabled,
|
||||
smartRailEnabled,
|
||||
setSmartRailEnabled,
|
||||
visibleBuiltInIds,
|
||||
setVisibleBuiltInIds,
|
||||
showCustomKeyModal,
|
||||
|
||||
@@ -21,6 +21,17 @@ import { styles as sessionStyles } from '../../session/mobile-session-styles'
|
||||
import { useKeyboardPersistingTaps } from '../../platform/keyboard-persisting-taps'
|
||||
import type { MobileSessionController } from '../../session/use-mobile-session-controller'
|
||||
import { useMobileSessionKeyboardLift } from './use-mobile-session-keyboard-lift'
|
||||
import {
|
||||
AGENT_SMART_KEY_STEP_MS,
|
||||
type AgentSmartKey
|
||||
} from '../../../../src/shared/terminal/input/agent-smart-keys'
|
||||
import type { TerminalAccessoryKey } from '../terminal-accessory-keys'
|
||||
import { resolveMobileTerminalTabSmartKeys } from './mobile-terminal-tab-agent'
|
||||
import { MobileSessionSmartKeys } from './MobileSessionSmartKeys'
|
||||
import { MobileSessionLatchKeys } from './MobileSessionLatchKeys'
|
||||
import { isAccessibilityClick, useTerminalKeyRowTouch } from './use-terminal-key-row-touch'
|
||||
|
||||
type PreparedPress = ReturnType<MobileSessionController['prepareAccessoryPress']>
|
||||
|
||||
// The terminal's key row above the live input; every key goes straight to the terminal.
|
||||
export function MobileSessionAccessoryKeys({
|
||||
@@ -46,10 +57,26 @@ export function MobileSessionAccessoryKeys({
|
||||
stopAccessoryRepeat,
|
||||
cancelAccessoryRepeat,
|
||||
prepareAccessoryPress,
|
||||
handlePaste
|
||||
handlePaste,
|
||||
dockKeys,
|
||||
activeSessionTab,
|
||||
terminals,
|
||||
smartRailEnabled
|
||||
} = controller
|
||||
const keyboardLift = useMobileSessionKeyboardLift(controller.dockBottomInset)
|
||||
const accessoryPresses = useRef(new Map<string, ReturnType<typeof prepareAccessoryPress>>())
|
||||
const accessoryPresses = useRef(new Map<string, PreparedPress>())
|
||||
const scrollRef = useRef<ScrollView>(null)
|
||||
const latestSmartKeys = useMemo(
|
||||
() =>
|
||||
smartRailEnabled ? resolveMobileTerminalTabSmartKeys(activeSessionTab, terminals) : null,
|
||||
[smartRailEnabled, activeSessionTab, terminals]
|
||||
)
|
||||
const touch = useTerminalKeyRowTouch({
|
||||
scrollRef,
|
||||
latest: latestSmartKeys,
|
||||
cancelAccessoryRepeat
|
||||
})
|
||||
const smartKeys = touch.shown
|
||||
const keepsKeyboard = useKeyboardPersistingTaps('always')
|
||||
// An unmounting Pressable never fires onPressOut, so a held key would outlive its row.
|
||||
useEffect(() => cancelAccessoryRepeat, [cancelAccessoryRepeat])
|
||||
@@ -70,8 +97,57 @@ export function MobileSessionAccessoryKeys({
|
||||
]
|
||||
const sendKeyLabel = (label: string) =>
|
||||
t('session.accessoryKeys.sendKey', 'Send {{label}}', { label })
|
||||
// Held Shift, Ctrl or Alt turn a key into its combo and are used up when it sends; keys that take none send as they are.
|
||||
const prepareBuiltInPress = (key: TerminalAccessoryKey): PreparedPress => {
|
||||
const chord = dockKeys.chordInput(key.id)
|
||||
const press = prepareAccessoryPress(chord ?? createTerminalLiveAccessoryInput(key))
|
||||
const takeChord = () => {
|
||||
if (chord) {
|
||||
dockKeys.takeModifiers()
|
||||
}
|
||||
}
|
||||
return {
|
||||
tap: () => {
|
||||
takeChord()
|
||||
return press.tap()
|
||||
},
|
||||
hold: (firstRepeatDelayMs) => {
|
||||
takeChord()
|
||||
press.hold(firstRepeatDelayMs)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Later writes belong to the same press, so a scroll after release mustn't drop them; a tab switch does.
|
||||
const sendSmartKey = (key: AgentSmartKey) => {
|
||||
const handle = controller.activeHandleRef.current
|
||||
void (async () => {
|
||||
for (const [index, bytes] of key.writes.entries()) {
|
||||
if (index > 0) {
|
||||
await new Promise((resolve) => setTimeout(resolve, AGENT_SMART_KEY_STEP_MS))
|
||||
}
|
||||
if (controller.activeHandleRef.current !== handle) {
|
||||
return
|
||||
}
|
||||
if (!(await prepareAccessoryPress({ bytes }).tap())) {
|
||||
return
|
||||
}
|
||||
}
|
||||
})()
|
||||
}
|
||||
const latchIndex = builtInKeys.findIndex((key) => key.id === 'tab') + 1
|
||||
const latchKeys = (
|
||||
<MobileSessionLatchKeys
|
||||
key="latches"
|
||||
modifiers={dockKeys.modifiers}
|
||||
disabled={!canSend}
|
||||
onPressIn={() => touch.arm('latch')}
|
||||
onPress={(modifier, event) =>
|
||||
touch.fire('latch', event, () => dockKeys.tapModifier(modifier))
|
||||
}
|
||||
/>
|
||||
)
|
||||
return (
|
||||
<View ref={keepsKeyboard} style={styles.keyRow}>
|
||||
<View ref={keepsKeyboard} style={styles.keyRow} {...touch.rowTouchHandlers}>
|
||||
{/* Why: fixed keyboard escape hatch; outside the ScrollView so it can't scroll away (#5106). */}
|
||||
{keyboardLift > 0 && (
|
||||
<Pressable
|
||||
@@ -98,23 +174,36 @@ export function MobileSessionAccessoryKeys({
|
||||
)}
|
||||
{/* Why: default tap handling makes the first key tap dismiss the keyboard and get swallowed (#5106). */}
|
||||
<ScrollView
|
||||
ref={scrollRef}
|
||||
style={styles.keyScroll}
|
||||
horizontal
|
||||
showsHorizontalScrollIndicator={false}
|
||||
showsVerticalScrollIndicator={false}
|
||||
contentContainerStyle={styles.keyScrollContent}
|
||||
keyboardShouldPersistTaps="always"
|
||||
onScrollBeginDrag={cancelAccessoryRepeat}
|
||||
onScroll={touch.onScroll}
|
||||
scrollEventThrottle={16}
|
||||
>
|
||||
{smartKeys ? (
|
||||
<MobileSessionSmartKeys
|
||||
keySet={smartKeys}
|
||||
disabled={!canSend}
|
||||
onPressIn={(key) => touch.arm(`smart:${key.id}`)}
|
||||
onPress={(key, event) => touch.fire(`smart:${key.id}`, event, () => sendSmartKey(key))}
|
||||
/>
|
||||
) : null}
|
||||
<Pressable
|
||||
style={keyStyle}
|
||||
disabled={!canSend}
|
||||
hitSlop={TERMINAL_KEY_HIT_SLOP}
|
||||
onPress={() => {
|
||||
if (activeHandle) {
|
||||
void toggleDisplayMode(activeHandle)
|
||||
}
|
||||
}}
|
||||
onPressIn={() => touch.arm('displayMode')}
|
||||
onPress={(event) =>
|
||||
touch.fire('displayMode', event, () => {
|
||||
if (activeHandle) {
|
||||
void toggleDisplayMode(activeHandle)
|
||||
}
|
||||
})
|
||||
}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={
|
||||
phoneDisplay
|
||||
@@ -133,7 +222,8 @@ export function MobileSessionAccessoryKeys({
|
||||
style={keyStyle}
|
||||
disabled={!canSend}
|
||||
hitSlop={TERMINAL_KEY_HIT_SLOP}
|
||||
onPress={() => void handlePaste()}
|
||||
onPressIn={() => touch.arm('paste')}
|
||||
onPress={(event) => touch.fire('paste', event, () => void handlePaste())}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={t(
|
||||
'session.accessoryKeys.pasteFromClipboard',
|
||||
@@ -143,20 +233,22 @@ export function MobileSessionAccessoryKeys({
|
||||
<Text style={styles.keyText}>{t('session.accessoryKeys.paste', 'Paste')}</Text>
|
||||
</Pressable>
|
||||
)}
|
||||
{builtInKeys.map((key) => (
|
||||
{latchIndex === 0 ? latchKeys : null}
|
||||
{builtInKeys.flatMap((key, index) => [
|
||||
<Pressable
|
||||
key={key.id}
|
||||
style={keyStyle}
|
||||
disabled={!canSend}
|
||||
hitSlop={TERMINAL_KEY_HIT_SLOP}
|
||||
onPressIn={(event) => {
|
||||
touch.arm(key.id)
|
||||
if (!key.repeatable) {
|
||||
return
|
||||
}
|
||||
const press = prepareAccessoryPress(createTerminalLiveAccessoryInput(key))
|
||||
accessoryPresses.current.set(key.id, press)
|
||||
const prepared = prepareBuiltInPress(key)
|
||||
accessoryPresses.current.set(key.id, prepared)
|
||||
if (event.type === 'keydown') {
|
||||
press.hold(TERMINAL_ACCESSORY_REPEAT_DELAY_MS)
|
||||
prepared.hold(TERMINAL_ACCESSORY_REPEAT_DELAY_MS)
|
||||
}
|
||||
}}
|
||||
onPressOut={() => {
|
||||
@@ -165,23 +257,23 @@ export function MobileSessionAccessoryKeys({
|
||||
}
|
||||
}}
|
||||
onPress={(event) => {
|
||||
if (key.repeatable) {
|
||||
// Accessibility clicks have no touch-down to prepare a sender.
|
||||
const accessibilityClick =
|
||||
event.type === 'click' &&
|
||||
'detail' in event.nativeEvent &&
|
||||
event.nativeEvent.detail === 0
|
||||
const press =
|
||||
(!accessibilityClick && accessoryPresses.current.get(key.id)) ||
|
||||
prepareAccessoryPress(createTerminalLiveAccessoryInput(key))
|
||||
accessoryPresses.current.delete(key.id)
|
||||
void press.tap()
|
||||
return
|
||||
}
|
||||
void handleAccessoryKey(createTerminalLiveAccessoryInput(key))
|
||||
// Accessibility clicks have no touch-down to prepare a sender.
|
||||
const prepared =
|
||||
(key.repeatable &&
|
||||
!isAccessibilityClick(event) &&
|
||||
accessoryPresses.current.get(key.id)) ||
|
||||
prepareBuiltInPress(key)
|
||||
accessoryPresses.current.delete(key.id)
|
||||
touch.fire(key.id, event, () => void prepared.tap())
|
||||
}}
|
||||
onLongPress={
|
||||
key.repeatable ? () => accessoryPresses.current.get(key.id)?.hold() : undefined
|
||||
key.repeatable
|
||||
? () => {
|
||||
if (touch.stillArmed(key.id)) {
|
||||
accessoryPresses.current.get(key.id)?.hold()
|
||||
}
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
delayLongPress={TERMINAL_ACCESSORY_REPEAT_DELAY_MS}
|
||||
// A web <button> clicks on Enter keydown as well, which would send a held key twice.
|
||||
@@ -189,15 +281,19 @@ export function MobileSessionAccessoryKeys({
|
||||
accessibilityLabel={key.accessibilityLabel ?? sendKeyLabel(key.label)}
|
||||
>
|
||||
<Text style={styles.keyText}>{key.label}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</Pressable>,
|
||||
index + 1 === latchIndex ? latchKeys : null
|
||||
])}
|
||||
{customKeys.map((key) => (
|
||||
<Pressable
|
||||
key={key.id}
|
||||
style={({ pressed }) => [...keyStyle({ pressed }), styles.customKey]}
|
||||
disabled={!canSend}
|
||||
hitSlop={TERMINAL_KEY_HIT_SLOP}
|
||||
onPress={() => void handleAccessoryKey({ bytes: key.bytes })}
|
||||
onPressIn={() => touch.arm(key.id)}
|
||||
onPress={(event) =>
|
||||
touch.fire(key.id, event, () => void handleAccessoryKey({ bytes: key.bytes }))
|
||||
}
|
||||
onLongPress={() => {
|
||||
triggerMediumImpact()
|
||||
setDeleteKeyTarget(key)
|
||||
@@ -216,7 +312,8 @@ export function MobileSessionAccessoryKeys({
|
||||
<Pressable
|
||||
style={({ pressed }) => [styles.key, pressed && styles.keyPressed]}
|
||||
hitSlop={TERMINAL_KEY_HIT_SLOP}
|
||||
onPress={() => setShowCustomKeyModal(true)}
|
||||
onPressIn={() => touch.arm('addKey')}
|
||||
onPress={(event) => touch.fire('addKey', event, () => setShowCustomKeyModal(true))}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={t('session.accessoryKeys.addCustomShortcut', 'Add custom shortcut')}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import { Pressable, Text, type GestureResponderEvent } from 'react-native'
|
||||
import type { TerminalShortcutModifier } from '../terminal-accessory-keys'
|
||||
import type { StickyModifiers } from '../terminal-sticky-modifiers'
|
||||
import { useMobileTranslation } from '../../i18n/use-mobile-translation'
|
||||
import { useMobileColorScheme } from '../../theme/use-mobile-color-scheme'
|
||||
import { TERMINAL_KEY_HIT_SLOP, terminalDockStyles as styles } from './terminal-dock-styles'
|
||||
|
||||
const LATCHES: readonly { id: TerminalShortcutModifier; label: string }[] = [
|
||||
{ id: 'shift', label: 'Shift' },
|
||||
{ id: 'ctrl', label: 'Ctrl' },
|
||||
{ id: 'alt', label: 'Alt' }
|
||||
]
|
||||
|
||||
/** Shift, Ctrl and Alt on the key row: a tap holds one for the next key, a double tap locks it. */
|
||||
export function MobileSessionLatchKeys({
|
||||
modifiers,
|
||||
disabled,
|
||||
onPressIn,
|
||||
onPress
|
||||
}: {
|
||||
modifiers: StickyModifiers
|
||||
disabled: boolean
|
||||
onPressIn: () => void
|
||||
onPress: (modifier: TerminalShortcutModifier, event: GestureResponderEvent) => void
|
||||
}) {
|
||||
useMobileColorScheme()
|
||||
const t = useMobileTranslation()
|
||||
const names: Record<TerminalShortcutModifier, string> = {
|
||||
shift: t('session.accessoryKeys.shift', 'Shift'),
|
||||
ctrl: t('session.accessoryKeys.control', 'Control'),
|
||||
alt: t('session.accessoryKeys.alt', 'Alt')
|
||||
}
|
||||
return LATCHES.map(({ id, label }) => {
|
||||
const latch = modifiers[id]
|
||||
return (
|
||||
<Pressable
|
||||
key={id}
|
||||
style={({ pressed }) => [
|
||||
styles.key,
|
||||
styles.keyLatch,
|
||||
latch === 'once' && styles.keyLatched,
|
||||
latch === 'locked' && styles.keyLocked,
|
||||
pressed && styles.keyPressed,
|
||||
disabled && styles.disabled
|
||||
]}
|
||||
disabled={disabled}
|
||||
hitSlop={TERMINAL_KEY_HIT_SLOP}
|
||||
onPressIn={onPressIn}
|
||||
onPress={(event) => onPress(id, event)}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={names[id]}
|
||||
accessibilityState={{ selected: latch !== 'off' }}
|
||||
>
|
||||
<Text style={[styles.keyText, latch === 'locked' && styles.keyTextLocked]}>{label}</Text>
|
||||
</Pressable>
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import { Pressable, Text, View, type GestureResponderEvent } from 'react-native'
|
||||
import type {
|
||||
AgentSmartKey,
|
||||
AgentSmartKeyName,
|
||||
AgentSmartKeySet
|
||||
} from '../../../../src/shared/terminal/input/agent-smart-keys'
|
||||
import { MobileAgentIcon } from '../../components/MobileAgentIcon'
|
||||
import type { Translate } from '../../i18n/mobile-i18n'
|
||||
import { useMobileTranslation } from '../../i18n/use-mobile-translation'
|
||||
import { useMobileColorScheme } from '../../theme/use-mobile-color-scheme'
|
||||
import { TERMINAL_KEY_HIT_SLOP, terminalDockStyles as styles } from './terminal-dock-styles'
|
||||
|
||||
function smartKeyWord(t: Translate, name: AgentSmartKeyName): string {
|
||||
switch (name) {
|
||||
case 'stop':
|
||||
return t('session.smartKeys.stop', 'Stop')
|
||||
case 'sendNow':
|
||||
return t('session.smartKeys.sendNow', 'Send now')
|
||||
case 'background':
|
||||
return t('session.smartKeys.background', 'Background')
|
||||
case 'mode':
|
||||
return t('session.smartKeys.mode', 'Mode')
|
||||
case 'yes':
|
||||
return t('session.smartKeys.yes', 'Yes')
|
||||
case 'always':
|
||||
return t('session.smartKeys.always', 'Always')
|
||||
case 'no':
|
||||
return t('session.smartKeys.no', 'No')
|
||||
case 'cancel':
|
||||
return t('session.smartKeys.cancel', 'Cancel')
|
||||
case 'history':
|
||||
return t('session.smartKeys.history', 'History')
|
||||
case 'rewind':
|
||||
return t('session.smartKeys.rewind', 'Rewind')
|
||||
case 'queue':
|
||||
return t('session.smartKeys.queue', 'Queue')
|
||||
case 'edit':
|
||||
return t('session.smartKeys.edit', 'Edit')
|
||||
case 'answer':
|
||||
return t('session.smartKeys.answer', 'Answer')
|
||||
case 'skip':
|
||||
return t('session.smartKeys.skip', 'Skip')
|
||||
case 'confirm':
|
||||
return t('session.smartKeys.confirm', 'Confirm')
|
||||
case 'reject':
|
||||
return t('session.smartKeys.reject', 'Reject')
|
||||
}
|
||||
}
|
||||
|
||||
/** The agent's keys for its current state, in a capsule at the front of the key row. */
|
||||
export function MobileSessionSmartKeys({
|
||||
keySet,
|
||||
disabled,
|
||||
onPressIn,
|
||||
onPress
|
||||
}: {
|
||||
keySet: AgentSmartKeySet
|
||||
disabled: boolean
|
||||
onPressIn: (key: AgentSmartKey) => void
|
||||
onPress: (key: AgentSmartKey, event: GestureResponderEvent) => void
|
||||
}) {
|
||||
useMobileColorScheme()
|
||||
const t = useMobileTranslation()
|
||||
return (
|
||||
<>
|
||||
<View style={styles.smartGroup}>
|
||||
<MobileAgentIcon agentId={keySet.agentId} size={13} />
|
||||
{keySet.keys.map((key) => {
|
||||
const word = key.name ? smartKeyWord(t, key.name) : null
|
||||
return (
|
||||
<Pressable
|
||||
key={key.id}
|
||||
style={({ pressed }) => [
|
||||
styles.key,
|
||||
key.primary && styles.smartKeyPrimary,
|
||||
pressed && styles.keyPressed,
|
||||
disabled && styles.disabled
|
||||
]}
|
||||
disabled={disabled}
|
||||
hitSlop={TERMINAL_KEY_HIT_SLOP}
|
||||
onPressIn={() => onPressIn(key)}
|
||||
onPress={(event) => onPress(key, event)}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={
|
||||
word
|
||||
? t('session.smartKeys.keyLabel', '{{word}}, sends {{combo}}', {
|
||||
word,
|
||||
combo: key.combo
|
||||
})
|
||||
: t('session.accessoryKeys.sendKey', 'Send {{label}}', { label: key.combo })
|
||||
}
|
||||
>
|
||||
{word ? (
|
||||
<View style={styles.smartKeyStack}>
|
||||
<Text style={[styles.smartKeyWord, key.primary && styles.smartKeyPrimaryText]}>
|
||||
{word}
|
||||
</Text>
|
||||
<Text style={[styles.smartKeyCombo, key.primary && styles.smartKeyPrimaryText]}>
|
||||
{key.combo}
|
||||
</Text>
|
||||
</View>
|
||||
) : (
|
||||
<Text style={styles.keyText}>{key.combo}</Text>
|
||||
)}
|
||||
</Pressable>
|
||||
)
|
||||
})}
|
||||
</View>
|
||||
<View style={styles.smartDivider} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,10 @@ import { agentTypeToIconAgent } from '../../../../src/shared/agent-status/presen
|
||||
import { resolveTabAgentFromSignalSnapshot } from '../../../../src/shared/tab-agent-from-signals'
|
||||
import type { AgentStatusEntry } from '../../../../src/shared/agent-status/contracts/agent-status-types'
|
||||
import type { TuiAgent } from '../../../../src/shared/agent-launch/catalog/tui-agent'
|
||||
import {
|
||||
resolveAgentSmartKeys,
|
||||
type AgentSmartKeySet
|
||||
} from '../../../../src/shared/terminal/input/agent-smart-keys'
|
||||
import { isBlankBrowserUrl } from '../../browser/browser-url'
|
||||
import { translate } from '../../i18n/mobile-i18n'
|
||||
import type { MobileSessionTab } from '../../session/tabs/mobile-session-tabs'
|
||||
@@ -114,3 +118,20 @@ export function getMobileSessionTabTitle(
|
||||
}
|
||||
return tab.title || translate('session.terminalTabAgent.terminal', 'Terminal')
|
||||
}
|
||||
|
||||
/** The keys for what the tab's agent is doing now, or null for a shell, an unknown agent or state. */
|
||||
export function resolveMobileTerminalTabSmartKeys(
|
||||
tab: MobileSessionTab | null | undefined,
|
||||
terminals: readonly { handle: string; agentIdentity?: string }[]
|
||||
): AgentSmartKeySet | null {
|
||||
if (tab?.type !== 'terminal' || !isMobileTerminalTabRunningAgent(tab)) {
|
||||
return null
|
||||
}
|
||||
return resolveAgentSmartKeys(
|
||||
resolveMobileTerminalTabOwnedAgentId(
|
||||
tab,
|
||||
getMobileTerminalTabHostAgentIdentity(tab, terminals)
|
||||
),
|
||||
tab.agentStatus
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ const KEY_HEIGHT = 32
|
||||
const KEY_ROW_HEIGHT = 46
|
||||
const KEY_GAP = spacing.sm
|
||||
const KEY_RADIUS = radii.control
|
||||
// The smart group wraps its keys with this much room on each side, inside the same row.
|
||||
const SMART_GROUP_INSET = spacing.xs
|
||||
|
||||
/** Grows each 32 pt key to the row's height and halfway into its neighbours' gaps. */
|
||||
export const TERMINAL_KEY_HIT_SLOP = {
|
||||
@@ -79,6 +81,58 @@ export const terminalDockStyles = themedStyleSheet(() => ({
|
||||
keyPressed: {
|
||||
opacity: feedback.pressedOpacity
|
||||
},
|
||||
// A Shift, Ctrl or Alt latch armed for the next key, and one locked on (the Duo rail's look).
|
||||
// A border on every latch, so arming one doesn't widen it.
|
||||
keyLatch: {
|
||||
borderWidth: 1,
|
||||
borderColor: 'transparent'
|
||||
},
|
||||
keyLatched: {
|
||||
borderColor: colors.textPrimary
|
||||
},
|
||||
keyLocked: {
|
||||
backgroundColor: colors.textPrimary
|
||||
},
|
||||
keyTextLocked: {
|
||||
color: colors.bgBase
|
||||
},
|
||||
smartGroup: {
|
||||
height: KEY_HEIGHT + SMART_GROUP_INSET * 2,
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
gap: SMART_GROUP_INSET,
|
||||
paddingLeft: spacing.sm,
|
||||
paddingRight: SMART_GROUP_INSET,
|
||||
borderRadius: KEY_RADIUS + SMART_GROUP_INSET,
|
||||
borderWidth: StyleSheet.hairlineWidth,
|
||||
borderColor: colors.composerBorder,
|
||||
backgroundColor: colors.composerSurface
|
||||
},
|
||||
smartDivider: {
|
||||
width: StyleSheet.hairlineWidth,
|
||||
height: KEY_HEIGHT - spacing.sm,
|
||||
backgroundColor: colors.translucentFill
|
||||
},
|
||||
smartKeyStack: {
|
||||
alignItems: 'center'
|
||||
},
|
||||
smartKeyWord: {
|
||||
color: colors.textPrimary,
|
||||
fontSize: typography.metaSize,
|
||||
fontWeight: '600'
|
||||
},
|
||||
smartKeyCombo: {
|
||||
color: colors.textSecondary,
|
||||
fontSize: 10,
|
||||
fontFamily: typography.monoFamily
|
||||
},
|
||||
// The prompt's accept key, in the app's filled primary.
|
||||
smartKeyPrimary: {
|
||||
backgroundColor: colors.surfaceBright
|
||||
},
|
||||
smartKeyPrimaryText: {
|
||||
color: colors.bgBase
|
||||
},
|
||||
ghostKey: {
|
||||
...key,
|
||||
backgroundColor: 'transparent'
|
||||
|
||||
@@ -49,6 +49,10 @@ export function useTerminalDockKeys({ activeHandle, sendInput }: UseTerminalDock
|
||||
return modifiers
|
||||
}
|
||||
|
||||
/** A row key with the held modifiers, or null when none is held or the key takes no modifier. */
|
||||
const chordInput = (key: string): TerminalLiveAccessoryInput | null =>
|
||||
hasStickyModifier(modifiers) ? terminalDockKeyInput(key, modifiers) : null
|
||||
|
||||
/** Sends a special key id (`arrowUp`, `tab`, `f5`…) or a printable character with the held modifiers. */
|
||||
const sendKey = (key: string): void => {
|
||||
const input = terminalDockKeyInput(key, takeModifiers())
|
||||
@@ -75,7 +79,7 @@ export function useTerminalDockKeys({ activeHandle, sendInput }: UseTerminalDock
|
||||
return true
|
||||
}
|
||||
|
||||
return { modifiers, tapModifier, sendKey, interceptTypedCharacter }
|
||||
return { modifiers, tapModifier, takeModifiers, chordInput, sendKey, interceptTypedCharacter }
|
||||
}
|
||||
|
||||
function terminalDockKeyInput(
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
import { useCallback, useEffect, useRef, useState, type RefObject } from 'react'
|
||||
import type {
|
||||
GestureResponderEvent,
|
||||
NativeScrollEvent,
|
||||
NativeSyntheticEvent,
|
||||
ScrollView
|
||||
} from 'react-native'
|
||||
import {
|
||||
sameSmartKeySet,
|
||||
type AgentSmartKeySet
|
||||
} from '../../../../src/shared/terminal/input/agent-smart-keys'
|
||||
|
||||
// The same movement the Duo rail allows before a touch stops counting as a press.
|
||||
const PRESS_MOVE_SLOP = 8
|
||||
// On the page a tap's press is the click after touchend; hold the row until then, or this long.
|
||||
const RELEASE_SETTLE_MS = 300
|
||||
|
||||
/** A web click with no pointer behind it: VoiceOver, Switch Control or a keyboard. */
|
||||
export function isAccessibilityClick(event: GestureResponderEvent): boolean {
|
||||
return event.type === 'click' && 'detail' in event.nativeEvent && event.nativeEvent.detail === 0
|
||||
}
|
||||
|
||||
/** A web click from a finger or mouse; one that never pressed its key landed on a key that moved. */
|
||||
function isPointerClick(event: GestureResponderEvent): boolean {
|
||||
return event.type === 'click' && !isAccessibilityClick(event)
|
||||
}
|
||||
|
||||
/**
|
||||
* Touch rules for the terminal key row: a key fires on release only if the row neither scrolled
|
||||
* nor moved under the finger since it went down, and `shown` holds still from touch-down until that
|
||||
* touch's press has landed. A new `shown` scrolls the row back to its start.
|
||||
*/
|
||||
export function useTerminalKeyRowTouch({
|
||||
scrollRef,
|
||||
latest,
|
||||
cancelAccessoryRepeat
|
||||
}: {
|
||||
scrollRef: RefObject<ScrollView | null>
|
||||
latest: AgentSmartKeySet | null
|
||||
cancelAccessoryRepeat: () => void
|
||||
}) {
|
||||
const [shown, setShown] = useState(latest)
|
||||
const touchRef = useRef({ down: false, moved: false, x: 0, y: 0 })
|
||||
const settleTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
const pressRevisionRef = useRef(0)
|
||||
const armedRef = useRef(new Map<string, number>())
|
||||
const scrollXRef = useRef(0)
|
||||
const latestRef = useRef(latest)
|
||||
// From touch-down until that touch's press lands (or the settle timer runs out).
|
||||
const holding = () => touchRef.current.down || settleTimerRef.current !== null
|
||||
const show = useCallback(() => {
|
||||
setShown((current) =>
|
||||
sameSmartKeySet(current, latestRef.current) ? current : latestRef.current
|
||||
)
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
latestRef.current = latest
|
||||
if (!holding()) {
|
||||
show()
|
||||
}
|
||||
}, [latest, show])
|
||||
const resetTo = useRef(shown)
|
||||
useEffect(() => {
|
||||
if (resetTo.current !== shown) {
|
||||
resetTo.current = shown
|
||||
scrollRef.current?.scrollTo({ x: 0, animated: false })
|
||||
}
|
||||
}, [scrollRef, shown])
|
||||
|
||||
// Scrolls on the page come only as DOM scroll events; onScrollBeginDrag never fires there.
|
||||
const cancelPresses = useCallback(() => {
|
||||
pressRevisionRef.current += 1
|
||||
cancelAccessoryRepeat()
|
||||
}, [cancelAccessoryRepeat])
|
||||
|
||||
const clearSettleTimer = useCallback(() => {
|
||||
if (settleTimerRef.current) {
|
||||
clearTimeout(settleTimerRef.current)
|
||||
settleTimerRef.current = null
|
||||
}
|
||||
}, [])
|
||||
useEffect(() => clearSettleTimer, [clearSettleTimer])
|
||||
const settle = useCallback(() => {
|
||||
clearSettleTimer()
|
||||
if (!touchRef.current.down) {
|
||||
show()
|
||||
}
|
||||
}, [clearSettleTimer, show])
|
||||
const released = useCallback(() => {
|
||||
touchRef.current.down = false
|
||||
settleTimerRef.current ??= setTimeout(settle, RELEASE_SETTLE_MS)
|
||||
}, [settle])
|
||||
|
||||
return {
|
||||
shown,
|
||||
rowTouchHandlers: {
|
||||
onTouchStart: (event: GestureResponderEvent) => {
|
||||
const { pageX, pageY } = event.nativeEvent
|
||||
touchRef.current = { down: true, moved: false, x: pageX, y: pageY }
|
||||
clearSettleTimer()
|
||||
},
|
||||
onTouchMove: (event: GestureResponderEvent) => {
|
||||
const { pageX, pageY } = event.nativeEvent
|
||||
const start = touchRef.current
|
||||
if (!start.moved && Math.hypot(pageX - start.x, pageY - start.y) > PRESS_MOVE_SLOP) {
|
||||
start.moved = true
|
||||
cancelPresses()
|
||||
}
|
||||
},
|
||||
onTouchEnd: released,
|
||||
onTouchCancel: () => {
|
||||
cancelPresses()
|
||||
released()
|
||||
}
|
||||
},
|
||||
// Only a finger moving the row cancels: the page also reports settling, focus and reset scrolls.
|
||||
onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
const x = event.nativeEvent.contentOffset.x
|
||||
const moved = x !== scrollXRef.current
|
||||
scrollXRef.current = x
|
||||
if (moved && touchRef.current.down) {
|
||||
cancelPresses()
|
||||
}
|
||||
},
|
||||
/** Marks a key as pressed; call from onPressIn. */
|
||||
arm: (id: string): void => {
|
||||
armedRef.current.set(id, pressRevisionRef.current)
|
||||
},
|
||||
/** Whether a key armed by a touch still counts, for a hold that starts before release. */
|
||||
stillArmed: (id: string): boolean => armedRef.current.get(id) === pressRevisionRef.current,
|
||||
/** Runs a key's action on release unless the row moved since it was armed, then lets the row change. */
|
||||
fire: (id: string, event: GestureResponderEvent, action: () => void): void => {
|
||||
const armedAt = armedRef.current.get(id)
|
||||
armedRef.current.delete(id)
|
||||
if (armedAt === undefined ? !isPointerClick(event) : armedAt === pressRevisionRef.current) {
|
||||
action()
|
||||
}
|
||||
settle()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ export type TerminalAccessoryLayout = {
|
||||
orderedBuiltInIds: string[]
|
||||
visibleBuiltInIds: string[]
|
||||
directionPadEnabled?: boolean
|
||||
/** Agent keys at the front of the phone's key row; off unless the user turns it on. */
|
||||
smartRail?: boolean
|
||||
}
|
||||
|
||||
export type TerminalAccessoryLayoutPreference = TerminalAccessoryLayout & {
|
||||
@@ -29,7 +31,8 @@ function defaultPreference(
|
||||
visibleBuiltInIds: directionPadAvailable
|
||||
? ids.filter((id) => !id.startsWith('arrow'))
|
||||
: [...ids],
|
||||
directionPadEnabled: true
|
||||
directionPadEnabled: true,
|
||||
smartRail: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,11 +91,9 @@ export function getDefaultTerminalAccessoryBuiltInIds(): string[] {
|
||||
export function getDefaultTerminalAccessoryLayout(
|
||||
directionPadAvailable = false
|
||||
): TerminalAccessoryLayout {
|
||||
const { orderedBuiltInIds, visibleBuiltInIds, directionPadEnabled } = defaultPreference(
|
||||
builtInIds(),
|
||||
directionPadAvailable
|
||||
)
|
||||
return { orderedBuiltInIds, visibleBuiltInIds, directionPadEnabled }
|
||||
const { orderedBuiltInIds, visibleBuiltInIds, directionPadEnabled, smartRail } =
|
||||
defaultPreference(builtInIds(), directionPadAvailable)
|
||||
return { orderedBuiltInIds, visibleBuiltInIds, directionPadEnabled, smartRail }
|
||||
}
|
||||
|
||||
export function normalizeTerminalAccessoryLayoutPreference(
|
||||
@@ -110,7 +111,8 @@ export function normalizeTerminalAccessoryLayoutPreference(
|
||||
orderedBuiltInIds: 'orderedBuiltInIds' in value ? value.orderedBuiltInIds : undefined,
|
||||
visibleBuiltInIds: 'visibleBuiltInIds' in value ? value.visibleBuiltInIds : undefined,
|
||||
knownBuiltInIds: 'knownBuiltInIds' in value ? value.knownBuiltInIds : undefined,
|
||||
directionPadEnabled: 'directionPadEnabled' in value ? value.directionPadEnabled : undefined
|
||||
directionPadEnabled: 'directionPadEnabled' in value ? value.directionPadEnabled : undefined,
|
||||
smartRail: 'smartRail' in value ? value.smartRail : undefined
|
||||
}
|
||||
const builtInSet = new Set(currentBuiltInIds)
|
||||
|
||||
@@ -131,6 +133,7 @@ export function normalizeTerminalAccessoryLayoutPreference(
|
||||
return {
|
||||
version: 2,
|
||||
directionPadEnabled: candidate.directionPadEnabled !== false,
|
||||
smartRail: candidate.smartRail === true,
|
||||
orderedBuiltInIds: ordered,
|
||||
visibleBuiltInIds: ordered.filter((id) => visibleSet.has(id))
|
||||
}
|
||||
@@ -153,6 +156,7 @@ export function normalizeTerminalAccessoryLayoutPreference(
|
||||
return {
|
||||
version: 2,
|
||||
directionPadEnabled: candidate.directionPadEnabled !== false,
|
||||
smartRail: candidate.smartRail === true,
|
||||
orderedBuiltInIds: [...currentBuiltInIds],
|
||||
visibleBuiltInIds: currentBuiltInIds.filter((id) => visibleSet.has(id))
|
||||
}
|
||||
@@ -174,6 +178,7 @@ export function createTerminalAccessoryLayoutPreference(
|
||||
return {
|
||||
version: 2,
|
||||
directionPadEnabled: layout.directionPadEnabled !== false,
|
||||
smartRail: layout.smartRail === true,
|
||||
orderedBuiltInIds: ordered,
|
||||
visibleBuiltInIds: ordered.filter((id) => visibleSet.has(id))
|
||||
}
|
||||
@@ -189,6 +194,7 @@ export function setTerminalAccessoryBuiltInVisible(
|
||||
if (!new Set(currentBuiltInIds).has(id)) {
|
||||
return {
|
||||
directionPadEnabled: preference.directionPadEnabled,
|
||||
smartRail: preference.smartRail,
|
||||
orderedBuiltInIds: preference.orderedBuiltInIds,
|
||||
visibleBuiltInIds: preference.visibleBuiltInIds
|
||||
}
|
||||
@@ -201,6 +207,7 @@ export function setTerminalAccessoryBuiltInVisible(
|
||||
}
|
||||
return {
|
||||
directionPadEnabled: preference.directionPadEnabled,
|
||||
smartRail: preference.smartRail,
|
||||
orderedBuiltInIds: preference.orderedBuiltInIds,
|
||||
visibleBuiltInIds: preference.orderedBuiltInIds.filter((builtInId) => visibleSet.has(builtInId))
|
||||
}
|
||||
@@ -217,6 +224,7 @@ export function reorderTerminalAccessoryBuiltInIds(
|
||||
)
|
||||
return {
|
||||
directionPadEnabled: preference.directionPadEnabled,
|
||||
smartRail: preference.smartRail,
|
||||
orderedBuiltInIds: preference.orderedBuiltInIds,
|
||||
visibleBuiltInIds: preference.visibleBuiltInIds
|
||||
}
|
||||
@@ -236,22 +244,24 @@ export function getVisibleTerminalAccessoryKeys(
|
||||
})
|
||||
}
|
||||
|
||||
export async function loadTerminalAccessoryLayout(
|
||||
// Throws only when the store can't be read; a malformed value reads as the defaults.
|
||||
async function readTerminalAccessoryLayout(
|
||||
directionPadAvailable: boolean
|
||||
): Promise<TerminalAccessoryLayoutPreference> {
|
||||
const raw = await AsyncStorage.getItem(TERMINAL_ACCESSORY_LAYOUT_STORAGE_KEY)
|
||||
let stored: unknown = null
|
||||
try {
|
||||
stored = raw ? JSON.parse(raw) : null
|
||||
} catch {}
|
||||
return normalizeTerminalAccessoryLayoutPreference(stored, builtInIds(), directionPadAvailable)
|
||||
}
|
||||
|
||||
export function loadTerminalAccessoryLayout(
|
||||
directionPadAvailable = false
|
||||
): Promise<TerminalAccessoryLayoutPreference> {
|
||||
try {
|
||||
const raw = await AsyncStorage.getItem(TERMINAL_ACCESSORY_LAYOUT_STORAGE_KEY)
|
||||
if (!raw) {
|
||||
return defaultPreference(builtInIds(), directionPadAvailable)
|
||||
}
|
||||
return normalizeTerminalAccessoryLayoutPreference(
|
||||
JSON.parse(raw),
|
||||
builtInIds(),
|
||||
directionPadAvailable
|
||||
)
|
||||
} catch {
|
||||
return defaultPreference(builtInIds(), directionPadAvailable)
|
||||
}
|
||||
return readTerminalAccessoryLayout(directionPadAvailable).catch(() =>
|
||||
defaultPreference(builtInIds(), directionPadAvailable)
|
||||
)
|
||||
}
|
||||
|
||||
export async function saveTerminalAccessoryLayout(layout: TerminalAccessoryLayout): Promise<void> {
|
||||
@@ -259,3 +269,20 @@ export async function saveTerminalAccessoryLayout(layout: TerminalAccessoryLayou
|
||||
const value = JSON.stringify(preference)
|
||||
await persistMirrored(TERMINAL_ACCESSORY_LAYOUT_STORAGE_KEY, value)
|
||||
}
|
||||
|
||||
// Serialize read-modify-write so quick toggles land in order.
|
||||
let layoutWriteTurn: Promise<unknown> = Promise.resolve()
|
||||
|
||||
/** Turns the Smart rail on or off, keeping the rest of the stored layout. */
|
||||
export function saveTerminalSmartRail(
|
||||
enabled: boolean,
|
||||
directionPadAvailable = false
|
||||
): Promise<void> {
|
||||
const run = layoutWriteTurn.then(async () => {
|
||||
// A failed read must not save defaults over the user's layout.
|
||||
const layout = await readTerminalAccessoryLayout(directionPadAvailable)
|
||||
await saveTerminalAccessoryLayout({ ...layout, smartRail: enabled })
|
||||
})
|
||||
layoutWriteTurn = run.catch(() => {})
|
||||
return run
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
type MessagePortMain
|
||||
} from 'electron'
|
||||
import { abortWhenRendererGone } from './renderer-lifetime-abort'
|
||||
import { mergeDictationTerms } from '../../shared/dictation-dictionary'
|
||||
import { dictationTermsFor } from '../../shared/dictation-dictionary'
|
||||
import { SPEECH_MODEL_CATALOG } from '../speech/model-catalog'
|
||||
import { deleteLocalSpeechModel } from '../speech/speech-model-deletion'
|
||||
import { getSpeechModelManager, getSpeechSttService } from '../speech/speech-runtime-service'
|
||||
@@ -220,7 +220,10 @@ export function registerSpeechHandlers(store: Store): void {
|
||||
break
|
||||
}
|
||||
},
|
||||
mergeDictationTerms(context?.repoTerms, store.getSettings().voice?.dictationTerms),
|
||||
dictationTermsFor(store.getSettings().voice, {
|
||||
dictationTerms: context?.repoTerms,
|
||||
displayName: context?.repoName
|
||||
}),
|
||||
owner,
|
||||
store.getSettings().voice
|
||||
)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { mergeDictationTerms, type DictationTerm } from '../../../shared/dictation-dictionary'
|
||||
import { dictationTermsFor, type DictationTerm } from '../../../shared/dictation-dictionary'
|
||||
import { getRepoIdFromWorktreeId } from '../../../shared/worktree/id'
|
||||
import type { RuntimeStore } from '../construction/runtime-store-contract'
|
||||
|
||||
/** This host's dictionary for a worktree: its repo's terms, then the personal ones. A folder workspace has no repo row, so it gets the personal ones. */
|
||||
/** This host's dictionary for a worktree; a folder workspace has no repo row, so it gets the personal terms. */
|
||||
export function hostDictationTerms(
|
||||
store: RuntimeStore,
|
||||
worktreeId: string | undefined
|
||||
): DictationTerm[] {
|
||||
const repo = worktreeId ? store.getRepo(getRepoIdFromWorktreeId(worktreeId)) : undefined
|
||||
return mergeDictationTerms(repo?.dictationTerms, store.getSettings().voice?.dictationTerms)
|
||||
return dictationTermsFor(store.getSettings().voice, repo)
|
||||
}
|
||||
|
||||
@@ -69,7 +69,9 @@ export class RuntimeMobileSpeechCatalog {
|
||||
dictationMode: voice.dictationMode === 'hold' ? 'hold' : 'toggle',
|
||||
dictationHoldToRecord: voice.dictationHoldToRecord !== false,
|
||||
removeFillerWords: voice.removeFillerWords !== false,
|
||||
dictationTerms: hostDictationTerms(store, worktreeId),
|
||||
// The phone has no Whisper prompt to bias, and its text pass would only join the name; keeping the
|
||||
// hint out also spares a phone page from before hints, which would treat the name as a full term.
|
||||
dictationTerms: hostDictationTerms(store, worktreeId).filter((entry) => !entry.hint),
|
||||
models
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@ export function downloadSileroVadInBackground(models: Pick<ModelManager, 'downlo
|
||||
// Settings never lists the VAD, so once its file is in place it stays; only a new models folder rechecks.
|
||||
let verifiedVadPath: string | undefined
|
||||
|
||||
/** The downloaded Silero VAD file; when it's missing, starts fetching it and returns undefined. */
|
||||
export function sileroVadModelPath(
|
||||
models: Pick<ModelManager, 'downloadModel' | 'getModelDir'>
|
||||
): string | undefined {
|
||||
function placedSileroVadPath(models: Pick<ModelManager, 'getModelDir'>): string | undefined {
|
||||
const [file] = SILERO_VAD_MODEL.downloadFiles
|
||||
const path = join(models.getModelDir(SILERO_VAD_MODEL.id), file.name)
|
||||
if (path === verifiedVadPath) {
|
||||
@@ -36,6 +33,24 @@ export function sileroVadModelPath(
|
||||
} catch {
|
||||
// Not downloaded yet, e.g. the model came before VAD support.
|
||||
}
|
||||
downloadSileroVadInBackground(models)
|
||||
return undefined
|
||||
}
|
||||
|
||||
/** Whether a model-state change for `modelId` means the Silero VAD file is now in place. */
|
||||
export function sileroVadLanded(
|
||||
models: Pick<ModelManager, 'getModelDir'>,
|
||||
modelId: string
|
||||
): boolean {
|
||||
return modelId === SILERO_VAD_MODEL.id && placedSileroVadPath(models) !== undefined
|
||||
}
|
||||
|
||||
/** The downloaded Silero VAD file; when it's missing, starts fetching it and returns undefined. */
|
||||
export function sileroVadModelPath(
|
||||
models: Pick<ModelManager, 'downloadModel' | 'getModelDir'>
|
||||
): string | undefined {
|
||||
const path = placedSileroVadPath(models)
|
||||
if (!path) {
|
||||
downloadSileroVadInBackground(models)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import type { ModelManager } from './model-manager'
|
||||
import type { SpeechModelState } from '../../shared/speech-types'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { beforeEach, describe, expect, it, onTestFinished, vi } from 'vitest'
|
||||
|
||||
const { MockWorker, getCreatedWorkerCount, getLastWorker, resetWorkers } = vi.hoisted(() => {
|
||||
class HoistedMockWorker extends EventTarget {
|
||||
@@ -104,9 +107,16 @@ const stoppedReply = (worker: InstanceType<typeof MockWorker>) => ({
|
||||
streamId: worker.messages.findLast((message) => message.type === 'stop')?.streamId
|
||||
})
|
||||
|
||||
const testModels = (models: Pick<ModelManager, 'getModelState' | 'getModelDir'>): ModelManager =>
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: SttService reads getModelState and getModelDir, and fetches the VAD with downloadModel.
|
||||
({ ...models, downloadModel: vi.fn().mockResolvedValue(undefined) }) as never
|
||||
const testModels = (
|
||||
models: Pick<ModelManager, 'getModelState' | 'getModelDir'>,
|
||||
onModelStateChange: ModelManager['setProgressCallback'] = () => () => {}
|
||||
): ModelManager =>
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: SttService reads getModelState and getModelDir, fetches the VAD with downloadModel and watches it land.
|
||||
({
|
||||
...models,
|
||||
downloadModel: vi.fn().mockResolvedValue(undefined),
|
||||
setProgressCallback: onModelStateChange
|
||||
}) as never
|
||||
|
||||
const readyModels = (): ModelManager =>
|
||||
testModels({
|
||||
@@ -122,6 +132,7 @@ async function flushMicrotasks(): Promise<void> {
|
||||
}
|
||||
|
||||
vi.mock('./model-catalog', () => ({
|
||||
isLocalSpeechModel: (manifest: { provider: string }) => manifest.provider === 'local',
|
||||
getCatalogModel: (id: string) =>
|
||||
id === 'openai-model'
|
||||
? {
|
||||
@@ -174,6 +185,31 @@ describe('SttService', () => {
|
||||
resetWorkers()
|
||||
})
|
||||
|
||||
it('reloads a recognizer loaded before the VAD landed once the dictation using it ends', async () => {
|
||||
const modelsDir = mkdtempSync(join(tmpdir(), 'stt-vad-'))
|
||||
onTestFinished(() => rmSync(modelsDir, { recursive: true, force: true }))
|
||||
const watchModels = vi.fn<ModelManager['setProgressCallback']>(() => () => {})
|
||||
const models = testModels(
|
||||
{ getModelState: readyModels().getModelState, getModelDir: (id) => join(modelsDir, id) },
|
||||
watchModels
|
||||
)
|
||||
const service = new SttService(models, spawnMockWorker)
|
||||
await service.startDictation('model-a', vi.fn<SttEventSink>(), undefined, 'desktop')
|
||||
const initOf = (worker = getLastWorker()) => worker?.messages.find((m) => m.type === 'init')
|
||||
expect(initOf()).toMatchObject({ vadModelPath: undefined })
|
||||
|
||||
const vadPath = join(modelsDir, 'silero-vad-v6.2', 'silero-vad-v6.2-F32.gguf')
|
||||
mkdirSync(join(modelsDir, 'silero-vad-v6.2'))
|
||||
writeFileSync(vadPath, Buffer.alloc(1_241_056))
|
||||
watchModels.mock.calls[0]?.[0]('silero-vad-v6.2', -1)
|
||||
await flushMicrotasks()
|
||||
expect(getCreatedWorkerCount()).toBe(1)
|
||||
|
||||
await service.stopDictation('desktop')
|
||||
await vi.waitFor(() => expect(getCreatedWorkerCount()).toBe(2))
|
||||
expect(initOf()).toMatchObject({ vadModelPath: vadPath })
|
||||
})
|
||||
|
||||
it('gives each device dictating at once only its own text from one recognizer', async () => {
|
||||
const service = new SttService(readyModels(), spawnMockWorker)
|
||||
const desktop = vi.fn<SttEventSink>()
|
||||
@@ -739,15 +775,19 @@ describe('SttService', () => {
|
||||
async (event) => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const models: Pick<ModelManager, 'getModelState' | 'getModelDir' | 'downloadModel'> = {
|
||||
const models: Pick<
|
||||
ModelManager,
|
||||
'getModelState' | 'getModelDir' | 'downloadModel' | 'setProgressCallback'
|
||||
> = {
|
||||
getModelState: vi.fn<ModelManager['getModelState']>().mockResolvedValue({
|
||||
id: 'model-a',
|
||||
status: 'ready'
|
||||
}),
|
||||
getModelDir: vi.fn<ModelManager['getModelDir']>().mockReturnValue('/tmp/model-a'),
|
||||
downloadModel: vi.fn().mockResolvedValue(undefined)
|
||||
downloadModel: vi.fn().mockResolvedValue(undefined),
|
||||
setProgressCallback: () => () => {}
|
||||
}
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: This lifecycle reads getModelState/getModelDir and downloadModel (VAD) on the model manager.
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: This lifecycle reads getModelState/getModelDir, downloadModel (VAD) and setProgressCallback on the model manager.
|
||||
const service = new SttService(models as ModelManager, spawnMockWorker)
|
||||
const sink = vi.fn<SttEventSink>()
|
||||
await service.startDictation('model-a', sink, undefined, 'desktop')
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from '../../shared/dictation-text-pipeline'
|
||||
import { getCatalogModel } from './model-catalog'
|
||||
import type { ModelManager } from './model-manager'
|
||||
import { sileroVadLanded } from './speech-vad-model'
|
||||
import type { SpawnSttWorkerProcess } from './stt-worker-process'
|
||||
import { prewarmSttModel } from './stt-session-prewarm'
|
||||
import { startSttDictation } from './stt-session-start'
|
||||
@@ -45,9 +46,30 @@ export class SttService {
|
||||
|
||||
constructor(modelManager: ModelManager, spawnWorker: SpawnSttWorkerProcess) {
|
||||
this.state = createSttSessionState(modelManager, spawnWorker)
|
||||
modelManager.setProgressCallback((modelId) => {
|
||||
if (sileroVadLanded(modelManager, modelId)) {
|
||||
void this.reloadForVad()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** `terms`: the dictionary for where this dictation goes, repo terms first (mergeDictationTerms). */
|
||||
/** A recognizer loaded before the VAD landed cuts text only at stop; reload it once no dictation uses it. */
|
||||
private async reloadForVad(): Promise<void> {
|
||||
const engine = this.state.engine
|
||||
if (!engine || engine.retired || engine.vadModelPath) {
|
||||
return
|
||||
}
|
||||
const { modelId, language } = engine
|
||||
const unloaded = this.unloadModelWhenIdle()
|
||||
const generation = this.state.prewarmGeneration
|
||||
await unloaded
|
||||
// A newer pre-warm or a dictation took over; loading is theirs now.
|
||||
if (this.state.prewarmGeneration === generation && !this.state.engine) {
|
||||
await this.prewarm(modelId, language)
|
||||
}
|
||||
}
|
||||
|
||||
/** `terms`: the dictionary for where this dictation goes, repo terms first (dictationTermsFor). */
|
||||
startDictation(
|
||||
modelId: string,
|
||||
sink: SttEventSink,
|
||||
|
||||
@@ -187,7 +187,7 @@ export function spawnSttEngine(
|
||||
if (!speechModulesDir) {
|
||||
throw new Error(LOCAL_SPEECH_UNAVAILABLE_ERROR)
|
||||
}
|
||||
// A VAD fetched now serves the next engine start.
|
||||
// A VAD fetched now reloads this engine once it is idle (SttService).
|
||||
const vadModelPath = sileroVadModelPath(state.modelManager)
|
||||
clearSttIdleTeardownTimer(state)
|
||||
const worker = state.spawnWorker()
|
||||
@@ -210,6 +210,7 @@ export function spawnSttEngine(
|
||||
worker,
|
||||
detach,
|
||||
retired: false,
|
||||
vadModelPath,
|
||||
onUnloaded: [],
|
||||
ready: readyPromise.catch((error: unknown) => {
|
||||
failSttEngine(state, engine, STT_WORKER_EXITED_ERROR)
|
||||
|
||||
@@ -19,6 +19,8 @@ export type SttEngine = SttRecognizerConfig & {
|
||||
detach: () => void
|
||||
/** Torn down on purpose, so a load it cut short is not a failure of the model. */
|
||||
retired: boolean
|
||||
/** Absent when the VAD wasn't downloaded yet at load, so this process cuts text only at stop. */
|
||||
vadModelPath: string | undefined
|
||||
/** Called once this process is gone; set when it must not outlive its last dictation. */
|
||||
onUnloaded: (() => void)[]
|
||||
}
|
||||
|
||||
@@ -11,5 +11,9 @@ export function captureDictationContext(): DictationContext {
|
||||
return {}
|
||||
}
|
||||
const repo = selectRepoByIdForActiveWorkspace(state, getRepoIdFromWorktreeId(worktreeId))
|
||||
return { worktreeId, ...(repo?.dictationTerms ? { repoTerms: repo.dictationTerms } : {}) }
|
||||
return {
|
||||
worktreeId,
|
||||
...(repo?.dictationTerms ? { repoTerms: repo.dictationTerms } : {}),
|
||||
...(repo ? { repoName: repo.displayName } : {})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { OpenAiCompatibleProviderDialog } from './OpenAiCompatibleProviderDialog
|
||||
import { OpenAiTranscriptionSettingsRow } from './OpenAiTranscriptionSettingsRow'
|
||||
import { handleVoiceDictationToggle } from './voice-dictation-toggle'
|
||||
import { VoiceDictationLanguageSetting } from './VoiceDictationLanguageSetting'
|
||||
import { VoiceVocabularySetting } from './VoiceVocabularySetting'
|
||||
import { VOICE_MICROPHONE_ROW_ID, VoiceInputSettings } from './VoiceInputSettings'
|
||||
import { VoiceSetupCard } from './VoiceSetupCard'
|
||||
import { cancelSpeechModelDownload, startSpeechModelDownload } from './speech-model-download'
|
||||
@@ -331,6 +332,13 @@ export function VoicePane({ settings, updateSettings }: VoicePaneProps): React.J
|
||||
|
||||
<Separator />
|
||||
|
||||
<VoiceVocabularySetting
|
||||
voiceSettings={voiceSettings}
|
||||
onUpdateVoiceSettings={updateVoiceSettings}
|
||||
/>
|
||||
|
||||
<Separator />
|
||||
|
||||
<div className="space-y-1">
|
||||
<SettingsSubsectionHeader title={t('components.settings.voice.cleanup.title', 'Cleanup')} />
|
||||
<SettingsSwitchRow
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
import { useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import { Plus, X } from 'lucide-react'
|
||||
import type { VoiceSettings } from '../../../../../shared/speech-types'
|
||||
import {
|
||||
MAX_DICTATION_TERMS,
|
||||
MAX_DICTATION_TERM_LENGTH,
|
||||
type DictationTerm
|
||||
} from '../../../../../shared/dictation-dictionary'
|
||||
import { getRepoExecutionHostId, type ExecutionHostId } from '../../../../../shared/execution-host'
|
||||
import { useAppStore } from '@/store'
|
||||
import { selectRepoByIdForActiveWorkspace } from '@/store/repos/active-workspace-repository'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { Button } from '../../ui/button'
|
||||
import { Input } from '../../ui/input'
|
||||
import {
|
||||
SettingsSegmentedControl,
|
||||
SettingsSubsectionHeader,
|
||||
SettingsSwitchRow
|
||||
} from '../form-controls/SettingsFormControls'
|
||||
|
||||
type VocabularyScope = 'personal' | 'repo'
|
||||
|
||||
type VoiceVocabularySettingProps = {
|
||||
voiceSettings: VoiceSettings
|
||||
onUpdateVoiceSettings: (updates: Partial<VoiceSettings>) => void
|
||||
}
|
||||
|
||||
const NO_TERMS: readonly DictationTerm[] = []
|
||||
|
||||
export function VoiceVocabularySetting({
|
||||
voiceSettings,
|
||||
onUpdateVoiceSettings
|
||||
}: VoiceVocabularySettingProps): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
// The repo you're working in; a folder workspace has none, so only personal terms show.
|
||||
const repo = useAppStore((s) => selectRepoByIdForActiveWorkspace(s, s.activeRepoId))
|
||||
const updateRepo = useAppStore((s) => s.updateRepo)
|
||||
const [chosenScope, setScope] = useState<VocabularyScope>('personal')
|
||||
// A repo write is a round trip (RPC for a remote host); the next edit builds on it, not on the stored list.
|
||||
const [pending, setPending] = useState<{
|
||||
repoId: string
|
||||
hostId: ExecutionHostId
|
||||
terms: DictationTerm[]
|
||||
} | null>(null)
|
||||
const scope = repo ? chosenScope : 'personal'
|
||||
const personalTerms = voiceSettings.dictationTerms ?? NO_TERMS
|
||||
const repoTerms =
|
||||
pending && repo && pending.repoId === repo.id && pending.hostId === getRepoExecutionHostId(repo)
|
||||
? pending.terms
|
||||
: (repo?.dictationTerms ?? NO_TERMS)
|
||||
const terms = scope === 'repo' ? repoTerms : personalTerms
|
||||
|
||||
const saveRepoTerms = async (
|
||||
repoId: string,
|
||||
hostId: ExecutionHostId,
|
||||
next: DictationTerm[]
|
||||
): Promise<void> => {
|
||||
const write = { repoId, hostId, terms: next }
|
||||
setPending(write)
|
||||
if (!(await updateRepo(repoId, { dictationTerms: next }, { hostId }))) {
|
||||
toast.error(
|
||||
t(
|
||||
'components.settings.voice.vocabulary.repoSaveFailed',
|
||||
"Couldn't save the repo's terms. The host running this repo may need an Orca update."
|
||||
)
|
||||
)
|
||||
}
|
||||
setPending((current) => (current === write ? null : current))
|
||||
}
|
||||
|
||||
const saveTerms = (next: DictationTerm[]): void => {
|
||||
if (scope === 'repo' && repo) {
|
||||
void saveRepoTerms(repo.id, getRepoExecutionHostId(repo), next)
|
||||
} else {
|
||||
onUpdateVoiceSettings({ dictationTerms: next })
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<SettingsSubsectionHeader
|
||||
title={t('components.settings.voice.vocabulary.title', 'Vocabulary')}
|
||||
description={t(
|
||||
'components.settings.voice.vocabulary.description',
|
||||
'Names and code terms to spell your way. Add what the model mishears it as, if it keeps getting it wrong.'
|
||||
)}
|
||||
/>
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{scope === 'repo' && repo
|
||||
? t(
|
||||
'components.settings.voice.vocabulary.repoScope',
|
||||
'Only used while you dictate in {{repo}}.',
|
||||
{ repo: repo.displayName }
|
||||
)
|
||||
: t('components.settings.voice.vocabulary.personalScope', 'Used in every repo.')}
|
||||
</p>
|
||||
{repo ? (
|
||||
<SettingsSegmentedControl
|
||||
size="sm"
|
||||
value={scope}
|
||||
onChange={setScope}
|
||||
ariaLabel={t('components.settings.voice.vocabulary.scope', 'Terms for')}
|
||||
options={[
|
||||
{
|
||||
value: 'personal',
|
||||
label: t('components.settings.voice.vocabulary.personal', 'Personal · {{total}}', {
|
||||
total: chipsBySpelling(personalTerms).length
|
||||
})
|
||||
},
|
||||
{
|
||||
value: 'repo',
|
||||
label: t('components.settings.voice.vocabulary.repo', '{{repo}} · {{total}}', {
|
||||
repo: repo.displayName,
|
||||
total: chipsBySpelling(repoTerms).length
|
||||
})
|
||||
}
|
||||
]}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
{terms.length > 0 ? (
|
||||
<ul className="flex flex-wrap gap-1.5">
|
||||
{chipsBySpelling(terms).map((chip) => (
|
||||
<VocabularyChip
|
||||
key={chip.term}
|
||||
chip={chip}
|
||||
onRemove={() => saveTerms(terms.filter((entry) => entry.term !== chip.term))}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
<VocabularyAddRow
|
||||
full={terms.length >= MAX_DICTATION_TERMS}
|
||||
onAdd={(entry) => {
|
||||
// A term already keys its own spelling, so a bare one needs no second entry.
|
||||
const exists = terms.some(
|
||||
(other) =>
|
||||
other.term === entry.term && (!entry.heardAs || other.heardAs === entry.heardAs)
|
||||
)
|
||||
if (!exists) {
|
||||
saveTerms([...terms, entry])
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<SettingsSwitchRow
|
||||
label={t(
|
||||
'components.settings.voice.vocabulary.repoNameHint',
|
||||
'Use the repo name as a hint'
|
||||
)}
|
||||
description={t(
|
||||
'components.settings.voice.vocabulary.repoNameHintDescription',
|
||||
"Helps recognize the repo's name."
|
||||
)}
|
||||
checked={voiceSettings.dictationRepoNameHint !== false}
|
||||
onChange={() =>
|
||||
onUpdateVoiceSettings({
|
||||
dictationRepoNameHint: voiceSettings.dictationRepoNameHint === false
|
||||
})
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
type VocabularyChipModel = { term: string; aliases: string[] }
|
||||
|
||||
// One chip per spelling: the stored list keeps one entry per "heard as".
|
||||
function chipsBySpelling(terms: readonly DictationTerm[]): VocabularyChipModel[] {
|
||||
const chips = new Map<string, VocabularyChipModel>()
|
||||
for (const { term, heardAs } of terms) {
|
||||
const chip = chips.get(term) ?? { term, aliases: [] }
|
||||
if (heardAs) {
|
||||
chip.aliases.push(heardAs)
|
||||
}
|
||||
chips.set(term, chip)
|
||||
}
|
||||
return [...chips.values()]
|
||||
}
|
||||
|
||||
function VocabularyChip({
|
||||
chip,
|
||||
onRemove
|
||||
}: {
|
||||
chip: VocabularyChipModel
|
||||
onRemove: () => void
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
return (
|
||||
<li className="inline-flex items-center gap-1.5 rounded-full border border-border bg-background py-0.5 pr-1 pl-2.5 text-xs">
|
||||
<span>{chip.term}</span>
|
||||
{chip.aliases.length > 0 ? (
|
||||
<span className="text-muted-foreground">
|
||||
{t('components.settings.voice.vocabulary.heardAsChip', '← {{heardAs}}', {
|
||||
heardAs: chip.aliases.join(', ')
|
||||
})}
|
||||
</span>
|
||||
) : null}
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-xs-round"
|
||||
className="size-4.5"
|
||||
aria-label={t('components.settings.voice.vocabulary.remove', 'Remove {{term}}', {
|
||||
term: chip.term
|
||||
})}
|
||||
onClick={onRemove}
|
||||
>
|
||||
<X />
|
||||
</Button>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
function VocabularyAddRow({
|
||||
full,
|
||||
onAdd
|
||||
}: {
|
||||
full: boolean
|
||||
onAdd: (entry: DictationTerm) => void
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const [term, setTerm] = useState('')
|
||||
const [heardAs, setHeardAs] = useState('')
|
||||
const canAdd = !full && term.trim() !== ''
|
||||
|
||||
const add = (): void => {
|
||||
if (!canAdd) {
|
||||
return
|
||||
}
|
||||
onAdd({ term: term.trim(), ...(heardAs.trim() ? { heardAs: heardAs.trim() } : {}) })
|
||||
setTerm('')
|
||||
setHeardAs('')
|
||||
}
|
||||
const addOnEnter = (event: React.KeyboardEvent<HTMLInputElement>): void => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault()
|
||||
add()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Input
|
||||
className="h-8 min-w-36 flex-1"
|
||||
value={term}
|
||||
maxLength={MAX_DICTATION_TERM_LENGTH}
|
||||
placeholder={t('components.settings.voice.vocabulary.term', 'Word or phrase')}
|
||||
aria-label={t('components.settings.voice.vocabulary.term', 'Word or phrase')}
|
||||
onChange={(event) => setTerm(event.target.value)}
|
||||
onKeyDown={addOnEnter}
|
||||
/>
|
||||
<Input
|
||||
className="h-8 min-w-36 flex-1"
|
||||
value={heardAs}
|
||||
maxLength={MAX_DICTATION_TERM_LENGTH}
|
||||
placeholder={t('components.settings.voice.vocabulary.heardAs', 'Heard as (optional)')}
|
||||
aria-label={t('components.settings.voice.vocabulary.heardAsLabel', 'Heard as')}
|
||||
onChange={(event) => setHeardAs(event.target.value)}
|
||||
onKeyDown={addOnEnter}
|
||||
/>
|
||||
<Button type="button" variant="outline" size="sm" disabled={!canAdd} onClick={add}>
|
||||
<Plus className="size-3.5" />
|
||||
{t('components.settings.voice.vocabulary.add', 'Add')}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -120,6 +120,24 @@ export const getVoicePaneSearchEntries = createLocalizedCatalog(() => [
|
||||
...translateSearchKeyword('auto.components.settings.voice.pane.search.10d45a9fce', 'stt')
|
||||
]
|
||||
},
|
||||
{
|
||||
title: translate('auto.components.settings.voice.pane.search.vocabularyTitle', 'Vocabulary'),
|
||||
description: translate(
|
||||
'auto.components.settings.voice.pane.search.vocabularyDescription',
|
||||
'Names and code terms dictation spells your way, for you or for one repo.'
|
||||
),
|
||||
keywords: [
|
||||
...translateSearchKeyword('auto.components.settings.voice.pane.search.7640ed9848', 'voice'),
|
||||
...translateSearchKeyword(
|
||||
'auto.components.settings.voice.pane.search.089d31a45b',
|
||||
'dictation'
|
||||
),
|
||||
...translateSearchKeyword(
|
||||
'auto.components.settings.voice.pane.search.vocabularyKeyword',
|
||||
'dictionary'
|
||||
)
|
||||
]
|
||||
},
|
||||
{
|
||||
title: translate(
|
||||
'auto.components.settings.voice.pane.search.fillerWordsTitle',
|
||||
|
||||
@@ -11299,7 +11299,10 @@
|
||||
"modelMemoryKeyword": "speicher",
|
||||
"fillerWordsTitle": "Füllwörter entfernen",
|
||||
"fillerWordsDescription": "Entfernt „äh“, „ähm“ und ähnliche Laute aus diktiertem Text.",
|
||||
"fillerWordsKeyword": "füllwörter"
|
||||
"fillerWordsKeyword": "füllwörter",
|
||||
"vocabularyTitle": "Wortschatz",
|
||||
"vocabularyDescription": "Namen und Code-Begriffe, die das Diktat auf deine Weise schreibt, für dich oder ein Repo.",
|
||||
"vocabularyKeyword": "wörterbuch"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -20746,6 +20749,24 @@
|
||||
"local": "Auf diesem Computer",
|
||||
"cloudDescription": "Cloud-Modelle senden deine Audiodaten an den Anbieter. Modelle auf diesem Computer behalten sie hier.",
|
||||
"sendsToCompatible": "Sendet deine Audiodaten an den Dienst, den du eingerichtet hast."
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "Wortschatz",
|
||||
"description": "Namen und Code-Begriffe, die du auf deine Weise geschrieben haben willst. Gib an, wie das Modell sie falsch hört, wenn es sie immer wieder verwechselt.",
|
||||
"repoScope": "Nur beim Diktieren in {{repo}}.",
|
||||
"personalScope": "In jedem Repo.",
|
||||
"scope": "Begriffe für",
|
||||
"personal": "Persönlich · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "{{term}} entfernen",
|
||||
"term": "Wort oder Wendung",
|
||||
"heardAs": "Gehört als (optional)",
|
||||
"heardAsLabel": "Gehört als",
|
||||
"add": "Hinzufügen",
|
||||
"repoNameHint": "Repo-Namen als Hinweis verwenden",
|
||||
"repoNameHintDescription": "Hilft, den Namen des Repos zu erkennen.",
|
||||
"repoSaveFailed": "Die Begriffe des Repos konnten nicht gespeichert werden. Auf dem Host dieses Repos ist eventuell ein Orca-Update nötig."
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -11635,7 +11635,10 @@
|
||||
"modelMemoryKeyword": "memory",
|
||||
"fillerWordsTitle": "Remove Filler Words",
|
||||
"fillerWordsDescription": "Drop “um”, “uh” and similar sounds from dictated text.",
|
||||
"fillerWordsKeyword": "filler words"
|
||||
"fillerWordsKeyword": "filler words",
|
||||
"vocabularyTitle": "Vocabulary",
|
||||
"vocabularyDescription": "Names and code terms dictation spells your way, for you or for one repo.",
|
||||
"vocabularyKeyword": "dictionary"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -21445,6 +21448,24 @@
|
||||
"where": "Where models run",
|
||||
"local": "On this computer",
|
||||
"cloudDescription": "Cloud models send your audio to the provider. Models on this computer keep it here."
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "Vocabulary",
|
||||
"description": "Names and code terms to spell your way. Add what the model mishears it as, if it keeps getting it wrong.",
|
||||
"repoScope": "Only used while you dictate in {{repo}}.",
|
||||
"personalScope": "Used in every repo.",
|
||||
"scope": "Terms for",
|
||||
"personal": "Personal · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "Remove {{term}}",
|
||||
"term": "Word or phrase",
|
||||
"heardAs": "Heard as (optional)",
|
||||
"heardAsLabel": "Heard as",
|
||||
"add": "Add",
|
||||
"repoNameHint": "Use the repo name as a hint",
|
||||
"repoNameHintDescription": "Helps recognize the repo's name.",
|
||||
"repoSaveFailed": "Couldn't save the repo's terms. The host running this repo may need an Orca update."
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -10882,7 +10882,10 @@
|
||||
"modelMemoryKeyword": "memoria",
|
||||
"fillerWordsTitle": "Quitar muletillas",
|
||||
"fillerWordsDescription": "Quita «ehm», «em» y sonidos parecidos del texto dictado.",
|
||||
"fillerWordsKeyword": "muletillas"
|
||||
"fillerWordsKeyword": "muletillas",
|
||||
"vocabularyTitle": "Vocabulario",
|
||||
"vocabularyDescription": "Nombres y términos de código que el dictado escribe a tu manera, para ti o para un repo.",
|
||||
"vocabularyKeyword": "diccionario"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -20534,6 +20537,24 @@
|
||||
"local": "En este equipo",
|
||||
"cloudDescription": "Los modelos en la nube envían tu audio al proveedor. Los de este equipo lo mantienen aquí.",
|
||||
"sendsToCompatible": "Envía tu audio al servicio que configuraste."
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "Vocabulario",
|
||||
"description": "Nombres y términos de código que se escriben a tu manera. Añade cómo lo oye mal el modelo si se equivoca una y otra vez.",
|
||||
"repoScope": "Solo se usa al dictar en {{repo}}.",
|
||||
"personalScope": "Se usa en todos los repos.",
|
||||
"scope": "Términos para",
|
||||
"personal": "Personal · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "Quitar {{term}}",
|
||||
"term": "Palabra o frase",
|
||||
"heardAs": "Se oye como (opcional)",
|
||||
"heardAsLabel": "Se oye como",
|
||||
"add": "Añadir",
|
||||
"repoNameHint": "Usar el nombre del repo como pista",
|
||||
"repoNameHintDescription": "Ayuda a reconocer el nombre del repo.",
|
||||
"repoSaveFailed": "No se pudieron guardar los términos del repo. Puede que el host de este repo necesite actualizar Orca."
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -11167,7 +11167,10 @@
|
||||
"modelMemoryKeyword": "mémoire",
|
||||
"fillerWordsTitle": "Supprimer les hésitations",
|
||||
"fillerWordsDescription": "Supprime « euh », « hum » et les sons similaires du texte dicté.",
|
||||
"fillerWordsKeyword": "hésitations"
|
||||
"fillerWordsKeyword": "hésitations",
|
||||
"vocabularyTitle": "Vocabulaire",
|
||||
"vocabularyDescription": "Noms et termes de code que la dictée écrit à votre façon, pour vous ou pour un dépôt.",
|
||||
"vocabularyKeyword": "dictionnaire"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -20851,6 +20854,24 @@
|
||||
"local": "Sur cet ordinateur",
|
||||
"cloudDescription": "Les modèles cloud envoient votre audio au fournisseur. Ceux de cet ordinateur le gardent ici.",
|
||||
"sendsToCompatible": "Envoie votre audio au service que vous avez configuré."
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "Vocabulaire",
|
||||
"description": "Noms et termes de code à écrire à votre façon. Ajoutez ce que le modèle entend à la place s’il se trompe toujours.",
|
||||
"repoScope": "Utilisé seulement quand vous dictez dans {{repo}}.",
|
||||
"personalScope": "Utilisé dans tous les dépôts.",
|
||||
"scope": "Termes pour",
|
||||
"personal": "Personnel · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "Retirer {{term}}",
|
||||
"term": "Mot ou expression",
|
||||
"heardAs": "Entendu comme (facultatif)",
|
||||
"heardAsLabel": "Entendu comme",
|
||||
"add": "Ajouter",
|
||||
"repoNameHint": "Utiliser le nom du dépôt comme indice",
|
||||
"repoNameHintDescription": "Aide à reconnaître le nom du dépôt.",
|
||||
"repoSaveFailed": "Impossible d’enregistrer les termes du dépôt. L’hôte de ce dépôt doit peut-être mettre Orca à jour."
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -10626,7 +10626,10 @@
|
||||
"modelMemoryKeyword": "メモリ",
|
||||
"fillerWordsTitle": "フィラーを削除",
|
||||
"fillerWordsDescription": "「えーと」「うーん」などのつなぎ言葉を音声入力のテキストから取り除きます。",
|
||||
"fillerWordsKeyword": "フィラー"
|
||||
"fillerWordsKeyword": "フィラー",
|
||||
"vocabularyTitle": "語彙",
|
||||
"vocabularyDescription": "音声入力が自分の書き方で表記する名前やコード用語。個人用またはリポジトリ用。",
|
||||
"vocabularyKeyword": "辞書"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -20027,6 +20030,24 @@
|
||||
"local": "このコンピューター",
|
||||
"cloudDescription": "クラウドモデルは音声をプロバイダーに送信します。このコンピューター上のモデルなら音声は外に出ません。",
|
||||
"sendsToCompatible": "音声を設定したサービスに送信します。"
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "語彙",
|
||||
"description": "名前やコード用語を自分の書き方で入力します。モデルが繰り返し聞き間違える場合は、聞き取られる言い方も追加してください。",
|
||||
"repoScope": "{{repo}} で音声入力するときだけ使います。",
|
||||
"personalScope": "すべてのリポジトリで使います。",
|
||||
"scope": "用語の対象",
|
||||
"personal": "個人 · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "{{term}} を削除",
|
||||
"term": "単語またはフレーズ",
|
||||
"heardAs": "聞き取られ方(任意)",
|
||||
"heardAsLabel": "聞き取られ方",
|
||||
"add": "追加",
|
||||
"repoNameHint": "リポジトリ名をヒントとして使う",
|
||||
"repoNameHintDescription": "リポジトリ名を認識しやすくします。",
|
||||
"repoSaveFailed": "リポジトリの用語を保存できませんでした。このリポジトリのホストで Orca の更新が必要かもしれません。"
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -10589,7 +10589,10 @@
|
||||
"modelMemoryKeyword": "메모리",
|
||||
"fillerWordsTitle": "군말 제거",
|
||||
"fillerWordsDescription": "받아쓴 텍스트에서 “음”, “흠” 같은 소리를 지웁니다.",
|
||||
"fillerWordsKeyword": "군말"
|
||||
"fillerWordsKeyword": "군말",
|
||||
"vocabularyTitle": "어휘",
|
||||
"vocabularyDescription": "받아쓰기가 원하는 대로 표기하는 이름과 코드 용어, 개인용 또는 저장소용.",
|
||||
"vocabularyKeyword": "사전"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -20027,6 +20030,24 @@
|
||||
"local": "이 컴퓨터",
|
||||
"cloudDescription": "클라우드 모델은 오디오를 제공업체로 보냅니다. 이 컴퓨터의 모델은 오디오를 밖으로 보내지 않습니다.",
|
||||
"sendsToCompatible": "오디오를 설정한 서비스로 보냅니다."
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "어휘",
|
||||
"description": "원하는 대로 표기할 이름과 코드 용어입니다. 모델이 계속 잘못 들으면 잘못 들리는 말도 추가하세요.",
|
||||
"repoScope": "{{repo}}에서 받아쓸 때만 사용합니다.",
|
||||
"personalScope": "모든 저장소에서 사용합니다.",
|
||||
"scope": "용어 대상",
|
||||
"personal": "개인 · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "{{term}} 삭제",
|
||||
"term": "단어 또는 구문",
|
||||
"heardAs": "들리는 말(선택)",
|
||||
"heardAsLabel": "들리는 말",
|
||||
"add": "추가",
|
||||
"repoNameHint": "저장소 이름을 힌트로 사용",
|
||||
"repoNameHintDescription": "저장소 이름을 더 잘 인식하도록 돕습니다.",
|
||||
"repoSaveFailed": "저장소 용어를 저장하지 못했습니다. 이 저장소의 호스트에서 Orca 업데이트가 필요할 수 있습니다."
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -6597,7 +6597,10 @@
|
||||
"modelMemoryKeyword": "memória",
|
||||
"fillerWordsTitle": "Remover hesitações",
|
||||
"fillerWordsDescription": "Remove “hã”, “hum” e sons parecidos do texto ditado.",
|
||||
"fillerWordsKeyword": "hesitações"
|
||||
"fillerWordsKeyword": "hesitações",
|
||||
"vocabularyTitle": "Vocabulário",
|
||||
"vocabularyDescription": "Nomes e termos de código que o ditado escreve do seu jeito, para você ou para um repositório.",
|
||||
"vocabularyKeyword": "dicionário"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -21716,6 +21719,24 @@
|
||||
"local": "Neste computador",
|
||||
"cloudDescription": "Modelos na nuvem enviam seu áudio ao provedor. Os deste computador o mantêm aqui.",
|
||||
"sendsToCompatible": "Envia seu áudio para o serviço que você configurou."
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "Vocabulário",
|
||||
"description": "Nomes e termos de código escritos do seu jeito. Adicione como o modelo os ouve errado, se ele continuar errando.",
|
||||
"repoScope": "Usado só ao ditar em {{repo}}.",
|
||||
"personalScope": "Usado em todos os repositórios.",
|
||||
"scope": "Termos para",
|
||||
"personal": "Pessoal · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "Remover {{term}}",
|
||||
"term": "Palavra ou frase",
|
||||
"heardAs": "Ouvido como (opcional)",
|
||||
"heardAsLabel": "Ouvido como",
|
||||
"add": "Adicionar",
|
||||
"repoNameHint": "Usar o nome do repositório como dica",
|
||||
"repoNameHintDescription": "Ajuda a reconhecer o nome do repositório.",
|
||||
"repoSaveFailed": "Não foi possível salvar os termos do repositório. O host deste repositório pode precisar de uma atualização do Orca."
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -11651,7 +11651,10 @@
|
||||
"modelMemoryKeyword": "память",
|
||||
"fillerWordsTitle": "Удалять слова-паразиты",
|
||||
"fillerWordsDescription": "Убирает «э», «эм» и похожие звуки из надиктованного текста.",
|
||||
"fillerWordsKeyword": "паразиты"
|
||||
"fillerWordsKeyword": "паразиты",
|
||||
"vocabularyTitle": "Словарь",
|
||||
"vocabularyDescription": "Имена и термины из кода, которые диктовка пишет по-вашему, для вас или для репозитория.",
|
||||
"vocabularyKeyword": "словарь"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -21433,6 +21436,24 @@
|
||||
"local": "На этом компьютере",
|
||||
"cloudDescription": "Облачные модели отправляют звук провайдеру. Модели на этом компьютере оставляют его здесь.",
|
||||
"sendsToCompatible": "Отправляет звук в настроенный вами сервис."
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "Словарь",
|
||||
"description": "Имена и термины из кода, которые нужно писать по-вашему. Если модель всё время ошибается, добавьте, как она их слышит.",
|
||||
"repoScope": "Используется только при диктовке в {{repo}}.",
|
||||
"personalScope": "Используется во всех репозиториях.",
|
||||
"scope": "Термины для",
|
||||
"personal": "Личные · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "Удалить {{term}}",
|
||||
"term": "Слово или фраза",
|
||||
"heardAs": "Слышится как (необязательно)",
|
||||
"heardAsLabel": "Слышится как",
|
||||
"add": "Добавить",
|
||||
"repoNameHint": "Использовать имя репозитория как подсказку",
|
||||
"repoNameHintDescription": "Помогает распознавать имя репозитория.",
|
||||
"repoSaveFailed": "Не удалось сохранить термины репозитория. Возможно, на хосте этого репозитория нужно обновить Orca."
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -11283,7 +11283,10 @@
|
||||
"modelMemoryKeyword": "bellek",
|
||||
"fillerWordsTitle": "Dolgu seslerini kaldır",
|
||||
"fillerWordsDescription": "Dikte edilen metinden “hmm” gibi duraksama seslerini çıkarır.",
|
||||
"fillerWordsKeyword": "dolgu"
|
||||
"fillerWordsKeyword": "dolgu",
|
||||
"vocabularyTitle": "Sözcük dağarcığı",
|
||||
"vocabularyDescription": "Diktenin senin yazımınla yazdığı adlar ve kod terimleri, senin için veya bir depo için.",
|
||||
"vocabularyKeyword": "sözlük"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -20728,6 +20731,24 @@
|
||||
"local": "Bu bilgisayarda",
|
||||
"cloudDescription": "Bulut modelleri sesinizi sağlayıcıya gönderir. Bu bilgisayardaki modeller sesi burada tutar.",
|
||||
"sendsToCompatible": "Sesinizi kurduğunuz hizmete gönderir."
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "Sözcük dağarcığı",
|
||||
"description": "Kendi yazımınla yazılacak adlar ve kod terimleri. Model sürekli yanlış duyuyorsa nasıl duyduğunu da ekle.",
|
||||
"repoScope": "Yalnızca {{repo}} içinde dikte ederken kullanılır.",
|
||||
"personalScope": "Her depoda kullanılır.",
|
||||
"scope": "Terimler",
|
||||
"personal": "Kişisel · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "{{term}} kaldır",
|
||||
"term": "Sözcük veya ifade",
|
||||
"heardAs": "Duyulan biçim (isteğe bağlı)",
|
||||
"heardAsLabel": "Duyulan biçim",
|
||||
"add": "Ekle",
|
||||
"repoNameHint": "Depo adını ipucu olarak kullan",
|
||||
"repoNameHintDescription": "Depo adının tanınmasına yardımcı olur.",
|
||||
"repoSaveFailed": "Deponun terimleri kaydedilemedi. Bu deponun ana makinesinde Orca güncellemesi gerekebilir."
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -11120,7 +11120,10 @@
|
||||
"modelMemoryKeyword": "記憶體",
|
||||
"fillerWordsTitle": "移除語氣詞",
|
||||
"fillerWordsDescription": "從聽寫文字中移除「嗯」「呃」之類的語氣詞。",
|
||||
"fillerWordsKeyword": "語氣詞"
|
||||
"fillerWordsKeyword": "語氣詞",
|
||||
"vocabularyTitle": "詞彙",
|
||||
"vocabularyDescription": "聽寫依你的寫法拼寫的名稱和程式碼術語,可用於個人或某個儲存庫。",
|
||||
"vocabularyKeyword": "詞典"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -20429,6 +20432,24 @@
|
||||
"local": "這台電腦",
|
||||
"cloudDescription": "雲端模型會把你的音訊傳送給服務商。本機模型會把音訊留在這台電腦上。",
|
||||
"sendsToCompatible": "會把你的音訊傳送到你設定的服務。"
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "詞彙",
|
||||
"description": "依你的寫法拼寫的名稱和程式碼術語。如果模型總是聽錯,可以加上它聽成的說法。",
|
||||
"repoScope": "僅在 {{repo}} 中聽寫時使用。",
|
||||
"personalScope": "在所有儲存庫中使用。",
|
||||
"scope": "術語範圍",
|
||||
"personal": "個人 · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "移除 {{term}}",
|
||||
"term": "詞語或片語",
|
||||
"heardAs": "聽成(選填)",
|
||||
"heardAsLabel": "聽成",
|
||||
"add": "新增",
|
||||
"repoNameHint": "將儲存庫名稱用作提示",
|
||||
"repoNameHintDescription": "幫助辨識儲存庫名稱。",
|
||||
"repoSaveFailed": "無法儲存儲存庫的術語。執行此儲存庫的主機可能需要更新 Orca。"
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -10589,7 +10589,10 @@
|
||||
"modelMemoryKeyword": "内存",
|
||||
"fillerWordsTitle": "移除语气词",
|
||||
"fillerWordsDescription": "从听写文本中去掉“嗯”“呃”之类的语气词。",
|
||||
"fillerWordsKeyword": "语气词"
|
||||
"fillerWordsKeyword": "语气词",
|
||||
"vocabularyTitle": "词汇",
|
||||
"vocabularyDescription": "听写按你的写法拼写的名称和代码术语,可用于个人或某个仓库。",
|
||||
"vocabularyKeyword": "词典"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -20026,6 +20029,24 @@
|
||||
"local": "这台电脑",
|
||||
"cloudDescription": "云端模型会把你的音频发送给服务商。本机模型会把音频留在这台电脑上。",
|
||||
"sendsToCompatible": "会把你的音频发送到你设置的服务。"
|
||||
},
|
||||
"vocabulary": {
|
||||
"title": "词汇",
|
||||
"description": "按你的写法拼写的名称和代码术语。如果模型总是听错,可以加上它听成的说法。",
|
||||
"repoScope": "仅在 {{repo}} 中听写时使用。",
|
||||
"personalScope": "在所有仓库中使用。",
|
||||
"scope": "术语范围",
|
||||
"personal": "个人 · {{total}}",
|
||||
"repo": "{{repo}} · {{total}}",
|
||||
"heardAsChip": "← {{heardAs}}",
|
||||
"remove": "移除 {{term}}",
|
||||
"term": "词语或短语",
|
||||
"heardAs": "听成(可选)",
|
||||
"heardAsLabel": "听成",
|
||||
"add": "添加",
|
||||
"repoNameHint": "将仓库名用作提示",
|
||||
"repoNameHintDescription": "帮助识别仓库名称。",
|
||||
"repoSaveFailed": "无法保存仓库的术语。运行此仓库的主机可能需要更新 Orca。"
|
||||
}
|
||||
},
|
||||
"repositoryHooks": {
|
||||
|
||||
@@ -158,6 +158,14 @@ export function createRepoUpdateActions(
|
||||
) {
|
||||
return false
|
||||
}
|
||||
// A host from before dictionaries drops the field and still answers with its row.
|
||||
if (
|
||||
sanitizedUpdates.dictationTerms !== undefined &&
|
||||
JSON.stringify(updatedRepo?.dictationTerms ?? []) !==
|
||||
JSON.stringify(sanitizedUpdates.dictationTerms)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
set((s) => {
|
||||
const nextRepos = s.repos.map((r) => {
|
||||
const matchesOwner = ownerHasExplicitHost
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { createDictationDictionary, mergeDictationTerms } from './dictation-dictionary'
|
||||
import {
|
||||
createDictationDictionary,
|
||||
dictationTermsFor,
|
||||
dictationVocabulary
|
||||
} from './dictation-dictionary'
|
||||
import { createDictationTextPipeline } from './dictation-text-pipeline'
|
||||
|
||||
const spell = (terms: Parameters<typeof createDictationDictionary>[0], text: string): string =>
|
||||
@@ -55,8 +59,21 @@ describe('createDictationDictionary', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('lets the repo name join its spoken words but never recase a single word', () => {
|
||||
const oneWord = dictationTermsFor({}, { displayName: 'orca' })
|
||||
const words = dictationTermsFor({}, { displayName: 'dd-scratch-repo' })
|
||||
|
||||
expect(createDictationDictionary(oneWord)).toBeNull()
|
||||
expect(dictationVocabulary(oneWord)).toEqual(['orca'])
|
||||
expect(spell(words, 'Open dd scratch repo now.')).toBe('Open dd-scratch-repo now.')
|
||||
expect(dictationTermsFor({ dictationRepoNameHint: false }, { displayName: 'orca' })).toEqual([])
|
||||
})
|
||||
|
||||
it("prefers a repo's spelling over a personal one", () => {
|
||||
const terms = mergeDictationTerms([{ term: 'RPC' }], [{ term: 'rpc' }])
|
||||
const terms = dictationTermsFor(
|
||||
{ dictationTerms: [{ term: 'rpc' }] },
|
||||
{ dictationTerms: [{ term: 'RPC' }] }
|
||||
)
|
||||
expect(spell(terms, 'Call the rpc.')).toBe('Call the RPC.')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/** A word or phrase dictation should spell `term`'s way, optionally also replacing what the model hears instead. */
|
||||
export type DictationTerm = { term: string; heardAs?: string }
|
||||
/**
|
||||
* A word or phrase dictation should spell `term`'s way, optionally also replacing what the model hears instead.
|
||||
* `hint` marks the repo name: it biases recognition and joins its words, but never recases a single word.
|
||||
*/
|
||||
export type DictationTerm = { term: string; heardAs?: string; hint?: true }
|
||||
|
||||
export const MAX_DICTATION_TERMS = 500
|
||||
export const MAX_DICTATION_TERM_LENGTH = 100
|
||||
@@ -20,32 +23,49 @@ function wordKey(text: string): string {
|
||||
return (text.normalize('NFKC').toLowerCase().match(WORD_RE) ?? []).join('')
|
||||
}
|
||||
|
||||
/** Well-formed entries only, trimmed and capped; undefined when the value isn't a list. */
|
||||
/** Well-formed, distinct entries only, trimmed and capped; undefined when the value isn't a list. */
|
||||
export function normalizeDictationTerms(value: unknown): DictationTerm[] | undefined {
|
||||
if (!Array.isArray(value)) {
|
||||
return undefined
|
||||
}
|
||||
const terms: DictationTerm[] = []
|
||||
const seen = new Set<string>()
|
||||
for (const entry of value) {
|
||||
const term: unknown = entry?.term
|
||||
const heardAs: unknown = entry?.heardAs
|
||||
if (typeof term !== 'string' || !term.trim()) {
|
||||
continue
|
||||
}
|
||||
const alias = typeof heardAs === 'string' ? heardAs.trim() : ''
|
||||
const spelling = term.trim().slice(0, MAX_DICTATION_TERM_LENGTH)
|
||||
const alias =
|
||||
typeof heardAs === 'string' ? heardAs.trim().slice(0, MAX_DICTATION_TERM_LENGTH) : ''
|
||||
// The same spelling and alias twice is one stored entry.
|
||||
const id = `${spelling}\u0000${alias}`
|
||||
if (seen.has(id)) {
|
||||
continue
|
||||
}
|
||||
seen.add(id)
|
||||
terms.push({
|
||||
term: term.trim().slice(0, MAX_DICTATION_TERM_LENGTH),
|
||||
...(alias ? { heardAs: alias.slice(0, MAX_DICTATION_TERM_LENGTH) } : {})
|
||||
term: spelling,
|
||||
...(alias ? { heardAs: alias } : {})
|
||||
})
|
||||
}
|
||||
return terms.slice(0, MAX_DICTATION_TERMS)
|
||||
}
|
||||
|
||||
/** Repo terms first, so a repo's spelling wins over a personal one for the same words. */
|
||||
export function mergeDictationTerms(repoTerms: unknown, personalTerms: unknown): DictationTerm[] {
|
||||
/**
|
||||
* The dictionary for a dictation into `repo` (none for a folder workspace): its terms first, so a repo's
|
||||
* spelling wins over a personal one, then the personal terms, then its name as a hint unless that's off.
|
||||
*/
|
||||
export function dictationTermsFor(
|
||||
voice: { dictationTerms?: unknown; dictationRepoNameHint?: boolean } | undefined,
|
||||
repo: { dictationTerms?: unknown; displayName?: string } | undefined
|
||||
): DictationTerm[] {
|
||||
const name = repo?.displayName?.trim().slice(0, MAX_DICTATION_TERM_LENGTH)
|
||||
return [
|
||||
...(normalizeDictationTerms(repoTerms) ?? []),
|
||||
...(normalizeDictationTerms(personalTerms) ?? [])
|
||||
...(normalizeDictationTerms(repo?.dictationTerms) ?? []),
|
||||
...(normalizeDictationTerms(voice?.dictationTerms) ?? []),
|
||||
...(name && voice?.dictationRepoNameHint !== false ? [{ term: name, hint: true as const }] : [])
|
||||
]
|
||||
}
|
||||
|
||||
@@ -75,8 +95,11 @@ export function createDictationDictionary(
|
||||
add(wordKey(heardAs), term)
|
||||
}
|
||||
}
|
||||
for (const { term } of terms ?? []) {
|
||||
add(wordKey(term), term)
|
||||
for (const { term, hint } of terms ?? []) {
|
||||
// A one-word repo name like "orca" would recase every "Orca"; only a name of several words joins.
|
||||
if (!hint || (term.match(WORD_RE)?.length ?? 0) > 1) {
|
||||
add(wordKey(term), term)
|
||||
}
|
||||
}
|
||||
if (byKey.size === 0 && unspacedAliases.length === 0) {
|
||||
return null
|
||||
|
||||
@@ -132,10 +132,13 @@ export type VoiceSettings = {
|
||||
speechGpu?: SpeechGpuMode
|
||||
/** Personal dictionary, used in every repo; each repo adds its own Repo.dictationTerms. */
|
||||
dictationTerms?: DictationTerm[]
|
||||
/** Adds the current repo's name as a hint (DictationTerm.hint). Absent = on. */
|
||||
dictationRepoNameHint?: boolean
|
||||
}
|
||||
|
||||
/** Where a dictation goes: an engine in the desktop's own process takes repoTerms, a host resolves worktreeId itself. */
|
||||
export type DictationContext = {
|
||||
worktreeId?: string
|
||||
repoTerms?: DictationTerm[]
|
||||
repoName?: string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { resolveAgentSmartKeys } from './agent-smart-keys'
|
||||
|
||||
const approval = JSON.stringify({ approval: { tool: 'Bash', summary: 'pnpm tc' } })
|
||||
const questions = JSON.stringify({
|
||||
questions: [
|
||||
{ question: 'Where?', options: [{ label: 'a' }, { label: 'b' }, { label: 'c' }] },
|
||||
{ question: 'Which?', options: [{ label: 'x' }, { label: 'y' }] }
|
||||
]
|
||||
})
|
||||
|
||||
describe('resolveAgentSmartKeys', () => {
|
||||
it('tells a permission prompt from a question by the prompt shape', () => {
|
||||
expect(
|
||||
resolveAgentSmartKeys('claude', { state: 'waiting', interactivePrompt: approval })?.state
|
||||
).toBe('permission')
|
||||
const ask = resolveAgentSmartKeys('claude', {
|
||||
state: 'waiting',
|
||||
interactivePrompt: questions,
|
||||
toolName: 'AskUserQuestion'
|
||||
})
|
||||
expect(ask?.state).toBe('question')
|
||||
// The phone can't see the open question tab, so it offers digits for the longest one.
|
||||
expect(ask?.keys.filter((key) => /^\d$/.test(key.combo)).map((key) => key.writes)).toEqual([
|
||||
['1'],
|
||||
['2'],
|
||||
['3']
|
||||
])
|
||||
})
|
||||
|
||||
it("opens Codex's async question with ⇧← before its digits", () => {
|
||||
const ask = resolveAgentSmartKeys('codex', {
|
||||
state: 'waiting',
|
||||
toolName: 'request_user_input_async',
|
||||
interactivePrompt: JSON.stringify({
|
||||
questions: [{ title: 'Which db?', options: ['a', 'b', 'c'] }, { title: 'Table name?' }]
|
||||
})
|
||||
})
|
||||
expect(ask?.state).toBe('question')
|
||||
expect(ask?.keys.map((key) => key.writes.join(''))).toEqual([
|
||||
'\x1b[1;2D',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'\r',
|
||||
'\x1d'
|
||||
])
|
||||
})
|
||||
|
||||
it('answers a Codex approval with y or n only and stops OpenCode with two separate Escapes', () => {
|
||||
// Codex's "don't ask again" key is `p` or `a` depending on the approval, which the hook doesn't carry.
|
||||
const codexApproval = resolveAgentSmartKeys('codex', {
|
||||
state: 'waiting',
|
||||
interactivePrompt: approval
|
||||
})?.keys.map((key) => key.writes)
|
||||
expect(codexApproval).toEqual([['y'], ['n']])
|
||||
const openCodeStop = resolveAgentSmartKeys('opencode', { state: 'working' })?.keys.find(
|
||||
(key) => key.name === 'stop'
|
||||
)
|
||||
expect(openCodeStop?.writes).toEqual(['\x1b', '\x1b'])
|
||||
})
|
||||
|
||||
it('shows nothing for an unknown agent, state or prompt', () => {
|
||||
expect(resolveAgentSmartKeys('gemini', { state: 'working' })).toBeNull()
|
||||
expect(resolveAgentSmartKeys('claude', { state: 'waiting' })).toBeNull()
|
||||
expect(
|
||||
resolveAgentSmartKeys('codex', { state: 'waiting', interactivePrompt: questions })
|
||||
).toBeNull()
|
||||
expect(resolveAgentSmartKeys('codex', { state: 'done' })).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,200 @@
|
||||
import type { AgentStatusEntry } from '../../agent-status/contracts/agent-status-types'
|
||||
import { hookRowAgentPhase } from '../../agent-status/lifecycle/agent-transitions'
|
||||
import { parseNativeChatApprovalEnvelope } from '../../native-chat/input/native-chat-approval-envelope'
|
||||
import { parseAskFromStatus } from '../../native-chat/input/native-chat-ask'
|
||||
import { resolveNativeChatTranscriptAgent } from '../../native-chat/native-chat-agent-support'
|
||||
|
||||
const ESC = '\x1b'
|
||||
const ARROW_UP = '\x1b[A'
|
||||
const ARROW_LEFT = '\x1b[D'
|
||||
const ARROW_RIGHT = '\x1b[C'
|
||||
const SHIFT_TAB = '\x1b[Z'
|
||||
const SHIFT_LEFT = '\x1b[1;2D'
|
||||
|
||||
/** The gap between a key's writes; ESC ESC in one write reads as Alt+Esc, not two presses. */
|
||||
export const AGENT_SMART_KEY_STEP_MS = 120
|
||||
|
||||
export type AgentSmartKeyAgent = 'claude' | 'codex' | 'opencode'
|
||||
|
||||
export type AgentSmartKeyState = 'working' | 'permission' | 'question' | 'idle'
|
||||
|
||||
export type AgentSmartKeyName =
|
||||
| 'stop'
|
||||
| 'sendNow'
|
||||
| 'background'
|
||||
| 'mode'
|
||||
| 'yes'
|
||||
| 'always'
|
||||
| 'no'
|
||||
| 'cancel'
|
||||
| 'history'
|
||||
| 'rewind'
|
||||
| 'queue'
|
||||
| 'edit'
|
||||
| 'answer'
|
||||
| 'skip'
|
||||
| 'confirm'
|
||||
| 'reject'
|
||||
|
||||
export type AgentSmartKey = {
|
||||
readonly id: string
|
||||
/** The word on the key; null when the combo itself is the label (digits, arrows). */
|
||||
readonly name: AgentSmartKeyName | null
|
||||
/** The real keys it presses. */
|
||||
readonly combo: string
|
||||
/** One terminal write each, AGENT_SMART_KEY_STEP_MS apart. */
|
||||
readonly writes: readonly string[]
|
||||
/** The prompt's accept key. */
|
||||
readonly primary?: true
|
||||
}
|
||||
|
||||
export type AgentSmartKeySet = {
|
||||
/** The tab's own agent, e.g. openclaude, for its icon. */
|
||||
readonly agentId: string
|
||||
readonly state: AgentSmartKeyState
|
||||
readonly keys: readonly AgentSmartKey[]
|
||||
}
|
||||
|
||||
type AgentSmartKeyRow = Pick<
|
||||
AgentStatusEntry,
|
||||
'state' | 'interrupted' | 'mainAgent' | 'interactivePrompt' | 'toolName'
|
||||
>
|
||||
|
||||
const word = (
|
||||
name: AgentSmartKeyName,
|
||||
combo: string,
|
||||
writes: readonly string[],
|
||||
primary?: true
|
||||
): AgentSmartKey => ({ id: name, name, combo, writes, ...(primary ? { primary } : {}) })
|
||||
|
||||
const plain = (id: string, combo: string, write: string): AgentSmartKey => ({
|
||||
id,
|
||||
name: null,
|
||||
combo,
|
||||
writes: [write]
|
||||
})
|
||||
|
||||
// Never a key that quits the agent, such as Ctrl+C on an empty Codex or OpenCode prompt.
|
||||
const STATE_KEYS: Record<
|
||||
AgentSmartKeyAgent,
|
||||
Partial<Record<Exclude<AgentSmartKeyState, 'question'>, readonly AgentSmartKey[]>>
|
||||
> = {
|
||||
claude: {
|
||||
working: [
|
||||
word('stop', 'Esc', [ESC]),
|
||||
word('sendNow', '⌃X ⌃S', ['\x18\x13']),
|
||||
word('background', '⌃B', ['\x02']),
|
||||
word('mode', '⇧Tab', [SHIFT_TAB])
|
||||
],
|
||||
permission: [
|
||||
word('yes', '1', ['1'], true),
|
||||
word('always', '2', ['2']),
|
||||
word('no', 'Esc', [ESC])
|
||||
],
|
||||
idle: [
|
||||
word('mode', '⇧Tab', [SHIFT_TAB]),
|
||||
word('history', '↑', [ARROW_UP]),
|
||||
word('rewind', 'Esc Esc', [ESC, ESC])
|
||||
]
|
||||
},
|
||||
codex: {
|
||||
working: [
|
||||
word('stop', 'Esc', [ESC]),
|
||||
word('queue', 'Tab', ['\t']),
|
||||
// Pulls the last queued message back into the composer.
|
||||
word('edit', '⇧←', [SHIFT_LEFT])
|
||||
],
|
||||
// No Always: it is `p` for a command-prefix rule and `a` otherwise, and the hook doesn't say which.
|
||||
// `n` turns down only this request; Esc would also drop every queued approval.
|
||||
permission: [word('yes', 'y', ['y'], true), word('no', 'n', ['n'])]
|
||||
},
|
||||
opencode: {
|
||||
// OpenCode asks for a second Esc before it interrupts.
|
||||
working: [word('stop', 'Esc Esc', [ESC, ESC])],
|
||||
permission: [
|
||||
plain('left', '←', ARROW_LEFT),
|
||||
plain('right', '→', ARROW_RIGHT),
|
||||
word('confirm', 'Enter', ['\r'], true),
|
||||
word('reject', 'Esc', [ESC])
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
function questionKeys(
|
||||
agent: AgentSmartKeyAgent,
|
||||
row: AgentSmartKeyRow
|
||||
): readonly AgentSmartKey[] | null {
|
||||
const ask = parseAskFromStatus(row.interactivePrompt, row.toolName)
|
||||
if (!ask) {
|
||||
return null
|
||||
}
|
||||
// The phone can't see which question is open, so offer digits for the longest one.
|
||||
const optionCount = Math.min(9, Math.max(0, ...ask.questions.map((q) => q.options.length)))
|
||||
const digits = Array.from({ length: optionCount }, (_, index) =>
|
||||
plain(`option${index + 1}`, String(index + 1), String(index + 1))
|
||||
)
|
||||
if (agent === 'codex') {
|
||||
// Codex keeps working while its async question waits collapsed under the composer; ⇧← opens it.
|
||||
return ask.replyAsMessage
|
||||
? [
|
||||
word('answer', '⇧←', [SHIFT_LEFT], true),
|
||||
...digits,
|
||||
plain('enter', 'Enter', '\r'),
|
||||
word('skip', '⌃]', ['\x1d'])
|
||||
]
|
||||
: null
|
||||
}
|
||||
if (agent !== 'claude' || optionCount === 0) {
|
||||
return null
|
||||
}
|
||||
return [
|
||||
...digits,
|
||||
plain('left', '←', ARROW_LEFT),
|
||||
plain('right', '→', ARROW_RIGHT),
|
||||
word('cancel', 'Esc', [ESC])
|
||||
]
|
||||
}
|
||||
|
||||
/** The keys for what a terminal agent is doing now, or null when its agent or state isn't known. */
|
||||
export function resolveAgentSmartKeys(
|
||||
agentId: string | null | undefined,
|
||||
row: AgentSmartKeyRow | null | undefined
|
||||
): AgentSmartKeySet | null {
|
||||
const transcriptAgent = resolveNativeChatTranscriptAgent(agentId)
|
||||
if (
|
||||
!agentId ||
|
||||
!row ||
|
||||
(transcriptAgent !== 'claude' && transcriptAgent !== 'codex' && transcriptAgent !== 'opencode')
|
||||
) {
|
||||
return null
|
||||
}
|
||||
const agent: AgentSmartKeyAgent = transcriptAgent
|
||||
const withKeys = (
|
||||
state: AgentSmartKeyState,
|
||||
keys: readonly AgentSmartKey[] | null | undefined
|
||||
): AgentSmartKeySet | null => (keys && keys.length > 0 ? { agentId, state, keys } : null)
|
||||
const phase = hookRowAgentPhase(row)
|
||||
if (phase === 'working') {
|
||||
return withKeys('working', STATE_KEYS[agent].working)
|
||||
}
|
||||
if (phase !== 'needs-you') {
|
||||
return withKeys('idle', STATE_KEYS[agent].idle)
|
||||
}
|
||||
if (parseNativeChatApprovalEnvelope(row.interactivePrompt, agent)) {
|
||||
return withKeys('permission', STATE_KEYS[agent].permission)
|
||||
}
|
||||
return withKeys('question', questionKeys(agent, row))
|
||||
}
|
||||
|
||||
/** Whether two sets draw the same keys, so a fresh status object doesn't redraw the row. */
|
||||
export function sameSmartKeySet(a: AgentSmartKeySet | null, b: AgentSmartKeySet | null): boolean {
|
||||
return (
|
||||
a === b ||
|
||||
(a !== null &&
|
||||
b !== null &&
|
||||
a.agentId === b.agentId &&
|
||||
a.state === b.state &&
|
||||
a.keys.length === b.keys.length &&
|
||||
a.keys.every((key, index) => key.id === b.keys[index]?.id))
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user