@thegitai/cli 1.1.0 → 1.1.2
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/dist/bin/browser-host.js +16 -0
- package/dist/src/browser/bridge.js +12 -0
- package/dist/src/core/clipboard.js +81 -28
- package/dist/src/git-available.js +54 -0
- package/dist/src/permissions.js +14 -4
- package/dist/src/session-safety.js +5 -0
- package/dist/src/session-store.js +3 -0
- package/dist/src/tools/browser.js +50 -2
- package/dist/src/tools/computer.js +7 -2
- package/dist/src/ui/repl.js +16 -15
- package/dist/src/ui/tui/build-frame.js +22 -3
- package/dist/src/ui/tui/shell-input.js +42 -0
- package/dist/src/ui/tui/user-input.js +10 -1
- package/package.json +6 -6
package/dist/bin/browser-host.js
CHANGED
|
@@ -11,6 +11,10 @@ const SCAN_INTERVAL_MS = 1000;
|
|
|
11
11
|
const NUL = String.fromCharCode(0);
|
|
12
12
|
const sessions = new Map();
|
|
13
13
|
const runtimeDir = browserRuntimeDir(process.env);
|
|
14
|
+
const startedAt = Date.now();
|
|
15
|
+
const YIELD_RETRY_MS = 15_000;
|
|
16
|
+
const yielded = new Map();
|
|
17
|
+
let extensionGreeted = false;
|
|
14
18
|
let extensionVersion = '';
|
|
15
19
|
let extensionProfileId = '';
|
|
16
20
|
let extensionProfileLabel = '';
|
|
@@ -138,6 +142,7 @@ function identity() {
|
|
|
138
142
|
: `profile ${extensionProfileId.slice(0, 6)}`),
|
|
139
143
|
platform: extensionPlatform || process.platform,
|
|
140
144
|
extensionVersion,
|
|
145
|
+
startedAt,
|
|
141
146
|
...(extensionLastFocusedAt > 0 ? { lastFocusedAt: extensionLastFocusedAt } : {}),
|
|
142
147
|
};
|
|
143
148
|
}
|
|
@@ -150,6 +155,7 @@ function handleExtensionFrame(frame) {
|
|
|
150
155
|
: '';
|
|
151
156
|
extensionPlatform = String(frame.platform ?? '');
|
|
152
157
|
extensionLastFocusedAt = Number(frame.lastFocusedAt) || 0;
|
|
158
|
+
extensionGreeted = true;
|
|
153
159
|
writeToExtension({ t: 'hello', protocol: BROWSER_PROTOCOL_VERSION });
|
|
154
160
|
publishSessions();
|
|
155
161
|
for (const link of sessions.values())
|
|
@@ -196,8 +202,11 @@ function publishSessions() {
|
|
|
196
202
|
});
|
|
197
203
|
}
|
|
198
204
|
function connectToSession(record, socketPath) {
|
|
205
|
+
const gaveWay = yielded.get(record.session);
|
|
199
206
|
if (sessions.has(record.session))
|
|
200
207
|
return;
|
|
208
|
+
if (gaveWay?.key === browserKey() && Date.now() - gaveWay.at < YIELD_RETRY_MS)
|
|
209
|
+
return;
|
|
201
210
|
const socket = net.createConnection(socketPath);
|
|
202
211
|
socket.setNoDelay(true);
|
|
203
212
|
const link = { key: record.session, socket, record };
|
|
@@ -224,6 +233,11 @@ function connectToSession(record, socketPath) {
|
|
|
224
233
|
catch {
|
|
225
234
|
continue;
|
|
226
235
|
}
|
|
236
|
+
if (frame?.t === 'superseded') {
|
|
237
|
+
yielded.set(record.session, { key: typeof frame.key === 'string' ? frame.key : browserKey(), at: Date.now() });
|
|
238
|
+
log(`a newer helper serves this browser in session ${record.session}`);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
227
241
|
writeToExtension({ ...frame, session: record.session });
|
|
228
242
|
}
|
|
229
243
|
});
|
|
@@ -240,6 +254,8 @@ function connectToSession(record, socketPath) {
|
|
|
240
254
|
});
|
|
241
255
|
}
|
|
242
256
|
function scanForSessions() {
|
|
257
|
+
if (!extensionGreeted && Date.now() - startedAt < 3000)
|
|
258
|
+
return;
|
|
243
259
|
let entries;
|
|
244
260
|
try {
|
|
245
261
|
entries = fs.readdirSync(runtimeDir);
|
|
@@ -76,6 +76,18 @@ export function startBrowserBridge({ sessionKey, label, cwd, env = process.env,
|
|
|
76
76
|
const existing = key ? browsers.get(key) : null;
|
|
77
77
|
const displaced = browsers.get(announced);
|
|
78
78
|
if (displaced && displaced.socket !== socket) {
|
|
79
|
+
const incoming = Number(frame.browser?.startedAt) || 0;
|
|
80
|
+
const current = Number(displaced.identity?.startedAt) || 0;
|
|
81
|
+
if (incoming && current && incoming < current) {
|
|
82
|
+
socket.write(`${JSON.stringify({ t: 'superseded', key: announced })}\n`);
|
|
83
|
+
socket.destroy();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
displaced.socket.write(`${JSON.stringify({ t: 'superseded', key: announced })}\n`);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
}
|
|
79
91
|
displaced.socket.destroy();
|
|
80
92
|
rejectDisconnectedRequests(displaced);
|
|
81
93
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execFileSync } from 'node:child_process';
|
|
1
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
2
2
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { MAX_IMAGE_SIZE_BYTES, SUPPORTED_IMAGE_MIME_TYPES as SUPPORTED_MIME_TYPES, sniffImageMimeType, } from './image-limits.js';
|
|
@@ -218,43 +218,96 @@ export function readClipboardText(platform = process.platform) {
|
|
|
218
218
|
function normalizeClipboardTextOutput(text) {
|
|
219
219
|
return text.replace(/\r?\n$/, '');
|
|
220
220
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
221
|
+
const CLIPBOARD_WRITE_TIMEOUT_MS = 4000;
|
|
222
|
+
let latestCopy = 0;
|
|
223
|
+
let runningWriter = null;
|
|
224
|
+
let copyQueue = Promise.resolve();
|
|
225
|
+
function runClipboardWriter(cmd, args, text) {
|
|
226
|
+
return new Promise((resolve, reject) => {
|
|
227
|
+
let settled = false;
|
|
228
|
+
const child = spawn(cmd, args, { stdio: ['pipe', 'ignore', 'ignore'] });
|
|
229
|
+
runningWriter = child;
|
|
230
|
+
const finish = (error) => {
|
|
231
|
+
if (settled)
|
|
232
|
+
return;
|
|
233
|
+
settled = true;
|
|
234
|
+
clearTimeout(timer);
|
|
235
|
+
if (runningWriter === child)
|
|
236
|
+
runningWriter = null;
|
|
237
|
+
if (error)
|
|
238
|
+
reject(error);
|
|
239
|
+
else
|
|
240
|
+
resolve();
|
|
241
|
+
};
|
|
242
|
+
const timer = setTimeout(() => {
|
|
243
|
+
child.kill();
|
|
244
|
+
finish(new Error(`did not finish within ${CLIPBOARD_WRITE_TIMEOUT_MS / 1000}s`));
|
|
245
|
+
}, CLIPBOARD_WRITE_TIMEOUT_MS);
|
|
246
|
+
child.on('error', (error) => finish(error));
|
|
247
|
+
child.on('exit', (code, signal) => {
|
|
248
|
+
if (code === 0)
|
|
249
|
+
finish();
|
|
250
|
+
else
|
|
251
|
+
finish(new Error(`exited with ${signal ?? code}`));
|
|
229
252
|
});
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
throw new ClipboardError(`Failed to write clipboard with ${cmd}: ${error.message}`, 'WRITE_FAILED');
|
|
234
|
-
}
|
|
253
|
+
child.stdin?.on('error', () => { });
|
|
254
|
+
child.stdin?.end(text);
|
|
255
|
+
});
|
|
235
256
|
}
|
|
236
|
-
|
|
237
|
-
|
|
257
|
+
function clipboardWriters(platform) {
|
|
258
|
+
if (platform === 'darwin')
|
|
259
|
+
return [['pbcopy', []]];
|
|
260
|
+
if (platform === 'win32')
|
|
261
|
+
return [['clip.exe', []]];
|
|
262
|
+
if (platform !== 'linux')
|
|
263
|
+
return [];
|
|
264
|
+
const writers = [];
|
|
265
|
+
if (isWayland())
|
|
266
|
+
writers.push(['wl-copy', []]);
|
|
267
|
+
writers.push(['xclip', ['-selection', 'clipboard']], ['xsel', ['--clipboard', '--input']]);
|
|
268
|
+
return writers;
|
|
269
|
+
}
|
|
270
|
+
function missingClipboardTool(platform) {
|
|
238
271
|
if (platform === 'darwin') {
|
|
239
|
-
|
|
240
|
-
return;
|
|
241
|
-
throw new ClipboardError('pbcopy is required to copy text on macOS.', 'NO_TOOL');
|
|
272
|
+
return new ClipboardError('pbcopy is required to copy text on macOS.', 'NO_TOOL');
|
|
242
273
|
}
|
|
243
274
|
if (platform === 'win32') {
|
|
244
|
-
|
|
245
|
-
return;
|
|
246
|
-
throw new ClipboardError('clip.exe is required to copy text on Windows.', 'NO_TOOL');
|
|
275
|
+
return new ClipboardError('clip.exe is required to copy text on Windows.', 'NO_TOOL');
|
|
247
276
|
}
|
|
248
277
|
if (platform === 'linux') {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
278
|
+
return new ClipboardError('wl-copy, xclip, or xsel is required to copy text. Install wl-clipboard, xclip, or xsel.', 'NO_TOOL');
|
|
279
|
+
}
|
|
280
|
+
return new ClipboardError(`Clipboard text copy is not supported on ${platform}.`, 'NO_TOOL');
|
|
281
|
+
}
|
|
282
|
+
export function writeClipboardText(text, platform = process.platform) {
|
|
283
|
+
const copy = ++latestCopy;
|
|
284
|
+
runningWriter?.kill();
|
|
285
|
+
const result = copyQueue.then(() => writeLatestCopy(String(text ?? ''), platform, copy));
|
|
286
|
+
copyQueue = result.catch(() => { });
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
async function writeLatestCopy(value, platform, copy) {
|
|
290
|
+
if (copy !== latestCopy)
|
|
291
|
+
return;
|
|
292
|
+
const writers = clipboardWriters(platform).filter(([cmd]) => whichSync(cmd));
|
|
293
|
+
if (!writers.length)
|
|
294
|
+
throw missingClipboardTool(platform);
|
|
295
|
+
const attempts = writers.length === 1 ? [writers[0], writers[0]] : writers;
|
|
296
|
+
const failures = [];
|
|
297
|
+
for (const [cmd, args] of attempts) {
|
|
298
|
+
if (copy !== latestCopy)
|
|
252
299
|
return;
|
|
253
|
-
|
|
300
|
+
try {
|
|
301
|
+
await runClipboardWriter(cmd, args, value);
|
|
254
302
|
return;
|
|
255
|
-
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
failures.push(`${cmd} ${error.message}`);
|
|
306
|
+
}
|
|
256
307
|
}
|
|
257
|
-
|
|
308
|
+
if (copy !== latestCopy)
|
|
309
|
+
return;
|
|
310
|
+
throw new ClipboardError(`Failed to write clipboard: ${failures.join('; ')}`, 'WRITE_FAILED');
|
|
258
311
|
}
|
|
259
312
|
export function loadImageFromFile(filePath) {
|
|
260
313
|
const resolved = path.resolve(filePath);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
const RECHECK_MISSING_MS = 60_000;
|
|
5
|
+
let checked = null;
|
|
6
|
+
function onPath(name, env) {
|
|
7
|
+
for (const dir of String(env.PATH ?? '').split(path.delimiter)) {
|
|
8
|
+
if (!dir)
|
|
9
|
+
continue;
|
|
10
|
+
const file = path.join(dir, name);
|
|
11
|
+
try {
|
|
12
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
13
|
+
return file;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
function probe(env) {
|
|
22
|
+
const found = onPath('git', env);
|
|
23
|
+
if (!found)
|
|
24
|
+
return false;
|
|
25
|
+
let real = found;
|
|
26
|
+
try {
|
|
27
|
+
real = fs.realpathSync(found);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (real !== '/usr/bin/git')
|
|
33
|
+
return true;
|
|
34
|
+
try {
|
|
35
|
+
const dir = execFileSync('/usr/bin/xcode-select', ['-p'], {
|
|
36
|
+
encoding: 'utf8',
|
|
37
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
38
|
+
timeout: 5000,
|
|
39
|
+
}).trim();
|
|
40
|
+
return fs.existsSync(path.join(dir, 'usr', 'bin', 'git'));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function gitAvailable(env = process.env) {
|
|
47
|
+
if (process.platform !== 'darwin')
|
|
48
|
+
return true;
|
|
49
|
+
if (checked && (checked.available || Date.now() - checked.at < RECHECK_MISSING_MS)) {
|
|
50
|
+
return checked.available;
|
|
51
|
+
}
|
|
52
|
+
checked = { available: probe(env), at: Date.now() };
|
|
53
|
+
return checked.available;
|
|
54
|
+
}
|
package/dist/src/permissions.js
CHANGED
|
@@ -238,7 +238,15 @@ function declinedSubject(bucket) {
|
|
|
238
238
|
}
|
|
239
239
|
return { noun: 'edit', effect: 'Nothing was changed' };
|
|
240
240
|
}
|
|
241
|
-
function
|
|
241
|
+
export function denialNote(decision) {
|
|
242
|
+
if (decision?.kind !== 'deny')
|
|
243
|
+
return '';
|
|
244
|
+
return String(decision.note ?? '').trim().slice(0, 1000);
|
|
245
|
+
}
|
|
246
|
+
export function userSaid(note) {
|
|
247
|
+
return note ? ` The user said: "${note}"` : '';
|
|
248
|
+
}
|
|
249
|
+
function declinedResponse(bucket, toolName, extra, note = '') {
|
|
242
250
|
const { noun, effect } = declinedSubject(bucket);
|
|
243
251
|
return {
|
|
244
252
|
ok: false,
|
|
@@ -248,9 +256,11 @@ function declinedResponse(bucket, toolName, extra) {
|
|
|
248
256
|
failureDetails: {
|
|
249
257
|
category: 'user_declined',
|
|
250
258
|
tool: toolName,
|
|
251
|
-
action:
|
|
259
|
+
action: note
|
|
260
|
+
? 'Respect the real user’s decision and do what they said instead. Do not retry the same or an equivalent action.'
|
|
261
|
+
: 'Respect the real user’s decision. Do not retry the same or an equivalent action; reconsider the approach or ask one specific question if needed.',
|
|
252
262
|
},
|
|
253
|
-
error: `The real user rejected this proposed ${noun}. ${effect}; this was not a tool failure or an automated system skip
|
|
263
|
+
error: `The real user rejected this proposed ${noun}. ${effect}; this was not a tool failure or an automated system skip.${userSaid(note)}`,
|
|
254
264
|
};
|
|
255
265
|
}
|
|
256
266
|
export async function ensurePermission(context, request, toolName, extra = {}) {
|
|
@@ -283,7 +293,7 @@ export async function ensurePermission(context, request, toolName, extra = {}) {
|
|
|
283
293
|
] : buildPermissionOptions(request.bucket, request.command, request.origin);
|
|
284
294
|
const decision = await context.requestPermission({ ...request, options });
|
|
285
295
|
if (decision.kind === 'deny') {
|
|
286
|
-
return declinedResponse(request.bucket, toolName, extra);
|
|
296
|
+
return declinedResponse(request.bucket, toolName, extra, denialNote(decision));
|
|
287
297
|
}
|
|
288
298
|
if (context.grants) {
|
|
289
299
|
if (decision.kind === 'always-mcp-tool' && decision.tool === request.mcpTool) {
|
|
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { ARTIFACT_IGNORE_DIRS, normalizeProjectRelativePath, shouldIgnoreArtifactPath, } from './artifact-policy.js';
|
|
5
5
|
import { hashBytes, readFileEditSnapshot, storedContentBuffer, } from './edit-journal.js';
|
|
6
6
|
import { deleteProjectFile, resolveProjectPath, writeProjectFile, writeProjectFileBuffer, } from './patcher.js';
|
|
7
|
+
import { gitAvailable } from './git-available.js';
|
|
7
8
|
const MAX_CHECKPOINTS = 20;
|
|
8
9
|
const MAX_SESSION_EDITS = 500;
|
|
9
10
|
const MAX_READ_RECORDS = 200;
|
|
@@ -770,6 +771,8 @@ export async function restoreCheckpointFiles(args) {
|
|
|
770
771
|
};
|
|
771
772
|
}
|
|
772
773
|
function git(args, cwd) {
|
|
774
|
+
if (!gitAvailable())
|
|
775
|
+
return null;
|
|
773
776
|
try {
|
|
774
777
|
return execFileSync('git', args, {
|
|
775
778
|
cwd,
|
|
@@ -783,6 +786,8 @@ function git(args, cwd) {
|
|
|
783
786
|
}
|
|
784
787
|
}
|
|
785
788
|
function gitBuffer(args, cwd) {
|
|
789
|
+
if (!gitAvailable())
|
|
790
|
+
return null;
|
|
786
791
|
try {
|
|
787
792
|
return execFileSync('git', args, {
|
|
788
793
|
cwd,
|
|
@@ -9,6 +9,7 @@ import { normalizeAssistantEditJournal } from './edit-journal.js';
|
|
|
9
9
|
import { createSessionGrants } from './permissions.js';
|
|
10
10
|
import { cloneSessionSafetyState, createSessionSafetyState, mergeLocalSessionSafetyState, normalizeSessionSafetyState, } from './session-safety.js';
|
|
11
11
|
import { singleLinePreview } from './utils.js';
|
|
12
|
+
import { gitAvailable } from './git-available.js';
|
|
12
13
|
const SESSION_STORE_VERSION = 1;
|
|
13
14
|
export const MAX_RECENT_SESSIONS = 10;
|
|
14
15
|
export { getSessionProjectKey };
|
|
@@ -221,6 +222,8 @@ export function pruneSavedSessions(rootDir, env = process.env) {
|
|
|
221
222
|
sweepGeneratedImages({ env });
|
|
222
223
|
}
|
|
223
224
|
export function readGitBranch(rootDir) {
|
|
225
|
+
if (!gitAvailable())
|
|
226
|
+
return null;
|
|
224
227
|
try {
|
|
225
228
|
const result = spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
|
|
226
229
|
cwd: rootDir,
|
|
@@ -7,7 +7,7 @@ import { isSupportedImageMimeType } from '../core/image-limits.js';
|
|
|
7
7
|
import { storeSessionImageBytes } from '../core/session-image-store.js';
|
|
8
8
|
import { browserAvailability, drainBrowserEvents, ensureBrowserBridge, resyncBrowserBridge, } from '../browser/session-bridge.js';
|
|
9
9
|
import { getClientStateDir } from '../client-state.js';
|
|
10
|
-
import { ensurePermission, originForUrl } from '../permissions.js';
|
|
10
|
+
import { denialNote, ensurePermission, originForUrl, userSaid } from '../permissions.js';
|
|
11
11
|
const READ_TIMEOUT_MS = 20000;
|
|
12
12
|
const NAVIGATE_TIMEOUT_MS = 45000;
|
|
13
13
|
const MAX_UPLOAD_BYTES = 10 * 1024 * 1024;
|
|
@@ -60,8 +60,56 @@ async function notConnected(context, { allowUnchosen = false, tabId } = {}) {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
const refused = await chromeAllowed(context);
|
|
64
|
+
if (refused)
|
|
65
|
+
return refused;
|
|
63
66
|
return allowUnchosen ? { ok: true } : profileChosen(context, Number(tabId));
|
|
64
67
|
}
|
|
68
|
+
const chromeAsks = new WeakMap();
|
|
69
|
+
async function chromeAllowed(context) {
|
|
70
|
+
if (context.grants?.browser)
|
|
71
|
+
return null;
|
|
72
|
+
if (!context.requestPermission) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
browserErrorCode: 'not_allowed',
|
|
76
|
+
error: 'Using Chrome needs the user to allow it, and they cannot be asked here.',
|
|
77
|
+
failureCategory: 'user_declined',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const ask = () => context.requestPermission({
|
|
81
|
+
bucket: 'browse',
|
|
82
|
+
alwaysAsk: true,
|
|
83
|
+
title: 'TheGitAI wants to use your Chrome',
|
|
84
|
+
body: 'It works in your Chrome tabs, signed in as you. Once allowed, it does not ask again in this session.',
|
|
85
|
+
options: [
|
|
86
|
+
{ label: 'Allow for this session', decision: { kind: 'once' } },
|
|
87
|
+
{ label: 'Deny', decision: { kind: 'deny' } },
|
|
88
|
+
],
|
|
89
|
+
});
|
|
90
|
+
let pending = context.grants ? chromeAsks.get(context.grants) : undefined;
|
|
91
|
+
if (!pending) {
|
|
92
|
+
pending = ask();
|
|
93
|
+
if (context.grants) {
|
|
94
|
+
const grants = context.grants;
|
|
95
|
+
chromeAsks.set(grants, pending);
|
|
96
|
+
const forget = () => chromeAsks.delete(grants);
|
|
97
|
+
pending.then(forget, forget);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const decision = await pending;
|
|
101
|
+
if (decision.kind !== 'deny') {
|
|
102
|
+
if (context.grants)
|
|
103
|
+
context.grants.browser = true;
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
ok: false,
|
|
108
|
+
browserErrorCode: 'not_allowed',
|
|
109
|
+
error: `The user did not allow TheGitAI to use Chrome. Do not use the browser tools for this request; do it another way or tell the user.${userSaid(denialNote(decision))}`,
|
|
110
|
+
failureCategory: 'user_declined',
|
|
111
|
+
};
|
|
112
|
+
}
|
|
65
113
|
const resolvedProfileNames = new Map();
|
|
66
114
|
function profileLabel(profile) {
|
|
67
115
|
const unnamed = /^profile ([0-9a-f]{6})$/.exec(profile);
|
|
@@ -680,7 +728,7 @@ export async function browserDownloads(context, args) {
|
|
|
680
728
|
await call(context, 'download.decide', { downloadId, accept: false });
|
|
681
729
|
return {
|
|
682
730
|
ok: false,
|
|
683
|
-
error:
|
|
731
|
+
error: `The user declined the download. It was cancelled and nothing was saved.${userSaid(denialNote(decision))}`,
|
|
684
732
|
failureCategory: 'user_declined',
|
|
685
733
|
};
|
|
686
734
|
}
|
|
@@ -4,6 +4,7 @@ import fs from 'node:fs';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import readline from 'node:readline';
|
|
6
6
|
import { storeSessionImageBytes } from '../core/session-image-store.js';
|
|
7
|
+
import { denialNote, userSaid } from '../permissions.js';
|
|
7
8
|
import { scopedSessionId } from '../session-context.js';
|
|
8
9
|
export const COMPUTER_OPERATIONS = [
|
|
9
10
|
'list_apps',
|
|
@@ -114,6 +115,7 @@ function send(helperPath, env, request, signal) {
|
|
|
114
115
|
}
|
|
115
116
|
const taskChoices = new Map();
|
|
116
117
|
const pendingChoices = new Map();
|
|
118
|
+
const deniedNotes = new Map();
|
|
117
119
|
function conversation() {
|
|
118
120
|
return scopedSessionId() ?? '';
|
|
119
121
|
}
|
|
@@ -146,6 +148,7 @@ async function askForDesktop(context, key) {
|
|
|
146
148
|
});
|
|
147
149
|
if (decision.kind !== 'computer') {
|
|
148
150
|
taskChoices.set(key, 'denied');
|
|
151
|
+
deniedNotes.set(key, denialNote(decision));
|
|
149
152
|
return null;
|
|
150
153
|
}
|
|
151
154
|
if (decision.session && context.grants)
|
|
@@ -190,6 +193,7 @@ export async function withComputerTurn(run) {
|
|
|
190
193
|
computerUsers.delete(token);
|
|
191
194
|
screenHolders.delete(token);
|
|
192
195
|
taskChoices.delete(key);
|
|
196
|
+
deniedNotes.delete(key);
|
|
193
197
|
if (screenHolders.size === 0)
|
|
194
198
|
await releaseComputerAfterTurn();
|
|
195
199
|
}
|
|
@@ -229,7 +233,7 @@ export function computerTool(operation) {
|
|
|
229
233
|
return {
|
|
230
234
|
ok: false,
|
|
231
235
|
error: context.requestPermission
|
|
232
|
-
?
|
|
236
|
+
? `The user did not allow TheGitAI to use apps on this computer for this request. Do not use the computer tools again for it; do it another way or tell the user.${userSaid(deniedNotes.get(conversation()) ?? '')}`
|
|
233
237
|
: 'Using apps on this computer needs the user to allow it, and they cannot be asked here.',
|
|
234
238
|
failureCategory: 'user_declined',
|
|
235
239
|
};
|
|
@@ -247,10 +251,11 @@ export function computerTool(operation) {
|
|
|
247
251
|
ok: false,
|
|
248
252
|
error: String(reply?.error ?? 'The desktop helper failed.'),
|
|
249
253
|
failureCategory: reply?.cancelled ? 'user_declined' : 'command_failed',
|
|
254
|
+
desktop,
|
|
250
255
|
};
|
|
251
256
|
}
|
|
252
257
|
const { png, width, height, text } = reply;
|
|
253
|
-
const result = { ok: true, state: String(text ?? '') };
|
|
258
|
+
const result = { ok: true, state: String(text ?? ''), desktop };
|
|
254
259
|
if (typeof png === 'string') {
|
|
255
260
|
result.screenshot = { width, height };
|
|
256
261
|
result.imageBytes = { base64Data: png, mimeType: 'image/png' };
|
package/dist/src/ui/repl.js
CHANGED
|
@@ -1688,22 +1688,10 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
1688
1688
|
});
|
|
1689
1689
|
};
|
|
1690
1690
|
const handleAppSelectionCopy = (text) => {
|
|
1691
|
-
|
|
1692
|
-
writeClipboardText(text);
|
|
1693
|
-
showTransientStatus('Copied selection');
|
|
1694
|
-
}
|
|
1695
|
-
catch (error) {
|
|
1696
|
-
appendError(`Selection copy failed: ${error.message}`);
|
|
1697
|
-
}
|
|
1691
|
+
void writeClipboardText(text).then(() => showTransientStatus('Copied selection'), (error) => appendError(`Selection copy failed: ${error.message}`));
|
|
1698
1692
|
};
|
|
1699
1693
|
const handleLinkCopy = (url) => {
|
|
1700
|
-
|
|
1701
|
-
writeClipboardText(url);
|
|
1702
|
-
showTransientStatus('Copied link');
|
|
1703
|
-
}
|
|
1704
|
-
catch (error) {
|
|
1705
|
-
appendError(`Link copy failed: ${error.message}`);
|
|
1706
|
-
}
|
|
1694
|
+
void writeClipboardText(url).then(() => showTransientStatus('Copied link'), (error) => appendError(`Link copy failed: ${error.message}`));
|
|
1707
1695
|
};
|
|
1708
1696
|
const handleLinkOpen = async (url) => {
|
|
1709
1697
|
try {
|
|
@@ -2086,6 +2074,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
2086
2074
|
...pauseBusyClock(current, Date.now()),
|
|
2087
2075
|
...closedJobsPickerFields(current),
|
|
2088
2076
|
approvalCursor: getDefaultApprovalCursor(request.options.length),
|
|
2077
|
+
approvalNote: '',
|
|
2089
2078
|
approvalOpenedAt: Date.now(),
|
|
2090
2079
|
approvalScrollOffset: 0,
|
|
2091
2080
|
approvalPrompt: {
|
|
@@ -2104,12 +2093,15 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
2104
2093
|
const handleInlineApprovalChoice = async (index) => {
|
|
2105
2094
|
const current = store.getState();
|
|
2106
2095
|
const options = current.approvalPrompt?.options ?? [];
|
|
2107
|
-
const
|
|
2096
|
+
const picked = options[index]?.decision ?? { kind: 'deny' };
|
|
2097
|
+
const note = String(current.approvalNote ?? '').trim();
|
|
2098
|
+
const chosen = picked.kind === 'deny' && note ? { ...picked, note } : picked;
|
|
2108
2099
|
const pendingResolve = resolvePermissionDecision;
|
|
2109
2100
|
resolvePermissionDecision = null;
|
|
2110
2101
|
store.update((next) => ({
|
|
2111
2102
|
...resumeBusyClock(next, Date.now()),
|
|
2112
2103
|
approvalCursor: getDefaultApprovalCursor(options.length),
|
|
2104
|
+
approvalNote: '',
|
|
2113
2105
|
approvalPrompt: null,
|
|
2114
2106
|
approvalScrollOffset: 0,
|
|
2115
2107
|
status: current.approvalPrompt?.returnStatus ?? next.status,
|
|
@@ -3406,6 +3398,15 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
|
|
|
3406
3398
|
title: 'Approvals',
|
|
3407
3399
|
});
|
|
3408
3400
|
}
|
|
3401
|
+
else if (decision.kind === 'computer') {
|
|
3402
|
+
appendTurnAwareEntry({
|
|
3403
|
+
body: decision.desktop === 'background'
|
|
3404
|
+
? 'Allowed for this request: using apps in the background.'
|
|
3405
|
+
: 'Allowed for this request: using apps on your screen.',
|
|
3406
|
+
kind: 'system',
|
|
3407
|
+
title: 'Approvals',
|
|
3408
|
+
});
|
|
3409
|
+
}
|
|
3409
3410
|
return decision;
|
|
3410
3411
|
};
|
|
3411
3412
|
const shellInputHandlers = {
|
|
@@ -736,6 +736,12 @@ function buildRecoveryStatusLines(status, width) {
|
|
|
736
736
|
function buildLiveLines(state, width, spinnerFrame, elapsedSeconds, nowMs) {
|
|
737
737
|
if (!state.busy)
|
|
738
738
|
return [];
|
|
739
|
+
if (state.approvalPrompt || state.sudoPrompt || state.userInputPrompt) {
|
|
740
|
+
return [
|
|
741
|
+
plainLine(''),
|
|
742
|
+
plainLine(buildWorkingClockLine(state, elapsedSeconds), { color: 'yellow' }),
|
|
743
|
+
];
|
|
744
|
+
}
|
|
739
745
|
const lines = [plainLine('')];
|
|
740
746
|
if (state.activeTurnInput) {
|
|
741
747
|
lines.push(...renderTranscriptEntryLines({
|
|
@@ -1382,15 +1388,28 @@ function buildOverlayLines(state, width, height, nowMs) {
|
|
|
1382
1388
|
if (padded)
|
|
1383
1389
|
lines.push(plainLine(''));
|
|
1384
1390
|
}
|
|
1385
|
-
const options =
|
|
1386
|
-
|
|
1391
|
+
const options = prompt.options ?? [];
|
|
1392
|
+
const noteRoom = Math.max(1, Math.min(3, height - lines.length - options.length - (padded ? 1 : 0) - 3));
|
|
1393
|
+
options.forEach((option, index) => {
|
|
1387
1394
|
const selected = index === state.approvalCursor;
|
|
1388
1395
|
lines.push(line(span(selected ? '› ' : ' ', {
|
|
1389
1396
|
color: selected ? APPROVAL_ACCENT_COLOR : 'gray',
|
|
1390
|
-
}), span(label, {
|
|
1397
|
+
}), span(option.label, {
|
|
1391
1398
|
color: selected ? APPROVAL_ACCENT_COLOR : undefined,
|
|
1392
1399
|
bold: selected,
|
|
1393
1400
|
})));
|
|
1401
|
+
if (!selected || option.decision?.kind !== 'deny')
|
|
1402
|
+
return;
|
|
1403
|
+
const note = String(state.approvalNote ?? '');
|
|
1404
|
+
if (!note) {
|
|
1405
|
+
lines.push(plainLine(' Type to tell TheGitAI what to do instead (optional)', { color: 'gray' }));
|
|
1406
|
+
return;
|
|
1407
|
+
}
|
|
1408
|
+
const rows = wrapText(`${note}▏`, Math.max(1, innerWidth - 5));
|
|
1409
|
+
const shown = rows.slice(-noteRoom);
|
|
1410
|
+
shown.forEach((text, row) => {
|
|
1411
|
+
lines.push(plainLine(` ${row === 0 && rows.length > shown.length ? '…' : ''}${text}`));
|
|
1412
|
+
});
|
|
1394
1413
|
});
|
|
1395
1414
|
if (padded)
|
|
1396
1415
|
lines.push(plainLine(''));
|
|
@@ -97,8 +97,25 @@ function insertPastedText(store, handlers, text) {
|
|
|
97
97
|
};
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
+
function appendToDenialNote(store, text) {
|
|
101
|
+
const state = store.getState();
|
|
102
|
+
if (state.approvalPrompt?.options?.[state.approvalCursor]?.decision?.kind !== 'deny')
|
|
103
|
+
return false;
|
|
104
|
+
const clean = text.replace(/[\u0000-\u001f\u007f]+/g, ' ');
|
|
105
|
+
store.update((current) => ({
|
|
106
|
+
...current,
|
|
107
|
+
approvalNote: `${current.approvalNote ?? ''}${clean}`.slice(0, 1000),
|
|
108
|
+
}));
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
100
111
|
function pasteTextFromClipboard(store, handlers) {
|
|
101
112
|
const current = store.getState();
|
|
113
|
+
if (current.approvalPrompt && !current.exiting) {
|
|
114
|
+
const text = (handlers.readClipboardText ?? readClipboardText)();
|
|
115
|
+
if (text)
|
|
116
|
+
appendToDenialNote(store, text);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
102
119
|
if (current.exiting ||
|
|
103
120
|
current.approvalPrompt ||
|
|
104
121
|
current.jobsPickerOpen ||
|
|
@@ -173,6 +190,8 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
173
190
|
})) {
|
|
174
191
|
return;
|
|
175
192
|
}
|
|
193
|
+
if (appendToDenialNote(store, event.text))
|
|
194
|
+
return;
|
|
176
195
|
insertPastedText(store, handlers, event.text);
|
|
177
196
|
return;
|
|
178
197
|
}
|
|
@@ -310,6 +329,29 @@ export function handleShellKeyEvent(store, handlers, event) {
|
|
|
310
329
|
if (approvalIsGuarded(state)) {
|
|
311
330
|
return;
|
|
312
331
|
}
|
|
332
|
+
const highlighted = state.approvalPrompt.options?.[state.approvalCursor];
|
|
333
|
+
if (highlighted?.decision?.kind === 'deny') {
|
|
334
|
+
if (key.backspace || key.delete) {
|
|
335
|
+
store.update((current) => ({
|
|
336
|
+
...current,
|
|
337
|
+
approvalNote: String(current.approvalNote ?? '').slice(0, -1),
|
|
338
|
+
}));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (!key.ctrl &&
|
|
342
|
+
!key.meta &&
|
|
343
|
+
!key.returnKey &&
|
|
344
|
+
!key.escape &&
|
|
345
|
+
key.input &&
|
|
346
|
+
!/[\u0000-\u001f\u007f]/.test(key.input)) {
|
|
347
|
+
const typed = key.input;
|
|
348
|
+
store.update((current) => ({
|
|
349
|
+
...current,
|
|
350
|
+
approvalNote: `${current.approvalNote ?? ''}${typed}`.slice(0, 1000),
|
|
351
|
+
}));
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
313
355
|
if (key.escape) {
|
|
314
356
|
void handlers.onResolveApproval(-1);
|
|
315
357
|
return;
|
|
@@ -554,10 +554,19 @@ function buildUserInputWindow(state, width, maxRows) {
|
|
|
554
554
|
offset = Math.max(0, Math.min(offset, maxOffset));
|
|
555
555
|
}
|
|
556
556
|
const visible = content.lines.slice(offset, offset + visibleRowBudget);
|
|
557
|
+
const above = offset;
|
|
558
|
+
const below = content.lines.length - offset - visible.length;
|
|
559
|
+
const more = [
|
|
560
|
+
...(above > 0 ? [`↑ ${above} more above`] : []),
|
|
561
|
+
...(below > 0 ? [`↓ ${below} more below`] : []),
|
|
562
|
+
];
|
|
563
|
+
const keys = above > 0 && below > 0 ? 'PgUp/PgDn' : below > 0 ? 'PgDn' : 'PgUp';
|
|
557
564
|
return {
|
|
558
565
|
lines: [
|
|
559
566
|
...visible,
|
|
560
|
-
plainLine(fitText(
|
|
567
|
+
plainLine(fitText(`${more.join(' · ')} · ${keys}`, width), {
|
|
568
|
+
color: below > 0 ? 'cyan' : 'gray',
|
|
569
|
+
}),
|
|
561
570
|
content.footer,
|
|
562
571
|
],
|
|
563
572
|
maxOffset,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thegitai/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "TheGitAI is an agentic AI coding tool for your terminal. It reads and searches your repository, writes and edits files, runs your tests, and verifies the change before handing it back.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentic-ai",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"@lydell/node-pty-linux-x64": "1.1.0",
|
|
46
46
|
"@lydell/node-pty-win32-arm64": "1.1.0",
|
|
47
47
|
"@lydell/node-pty-win32-x64": "1.1.0",
|
|
48
|
-
"@thegitai/tui-darwin-arm64": "1.1.
|
|
49
|
-
"@thegitai/tui-darwin-x64": "1.1.
|
|
50
|
-
"@thegitai/tui-linux-arm64": "1.1.
|
|
51
|
-
"@thegitai/tui-linux-x64": "1.1.
|
|
52
|
-
"@thegitai/tui-win32-x64": "1.1.
|
|
48
|
+
"@thegitai/tui-darwin-arm64": "1.1.2",
|
|
49
|
+
"@thegitai/tui-darwin-x64": "1.1.2",
|
|
50
|
+
"@thegitai/tui-linux-arm64": "1.1.2",
|
|
51
|
+
"@thegitai/tui-linux-x64": "1.1.2",
|
|
52
|
+
"@thegitai/tui-win32-x64": "1.1.2",
|
|
53
53
|
"@vscode/ripgrep": "1.18.0"
|
|
54
54
|
},
|
|
55
55
|
"repository": {
|