@thegitai/cli 1.7.0 → 1.9.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 +3 -2
- package/dist/src/api/voice.js +96 -0
- package/dist/src/help-text.js +8 -1
- package/dist/src/keyboard-shortcuts.js +8 -3
- package/dist/src/preferences.js +8 -2
- package/dist/src/tools/computer.js +98 -14
- package/dist/src/ui/repl.js +145 -3
- package/dist/src/ui/slash-commands.js +1 -0
- package/dist/src/ui/tui/bridge.js +50 -0
- package/dist/src/ui/tui/build-frame.js +56 -11
- package/dist/src/ui/tui/shell-input.js +2 -0
- package/dist/src/ui/tui/shortcuts.js +2 -0
- package/dist/src/ui/tui/voice-dictation.js +438 -0
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ This package is the CLI. The same agent is also available as a
|
|
|
16
16
|
- **Your signed-in Chrome** - with the TheGitAI Chrome extension it works in the
|
|
17
17
|
browser you already have open, signed in as you, in its own tab group.
|
|
18
18
|
- **Computer Control** - it uses the apps on your computer on Linux, macOS and Windows:
|
|
19
|
-
in front of you, or, on Linux and macOS, on a screen of its own while you keep working.
|
|
19
|
+
in front of you, or, on Linux and macOS, on a screen of its own that you can pause and take over while you keep working.
|
|
20
20
|
[Setup guide](https://thegit.ai/docs/computer-control/overview).
|
|
21
21
|
- **Skills** - teach it your team's workflows as `SKILL.md` folders. It uses one
|
|
22
22
|
when a request calls for it, or when you type `/<name>`.
|
|
@@ -29,7 +29,8 @@ This package is the CLI. The same agent is also available as a
|
|
|
29
29
|
- **Beyond source code** - reads PDF, Word and Excel files, edits Word
|
|
30
30
|
documents, looks at screenshots, generates images, and searches and fetches
|
|
31
31
|
the web.
|
|
32
|
-
- **
|
|
32
|
+
- **Voice dictation** - run `/voice`, then hold Space and talk. Your words appear in the prompt as you speak, and nothing is sent until you press Enter.
|
|
33
|
+
- **Keyboard shortcuts** - open `/keybindings` to edit the keys for mode switching, image paste, background jobs, notifications, and dictation. Saved changes apply in the current session.
|
|
33
34
|
- **Steering and recovery** - send corrections while it works, switch between
|
|
34
35
|
Default, Bypass all permissions and Plan modes, and undo an edit, a turn or a
|
|
35
36
|
file, or restore a checkpoint.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createTraceContext, failureCode, failureDetails, failureMessage, normalizeServerUrl, readJsonResponse, ServerApiError, } from './http.js';
|
|
2
|
+
const TRANSCRIBE_TIMEOUT_MS = 90_000;
|
|
3
|
+
export async function transcribeRecording({ config, audio, hints = [], signal, fetchImpl = globalThis.fetch, }) {
|
|
4
|
+
const trace = createTraceContext();
|
|
5
|
+
const timeout = AbortSignal.timeout(TRANSCRIBE_TIMEOUT_MS);
|
|
6
|
+
const response = await fetchImpl(`${normalizeServerUrl(config.serverUrl)}/v1/voice/transcribe`, {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
headers: {
|
|
9
|
+
authorization: `Bearer ${config.token}`,
|
|
10
|
+
...trace.headers,
|
|
11
|
+
'content-type': 'audio/wav',
|
|
12
|
+
...(hints.length ? { 'x-thegitai-voice-hints': encodeURIComponent(JSON.stringify(hints)) } : {}),
|
|
13
|
+
},
|
|
14
|
+
body: new Uint8Array(audio),
|
|
15
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
16
|
+
});
|
|
17
|
+
const data = await readJsonResponse(response);
|
|
18
|
+
if (!response.ok) {
|
|
19
|
+
throw new ServerApiError(failureMessage(data, response.status), response.status, trace.traceId, failureCode(data), failureDetails(data));
|
|
20
|
+
}
|
|
21
|
+
return typeof data?.text === 'string' ? data.text : '';
|
|
22
|
+
}
|
|
23
|
+
export function openVoiceStream({ config, onText, WebSocketImpl = globalThis.WebSocket, }) {
|
|
24
|
+
if (typeof WebSocketImpl !== 'function')
|
|
25
|
+
return null;
|
|
26
|
+
let socket;
|
|
27
|
+
try {
|
|
28
|
+
socket = new WebSocketImpl(`${normalizeServerUrl(config.serverUrl).replace(/^http/i, 'ws')}/v1/voice/stream`);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
socket.binaryType = 'arraybuffer';
|
|
34
|
+
const queued = [];
|
|
35
|
+
let open = false;
|
|
36
|
+
let ready = false;
|
|
37
|
+
let closed = false;
|
|
38
|
+
socket.addEventListener('open', () => {
|
|
39
|
+
if (closed) {
|
|
40
|
+
socket.close();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
open = true;
|
|
44
|
+
socket.send(JSON.stringify({ type: 'start', token: config.token }));
|
|
45
|
+
});
|
|
46
|
+
socket.addEventListener('message', (event) => {
|
|
47
|
+
if (closed || typeof event.data !== 'string')
|
|
48
|
+
return;
|
|
49
|
+
let message = null;
|
|
50
|
+
try {
|
|
51
|
+
message = JSON.parse(event.data);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (message?.type === 'ready' && !ready) {
|
|
57
|
+
ready = true;
|
|
58
|
+
for (const chunk of queued.splice(0))
|
|
59
|
+
socket.send(chunk);
|
|
60
|
+
}
|
|
61
|
+
else if (message?.type === 'text' && typeof message.text === 'string') {
|
|
62
|
+
onText(message.text);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
socket.addEventListener('error', () => {
|
|
66
|
+
closed = true;
|
|
67
|
+
});
|
|
68
|
+
socket.addEventListener('close', () => {
|
|
69
|
+
closed = true;
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
send(chunk) {
|
|
73
|
+
if (closed)
|
|
74
|
+
return;
|
|
75
|
+
const copy = new Uint8Array(chunk);
|
|
76
|
+
if (ready)
|
|
77
|
+
socket.send(copy);
|
|
78
|
+
else
|
|
79
|
+
queued.push(copy);
|
|
80
|
+
},
|
|
81
|
+
close() {
|
|
82
|
+
if (closed)
|
|
83
|
+
return;
|
|
84
|
+
closed = true;
|
|
85
|
+
if (open) {
|
|
86
|
+
try {
|
|
87
|
+
socket.send(JSON.stringify({ type: 'stop' }));
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
socket.close();
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
package/dist/src/help-text.js
CHANGED
|
@@ -109,6 +109,12 @@ function helpMarkdown(shortcuts = {}) {
|
|
|
109
109
|
' back for editing and **Esc**/**Ctrl+C** discards it; both unlock the',
|
|
110
110
|
` composer for the next message. **${key('pasteImage')}** pastes a screenshot onto the`,
|
|
111
111
|
' queued message, and it is delivered into the running turn with the text.',
|
|
112
|
+
`- **/voice** turns voice dictation on, and it stays on between sessions. Then hold **${key('pushToTalk')}**`,
|
|
113
|
+
' to talk and let go to stop: your words land in the composer at the cursor and',
|
|
114
|
+
' are never sent on their own. **Esc** or **Ctrl+C** cancels a recording.',
|
|
115
|
+
' `/voice tap` switches to tap to start and tap again to stop, `/voice hold`',
|
|
116
|
+
' switches back, and `/voice off` turns it off. The microphone is used only',
|
|
117
|
+
' while you record.',
|
|
112
118
|
`- **${key('notifications')}** turns desktop notifications on or off. One is raised when a turn`,
|
|
113
119
|
' ends and when a permission prompt or a question is waiting for you, but',
|
|
114
120
|
' only while the terminal is in the background - if you are looking at the',
|
|
@@ -165,8 +171,9 @@ function helpMarkdown(shortcuts = {}) {
|
|
|
165
171
|
'- `/jobs output <id>` - print one job\'s full captured output',
|
|
166
172
|
'- `/jobs kill <id>` - stop one background job',
|
|
167
173
|
`- \`/notify\` - turn desktop notifications on or off (same as ${key('notifications')})`,
|
|
174
|
+
'- `/voice` - turn voice dictation on or off; `/voice hold` or `/voice tap` picks how you record',
|
|
168
175
|
'- `/keybindings` - change the keys for the agent mode, image paste, background',
|
|
169
|
-
' jobs and
|
|
176
|
+
' jobs, notifications and dictation',
|
|
170
177
|
'- `/new` - start a new conversation; this session remains saved',
|
|
171
178
|
'- `/logout` - sign out and quit',
|
|
172
179
|
'- `/exit` - quit the session',
|
|
@@ -5,6 +5,7 @@ export function defaultShortcuts(platform = process.platform) {
|
|
|
5
5
|
pasteImage: platform === 'win32' ? ['Alt+V', 'Ctrl+V'] : ['Ctrl+V'],
|
|
6
6
|
backgroundJobs: ['Ctrl+B'],
|
|
7
7
|
notifications: ['Ctrl+G'],
|
|
8
|
+
pushToTalk: ['Space'],
|
|
8
9
|
};
|
|
9
10
|
}
|
|
10
11
|
export function shortcutLabel(id, overrides = {}, platform = process.platform) {
|
|
@@ -13,9 +14,11 @@ export function shortcutLabel(id, overrides = {}, platform = process.platform) {
|
|
|
13
14
|
export function matchesShortcut(id, key, overrides = {}) {
|
|
14
15
|
const chord = key.tab
|
|
15
16
|
? key.shift && !key.ctrl && !key.meta ? 'Shift+Tab' : ''
|
|
16
|
-
: key.
|
|
17
|
-
?
|
|
18
|
-
:
|
|
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
|
+
: '';
|
|
19
22
|
return chord !== '' && (overrides[id] ?? defaultShortcuts()[id]).includes(chord);
|
|
20
23
|
}
|
|
21
24
|
export function parseShortcutFile(value, platform = process.platform) {
|
|
@@ -44,6 +47,8 @@ export function parseShortcutFile(value, platform = process.platform) {
|
|
|
44
47
|
}))];
|
|
45
48
|
if (overrides[id].length === 0)
|
|
46
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".');
|
|
47
52
|
}
|
|
48
53
|
const owners = new Map();
|
|
49
54
|
for (const [id, keys] of Object.entries({ ...defaults, ...overrides })) {
|
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) {
|
|
@@ -23,6 +23,9 @@ export const COMPUTER_OPERATIONS = [
|
|
|
23
23
|
];
|
|
24
24
|
const CALL_TIMEOUT_MS = 90_000;
|
|
25
25
|
const TYPE_MS_PER_CHARACTER = 20;
|
|
26
|
+
const SCREEN_CHECK_MS = 3_000;
|
|
27
|
+
const PAUSE_LIMIT_MS = 25 * 60_000;
|
|
28
|
+
const WAIT_SECONDS = 20;
|
|
26
29
|
let helper = null;
|
|
27
30
|
const currentTurn = new AsyncLocalStorage();
|
|
28
31
|
const computerUsers = new Set();
|
|
@@ -78,11 +81,11 @@ function startHelper(helperPath, env) {
|
|
|
78
81
|
proc.on('error', (error) => fail(`The desktop helper could not start: ${error.message}`));
|
|
79
82
|
return state;
|
|
80
83
|
}
|
|
81
|
-
function send(helperPath, env, request, signal) {
|
|
84
|
+
function send(helperPath, env, request, signal, probe) {
|
|
82
85
|
if (!helper)
|
|
83
86
|
helper = startHelper(helperPath, env);
|
|
84
87
|
const state = helper;
|
|
85
|
-
if (request.op !== 'end')
|
|
88
|
+
if (request.op !== 'end' && !probe)
|
|
86
89
|
state.inUse = true;
|
|
87
90
|
const id = state.nextId++;
|
|
88
91
|
const owner = currentTurn.getStore();
|
|
@@ -95,11 +98,11 @@ function send(helperPath, env, request, signal) {
|
|
|
95
98
|
state.proc.stdin.write(`${JSON.stringify({ op: 'end', id: state.nextId++ })}\n`);
|
|
96
99
|
return true;
|
|
97
100
|
};
|
|
98
|
-
const timeoutMs = CALL_TIMEOUT_MS +
|
|
101
|
+
const timeoutMs = probe?.timeoutMs ?? CALL_TIMEOUT_MS +
|
|
99
102
|
(request.op === 'type_text' ? String(request.text ?? '').length * TYPE_MS_PER_CHARACTER : 0);
|
|
100
103
|
return new Promise((resolve) => {
|
|
101
104
|
const timer = setTimeout(() => {
|
|
102
|
-
const stopped = stop();
|
|
105
|
+
const stopped = probe ? false : stop();
|
|
103
106
|
state.pending.delete(id);
|
|
104
107
|
const seconds = Math.round(timeoutMs / 1000);
|
|
105
108
|
resolve({
|
|
@@ -119,25 +122,38 @@ const deniedNotes = new Map();
|
|
|
119
122
|
function conversation() {
|
|
120
123
|
return scopedSessionId() ?? '';
|
|
121
124
|
}
|
|
122
|
-
function promptBody() {
|
|
125
|
+
function promptBody(screenNeedsLogin) {
|
|
123
126
|
if (process.platform === 'win32') {
|
|
124
127
|
return "It works on your screen: it moves your pointer and types until it's done. Press Esc anytime to take over.";
|
|
125
128
|
}
|
|
126
129
|
const background = process.platform === 'darwin'
|
|
127
130
|
? 'In the background, it works on a virtual display in your login session. Adding the display can briefly move your pointer before restoring it. Targeted input is experimental: some apps can take focus or ignore gestures. Hover requires control on your screen. You can move the same running window to your desktop afterward. '
|
|
128
131
|
: 'In the background, it works on a screen of its own with its own mouse and keyboard, so you keep yours. ';
|
|
132
|
+
if (screenNeedsLogin) {
|
|
133
|
+
return background +
|
|
134
|
+
'You can watch it in a small window.\n' +
|
|
135
|
+
'To let it work on your screen, log out and back in once, then ask again.';
|
|
136
|
+
}
|
|
129
137
|
return background +
|
|
130
138
|
'You can watch it in a small window.\n' +
|
|
131
139
|
"On your screen, it moves your pointer and types until it's done. Press Esc anytime to take over.";
|
|
132
140
|
}
|
|
133
|
-
async function
|
|
141
|
+
async function screenNeedsLogin(helperPath, env, signal) {
|
|
142
|
+
if (process.platform !== 'linux')
|
|
143
|
+
return false;
|
|
144
|
+
const reply = await send(helperPath, env, { op: 'screen_ready' }, signal, { timeoutMs: SCREEN_CHECK_MS });
|
|
145
|
+
return reply?.ok === true && reply.text === 'log_in';
|
|
146
|
+
}
|
|
147
|
+
async function askForDesktop(context, key, helperPath, env) {
|
|
134
148
|
if (!context.requestPermission)
|
|
135
149
|
return null;
|
|
150
|
+
const needsLogin = await screenNeedsLogin(helperPath, env, context.signal);
|
|
151
|
+
context.signal?.throwIfAborted();
|
|
136
152
|
const decision = await context.requestPermission({
|
|
137
153
|
bucket: 'computer',
|
|
138
154
|
alwaysAsk: true,
|
|
139
155
|
title: 'TheGitAI wants to use apps on this computer',
|
|
140
|
-
body: promptBody(),
|
|
156
|
+
body: promptBody(needsLogin),
|
|
141
157
|
options: process.platform === 'win32'
|
|
142
158
|
? [
|
|
143
159
|
{ label: 'Allow on my screen', decision: { kind: 'computer', desktop: 'screen', session: false } },
|
|
@@ -165,7 +181,7 @@ async function askForDesktop(context, key) {
|
|
|
165
181
|
taskChoices.set(key, decision.desktop);
|
|
166
182
|
return decision.desktop;
|
|
167
183
|
}
|
|
168
|
-
function chooseDesktop(context) {
|
|
184
|
+
function chooseDesktop(context, helperPath, env) {
|
|
169
185
|
const remembered = context.grants?.computer;
|
|
170
186
|
if (remembered)
|
|
171
187
|
return Promise.resolve(remembered);
|
|
@@ -177,11 +193,50 @@ function chooseDesktop(context) {
|
|
|
177
193
|
return Promise.resolve(choice);
|
|
178
194
|
let pending = pendingChoices.get(key);
|
|
179
195
|
if (!pending) {
|
|
180
|
-
pending = askForDesktop(context, key).finally(() => pendingChoices.delete(key));
|
|
196
|
+
pending = askForDesktop(context, key, helperPath, env).finally(() => pendingChoices.delete(key));
|
|
181
197
|
pendingChoices.set(key, pending);
|
|
182
198
|
}
|
|
183
199
|
return pending;
|
|
184
200
|
}
|
|
201
|
+
function askAgain(context) {
|
|
202
|
+
if (!context.requestPermission)
|
|
203
|
+
return;
|
|
204
|
+
if (context.grants)
|
|
205
|
+
delete context.grants.computer;
|
|
206
|
+
const key = conversation();
|
|
207
|
+
if (taskChoices.get(key) !== 'denied')
|
|
208
|
+
taskChoices.delete(key);
|
|
209
|
+
}
|
|
210
|
+
function permissionLine(context, desktop) {
|
|
211
|
+
const where = desktop === 'background' ? "TheGitAI's background screen" : "the user's own screen";
|
|
212
|
+
const span = context.grants?.computer === desktop ? 'for this session' : 'for this request';
|
|
213
|
+
return `Permission: ${where}, ${span}.`;
|
|
214
|
+
}
|
|
215
|
+
function stoppedNote(desktop) {
|
|
216
|
+
const how = desktop === 'background' ? " with Stop in the window showing TheGitAI's screen" : '';
|
|
217
|
+
return `The user took back control${how}. That is their choice, not an error: do not use the computer tools again for this request, and tell them what you had done.`;
|
|
218
|
+
}
|
|
219
|
+
const CLOSED_NOTE = "The user closed the window showing TheGitAI's screen, which closes that screen and the apps on it. " +
|
|
220
|
+
'That is their choice, not an error: do not use the computer tools again for this request, and tell them what you had done.';
|
|
221
|
+
const RESUMED_NOTE = "The user paused you on TheGitAI's screen to use it themselves, then pressed Resume. That is their choice, not an error. " +
|
|
222
|
+
'This action was stopped and may have done only part of its work. Look at the app again before you continue, ' +
|
|
223
|
+
'do not repeat what already took effect, and expect changes they made while you waited.';
|
|
224
|
+
const STILL_PAUSED_NOTE = "The user paused you on TheGitAI's screen and has not pressed Resume yet. That is their choice, not an error. " +
|
|
225
|
+
'Do not use the computer tools again for now: tell them what is left, and that they can ask you in the chat to continue when they are ready.';
|
|
226
|
+
async function waitForResume(context, helperPath, env, desktop) {
|
|
227
|
+
context.onStatus("Paused on TheGitAI's screen. Waiting for Resume.");
|
|
228
|
+
const started = Date.now();
|
|
229
|
+
while (Date.now() - started < PAUSE_LIMIT_MS) {
|
|
230
|
+
context.signal?.throwIfAborted();
|
|
231
|
+
const reply = await send(helperPath, env, { op: 'wait', desktop, seconds: WAIT_SECONDS }, context.signal);
|
|
232
|
+
context.signal?.throwIfAborted();
|
|
233
|
+
if (!reply?.ok)
|
|
234
|
+
return 'paused';
|
|
235
|
+
if (reply.text === 'resumed' || reply.text === 'stopped' || reply.text === 'closed')
|
|
236
|
+
return reply.text;
|
|
237
|
+
}
|
|
238
|
+
return 'paused';
|
|
239
|
+
}
|
|
185
240
|
export async function withComputerTurn(run) {
|
|
186
241
|
const token = Symbol();
|
|
187
242
|
const key = conversation();
|
|
@@ -225,7 +280,11 @@ export function computerTool(operation) {
|
|
|
225
280
|
failureCategory: 'policy_blocked',
|
|
226
281
|
};
|
|
227
282
|
}
|
|
228
|
-
|
|
283
|
+
if (operation === 'list_apps' && args.ask_again === true)
|
|
284
|
+
askAgain(context);
|
|
285
|
+
const request = { ...args };
|
|
286
|
+
delete request.ask_again;
|
|
287
|
+
const desktop = await chooseDesktop(context, helperPath, env);
|
|
229
288
|
context.signal?.throwIfAborted();
|
|
230
289
|
if (!desktop) {
|
|
231
290
|
return {
|
|
@@ -241,17 +300,42 @@ export function computerTool(operation) {
|
|
|
241
300
|
const turn = currentTurn.getStore();
|
|
242
301
|
if (turn)
|
|
243
302
|
computerUsers.add(turn);
|
|
244
|
-
const reply = await send(helperPath, env, { ...
|
|
303
|
+
const reply = await send(helperPath, env, { ...request, op: operation, desktop }, context.signal);
|
|
304
|
+
if (reply?.paused) {
|
|
305
|
+
const outcome = await waitForResume(context, helperPath, env, desktop);
|
|
306
|
+
return {
|
|
307
|
+
ok: false,
|
|
308
|
+
error: outcome === 'resumed' ? RESUMED_NOTE
|
|
309
|
+
: outcome === 'stopped' ? stoppedNote(desktop)
|
|
310
|
+
: outcome === 'closed' ? CLOSED_NOTE
|
|
311
|
+
: STILL_PAUSED_NOTE,
|
|
312
|
+
failureCategory: 'user_declined',
|
|
313
|
+
userControl: outcome,
|
|
314
|
+
desktop,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
if (reply?.skipped) {
|
|
318
|
+
return { ok: false, skipped: true, error: String(reply.error ?? ''), failureCategory: 'command_failed', desktop };
|
|
319
|
+
}
|
|
320
|
+
if (reply?.cancelled && !String(reply.error ?? '').startsWith('Only the user can fix this')) {
|
|
321
|
+
return {
|
|
322
|
+
ok: false,
|
|
323
|
+
error: reply.closed ? CLOSED_NOTE : stoppedNote(desktop),
|
|
324
|
+
failureCategory: 'user_declined',
|
|
325
|
+
userControl: reply.closed ? 'closed' : 'stopped',
|
|
326
|
+
desktop,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
245
329
|
if (!reply?.ok) {
|
|
246
330
|
return {
|
|
247
331
|
ok: false,
|
|
248
|
-
error: String(reply?.error ?? 'The desktop helper failed.'),
|
|
249
|
-
failureCategory:
|
|
332
|
+
error: `${String(reply?.error ?? 'The desktop helper failed.')}\n${permissionLine(context, desktop)}`,
|
|
333
|
+
failureCategory: 'command_failed',
|
|
250
334
|
desktop,
|
|
251
335
|
};
|
|
252
336
|
}
|
|
253
337
|
const { png, width, height, text } = reply;
|
|
254
|
-
const result = { ok: true, state: String(text ?? ''), desktop };
|
|
338
|
+
const result = { ok: true, state: `${String(text ?? '')}\n${permissionLine(context, desktop)}`, desktop };
|
|
255
339
|
if (typeof png === 'string') {
|
|
256
340
|
result.screenshot = { width, height };
|
|
257
341
|
result.imageBytes = { base64Data: png, mimeType: 'image/png' };
|
package/dist/src/ui/repl.js
CHANGED
|
@@ -9,6 +9,8 @@ import { AGENT_MODE_LOCKED_STATUS, approvalScrollLimit, buildTuiFrame, modelPick
|
|
|
9
9
|
import { createAttentionController, INITIAL_TERMINAL_FOCUS, } from './tui/attention.js';
|
|
10
10
|
import { backendFor, createNotificationQueue, } from './tui/desktop-notification.js';
|
|
11
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';
|
|
12
14
|
import { createTerminalTitleController } from './tui/terminal-title.js';
|
|
13
15
|
import { captureTerminalWrites, releaseTerminalWrites, } from './tui/terminal-writes.js';
|
|
14
16
|
import { getInputCommandToken, getSlashCommandSuggestions, isSkillSlashCommand, setSkillSlashCommands, SLASH_COMMANDS, slashCommandMatchesToken, } from './slash-commands.js';
|
|
@@ -25,20 +27,20 @@ import { formatTurnRecoveryStatus } from '../api/turn-recovery.js';
|
|
|
25
27
|
import { createJobWaitTracker } from '../job-follow-up.js';
|
|
26
28
|
import { getJobBufferedOutput, getJobOutputPreview, hasRunningBackgroundJobs, killAllBackgroundJobs, killBackgroundJob, listBackgroundJobs, setBackgroundJobSession, setBackgroundJobUpdateHook, } from '../background-jobs.js';
|
|
27
29
|
import { clearTodos, listTodos, setTodoSession } from '../todo-list.js';
|
|
28
|
-
import { setScratchSession } from '../scratch-dir.js';
|
|
30
|
+
import { ensureSessionScratchDir, setScratchSession } from '../scratch-dir.js';
|
|
29
31
|
import { setImageStoreSession } from '../core/session-image-store.js';
|
|
30
32
|
import { runMemoryCommand } from '../memory/command.js';
|
|
31
33
|
import { cancelActiveCommand } from '../executor.js';
|
|
32
34
|
import { isTurnFailureMarker } from '../turn-failure-marker.js';
|
|
33
35
|
import { clearCliAuthConfig, logoutFromServer, } from '../api/auth.js';
|
|
34
|
-
import { authenticationErrorMessage, isAuthenticationError, } from '../api/http.js';
|
|
36
|
+
import { authenticationErrorMessage, isAuthenticationError, ServerApiError, } from '../api/http.js';
|
|
35
37
|
import { buildRefusalNotice } from '../quota-notice.js';
|
|
36
38
|
import { createUsageNoticeTracker } from '../usage-notice.js';
|
|
37
39
|
import { createUserInputPromptState, formatUserInputTranscript, } from './tui/user-input.js';
|
|
38
40
|
import { setCommandOutputHook, withTuiMode } from '../runtime-mode.js';
|
|
39
41
|
import { collectBackgroundJobUiKillMutations, collectBackgroundJobUiOutputMutations, } from '../tool-executor.js';
|
|
40
42
|
import { startNewConversation, } from '../session.js';
|
|
41
|
-
import { applySessionSnapshot, listSessionMetadata, loadSessionSnapshot, saveSessionState, sessionHasUserMessage, } from '../session-store.js';
|
|
43
|
+
import { applySessionSnapshot, listSessionMetadata, loadSessionSnapshot, readGitBranch, saveSessionState, sessionHasUserMessage, } from '../session-store.js';
|
|
42
44
|
import { truncate } from '../utils.js';
|
|
43
45
|
import { TOOL_MAP } from '../tools/index.js';
|
|
44
46
|
import { countStep, EMPTY_TURN_STEPS, turnStepFields, } from './turn-steps.js';
|
|
@@ -1200,6 +1202,10 @@ function createInitialShellState(session, serverModels, debugUi, serverUrl) {
|
|
|
1200
1202
|
input: '',
|
|
1201
1203
|
maxToolSteps: session.maxToolSteps,
|
|
1202
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,
|
|
1203
1209
|
terminalFocused: INITIAL_TERMINAL_FOCUS,
|
|
1204
1210
|
jobsPickerExpandedId: null,
|
|
1205
1211
|
jobsPickerIndex: 0,
|
|
@@ -2398,6 +2404,122 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
2398
2404
|
}
|
|
2399
2405
|
showTransientStatus(enabled ? 'Notifications on' : 'Notifications off');
|
|
2400
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
|
+
};
|
|
2401
2523
|
const openJobsPicker = () => {
|
|
2402
2524
|
if (store.getState().jobsPickerOpen)
|
|
2403
2525
|
return;
|
|
@@ -2926,6 +3048,16 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
2926
3048
|
toggleNotifications();
|
|
2927
3049
|
return;
|
|
2928
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
|
+
}
|
|
2929
3061
|
appendTurnAwareEntry({
|
|
2930
3062
|
body: "Slash commands can't be queued while a turn is running. " +
|
|
2931
3063
|
'Use /jobs for background jobs or /notify to toggle notifications.',
|
|
@@ -3063,6 +3195,10 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3063
3195
|
toggleNotifications();
|
|
3064
3196
|
return;
|
|
3065
3197
|
}
|
|
3198
|
+
if (input === '/voice' || input.startsWith('/voice ')) {
|
|
3199
|
+
await handleVoiceCommand(input.slice('/voice'.length).trim());
|
|
3200
|
+
return;
|
|
3201
|
+
}
|
|
3066
3202
|
if (input === '/jobs' || input.startsWith('/jobs ')) {
|
|
3067
3203
|
const jobsArgs = input.slice('/jobs'.length).trim();
|
|
3068
3204
|
if (!jobsArgs) {
|
|
@@ -3712,6 +3848,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3712
3848
|
onSelectModel: handleInlineModelSelection,
|
|
3713
3849
|
onOpenJobsPicker: openJobsPicker,
|
|
3714
3850
|
onToggleNotifications: toggleNotifications,
|
|
3851
|
+
onVoiceKey: (key) => voiceDictation.handleKey(key),
|
|
3715
3852
|
onJobsPickerOutput: handleJobsPickerOutput,
|
|
3716
3853
|
onJobsPickerKill: handleJobsPickerKill,
|
|
3717
3854
|
onSudoPasswordInput: handleSudoPasswordInput,
|
|
@@ -3770,6 +3907,10 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3770
3907
|
void remountTui();
|
|
3771
3908
|
return;
|
|
3772
3909
|
}
|
|
3910
|
+
if (message.kind.startsWith('voice')) {
|
|
3911
|
+
voiceDictation.handleEvent(message);
|
|
3912
|
+
return;
|
|
3913
|
+
}
|
|
3773
3914
|
handleShellKeyEvent(store, shellInputHandlers, message);
|
|
3774
3915
|
renderCurrentFrame();
|
|
3775
3916
|
}
|
|
@@ -3782,6 +3923,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3782
3923
|
await done;
|
|
3783
3924
|
}
|
|
3784
3925
|
finally {
|
|
3926
|
+
voiceDictation.dispose();
|
|
3785
3927
|
stopWatchingKeys();
|
|
3786
3928
|
clearInterval(spinnerTimer);
|
|
3787
3929
|
clearInterval(clockTimer);
|
|
@@ -15,6 +15,7 @@ export const SLASH_COMMANDS = [
|
|
|
15
15
|
command: '/notify',
|
|
16
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' },
|
|
18
19
|
{ command: '/keybindings', description: 'Change your keyboard shortcuts' },
|
|
19
20
|
{ command: '/report', description: 'Report a bug or request a feature privately on the TheGitAI website' },
|
|
20
21
|
{ command: '/about', description: 'Show version and platform info' },
|