@thegitai/cli 1.6.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/src/api/voice.js +96 -0
- package/dist/src/help-text.js +239 -226
- package/dist/src/keybindings-file.js +38 -0
- package/dist/src/keyboard-shortcuts.js +62 -0
- package/dist/src/preferences.js +8 -2
- package/dist/src/ui/repl.js +162 -5
- package/dist/src/ui/slash-commands.js +3 -1
- package/dist/src/ui/tui/bridge.js +50 -0
- package/dist/src/ui/tui/build-frame.js +64 -15
- package/dist/src/ui/tui/shell-input.js +12 -14
- package/dist/src/ui/tui/shortcuts.js +10 -5
- package/dist/src/ui/tui/voice-dictation.js +438 -0
- package/package.json +10 -7
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const RESERVED_KEYS = ['Ctrl+C', 'Ctrl+H', 'Ctrl+I', 'Ctrl+J', 'Ctrl+M'];
|
|
2
|
+
export function defaultShortcuts(platform = process.platform) {
|
|
3
|
+
return {
|
|
4
|
+
cycleMode: ['Shift+Tab'],
|
|
5
|
+
pasteImage: platform === 'win32' ? ['Alt+V', 'Ctrl+V'] : ['Ctrl+V'],
|
|
6
|
+
backgroundJobs: ['Ctrl+B'],
|
|
7
|
+
notifications: ['Ctrl+G'],
|
|
8
|
+
pushToTalk: ['Space'],
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function shortcutLabel(id, overrides = {}, platform = process.platform) {
|
|
12
|
+
return (overrides[id] ?? defaultShortcuts(platform)[id]).join(' / ');
|
|
13
|
+
}
|
|
14
|
+
export function matchesShortcut(id, key, overrides = {}) {
|
|
15
|
+
const chord = key.tab
|
|
16
|
+
? key.shift && !key.ctrl && !key.meta ? 'Shift+Tab' : ''
|
|
17
|
+
: key.input === ' ' && !key.ctrl && !key.meta
|
|
18
|
+
? 'Space'
|
|
19
|
+
: key.ctrl !== key.meta && !key.shift && /^[a-z]$/i.test(key.input)
|
|
20
|
+
? `${key.ctrl ? 'Ctrl' : 'Alt'}+${key.input.toUpperCase()}`
|
|
21
|
+
: '';
|
|
22
|
+
return chord !== '' && (overrides[id] ?? defaultShortcuts()[id]).includes(chord);
|
|
23
|
+
}
|
|
24
|
+
export function parseShortcutFile(value, platform = process.platform) {
|
|
25
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
26
|
+
throw new Error('Expected an object such as { "cycleMode": "Ctrl+T" }.');
|
|
27
|
+
}
|
|
28
|
+
const defaults = defaultShortcuts(platform);
|
|
29
|
+
const overrides = {};
|
|
30
|
+
for (const [name, setting] of Object.entries(value)) {
|
|
31
|
+
if (name.startsWith('$'))
|
|
32
|
+
continue;
|
|
33
|
+
if (!Object.hasOwn(defaults, name)) {
|
|
34
|
+
throw new Error(`Unknown action "${name}". Use ${Object.keys(defaults).join(', ')}.`);
|
|
35
|
+
}
|
|
36
|
+
const id = name;
|
|
37
|
+
const list = Array.isArray(setting) ? setting : [setting];
|
|
38
|
+
overrides[id] = [...new Set(list.map((raw) => {
|
|
39
|
+
const match = typeof raw === 'string' ? /^\s*(ctrl|alt)\s*\+\s*([a-z])\s*$/i.exec(raw) : null;
|
|
40
|
+
const key = match
|
|
41
|
+
? `${match[1].toLowerCase() === 'ctrl' ? 'Ctrl' : 'Alt'}+${match[2].toUpperCase()}`
|
|
42
|
+
: defaults[id].find((item) => typeof raw === 'string' && item.toLowerCase() === raw.trim().toLowerCase());
|
|
43
|
+
if (!key || RESERVED_KEYS.includes(key)) {
|
|
44
|
+
throw new Error(`"${String(raw)}" can't be used for ${id}. Use Ctrl or Alt with a letter, like Ctrl+T (not Ctrl+C, H, I, J or M).`);
|
|
45
|
+
}
|
|
46
|
+
return key;
|
|
47
|
+
}))];
|
|
48
|
+
if (overrides[id].length === 0)
|
|
49
|
+
throw new Error(`Give ${id} a key, like "Ctrl+T".`);
|
|
50
|
+
if (id === 'pushToTalk' && overrides[id].length > 1)
|
|
51
|
+
throw new Error('Give pushToTalk one key, like "Space" or "Ctrl+K".');
|
|
52
|
+
}
|
|
53
|
+
const owners = new Map();
|
|
54
|
+
for (const [id, keys] of Object.entries({ ...defaults, ...overrides })) {
|
|
55
|
+
for (const key of keys) {
|
|
56
|
+
if (owners.has(key))
|
|
57
|
+
throw new Error(`${key} is set for both ${owners.get(key)} and ${id}.`);
|
|
58
|
+
owners.set(key, id);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return overrides;
|
|
62
|
+
}
|
package/dist/src/preferences.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { getClientStateDir } from './client-state.js';
|
|
4
4
|
export const DEFAULT_PREFERENCES = {
|
|
5
5
|
notifications: true,
|
|
6
|
+
voice: { enabled: false, mode: 'hold', hints: 0 },
|
|
6
7
|
};
|
|
7
8
|
export function getPreferencesPath(env = process.env) {
|
|
8
9
|
return path.join(getClientStateDir(env), 'prefs.json');
|
|
@@ -10,15 +11,20 @@ export function getPreferencesPath(env = process.env) {
|
|
|
10
11
|
export function readPreferences(env = process.env) {
|
|
11
12
|
const filePath = getPreferencesPath(env);
|
|
12
13
|
if (!existsSync(filePath))
|
|
13
|
-
return { ...DEFAULT_PREFERENCES };
|
|
14
|
+
return { ...DEFAULT_PREFERENCES, voice: { ...DEFAULT_PREFERENCES.voice } };
|
|
14
15
|
try {
|
|
15
16
|
const parsed = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
16
17
|
return {
|
|
17
18
|
notifications: parsed.notifications === false ? false : DEFAULT_PREFERENCES.notifications,
|
|
19
|
+
voice: {
|
|
20
|
+
enabled: parsed.voice?.enabled === true,
|
|
21
|
+
mode: parsed.voice?.mode === 'tap' ? 'tap' : 'hold',
|
|
22
|
+
hints: Number.isInteger(parsed.voice?.hints) ? Math.max(0, parsed.voice.hints) : 0,
|
|
23
|
+
},
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
26
|
catch {
|
|
21
|
-
return { ...DEFAULT_PREFERENCES };
|
|
27
|
+
return { ...DEFAULT_PREFERENCES, voice: { ...DEFAULT_PREFERENCES.voice } };
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
export function writePreferences(preferences, env = process.env) {
|
package/dist/src/ui/repl.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { keybindingsPath, prepareKeybindings, watchKeybindings } from '../keybindings-file.js';
|
|
1
2
|
import { sessionMcp } from '../mcp-client.js';
|
|
2
3
|
import { projectModelEffort, readProjectModelEfforts, saveProjectModelEffort } from '../project-model-preferences.js';
|
|
3
4
|
import { REASONING_EFFORT_LABELS } from '../reasoning-effort.js';
|
|
@@ -8,6 +9,8 @@ import { AGENT_MODE_LOCKED_STATUS, approvalScrollLimit, buildTuiFrame, modelPick
|
|
|
8
9
|
import { createAttentionController, INITIAL_TERMINAL_FOCUS, } from './tui/attention.js';
|
|
9
10
|
import { backendFor, createNotificationQueue, } from './tui/desktop-notification.js';
|
|
10
11
|
import { readPreferences, writePreferences } from '../preferences.js';
|
|
12
|
+
import { createVoiceDictation, isRemoteSession, voiceErrorMessage, voiceKeyLabel, } from './tui/voice-dictation.js';
|
|
13
|
+
import { openVoiceStream, transcribeRecording } from '../api/voice.js';
|
|
11
14
|
import { createTerminalTitleController } from './tui/terminal-title.js';
|
|
12
15
|
import { captureTerminalWrites, releaseTerminalWrites, } from './tui/terminal-writes.js';
|
|
13
16
|
import { getInputCommandToken, getSlashCommandSuggestions, isSkillSlashCommand, setSkillSlashCommands, SLASH_COMMANDS, slashCommandMatchesToken, } from './slash-commands.js';
|
|
@@ -24,20 +27,20 @@ import { formatTurnRecoveryStatus } from '../api/turn-recovery.js';
|
|
|
24
27
|
import { createJobWaitTracker } from '../job-follow-up.js';
|
|
25
28
|
import { getJobBufferedOutput, getJobOutputPreview, hasRunningBackgroundJobs, killAllBackgroundJobs, killBackgroundJob, listBackgroundJobs, setBackgroundJobSession, setBackgroundJobUpdateHook, } from '../background-jobs.js';
|
|
26
29
|
import { clearTodos, listTodos, setTodoSession } from '../todo-list.js';
|
|
27
|
-
import { setScratchSession } from '../scratch-dir.js';
|
|
30
|
+
import { ensureSessionScratchDir, setScratchSession } from '../scratch-dir.js';
|
|
28
31
|
import { setImageStoreSession } from '../core/session-image-store.js';
|
|
29
32
|
import { runMemoryCommand } from '../memory/command.js';
|
|
30
33
|
import { cancelActiveCommand } from '../executor.js';
|
|
31
34
|
import { isTurnFailureMarker } from '../turn-failure-marker.js';
|
|
32
35
|
import { clearCliAuthConfig, logoutFromServer, } from '../api/auth.js';
|
|
33
|
-
import { authenticationErrorMessage, isAuthenticationError, } from '../api/http.js';
|
|
36
|
+
import { authenticationErrorMessage, isAuthenticationError, ServerApiError, } from '../api/http.js';
|
|
34
37
|
import { buildRefusalNotice } from '../quota-notice.js';
|
|
35
38
|
import { createUsageNoticeTracker } from '../usage-notice.js';
|
|
36
39
|
import { createUserInputPromptState, formatUserInputTranscript, } from './tui/user-input.js';
|
|
37
40
|
import { setCommandOutputHook, withTuiMode } from '../runtime-mode.js';
|
|
38
41
|
import { collectBackgroundJobUiKillMutations, collectBackgroundJobUiOutputMutations, } from '../tool-executor.js';
|
|
39
42
|
import { startNewConversation, } from '../session.js';
|
|
40
|
-
import { applySessionSnapshot, listSessionMetadata, loadSessionSnapshot, saveSessionState, sessionHasUserMessage, } from '../session-store.js';
|
|
43
|
+
import { applySessionSnapshot, listSessionMetadata, loadSessionSnapshot, readGitBranch, saveSessionState, sessionHasUserMessage, } from '../session-store.js';
|
|
41
44
|
import { truncate } from '../utils.js';
|
|
42
45
|
import { TOOL_MAP } from '../tools/index.js';
|
|
43
46
|
import { countStep, EMPTY_TURN_STEPS, turnStepFields, } from './turn-steps.js';
|
|
@@ -1199,12 +1202,17 @@ function createInitialShellState(session, serverModels, debugUi, serverUrl) {
|
|
|
1199
1202
|
input: '',
|
|
1200
1203
|
maxToolSteps: session.maxToolSteps,
|
|
1201
1204
|
notificationsEnabled: readPreferences(session.env).notifications,
|
|
1205
|
+
voice: null,
|
|
1206
|
+
voiceEnabled: readPreferences(session.env).voice.enabled && !isRemoteSession(session.env),
|
|
1207
|
+
voiceHint: false,
|
|
1208
|
+
voiceMode: readPreferences(session.env).voice.mode,
|
|
1202
1209
|
terminalFocused: INITIAL_TERMINAL_FOCUS,
|
|
1203
1210
|
jobsPickerExpandedId: null,
|
|
1204
1211
|
jobsPickerIndex: 0,
|
|
1205
1212
|
jobsPickerOpen: false,
|
|
1206
1213
|
modelPickerIndex: getDefaultModelPickerIndex(session.modelId, serverModels.models),
|
|
1207
1214
|
modelPickerOpen: false,
|
|
1215
|
+
shortcuts: {},
|
|
1208
1216
|
shortcutsOpen: false,
|
|
1209
1217
|
skillsPickerIndex: 0,
|
|
1210
1218
|
skillsPickerItems: [],
|
|
@@ -2396,6 +2404,122 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
2396
2404
|
}
|
|
2397
2405
|
showTransientStatus(enabled ? 'Notifications on' : 'Notifications off');
|
|
2398
2406
|
};
|
|
2407
|
+
const voiceHints = () => [basename(session.rootDir), readGitBranch(session.rootDir) ?? '']
|
|
2408
|
+
.map((hint) => hint.trim())
|
|
2409
|
+
.filter((hint, index, all) => hint && all.indexOf(hint) === index);
|
|
2410
|
+
const transcribeDictation = async (audio, signal) => {
|
|
2411
|
+
try {
|
|
2412
|
+
return await transcribeRecording({ config: authConfig, audio, hints: voiceHints(), signal });
|
|
2413
|
+
}
|
|
2414
|
+
catch (error) {
|
|
2415
|
+
if (signal.aborted)
|
|
2416
|
+
throw error;
|
|
2417
|
+
const notice = buildRefusalNotice(error);
|
|
2418
|
+
if (notice)
|
|
2419
|
+
throw new Error(notice.body);
|
|
2420
|
+
if (isAuthenticationError(error))
|
|
2421
|
+
throw new Error(authenticationErrorMessage(error));
|
|
2422
|
+
if (error instanceof ServerApiError && error.status < 500 && error.message)
|
|
2423
|
+
throw new Error(error.message);
|
|
2424
|
+
throw new Error("Couldn't transcribe that, try again.");
|
|
2425
|
+
}
|
|
2426
|
+
};
|
|
2427
|
+
const voiceDictation = createVoiceDictation({
|
|
2428
|
+
getState: () => store.getState(),
|
|
2429
|
+
update: (change) => store.update(change),
|
|
2430
|
+
canDictate: (state) => !state.approvalPrompt &&
|
|
2431
|
+
!state.sudoPrompt &&
|
|
2432
|
+
!state.userInputPrompt &&
|
|
2433
|
+
!state.modelPickerOpen &&
|
|
2434
|
+
!state.resumePickerOpen &&
|
|
2435
|
+
!state.skillsPickerOpen &&
|
|
2436
|
+
!state.jobsPickerOpen &&
|
|
2437
|
+
!state.shortcutsOpen &&
|
|
2438
|
+
!state.exiting &&
|
|
2439
|
+
state.exitConfirmUntil == null &&
|
|
2440
|
+
!(state.busy && state.queuedMessage),
|
|
2441
|
+
start: (file, maxSeconds) => bridge.voiceStart(file, maxSeconds),
|
|
2442
|
+
stop: () => bridge.voiceStop(),
|
|
2443
|
+
cancel: () => bridge.voiceCancel(),
|
|
2444
|
+
probe: () => bridge.voiceProbe(),
|
|
2445
|
+
scratchDir: () => ensureSessionScratchDir(),
|
|
2446
|
+
transcribe: transcribeDictation,
|
|
2447
|
+
openStream: (onText) => openVoiceStream({ config: authConfig, onText }),
|
|
2448
|
+
report: (body) => appendStaticEntry({ kind: 'error', title: 'Voice', body }),
|
|
2449
|
+
notice: (body) => appendStaticEntry({ kind: 'system', title: 'Voice', body }),
|
|
2450
|
+
status: (text) => showTransientStatus(text),
|
|
2451
|
+
});
|
|
2452
|
+
const countVoiceHint = () => {
|
|
2453
|
+
const prefs = readPreferences(session.env);
|
|
2454
|
+
if (!prefs.voice.enabled || prefs.voice.hints >= 3 || isRemoteSession(session.env))
|
|
2455
|
+
return;
|
|
2456
|
+
store.update((current) => ({ ...current, voiceHint: true }));
|
|
2457
|
+
try {
|
|
2458
|
+
writePreferences({ ...prefs, voice: { ...prefs.voice, hints: prefs.voice.hints + 1 } }, session.env);
|
|
2459
|
+
}
|
|
2460
|
+
catch {
|
|
2461
|
+
}
|
|
2462
|
+
};
|
|
2463
|
+
countVoiceHint();
|
|
2464
|
+
const voiceOnMessage = (mode) => {
|
|
2465
|
+
const key = voiceKeyLabel(store.getState().shortcuts);
|
|
2466
|
+
const how = mode === 'hold'
|
|
2467
|
+
? `Hold ${key} to talk and let go to stop.`
|
|
2468
|
+
: key === 'Space'
|
|
2469
|
+
? 'Tap Space in an empty message box to start, and tap it again to stop.'
|
|
2470
|
+
: `Tap ${key} to start, and tap it again to stop.`;
|
|
2471
|
+
return `Dictation on (${mode}). ${how} Your words go into the message box, and nothing is sent until you press Enter. Esc cancels a recording.`;
|
|
2472
|
+
};
|
|
2473
|
+
const handleVoiceCommand = async (arg) => {
|
|
2474
|
+
const state = store.getState();
|
|
2475
|
+
const choice = arg.toLowerCase();
|
|
2476
|
+
let next;
|
|
2477
|
+
if (!choice)
|
|
2478
|
+
next = { enabled: !state.voiceEnabled, mode: state.voiceMode };
|
|
2479
|
+
else if (choice === 'on')
|
|
2480
|
+
next = { enabled: true, mode: state.voiceMode };
|
|
2481
|
+
else if (choice === 'off')
|
|
2482
|
+
next = { enabled: false, mode: state.voiceMode };
|
|
2483
|
+
else if (choice === 'hold' || choice === 'tap')
|
|
2484
|
+
next = { enabled: true, mode: choice };
|
|
2485
|
+
else {
|
|
2486
|
+
appendStaticEntry({ kind: 'error', title: 'Voice', body: 'Use /voice, /voice hold, /voice tap or /voice off.' });
|
|
2487
|
+
return;
|
|
2488
|
+
}
|
|
2489
|
+
if (next.enabled && !state.voiceEnabled) {
|
|
2490
|
+
if (isRemoteSession(session.env)) {
|
|
2491
|
+
appendStaticEntry({
|
|
2492
|
+
kind: 'error',
|
|
2493
|
+
title: 'Voice',
|
|
2494
|
+
body: "Voice dictation needs a microphone on this computer, so it doesn't work over SSH.",
|
|
2495
|
+
});
|
|
2496
|
+
return;
|
|
2497
|
+
}
|
|
2498
|
+
const probe = await voiceDictation.probe();
|
|
2499
|
+
if (!probe.ok) {
|
|
2500
|
+
appendStaticEntry({ kind: 'error', title: 'Voice', body: voiceErrorMessage(probe.code, probe.detail) });
|
|
2501
|
+
return;
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
else if (!next.enabled) {
|
|
2505
|
+
voiceDictation.cancel();
|
|
2506
|
+
}
|
|
2507
|
+
const wasEnabled = state.voiceEnabled;
|
|
2508
|
+
store.update((current) => ({ ...current, voiceEnabled: next.enabled, voiceMode: next.mode }));
|
|
2509
|
+
try {
|
|
2510
|
+
const prefs = readPreferences(session.env);
|
|
2511
|
+
writePreferences({ ...prefs, voice: { ...prefs.voice, ...next } }, session.env);
|
|
2512
|
+
}
|
|
2513
|
+
catch {
|
|
2514
|
+
}
|
|
2515
|
+
if (next.enabled && !wasEnabled && !store.getState().voiceHint)
|
|
2516
|
+
countVoiceHint();
|
|
2517
|
+
appendStaticEntry({
|
|
2518
|
+
kind: 'system',
|
|
2519
|
+
title: 'Voice',
|
|
2520
|
+
body: next.enabled ? voiceOnMessage(next.mode) : 'Dictation off.',
|
|
2521
|
+
});
|
|
2522
|
+
};
|
|
2399
2523
|
const openJobsPicker = () => {
|
|
2400
2524
|
if (store.getState().jobsPickerOpen)
|
|
2401
2525
|
return;
|
|
@@ -2924,9 +3048,19 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
2924
3048
|
toggleNotifications();
|
|
2925
3049
|
return;
|
|
2926
3050
|
}
|
|
3051
|
+
if (input === '/voice' || input.startsWith('/voice ')) {
|
|
3052
|
+
store.update((current) => ({
|
|
3053
|
+
...current,
|
|
3054
|
+
cursor: 0,
|
|
3055
|
+
input: '',
|
|
3056
|
+
pastedChunks: [],
|
|
3057
|
+
}));
|
|
3058
|
+
await handleVoiceCommand(input.slice('/voice'.length).trim());
|
|
3059
|
+
return;
|
|
3060
|
+
}
|
|
2927
3061
|
appendTurnAwareEntry({
|
|
2928
3062
|
body: "Slash commands can't be queued while a turn is running. " +
|
|
2929
|
-
'
|
|
3063
|
+
'Use /jobs for background jobs or /notify to toggle notifications.',
|
|
2930
3064
|
kind: 'system',
|
|
2931
3065
|
title: 'Queued',
|
|
2932
3066
|
});
|
|
@@ -3025,9 +3159,20 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3025
3159
|
await flushQueuedMessage();
|
|
3026
3160
|
return;
|
|
3027
3161
|
}
|
|
3162
|
+
if (input === '/keybindings') {
|
|
3163
|
+
const file = keybindingsPath(session.env);
|
|
3164
|
+
try {
|
|
3165
|
+
prepareKeybindings(file);
|
|
3166
|
+
appendStaticEntry({ kind: 'system', title: 'Keyboard shortcuts', body: `Edit ${file} in any editor. Saved changes apply right away.` });
|
|
3167
|
+
}
|
|
3168
|
+
catch (error) {
|
|
3169
|
+
appendStaticEntry({ kind: 'error', title: 'Keyboard shortcuts', body: error.message });
|
|
3170
|
+
}
|
|
3171
|
+
return;
|
|
3172
|
+
}
|
|
3028
3173
|
if (input === '/help') {
|
|
3029
3174
|
appendStaticEntry({
|
|
3030
|
-
body: formatInteractiveHelpText(),
|
|
3175
|
+
body: formatInteractiveHelpText(store.getState().shortcuts),
|
|
3031
3176
|
kind: 'system',
|
|
3032
3177
|
title: 'Help',
|
|
3033
3178
|
});
|
|
@@ -3050,6 +3195,10 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3050
3195
|
toggleNotifications();
|
|
3051
3196
|
return;
|
|
3052
3197
|
}
|
|
3198
|
+
if (input === '/voice' || input.startsWith('/voice ')) {
|
|
3199
|
+
await handleVoiceCommand(input.slice('/voice'.length).trim());
|
|
3200
|
+
return;
|
|
3201
|
+
}
|
|
3053
3202
|
if (input === '/jobs' || input.startsWith('/jobs ')) {
|
|
3054
3203
|
const jobsArgs = input.slice('/jobs'.length).trim();
|
|
3055
3204
|
if (!jobsArgs) {
|
|
@@ -3699,6 +3848,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3699
3848
|
onSelectModel: handleInlineModelSelection,
|
|
3700
3849
|
onOpenJobsPicker: openJobsPicker,
|
|
3701
3850
|
onToggleNotifications: toggleNotifications,
|
|
3851
|
+
onVoiceKey: (key) => voiceDictation.handleKey(key),
|
|
3702
3852
|
onJobsPickerOutput: handleJobsPickerOutput,
|
|
3703
3853
|
onJobsPickerKill: handleJobsPickerKill,
|
|
3704
3854
|
onSudoPasswordInput: handleSudoPasswordInput,
|
|
@@ -3757,6 +3907,10 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3757
3907
|
void remountTui();
|
|
3758
3908
|
return;
|
|
3759
3909
|
}
|
|
3910
|
+
if (message.kind.startsWith('voice')) {
|
|
3911
|
+
voiceDictation.handleEvent(message);
|
|
3912
|
+
return;
|
|
3913
|
+
}
|
|
3760
3914
|
handleShellKeyEvent(store, shellInputHandlers, message);
|
|
3761
3915
|
renderCurrentFrame();
|
|
3762
3916
|
}
|
|
@@ -3764,10 +3918,13 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3764
3918
|
setCommandOutputHook((text) => {
|
|
3765
3919
|
store.update((current) => appendCommandLog(current, text));
|
|
3766
3920
|
});
|
|
3921
|
+
const stopWatchingKeys = watchKeybindings(keybindingsPath(session.env), (shortcuts) => store.update((current) => ({ ...current, shortcuts })), (body) => appendStaticEntry({ kind: 'error', title: 'Keyboard shortcuts', body }));
|
|
3767
3922
|
try {
|
|
3768
3923
|
await done;
|
|
3769
3924
|
}
|
|
3770
3925
|
finally {
|
|
3926
|
+
voiceDictation.dispose();
|
|
3927
|
+
stopWatchingKeys();
|
|
3771
3928
|
clearInterval(spinnerTimer);
|
|
3772
3929
|
clearInterval(clockTimer);
|
|
3773
3930
|
unsubscribe();
|
|
@@ -13,8 +13,10 @@ export const SLASH_COMMANDS = [
|
|
|
13
13
|
{ command: '/jobs', description: 'Background jobs: pick to view output or kill' },
|
|
14
14
|
{
|
|
15
15
|
command: '/notify',
|
|
16
|
-
description: 'Toggle desktop notifications when a turn ends
|
|
16
|
+
description: 'Toggle desktop notifications when a turn ends',
|
|
17
17
|
},
|
|
18
|
+
{ command: '/voice', description: 'Voice dictation on or off; /voice hold or /voice tap picks how' },
|
|
19
|
+
{ command: '/keybindings', description: 'Change your keyboard shortcuts' },
|
|
18
20
|
{ command: '/report', description: 'Report a bug or request a feature privately on the TheGitAI website' },
|
|
19
21
|
{ command: '/about', description: 'Show version and platform info' },
|
|
20
22
|
{ command: '/logout', description: 'Sign out and quit' },
|
|
@@ -71,6 +71,44 @@ function normalizeChildMessage(raw) {
|
|
|
71
71
|
offset: Number(raw.offset ?? 0),
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
+
if (raw.kind === 'voiceStarted') {
|
|
75
|
+
return {
|
|
76
|
+
op: 'event',
|
|
77
|
+
kind: 'voiceStarted',
|
|
78
|
+
recorder: String(raw.recorder ?? ''),
|
|
79
|
+
...(typeof raw.path === 'string' ? { path: raw.path } : {}),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (raw.kind === 'voiceLevel') {
|
|
83
|
+
return {
|
|
84
|
+
op: 'event',
|
|
85
|
+
kind: 'voiceLevel',
|
|
86
|
+
level: Number(raw.level ?? 0),
|
|
87
|
+
...(typeof raw.audio === 'string' ? { audio: raw.audio } : {}),
|
|
88
|
+
...(typeof raw.path === 'string' ? { path: raw.path } : {}),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (raw.kind === 'voiceDone') {
|
|
92
|
+
return { op: 'event', kind: 'voiceDone', path: String(raw.path ?? ''), seconds: Number(raw.seconds ?? 0) };
|
|
93
|
+
}
|
|
94
|
+
if (raw.kind === 'voiceError') {
|
|
95
|
+
return {
|
|
96
|
+
op: 'event',
|
|
97
|
+
kind: 'voiceError',
|
|
98
|
+
code: String(raw.code ?? 'failed'),
|
|
99
|
+
detail: String(raw.detail ?? ''),
|
|
100
|
+
...(typeof raw.path === 'string' ? { path: raw.path } : {}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (raw.kind === 'voiceProbe') {
|
|
104
|
+
return {
|
|
105
|
+
op: 'event',
|
|
106
|
+
kind: 'voiceProbe',
|
|
107
|
+
ok: raw.ok === true,
|
|
108
|
+
code: String(raw.code ?? ''),
|
|
109
|
+
detail: String(raw.detail ?? ''),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
74
112
|
if (raw.kind !== 'key') {
|
|
75
113
|
return null;
|
|
76
114
|
}
|
|
@@ -191,6 +229,18 @@ export function createRatatuiBridge() {
|
|
|
191
229
|
setTitle(title) {
|
|
192
230
|
writeParent({ op: 'title', text: title });
|
|
193
231
|
},
|
|
232
|
+
voiceStart(path, maxSeconds) {
|
|
233
|
+
writeParent({ op: 'voiceStart', path, maxSeconds });
|
|
234
|
+
},
|
|
235
|
+
voiceStop() {
|
|
236
|
+
writeParent({ op: 'voiceStop' });
|
|
237
|
+
},
|
|
238
|
+
voiceCancel() {
|
|
239
|
+
writeParent({ op: 'voiceCancel' });
|
|
240
|
+
},
|
|
241
|
+
voiceProbe() {
|
|
242
|
+
writeParent({ op: 'voiceProbe' });
|
|
243
|
+
},
|
|
194
244
|
async close() {
|
|
195
245
|
if (closed)
|
|
196
246
|
return;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { shortcutLabel } from '../../keyboard-shortcuts.js';
|
|
2
|
+
import { joinDictatedText, VOICE_GRADIENT, voiceClock, voiceHint, voiceLevelGlyph, voiceSpinner, voiceWave, } from './voice-dictation.js';
|
|
1
3
|
import { modelPickerWindow, modelPickerScrollLabel } from './model-picker-window.js';
|
|
2
4
|
import { fitModelLabel } from './model-label.js';
|
|
3
5
|
import { projectModelEffort } from '../../project-model-preferences.js';
|
|
@@ -48,8 +50,29 @@ export function footerNotificationHint(status) {
|
|
|
48
50
|
return FOOTER_NOTIFICATIONS_OFF;
|
|
49
51
|
return '';
|
|
50
52
|
}
|
|
51
|
-
const FOOTER_CYCLE_HINT = ' (shift+tab to cycle)';
|
|
52
53
|
const OVERLAY_PANEL_MAX_WIDTH = 86;
|
|
54
|
+
function voiceTitle(state, at = Date.now()) {
|
|
55
|
+
const activity = state.voice;
|
|
56
|
+
if (!activity)
|
|
57
|
+
return null;
|
|
58
|
+
const muted = { color: mutedColor() };
|
|
59
|
+
if (activity.phase === 'warmup')
|
|
60
|
+
return line(span(' keep holding… ', muted));
|
|
61
|
+
if (activity.phase === 'starting')
|
|
62
|
+
return line(span(' ○ starting… ', muted));
|
|
63
|
+
if (activity.phase === 'transcribing') {
|
|
64
|
+
return line(span(` ${voiceSpinner(activity.tick)} `, { color: 'cyan' }), span('transcribing… ', muted));
|
|
65
|
+
}
|
|
66
|
+
const pulse = Math.floor(at / 500) % 2 === 0;
|
|
67
|
+
return line(span(' ● ', { color: 'red', bold: pulse, dim: !pulse }), span(`${voiceClock(activity, at)} `, muted), ...voiceWave(activity.levels).map((glyph, index) => span(glyph, { color: VOICE_GRADIENT[index] })), span(' listening… ', muted));
|
|
68
|
+
}
|
|
69
|
+
function voiceCursor(state, at = Date.now()) {
|
|
70
|
+
const activity = state.voice;
|
|
71
|
+
if (!activity || activity.phase !== 'recording')
|
|
72
|
+
return null;
|
|
73
|
+
const level = activity.levels[activity.levels.length - 1] ?? 0;
|
|
74
|
+
return span(voiceLevelGlyph(level), { color: VOICE_GRADIENT[Math.floor(at / 150) % VOICE_GRADIENT.length] });
|
|
75
|
+
}
|
|
53
76
|
const USER_INPUT_PANEL_MAX_WIDTH = 120;
|
|
54
77
|
const OVERLAY_PANEL_MARGIN_LINES = 2;
|
|
55
78
|
const OVERLAY_PANEL_MARGIN_MIN_ROWS = 30;
|
|
@@ -73,13 +96,13 @@ function composerMarkerMask(text) {
|
|
|
73
96
|
}
|
|
74
97
|
return mask;
|
|
75
98
|
}
|
|
76
|
-
function composerRowSpans(text, mask, cursorCol) {
|
|
99
|
+
function composerRowSpans(text, mask, cursorCol, dim = [], cursorSpan = null) {
|
|
77
100
|
const spans = [];
|
|
78
|
-
const push = (value, marker, cursor) => {
|
|
101
|
+
const push = (value, marker, cursor, faded = false) => {
|
|
79
102
|
if (!value)
|
|
80
103
|
return;
|
|
81
104
|
spans.push(span(value, {
|
|
82
|
-
...(marker ? { color: 'cyan' } : {}),
|
|
105
|
+
...(marker ? { color: 'cyan' } : faded ? { color: mutedColor() } : {}),
|
|
83
106
|
...(cursor ? { inverse: true } : {}),
|
|
84
107
|
}));
|
|
85
108
|
};
|
|
@@ -87,10 +110,11 @@ function composerRowSpans(text, mask, cursorCol) {
|
|
|
87
110
|
const flushTo = (end) => {
|
|
88
111
|
while (cut < end) {
|
|
89
112
|
const marker = mask[cut] ?? false;
|
|
113
|
+
const faded = dim[cut] ?? false;
|
|
90
114
|
let runEnd = cut + 1;
|
|
91
|
-
while (runEnd < end && (mask[runEnd] ?? false) === marker)
|
|
115
|
+
while (runEnd < end && (mask[runEnd] ?? false) === marker && (dim[runEnd] ?? false) === faded)
|
|
92
116
|
runEnd += 1;
|
|
93
|
-
push(text.slice(cut, runEnd), marker, false);
|
|
117
|
+
push(text.slice(cut, runEnd), marker, false, faded);
|
|
94
118
|
cut = runEnd;
|
|
95
119
|
}
|
|
96
120
|
};
|
|
@@ -99,15 +123,18 @@ function composerRowSpans(text, mask, cursorCol) {
|
|
|
99
123
|
return spans;
|
|
100
124
|
}
|
|
101
125
|
flushTo(Math.min(cursorCol, text.length));
|
|
102
|
-
|
|
126
|
+
if (cursorSpan && cursorCol >= text.length)
|
|
127
|
+
spans.push(cursorSpan);
|
|
128
|
+
else
|
|
129
|
+
push(text[cursorCol] ?? ' ', mask[cursorCol] ?? false, true);
|
|
103
130
|
cut = Math.min(cursorCol + 1, text.length);
|
|
104
131
|
flushTo(text.length);
|
|
105
132
|
return spans;
|
|
106
133
|
}
|
|
107
|
-
function buildComposerInputLines(input, cursor, promptLabel, placeholder, width) {
|
|
134
|
+
function buildComposerInputLines(input, cursor, promptLabel, placeholder, width, { dim, cursorSpan = null } = {}) {
|
|
108
135
|
if (!input) {
|
|
109
136
|
return [
|
|
110
|
-
line(span(promptLabel, { color: 'cyan' }), span(' ', { inverse: true }), span(placeholder, { color: mutedColor() })),
|
|
137
|
+
line(span(promptLabel, { color: 'cyan' }), cursorSpan ?? span(' ', { inverse: true }), span(placeholder, { color: mutedColor() })),
|
|
111
138
|
];
|
|
112
139
|
}
|
|
113
140
|
const labelWidth = promptLabel.length;
|
|
@@ -121,6 +148,11 @@ function buildComposerInputLines(input, cursor, promptLabel, placeholder, width)
|
|
|
121
148
|
consumed += row.length;
|
|
122
149
|
}
|
|
123
150
|
const mask = composerMarkerMask(rows.join(''));
|
|
151
|
+
const rowsOffset = (offset) => offset - (input.slice(0, offset).match(/[\r\n]/g)?.length ?? 0);
|
|
152
|
+
const [dimStart, dimEnd] = dim ? [rowsOffset(dim[0]), rowsOffset(dim[1])] : [0, 0];
|
|
153
|
+
const dimMask = dim
|
|
154
|
+
? Array.from({ length: consumed }, (_, index) => index >= dimStart && index < dimEnd)
|
|
155
|
+
: [];
|
|
124
156
|
return rows
|
|
125
157
|
.slice(firstRow, firstRow + COMPOSER_INPUT_MAX_ROWS)
|
|
126
158
|
.map((text, index) => {
|
|
@@ -129,7 +161,7 @@ function buildComposerInputLines(input, cursor, promptLabel, placeholder, width)
|
|
|
129
161
|
const label = index === 0
|
|
130
162
|
? span(promptLabel, { color: 'cyan' })
|
|
131
163
|
: span(' '.repeat(labelWidth));
|
|
132
|
-
return line(label, ...composerRowSpans(text, mask.slice(rowStart, rowStart + text.length), absoluteRow === cursorRow ? cursorCol : null));
|
|
164
|
+
return line(label, ...composerRowSpans(text, mask.slice(rowStart, rowStart + text.length), absoluteRow === cursorRow ? cursorCol : null, dimMask.slice(rowStart, rowStart + text.length), cursorSpan));
|
|
133
165
|
});
|
|
134
166
|
}
|
|
135
167
|
function getEntryColor(kind) {
|
|
@@ -489,7 +521,9 @@ function backgroundJobIndicatorSpans(state) {
|
|
|
489
521
|
if (runningCount === 0)
|
|
490
522
|
return [];
|
|
491
523
|
const noun = runningCount === 1 ? 'shell' : 'shells';
|
|
492
|
-
const hint = state.busy
|
|
524
|
+
const hint = state.busy
|
|
525
|
+
? ` · ${shortcutLabel('backgroundJobs', state.shortcuts).toLowerCase()}`
|
|
526
|
+
: ' · /jobs';
|
|
493
527
|
return [
|
|
494
528
|
span(' ', { color: 'gray', dim: true }),
|
|
495
529
|
span(`● ${runningCount} ${noun} running`, { color: 'green', bold: true }),
|
|
@@ -618,7 +652,9 @@ function composerFooterModeLines(state, contentWidth, modelLabel, usageWidth, us
|
|
|
618
652
|
const row = fitComposerFooterRow({
|
|
619
653
|
modeLabels,
|
|
620
654
|
modeLabelFallback: `Mode: ${agentModeShortLabel(state.agentMode)}`,
|
|
621
|
-
cycleHint: state.busy
|
|
655
|
+
cycleHint: state.busy
|
|
656
|
+
? ''
|
|
657
|
+
: ` (${shortcutLabel('cycleMode', state.shortcuts).toLowerCase()} to cycle)`,
|
|
622
658
|
rightHints: composerFooterRightHints(state),
|
|
623
659
|
leadWidth: combined ? displayWidth(modelLabel + effortText) + FOOTER_MODEL_SEPARATOR.length : 0,
|
|
624
660
|
tailWidth,
|
|
@@ -1481,7 +1517,7 @@ function buildOverlayLines(state, width, height, nowMs) {
|
|
|
1481
1517
|
return buildOverlayPanel(lines, width, OVERLAY_BORDER_COLOR, height);
|
|
1482
1518
|
}
|
|
1483
1519
|
if (state.shortcutsOpen) {
|
|
1484
|
-
lines.push(...buildShortcutsPanel(buildShortcutGroups(), width, height));
|
|
1520
|
+
lines.push(...buildShortcutsPanel(buildShortcutGroups(process.platform, state.shortcuts), width, height));
|
|
1485
1521
|
}
|
|
1486
1522
|
if (state.skillsPickerOpen) {
|
|
1487
1523
|
lines.push(...buildSkillsPickerPanel(state.skillsPickerItems ?? [], state.skillsPickerIndex ?? 0, width, height));
|
|
@@ -1645,14 +1681,27 @@ export function buildTuiFrame(state, cols, rows, spinnerFrame, elapsedSeconds, n
|
|
|
1645
1681
|
}
|
|
1646
1682
|
else {
|
|
1647
1683
|
const promptLabel = composerPromptLabel(state);
|
|
1648
|
-
const
|
|
1684
|
+
const basePlaceholder = state.busy
|
|
1649
1685
|
? 'Type to queue the next message'
|
|
1650
1686
|
: 'Type a request or /help';
|
|
1651
|
-
|
|
1687
|
+
const placeholder = state.voice
|
|
1688
|
+
? ''
|
|
1689
|
+
: state.voiceEnabled && state.voiceHint
|
|
1690
|
+
? `${basePlaceholder} · ${voiceHint({ shortcuts: state.shortcuts ?? {}, voiceMode: state.voiceMode ?? 'hold' })}`
|
|
1691
|
+
: basePlaceholder;
|
|
1692
|
+
const interim = state.voice?.interim.trim() ?? '';
|
|
1693
|
+
const shown = interim
|
|
1694
|
+
? joinDictatedText(state.input, state.cursor, interim)
|
|
1695
|
+
: { input: state.input, cursor: state.cursor };
|
|
1696
|
+
composerLines.push(...buildComposerInputLines(shown.input, shown.cursor, promptLabel, placeholder, contentWidth, {
|
|
1697
|
+
...(interim ? { dim: [shown.cursor - interim.length, shown.cursor] } : {}),
|
|
1698
|
+
cursorSpan: voiceCursor(state),
|
|
1699
|
+
}));
|
|
1652
1700
|
}
|
|
1653
1701
|
sections.push({
|
|
1654
1702
|
kind: 'composer',
|
|
1655
1703
|
lines: [...composerLines, plainLine(''), ...composerFooterLines(state, contentWidth)],
|
|
1704
|
+
...(voiceTitle(state) ? { title: voiceTitle(state) } : {}),
|
|
1656
1705
|
});
|
|
1657
1706
|
}
|
|
1658
1707
|
if (state.userInputPrompt) {
|