@thegitai/cli 1.1.4 → 1.2.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.
package/dist/bin/browser-host.js
CHANGED
|
@@ -20,10 +20,27 @@ let extensionProfileId = '';
|
|
|
20
20
|
let extensionProfileLabel = '';
|
|
21
21
|
let extensionPlatform = '';
|
|
22
22
|
let extensionLastFocusedAt = 0;
|
|
23
|
+
let stopping = false;
|
|
23
24
|
function log(message) {
|
|
24
25
|
process.stderr.write(`[thegitai-browser-host] ${message}\n`);
|
|
25
26
|
}
|
|
27
|
+
function stop(code) {
|
|
28
|
+
if (stopping)
|
|
29
|
+
return;
|
|
30
|
+
stopping = true;
|
|
31
|
+
for (const link of sessions.values())
|
|
32
|
+
link.socket.destroy();
|
|
33
|
+
process.exit(code);
|
|
34
|
+
}
|
|
35
|
+
process.on('uncaughtException', (error) => {
|
|
36
|
+
if (!stopping)
|
|
37
|
+
log(`stopping after an unexpected error: ${error?.stack ?? error}`);
|
|
38
|
+
stop(1);
|
|
39
|
+
});
|
|
40
|
+
process.stdout.on('error', () => stop(0));
|
|
26
41
|
function writeToExtension(frame) {
|
|
42
|
+
if (stopping)
|
|
43
|
+
return;
|
|
27
44
|
const payload = Buffer.from(JSON.stringify(frame), 'utf8');
|
|
28
45
|
if (payload.length > MAX_FRAME_BYTES) {
|
|
29
46
|
for (const fragment of fragmentPayload(payload, crypto.randomUUID())) {
|
|
@@ -44,11 +61,7 @@ process.stdin.on('data', (chunk) => {
|
|
|
44
61
|
for (const frame of frames)
|
|
45
62
|
handleExtensionFrame(frame);
|
|
46
63
|
});
|
|
47
|
-
process.stdin.on('end', () =>
|
|
48
|
-
for (const link of sessions.values())
|
|
49
|
-
link.socket.destroy();
|
|
50
|
-
process.exit(0);
|
|
51
|
-
});
|
|
64
|
+
process.stdin.on('end', () => stop(0));
|
|
52
65
|
function describeParentBrowser() {
|
|
53
66
|
const cmdline = process.platform === 'win32' ? windowsParentCommandLine() : unixParentCommandLine();
|
|
54
67
|
const userDataArg = cmdline.find((part) => part.startsWith('--user-data-dir='));
|
package/dist/src/api/chat.js
CHANGED
|
@@ -13,6 +13,7 @@ import { createTraceContext, gatewayFailureCategory, normalizeServerUrl, QUOTA_E
|
|
|
13
13
|
import { createTurnRecovery, fetchTurnAttempt, interruptedStream, isRetryableTurnStatus, isTurnRecoveryExhausted, readTurnChunk, } from './turn-recovery.js';
|
|
14
14
|
import { collectClientEnvironment } from '../client-environment.js';
|
|
15
15
|
import { collectProjectOrientation } from '../project-orientation.js';
|
|
16
|
+
import { collectProjectInstructionFiles } from '../project-instructions.js';
|
|
16
17
|
import { collectSkillRequest } from '../skills/discovery.js';
|
|
17
18
|
import { describeSessionImageStore } from '../core/session-image-store.js';
|
|
18
19
|
import { autoAttachImages } from '../core/image-path-extractor.js';
|
|
@@ -760,6 +761,8 @@ async function sendServerUserMessageInner({ config, session, input, jobFollowUp
|
|
|
760
761
|
for (const err of autoAttach.errors) {
|
|
761
762
|
session.onStatus(`Image: ${err}`);
|
|
762
763
|
}
|
|
764
|
+
const projectInstructionFiles = collectProjectInstructionFiles(session.rootDir, session.clientState.safety) ??
|
|
765
|
+
undefined;
|
|
763
766
|
const request = {
|
|
764
767
|
clientTurnId: randomUUID(),
|
|
765
768
|
mcpTools: await sessionMcp(session).discover(signal),
|
|
@@ -773,6 +776,7 @@ async function sendServerUserMessageInner({ config, session, input, jobFollowUp
|
|
|
773
776
|
...(jobFollowUp ? { jobFollowUp: true } : {}),
|
|
774
777
|
clientEnvironment: collectClientEnvironment({ env: session.env }),
|
|
775
778
|
projectOrientation: collectProjectOrientation(session.rootDir) ?? undefined,
|
|
779
|
+
projectInstructionFiles,
|
|
776
780
|
sessionImageStore: describeSessionImageStore(session.env) ?? undefined,
|
|
777
781
|
imageAttachments: imageAttachmentsForServer(requestImageAttachments),
|
|
778
782
|
...(session.maxToolStepsWasExplicit || !browserExtensionSeen(session.env)
|
|
@@ -53,9 +53,8 @@ function writeLauncher(env, hostScript, platform = process.platform) {
|
|
|
53
53
|
const launcherPath = path.join(dir, 'browser-bridge-host.bat');
|
|
54
54
|
const contents = [
|
|
55
55
|
'@echo off',
|
|
56
|
-
process.versions.electron
|
|
57
|
-
|
|
58
|
-
: `"${process.execPath}" "${hostScript}" %*`,
|
|
56
|
+
...(process.versions.electron ? ['set ELECTRON_RUN_AS_NODE=1'] : []),
|
|
57
|
+
`"${process.execPath}" "${hostScript}" %*`,
|
|
59
58
|
'',
|
|
60
59
|
].join('\r\n');
|
|
61
60
|
const existingBat = fs.existsSync(launcherPath)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { closeSync, fstatSync, openSync, readdirSync, readSync, realpathSync, } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getCurrentFileHash, redactContentWithStableTokens, } from './session-safety.js';
|
|
4
|
+
const INSTRUCTION_FILE_NAMES = new Set(['agents.md', 'agent.md', 'claude.md']);
|
|
5
|
+
const MAX_FILES = 6;
|
|
6
|
+
const MAX_LISTED_FILES = 12;
|
|
7
|
+
const MAX_FILE_CHARS = 32_000;
|
|
8
|
+
const MAX_TOTAL_CHARS = 64_000;
|
|
9
|
+
const MAX_READ_BYTES = 256 * 1024;
|
|
10
|
+
const MAX_NAME_CHARS = 120;
|
|
11
|
+
export function isProjectInstructionFileName(name) {
|
|
12
|
+
return INSTRUCTION_FILE_NAMES.has(name.toLowerCase());
|
|
13
|
+
}
|
|
14
|
+
function clipToLines(text, maxChars) {
|
|
15
|
+
if (text.length <= maxChars)
|
|
16
|
+
return { content: text, clipped: false };
|
|
17
|
+
const cut = maxChars > 0 ? text.lastIndexOf('\n', maxChars - 1) : -1;
|
|
18
|
+
return { content: cut >= 0 ? text.slice(0, cut + 1) : '', clipped: true };
|
|
19
|
+
}
|
|
20
|
+
function countLines(text) {
|
|
21
|
+
if (!text)
|
|
22
|
+
return 0;
|
|
23
|
+
const lines = text.split('\n').length;
|
|
24
|
+
return text.endsWith('\n') ? lines - 1 : lines;
|
|
25
|
+
}
|
|
26
|
+
export function normalizeProjectInstructionFiles(value) {
|
|
27
|
+
if (!Array.isArray(value))
|
|
28
|
+
return null;
|
|
29
|
+
const files = [];
|
|
30
|
+
let loaded = 0;
|
|
31
|
+
let total = 0;
|
|
32
|
+
for (const item of value) {
|
|
33
|
+
if (files.length >= MAX_LISTED_FILES)
|
|
34
|
+
break;
|
|
35
|
+
if (!item || typeof item !== 'object')
|
|
36
|
+
continue;
|
|
37
|
+
const record = item;
|
|
38
|
+
if (typeof record.name !== 'string' || typeof record.content !== 'string')
|
|
39
|
+
continue;
|
|
40
|
+
const name = record.name
|
|
41
|
+
.replace(/[\u0000-\u001f\u007f/\\]/g, '')
|
|
42
|
+
.trim()
|
|
43
|
+
.slice(0, MAX_NAME_CHARS);
|
|
44
|
+
if (!isProjectInstructionFileName(name))
|
|
45
|
+
continue;
|
|
46
|
+
const text = record.content.replace(/\r\n/g, '\n');
|
|
47
|
+
if (!text.trim() && record.truncated !== true)
|
|
48
|
+
continue;
|
|
49
|
+
const budget = loaded < MAX_FILES ? Math.min(MAX_FILE_CHARS, MAX_TOTAL_CHARS - total) : 0;
|
|
50
|
+
const { content, clipped } = clipToLines(text, budget);
|
|
51
|
+
if (!content.trim()) {
|
|
52
|
+
files.push({ name, content: '', shownLines: 0, truncated: true });
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
loaded += 1;
|
|
56
|
+
total += content.length;
|
|
57
|
+
files.push({
|
|
58
|
+
name,
|
|
59
|
+
content,
|
|
60
|
+
shownLines: countLines(content),
|
|
61
|
+
truncated: clipped || record.truncated === true,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return files.length > 0 ? files : null;
|
|
65
|
+
}
|
|
66
|
+
function readInstructionFile(filePath, rootReal) {
|
|
67
|
+
let fd = null;
|
|
68
|
+
try {
|
|
69
|
+
const real = realpathSync(filePath);
|
|
70
|
+
const relative = path.relative(rootReal, real);
|
|
71
|
+
if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
fd = openSync(real, 'r');
|
|
75
|
+
const stat = fstatSync(fd);
|
|
76
|
+
if (!stat.isFile())
|
|
77
|
+
return null;
|
|
78
|
+
const size = Math.min(stat.size, MAX_READ_BYTES);
|
|
79
|
+
const buffer = Buffer.alloc(size);
|
|
80
|
+
const read = size > 0 ? readSync(fd, buffer, 0, size, 0) : 0;
|
|
81
|
+
const text = buffer.subarray(0, read).toString('utf8');
|
|
82
|
+
if (text.includes('\u0000'))
|
|
83
|
+
return null;
|
|
84
|
+
return { text, partial: stat.size > MAX_READ_BYTES };
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
if (fd !== null)
|
|
91
|
+
closeSync(fd);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function collectProjectInstructionFiles(rootDir, safety) {
|
|
95
|
+
let rootReal;
|
|
96
|
+
let names;
|
|
97
|
+
try {
|
|
98
|
+
rootReal = realpathSync(rootDir);
|
|
99
|
+
names = readdirSync(rootDir)
|
|
100
|
+
.filter(isProjectInstructionFileName)
|
|
101
|
+
.sort();
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const files = [];
|
|
107
|
+
const seen = new Set();
|
|
108
|
+
for (const name of names) {
|
|
109
|
+
const filePath = path.join(rootDir, name);
|
|
110
|
+
const file = readInstructionFile(filePath, rootReal);
|
|
111
|
+
if (!file || !file.text.trim() || seen.has(file.text))
|
|
112
|
+
continue;
|
|
113
|
+
seen.add(file.text);
|
|
114
|
+
const content = safety
|
|
115
|
+
? redactContentWithStableTokens(safety, file.text, name, getCurrentFileHash(rootDir, filePath)).content
|
|
116
|
+
: file.text;
|
|
117
|
+
files.push({ name, content, truncated: file.partial });
|
|
118
|
+
}
|
|
119
|
+
return normalizeProjectInstructionFiles(files);
|
|
120
|
+
}
|
|
@@ -24,10 +24,8 @@ export const COMPUTER_OPERATIONS = [
|
|
|
24
24
|
const CALL_TIMEOUT_MS = 90_000;
|
|
25
25
|
const TYPE_MS_PER_CHARACTER = 20;
|
|
26
26
|
let helper = null;
|
|
27
|
-
const activeTurns = new Set();
|
|
28
27
|
const currentTurn = new AsyncLocalStorage();
|
|
29
28
|
const computerUsers = new Set();
|
|
30
|
-
const screenHolders = new Set();
|
|
31
29
|
function defaultHelperPath(env) {
|
|
32
30
|
const home = env.HOME?.trim();
|
|
33
31
|
const dataHome = env.XDG_DATA_HOME?.trim() || (home ? path.join(home, '.local', 'share') : '');
|
|
@@ -47,7 +45,7 @@ export function computerHelperPath(env = process.env) {
|
|
|
47
45
|
}
|
|
48
46
|
function startHelper(helperPath, env) {
|
|
49
47
|
const proc = spawn(helperPath, [], { stdio: ['pipe', 'pipe', 'ignore'], env });
|
|
50
|
-
const state = { proc, pending: new Map(), nextId: 1, inUse: false,
|
|
48
|
+
const state = { proc, pending: new Map(), nextId: 1, inUse: false, path: helperPath, env };
|
|
51
49
|
readline.createInterface({ input: proc.stdout }).on('line', (line) => {
|
|
52
50
|
let message;
|
|
53
51
|
try {
|
|
@@ -82,8 +80,6 @@ function send(helperPath, env, request, signal) {
|
|
|
82
80
|
const state = helper;
|
|
83
81
|
if (request.op !== 'end')
|
|
84
82
|
state.inUse = true;
|
|
85
|
-
if (request.desktop === 'background' && request.op !== 'begin')
|
|
86
|
-
state.backgroundUsed = true;
|
|
87
83
|
const id = state.nextId++;
|
|
88
84
|
const owner = currentTurn.getStore();
|
|
89
85
|
const stop = () => {
|
|
@@ -176,25 +172,14 @@ function chooseDesktop(context) {
|
|
|
176
172
|
export async function withComputerTurn(run) {
|
|
177
173
|
const token = Symbol();
|
|
178
174
|
const key = conversation();
|
|
179
|
-
activeTurns.add(token);
|
|
180
175
|
try {
|
|
181
|
-
const state = helper;
|
|
182
|
-
if (activeTurns.size === 1 && state?.backgroundUsed) {
|
|
183
|
-
const response = await send(state.path, state.env, { op: 'begin', desktop: 'background' });
|
|
184
|
-
if (response?.ok)
|
|
185
|
-
screenHolders.add(token);
|
|
186
|
-
else
|
|
187
|
-
state.backgroundUsed = false;
|
|
188
|
-
}
|
|
189
176
|
return await currentTurn.run(token, run);
|
|
190
177
|
}
|
|
191
178
|
finally {
|
|
192
|
-
activeTurns.delete(token);
|
|
193
179
|
computerUsers.delete(token);
|
|
194
|
-
screenHolders.delete(token);
|
|
195
180
|
taskChoices.delete(key);
|
|
196
181
|
deniedNotes.delete(key);
|
|
197
|
-
if (
|
|
182
|
+
if (computerUsers.size === 0)
|
|
198
183
|
await releaseComputerAfterTurn();
|
|
199
184
|
}
|
|
200
185
|
}
|
|
@@ -241,10 +226,8 @@ export function computerTool(operation) {
|
|
|
241
226
|
const title = String(args.title ?? '').trim();
|
|
242
227
|
context.onStatus(title || operation.replace(/_/g, ' '));
|
|
243
228
|
const turn = currentTurn.getStore();
|
|
244
|
-
if (turn)
|
|
229
|
+
if (turn)
|
|
245
230
|
computerUsers.add(turn);
|
|
246
|
-
screenHolders.add(turn);
|
|
247
|
-
}
|
|
248
231
|
const reply = await send(helperPath, env, { ...args, op: operation, desktop }, context.signal);
|
|
249
232
|
if (!reply?.ok) {
|
|
250
233
|
return {
|
|
@@ -6,7 +6,7 @@ import { readProjectFile } from '../patcher.js';
|
|
|
6
6
|
import { isWithinSessionScratchDir } from '../scratch-dir.js';
|
|
7
7
|
import { repairFilePath } from './path-suggest.js';
|
|
8
8
|
import { dotenvFitsRedactionBudget, getCurrentFileHash, recordReadCoverage, redactContentWithStableTokens, redactDotenvWithStableTokens, } from '../session-safety.js';
|
|
9
|
-
import { readFileRange
|
|
9
|
+
import { readFileRange } from '../utils.js';
|
|
10
10
|
import { IMAGE_MIME_BY_EXT } from '../core/image-limits.js';
|
|
11
11
|
import { readImageFile } from './read-image-file.js';
|
|
12
12
|
import { isSkillsRelativePath } from '../skills/discovery.js';
|
|
@@ -95,15 +95,26 @@ export async function readFile(context, args) {
|
|
|
95
95
|
: redactContentWithStableTokens(safety, range.content, projectPath, hash)
|
|
96
96
|
: { content: range.content, tokens: [] };
|
|
97
97
|
const contentTruncated = redacted.content.length > MAX_FILE_READ_CHARS;
|
|
98
|
+
const head = redacted.content.slice(0, MAX_FILE_READ_CHARS);
|
|
99
|
+
const lastBreak = contentTruncated ? head.lastIndexOf('\n') : -1;
|
|
100
|
+
const lineCut = contentTruncated && lastBreak < 0;
|
|
101
|
+
const deliveredContent = !contentTruncated
|
|
102
|
+
? redacted.content
|
|
103
|
+
: lineCut
|
|
104
|
+
? head
|
|
105
|
+
: head.slice(0, lastBreak);
|
|
98
106
|
const deliveredEndLine = contentTruncated
|
|
99
|
-
? Math.min(range.endLine, range.startLine +
|
|
100
|
-
redacted.content.slice(0, MAX_FILE_READ_CHARS).split('\n').length -
|
|
101
|
-
1)
|
|
107
|
+
? Math.min(range.endLine, range.startLine + deliveredContent.split('\n').length - 1)
|
|
102
108
|
: range.endLine;
|
|
109
|
+
const continueNote = !contentTruncated
|
|
110
|
+
? ''
|
|
111
|
+
: lineCut
|
|
112
|
+
? `\n... (line ${range.startLine} is longer than ${MAX_FILE_READ_CHARS} characters and only its start is shown; read the rest of that line with run_command or grep_code${range.startLine < range.totalLines ? `, and continue the file with startLine ${range.startLine + 1}` : ''})`
|
|
113
|
+
: `\n... (truncated after line ${deliveredEndLine} of ${range.totalLines}; call read_file with startLine ${deliveredEndLine + 1} to continue)`;
|
|
103
114
|
const fullFile = range.startLine === 1 &&
|
|
104
115
|
deliveredEndLine === range.totalLines &&
|
|
105
116
|
!contentTruncated;
|
|
106
|
-
if (projectPath && safety) {
|
|
117
|
+
if (projectPath && safety && !lineCut) {
|
|
107
118
|
recordReadCoverage(safety, {
|
|
108
119
|
filePath: projectPath,
|
|
109
120
|
hash,
|
|
@@ -120,7 +131,7 @@ export async function readFile(context, args) {
|
|
|
120
131
|
totalLines: range.totalLines,
|
|
121
132
|
startLine: range.startLine,
|
|
122
133
|
endLine: deliveredEndLine,
|
|
123
|
-
content:
|
|
134
|
+
content: `${deliveredContent}${continueNote}`,
|
|
124
135
|
contentHash: hash,
|
|
125
136
|
readCoverage: {
|
|
126
137
|
fullFile,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thegitai/cli",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.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
|
|
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.2.1",
|
|
49
|
+
"@thegitai/tui-darwin-x64": "1.2.1",
|
|
50
|
+
"@thegitai/tui-linux-arm64": "1.2.1",
|
|
51
|
+
"@thegitai/tui-linux-x64": "1.2.1",
|
|
52
|
+
"@thegitai/tui-win32-x64": "1.2.1",
|
|
53
53
|
"@vscode/ripgrep": "1.18.0"
|
|
54
54
|
},
|
|
55
55
|
"repository": {
|