@thegitai/cli 1.1.0 → 1.1.1

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.
@@ -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
- function tryWriteClipboardCommand(cmd, args, text) {
222
- if (!whichSync(cmd))
223
- return false;
224
- try {
225
- execFileSync(cmd, args, {
226
- input: text,
227
- timeout: 2000,
228
- stdio: ['pipe', 'ignore', 'ignore'],
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
- return true;
231
- }
232
- catch (error) {
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
- export function writeClipboardText(text, platform = process.platform) {
237
- const value = String(text ?? '');
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
- if (tryWriteClipboardCommand('pbcopy', [], value))
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
- if (tryWriteClipboardCommand('clip.exe', [], value))
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
- if (isWayland() && tryWriteClipboardCommand('wl-copy', [], value))
250
- return;
251
- if (tryWriteClipboardCommand('xclip', ['-selection', 'clipboard'], value))
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
- if (tryWriteClipboardCommand('xsel', ['--clipboard', '--input'], value))
300
+ try {
301
+ await runClipboardWriter(cmd, args, value);
254
302
  return;
255
- throw new ClipboardError('wl-copy, xclip, or xsel is required to copy text. Install wl-clipboard, xclip, or xsel.', 'NO_TOOL');
303
+ }
304
+ catch (error) {
305
+ failures.push(`${cmd} ${error.message}`);
306
+ }
256
307
  }
257
- throw new ClipboardError(`Clipboard text copy is not supported on ${platform}.`, 'NO_TOOL');
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);
@@ -247,10 +247,11 @@ export function computerTool(operation) {
247
247
  ok: false,
248
248
  error: String(reply?.error ?? 'The desktop helper failed.'),
249
249
  failureCategory: reply?.cancelled ? 'user_declined' : 'command_failed',
250
+ desktop,
250
251
  };
251
252
  }
252
253
  const { png, width, height, text } = reply;
253
- const result = { ok: true, state: String(text ?? '') };
254
+ const result = { ok: true, state: String(text ?? ''), desktop };
254
255
  if (typeof png === 'string') {
255
256
  result.screenshot = { width, height };
256
257
  result.imageBytes = { base64Data: png, mimeType: 'image/png' };
@@ -1688,22 +1688,10 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
1688
1688
  });
1689
1689
  };
1690
1690
  const handleAppSelectionCopy = (text) => {
1691
- try {
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
- try {
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 {
@@ -3406,6 +3394,15 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
3406
3394
  title: 'Approvals',
3407
3395
  });
3408
3396
  }
3397
+ else if (decision.kind === 'computer') {
3398
+ appendTurnAwareEntry({
3399
+ body: decision.desktop === 'background'
3400
+ ? 'Allowed for this request: using apps in the background.'
3401
+ : 'Allowed for this request: using apps on your screen.',
3402
+ kind: 'system',
3403
+ title: 'Approvals',
3404
+ });
3405
+ }
3409
3406
  return decision;
3410
3407
  };
3411
3408
  const shellInputHandlers = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thegitai/cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
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.0",
49
- "@thegitai/tui-darwin-x64": "1.1.0",
50
- "@thegitai/tui-linux-arm64": "1.1.0",
51
- "@thegitai/tui-linux-x64": "1.1.0",
52
- "@thegitai/tui-win32-x64": "1.1.0",
48
+ "@thegitai/tui-darwin-arm64": "1.1.1",
49
+ "@thegitai/tui-darwin-x64": "1.1.1",
50
+ "@thegitai/tui-linux-arm64": "1.1.1",
51
+ "@thegitai/tui-linux-x64": "1.1.1",
52
+ "@thegitai/tui-win32-x64": "1.1.1",
53
53
  "@vscode/ripgrep": "1.18.0"
54
54
  },
55
55
  "repository": {