@thegitai/cli 1.0.0-preview.8 → 1.0.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/LICENSE +1 -1
- package/README.md +301 -15
- package/dist/bin/ai.js +142 -112
- package/dist/bin/browser-host.js +284 -0
- package/dist/src/agent-mode.js +33 -7
- package/dist/src/api/auth.js +8 -2
- package/dist/src/api/browser-login.js +147 -35
- package/dist/src/api/chat.js +703 -166
- package/dist/src/api/contracts.js +55 -1
- package/dist/src/api/default-host.js +1 -0
- package/dist/src/api/http.js +168 -8
- package/dist/src/api/models.js +47 -9
- package/dist/src/api/startup-handshake.js +36 -0
- package/dist/src/api/turn-recovery.js +189 -0
- package/dist/src/background-jobs.js +8 -2
- package/dist/src/browser/bridge.js +268 -0
- package/dist/src/browser/chrome-profiles.js +73 -0
- package/dist/src/browser/framing.js +42 -0
- package/dist/src/browser/native-host.js +219 -0
- package/dist/src/browser/protocol.js +46 -0
- package/dist/src/browser/session-bridge.js +130 -0
- package/dist/src/cli-args.js +19 -5
- package/dist/src/client-environment.js +2 -0
- package/dist/src/core/clipboard.js +8 -14
- package/dist/src/core/image-limits.js +56 -0
- package/dist/src/core/image-path-extractor.js +70 -3
- package/dist/src/core/session-image-store.js +246 -0
- package/dist/src/edit-journal.js +33 -2
- package/dist/src/executor.js +26 -4
- package/dist/src/help-text.js +152 -41
- package/dist/src/install-id.js +32 -0
- package/dist/src/job-follow-up.js +40 -0
- package/dist/src/mcp-client.js +335 -0
- package/dist/src/mcp-command.js +176 -0
- package/dist/src/mcp-config.js +123 -0
- package/dist/src/mcp-sdk.js +3 -0
- package/dist/src/mcp-types.js +26 -0
- package/dist/src/patcher.js +46 -4
- package/dist/src/permissions.js +301 -0
- package/dist/src/preferences.js +39 -0
- package/dist/src/project-key.js +11 -0
- package/dist/src/project-model-preferences.js +74 -0
- package/dist/src/quota-notice.js +62 -0
- package/dist/src/reasoning-effort.js +27 -0
- package/dist/src/session-safety.js +0 -12
- package/dist/src/session-store.js +123 -30
- package/dist/src/session.js +12 -4
- package/dist/src/signin.js +58 -0
- package/dist/src/skills/discovery.js +280 -0
- package/dist/src/skills/frontmatter.js +192 -0
- package/dist/src/skills/install.js +394 -0
- package/dist/src/skills/types.js +43 -0
- package/dist/src/skills-command.js +71 -0
- package/dist/src/tool-executor.js +41 -51
- package/dist/src/tools/browser.js +928 -0
- package/dist/src/tools/delete-file.js +21 -5
- package/dist/src/tools/index.js +34 -10
- package/dist/src/tools/patch-file.js +14 -29
- package/dist/src/tools/read-file.js +7 -1
- package/dist/src/tools/read-image-file.js +85 -0
- package/dist/src/tools/replace-document-text.js +28 -18
- package/dist/src/tools/restore-checkpoint.js +1 -2
- package/dist/src/tools/run-command.js +14 -71
- package/dist/src/tools/run-node-script.js +12 -81
- package/dist/src/tools/save-generated-image.js +120 -0
- package/dist/src/tools/shell-diagnostics.js +246 -72
- package/dist/src/tools/str-replace.js +14 -29
- package/dist/src/tools/undo-edit.js +2 -7
- package/dist/src/tools/use-skill.js +38 -0
- package/dist/src/tools/write-file.js +69 -14
- package/dist/src/ui/prompt-history-store.js +1 -1
- package/dist/src/ui/repl.js +1155 -301
- package/dist/src/ui/slash-commands.js +140 -0
- package/dist/src/ui/tui/attention.js +25 -0
- package/dist/src/ui/tui/bridge.js +38 -5
- package/dist/src/ui/tui/build-frame.js +903 -304
- package/dist/src/ui/tui/composer-layout.js +76 -0
- package/dist/src/ui/tui/desktop-notification.js +118 -0
- package/dist/src/ui/tui/markdown-render.js +21 -11
- package/dist/src/ui/tui/model-label.js +13 -0
- package/dist/src/ui/tui/shell-input.js +266 -61
- package/dist/src/ui/tui/shortcuts.js +61 -0
- package/dist/src/ui/tui/terminal-theme.js +28 -0
- package/dist/src/ui/tui/text.js +31 -6
- package/dist/src/ui/tui/user-input.js +593 -0
- package/dist/src/update-check.js +205 -0
- package/dist/src/usage-notice.js +52 -0
- package/dist/src/usage.js +25 -2
- package/dist/src/utils.js +13 -0
- package/dist/src/version.js +52 -2
- package/dist/vendor/mcp/LICENSES.txt +414 -0
- package/dist/vendor/mcp/client.cjs +82 -0
- package/package.json +22 -9
- package/dist/src/project-index.js +0 -233
- package/dist/src/tools/code-intel.js +0 -472
- package/dist/src/tools/find-symbol.js +0 -70
- package/dist/src/tools/hover-symbol.js +0 -95
- package/dist/src/tools/list-symbols.js +0 -55
- package/dist/src/tools/search-code.js +0 -37
- package/dist/src/tools/signature-help.js +0 -118
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { getClientStateDir } from '../client-state.js';
|
|
5
|
+
import { MAX_IMAGE_SIZE_BYTES, imageExtensionForMime, isSupportedImageMimeType, sniffImageMimeType, } from './image-limits.js';
|
|
6
|
+
const IMAGE_FILE_MODE = 0o600;
|
|
7
|
+
const IMAGE_DIR_MODE = 0o700;
|
|
8
|
+
export const SESSION_IMAGE_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
9
|
+
let activeSessionId = null;
|
|
10
|
+
export function setImageStoreSession(sessionId) {
|
|
11
|
+
activeSessionId = String(sessionId ?? '').trim() || null;
|
|
12
|
+
contentIndex.clear();
|
|
13
|
+
}
|
|
14
|
+
const contentIndex = new Map();
|
|
15
|
+
function imageContentKey(base64Data) {
|
|
16
|
+
return createHash('sha256').update(base64Data).digest('hex');
|
|
17
|
+
}
|
|
18
|
+
function rememberStoredImage(base64Data, cachePath) {
|
|
19
|
+
contentIndex.set(imageContentKey(base64Data), cachePath);
|
|
20
|
+
}
|
|
21
|
+
export function findStoredImageByContent(base64Data) {
|
|
22
|
+
const cachePath = contentIndex.get(imageContentKey(base64Data));
|
|
23
|
+
if (!cachePath)
|
|
24
|
+
return undefined;
|
|
25
|
+
if (!existsSync(cachePath)) {
|
|
26
|
+
contentIndex.delete(imageContentKey(base64Data));
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return cachePath;
|
|
30
|
+
}
|
|
31
|
+
export function getImageStoreSession() {
|
|
32
|
+
return activeSessionId;
|
|
33
|
+
}
|
|
34
|
+
function safeSessionDirName(sessionId) {
|
|
35
|
+
const normalized = String(sessionId ?? '').trim();
|
|
36
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(normalized)) {
|
|
37
|
+
throw new Error(`Invalid session id "${sessionId}".`);
|
|
38
|
+
}
|
|
39
|
+
return normalized;
|
|
40
|
+
}
|
|
41
|
+
export function getSessionImageBaseDir(env = process.env) {
|
|
42
|
+
return path.join(getClientStateDir(env), 'sessions', 'images');
|
|
43
|
+
}
|
|
44
|
+
export function getSessionImageDir(sessionId, env = process.env) {
|
|
45
|
+
return path.join(getSessionImageBaseDir(env), safeSessionDirName(sessionId));
|
|
46
|
+
}
|
|
47
|
+
function nextImageNumber(dir) {
|
|
48
|
+
if (!existsSync(dir))
|
|
49
|
+
return 1;
|
|
50
|
+
let highest = 0;
|
|
51
|
+
for (const name of readdirSync(dir)) {
|
|
52
|
+
const parsed = Number.parseInt(path.basename(name, path.extname(name)), 10);
|
|
53
|
+
if (Number.isInteger(parsed) && parsed > highest)
|
|
54
|
+
highest = parsed;
|
|
55
|
+
}
|
|
56
|
+
return highest + 1;
|
|
57
|
+
}
|
|
58
|
+
function ensureSessionImageDir(sessionId, env) {
|
|
59
|
+
const dir = getSessionImageDir(sessionId, env);
|
|
60
|
+
mkdirSync(dir, { recursive: true, mode: IMAGE_DIR_MODE });
|
|
61
|
+
return dir;
|
|
62
|
+
}
|
|
63
|
+
export function storeSessionImageBytes({ sessionId, base64Data, mimeType, env = process.env, }) {
|
|
64
|
+
const dir = ensureSessionImageDir(sessionId, env);
|
|
65
|
+
const index = nextImageNumber(dir);
|
|
66
|
+
const cachePath = path.join(dir, `${index}${imageExtensionForMime(mimeType)}`);
|
|
67
|
+
writeFileSync(cachePath, Buffer.from(base64Data, 'base64'), {
|
|
68
|
+
mode: IMAGE_FILE_MODE,
|
|
69
|
+
});
|
|
70
|
+
rememberStoredImage(base64Data, cachePath);
|
|
71
|
+
return { cachePath, mimeType, base64Data, index };
|
|
72
|
+
}
|
|
73
|
+
export function tryCacheAttachmentBytes({ base64Data, mimeType, env = process.env, }) {
|
|
74
|
+
if (!activeSessionId)
|
|
75
|
+
return undefined;
|
|
76
|
+
try {
|
|
77
|
+
const stored = storeSessionImageBytes({
|
|
78
|
+
sessionId: activeSessionId,
|
|
79
|
+
base64Data,
|
|
80
|
+
mimeType,
|
|
81
|
+
env,
|
|
82
|
+
});
|
|
83
|
+
return { cachePath: stored.cachePath, index: stored.index };
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export function isSessionStorePath(candidate, env = process.env) {
|
|
90
|
+
if (!activeSessionId)
|
|
91
|
+
return false;
|
|
92
|
+
const dir = getSessionImageDir(activeSessionId, env);
|
|
93
|
+
const resolved = path.resolve(candidate);
|
|
94
|
+
return (resolved.startsWith(dir + path.sep) && path.dirname(resolved) === dir);
|
|
95
|
+
}
|
|
96
|
+
export function readSessionImageByIndex(index, env = process.env) {
|
|
97
|
+
if (!activeSessionId || !Number.isInteger(index) || index < 1)
|
|
98
|
+
return null;
|
|
99
|
+
const dir = getSessionImageDir(activeSessionId, env);
|
|
100
|
+
if (!existsSync(dir))
|
|
101
|
+
return null;
|
|
102
|
+
try {
|
|
103
|
+
for (const name of readdirSync(dir)) {
|
|
104
|
+
if (Number.parseInt(path.basename(name, path.extname(name)), 10) === index) {
|
|
105
|
+
return readSessionImage(path.join(dir, name));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
export function describeSessionImageStore(env = process.env) {
|
|
115
|
+
if (!activeSessionId)
|
|
116
|
+
return null;
|
|
117
|
+
const dir = getSessionImageDir(activeSessionId, env);
|
|
118
|
+
if (!existsSync(dir))
|
|
119
|
+
return null;
|
|
120
|
+
const indices = [];
|
|
121
|
+
try {
|
|
122
|
+
for (const name of readdirSync(dir)) {
|
|
123
|
+
const parsed = Number.parseInt(path.basename(name, path.extname(name)), 10);
|
|
124
|
+
if (Number.isInteger(parsed) && parsed >= 1)
|
|
125
|
+
indices.push(parsed);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
if (indices.length === 0)
|
|
132
|
+
return null;
|
|
133
|
+
return { dir, indices: indices.sort((a, b) => a - b) };
|
|
134
|
+
}
|
|
135
|
+
const MAX_STORE_DIR_CHARS = 512;
|
|
136
|
+
const MAX_STORE_INDICES = 200;
|
|
137
|
+
const STORE_CONTROL_CHARS = /[\u0000-\u001f\u007f]/g;
|
|
138
|
+
export function normalizeSessionImageStore(value) {
|
|
139
|
+
if (!value || typeof value !== 'object')
|
|
140
|
+
return null;
|
|
141
|
+
const record = value;
|
|
142
|
+
const dir = String(record.dir ?? '')
|
|
143
|
+
.replace(STORE_CONTROL_CHARS, ' ')
|
|
144
|
+
.trim()
|
|
145
|
+
.slice(0, MAX_STORE_DIR_CHARS);
|
|
146
|
+
if (!dir)
|
|
147
|
+
return null;
|
|
148
|
+
const seen = new Set();
|
|
149
|
+
for (const raw of Array.isArray(record.indices) ? record.indices : []) {
|
|
150
|
+
const parsed = Number(raw);
|
|
151
|
+
if (!Number.isInteger(parsed) || parsed < 1)
|
|
152
|
+
continue;
|
|
153
|
+
seen.add(parsed);
|
|
154
|
+
if (seen.size >= MAX_STORE_INDICES)
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
if (seen.size === 0)
|
|
158
|
+
return null;
|
|
159
|
+
return { dir, indices: [...seen].sort((a, b) => a - b) };
|
|
160
|
+
}
|
|
161
|
+
export class SessionImageError extends Error {
|
|
162
|
+
code;
|
|
163
|
+
constructor(message, code) {
|
|
164
|
+
super(message);
|
|
165
|
+
this.code = code;
|
|
166
|
+
this.name = 'SessionImageError';
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export function storeSessionImageFromPath({ sessionId, sourcePath, env = process.env, }) {
|
|
170
|
+
const resolved = path.resolve(sourcePath);
|
|
171
|
+
if (!existsSync(resolved) || !statSync(resolved).isFile()) {
|
|
172
|
+
throw new SessionImageError(`Image file not found: ${resolved}`, 'NOT_FOUND');
|
|
173
|
+
}
|
|
174
|
+
const size = statSync(resolved).size;
|
|
175
|
+
if (size > MAX_IMAGE_SIZE_BYTES) {
|
|
176
|
+
throw new SessionImageError(`Image file exceeds ${Math.round(MAX_IMAGE_SIZE_BYTES / 1024 / 1024)}MB limit (${(size / 1024 / 1024).toFixed(1)}MB): ${resolved}`, 'TOO_LARGE');
|
|
177
|
+
}
|
|
178
|
+
const bytes = readFileSync(resolved);
|
|
179
|
+
const sniffed = sniffImageMimeType(bytes);
|
|
180
|
+
if (!sniffed || !isSupportedImageMimeType(sniffed)) {
|
|
181
|
+
throw new SessionImageError(`Not a supported image file: ${resolved}. Supported: PNG, JPEG, GIF, WebP.`, 'UNSUPPORTED');
|
|
182
|
+
}
|
|
183
|
+
const dir = ensureSessionImageDir(sessionId, env);
|
|
184
|
+
const index = nextImageNumber(dir);
|
|
185
|
+
const cachePath = path.join(dir, `${index}${imageExtensionForMime(sniffed)}`);
|
|
186
|
+
writeFileSync(cachePath, bytes, { mode: IMAGE_FILE_MODE });
|
|
187
|
+
const base64Data = bytes.toString('base64');
|
|
188
|
+
rememberStoredImage(base64Data, cachePath);
|
|
189
|
+
return { cachePath, mimeType: sniffed, base64Data, index };
|
|
190
|
+
}
|
|
191
|
+
export function readSessionImage(cachePath) {
|
|
192
|
+
try {
|
|
193
|
+
if (!existsSync(cachePath))
|
|
194
|
+
return null;
|
|
195
|
+
const bytes = readFileSync(cachePath);
|
|
196
|
+
const sniffed = sniffImageMimeType(bytes);
|
|
197
|
+
if (!sniffed)
|
|
198
|
+
return null;
|
|
199
|
+
const parsed = Number.parseInt(path.basename(cachePath, path.extname(cachePath)), 10);
|
|
200
|
+
const base64Data = bytes.toString('base64');
|
|
201
|
+
rememberStoredImage(base64Data, cachePath);
|
|
202
|
+
return {
|
|
203
|
+
cachePath,
|
|
204
|
+
mimeType: sniffed,
|
|
205
|
+
base64Data,
|
|
206
|
+
index: Number.isInteger(parsed) ? parsed : 0,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
export function pruneSessionImages(sessionId, env = process.env) {
|
|
214
|
+
try {
|
|
215
|
+
rmSync(getSessionImageDir(sessionId, env), { recursive: true, force: true });
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
export function sweepOrphanSessionImages({ activeSessionIds, maxAgeMs = SESSION_IMAGE_MAX_AGE_MS, env = process.env, now = Date.now(), }) {
|
|
221
|
+
const baseDir = getSessionImageBaseDir(env);
|
|
222
|
+
if (!existsSync(baseDir))
|
|
223
|
+
return 0;
|
|
224
|
+
let removed = 0;
|
|
225
|
+
let entries;
|
|
226
|
+
try {
|
|
227
|
+
entries = readdirSync(baseDir);
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
for (const entry of entries) {
|
|
233
|
+
if (activeSessionIds.has(entry))
|
|
234
|
+
continue;
|
|
235
|
+
const dir = path.join(baseDir, entry);
|
|
236
|
+
try {
|
|
237
|
+
if (now - statSync(dir).mtimeMs < maxAgeMs)
|
|
238
|
+
continue;
|
|
239
|
+
rmSync(dir, { recursive: true, force: true });
|
|
240
|
+
removed += 1;
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return removed;
|
|
246
|
+
}
|
package/dist/src/edit-journal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { existsSync, lstatSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { closeSync, existsSync, lstatSync, openSync, readFileSync, readSync, } from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { BINARY_ARTIFACT_EXTENSIONS } from './artifact-policy.js';
|
|
6
6
|
import { resolveProjectPath } from './patcher.js';
|
|
@@ -30,13 +30,33 @@ function snapshotEncoding(filePath, content) {
|
|
|
30
30
|
return 'base64';
|
|
31
31
|
return 'utf8';
|
|
32
32
|
}
|
|
33
|
+
const MAX_SNAPSHOT_READ_BYTES = MAX_STORED_CONTENT_CHARS;
|
|
34
|
+
const SNAPSHOT_HASH_CHUNK_BYTES = 1024 * 1024;
|
|
35
|
+
function hashFileInChunks(absPath) {
|
|
36
|
+
const hash = createHash('sha256');
|
|
37
|
+
const chunk = Buffer.allocUnsafe(SNAPSHOT_HASH_CHUNK_BYTES);
|
|
38
|
+
const fd = openSync(absPath, 'r');
|
|
39
|
+
try {
|
|
40
|
+
for (;;) {
|
|
41
|
+
const read = readSync(fd, chunk, 0, chunk.length, null);
|
|
42
|
+
if (read <= 0)
|
|
43
|
+
break;
|
|
44
|
+
hash.update(chunk.subarray(0, read));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
closeSync(fd);
|
|
49
|
+
}
|
|
50
|
+
return `sha256:${hash.digest('hex')}`;
|
|
51
|
+
}
|
|
33
52
|
export function readFileEditSnapshot(rootDir, filePath) {
|
|
34
53
|
try {
|
|
35
54
|
const absPath = resolveProjectPath(rootDir, filePath);
|
|
36
55
|
if (!existsSync(absPath)) {
|
|
37
56
|
return { exists: false, content: null, contentEncoding: 'utf8', hash: null };
|
|
38
57
|
}
|
|
39
|
-
|
|
58
|
+
const stat = lstatSync(absPath);
|
|
59
|
+
if (stat.isSymbolicLink()) {
|
|
40
60
|
return {
|
|
41
61
|
exists: true,
|
|
42
62
|
content: null,
|
|
@@ -45,6 +65,17 @@ export function readFileEditSnapshot(rootDir, filePath) {
|
|
|
45
65
|
error: `Refusing to snapshot symbolic link: ${filePath}`,
|
|
46
66
|
};
|
|
47
67
|
}
|
|
68
|
+
if (stat.isFile() && stat.size > MAX_SNAPSHOT_READ_BYTES) {
|
|
69
|
+
return {
|
|
70
|
+
exists: true,
|
|
71
|
+
content: null,
|
|
72
|
+
contentEncoding: BINARY_ARTIFACT_EXTENSIONS.has(path.extname(filePath).toLowerCase())
|
|
73
|
+
? 'base64'
|
|
74
|
+
: 'utf8',
|
|
75
|
+
hash: hashFileInChunks(absPath),
|
|
76
|
+
error: `File is too large to snapshot (${stat.size} bytes).`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
48
79
|
const content = readFileSync(absPath);
|
|
49
80
|
const encoding = snapshotEncoding(filePath, content);
|
|
50
81
|
return {
|
package/dist/src/executor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import chalk from './colors.js';
|
|
2
2
|
import { execFileSync, spawn } from 'child_process';
|
|
3
|
-
import { existsSync, statSync } from 'fs';
|
|
3
|
+
import { accessSync, constants as fsConstants, existsSync, statSync } from 'fs';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import os from 'os';
|
|
6
6
|
import path from 'path';
|
|
@@ -571,7 +571,7 @@ export function getBlockedCommandReason(command, hasTimeout, rootDir) {
|
|
|
571
571
|
const ignoredDir = findIgnoredPathInspection(command, rootDir);
|
|
572
572
|
if (ignoredDir?.startsWith(OS_TEMP_BLOCK_MARKER)) {
|
|
573
573
|
const tempName = ignoredDir.slice(OS_TEMP_BLOCK_MARKER.length);
|
|
574
|
-
return `Listing or scanning the shared OS temp directory (${tempName}) is blocked because it can contain other users' and processes' files. Use the session scratch directory ${ensureSessionScratchDir()} for temporary scripts and files
|
|
574
|
+
return `Listing or scanning the shared OS temp directory (${tempName}) is blocked because it can contain other users' and processes' files. Use the session scratch directory ${ensureSessionScratchDir()} for temporary scripts and files - creating, running, and listing are all allowed there - or reference an exact file path.`;
|
|
575
575
|
}
|
|
576
576
|
if (ignoredDir) {
|
|
577
577
|
return `Command inspects an off-limits generated or dependency directory (${ignoredDir}). Avoid that path.`;
|
|
@@ -596,7 +596,7 @@ export function commandUsesSudo(command) {
|
|
|
596
596
|
}
|
|
597
597
|
export function sudoPromptFromTail(text) {
|
|
598
598
|
const tail = text.slice(-1000).replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '');
|
|
599
|
-
const match = tail.match(/(?:\[sudo\][^\r\n]*password[^\r\n]*:
|
|
599
|
+
const match = tail.match(/(?:\[sudo\][^\r\n]*password[^\r\n]*: ?|\[?sudo[^\r\n]*password[^\r\n]*: ?|password[^\r\n]*: ?)$/i);
|
|
600
600
|
return match?.[0] ?? null;
|
|
601
601
|
}
|
|
602
602
|
function isSudoPromptLine(text) {
|
|
@@ -637,6 +637,28 @@ export function buildCommandEnv(cwd) {
|
|
|
637
637
|
THEGITAI_SCRATCH_DIR: ensureSessionScratchDir(),
|
|
638
638
|
};
|
|
639
639
|
}
|
|
640
|
+
let cachedCommandShell;
|
|
641
|
+
function findBashPath() {
|
|
642
|
+
const fromPath = (process.env.PATH ?? '')
|
|
643
|
+
.split(path.delimiter)
|
|
644
|
+
.filter(Boolean)
|
|
645
|
+
.map((dir) => path.join(dir, 'bash'));
|
|
646
|
+
for (const candidate of [...fromPath, '/bin/bash', '/usr/bin/bash']) {
|
|
647
|
+
try {
|
|
648
|
+
accessSync(candidate, fsConstants.X_OK);
|
|
649
|
+
return candidate;
|
|
650
|
+
}
|
|
651
|
+
catch { }
|
|
652
|
+
}
|
|
653
|
+
return null;
|
|
654
|
+
}
|
|
655
|
+
export function resolveCommandShell() {
|
|
656
|
+
if (cachedCommandShell !== undefined)
|
|
657
|
+
return cachedCommandShell;
|
|
658
|
+
cachedCommandShell =
|
|
659
|
+
process.platform === 'win32' ? true : (findBashPath() ?? true);
|
|
660
|
+
return cachedCommandShell;
|
|
661
|
+
}
|
|
640
662
|
function sanitizePtyOutput(command, output, cwd, secrets) {
|
|
641
663
|
return sanitizeCommandText(command, stripSudoPromptText(redactSecrets(output, secrets)), cwd);
|
|
642
664
|
}
|
|
@@ -822,7 +844,7 @@ export async function runCommand(command, cwd, { requestSudoPassword, timeout, }
|
|
|
822
844
|
let killTimer = null;
|
|
823
845
|
const child = spawn(command, {
|
|
824
846
|
cwd,
|
|
825
|
-
shell:
|
|
847
|
+
shell: resolveCommandShell(),
|
|
826
848
|
detached: process.platform !== 'win32',
|
|
827
849
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
828
850
|
env: buildCommandEnv(cwd),
|
package/dist/src/help-text.js
CHANGED
|
@@ -14,51 +14,103 @@ const PASTE_SHORTCUT = pasteShortcutForPlatform();
|
|
|
14
14
|
const HELP_MARKDOWN = [
|
|
15
15
|
'# TheGitAI',
|
|
16
16
|
'',
|
|
17
|
-
'Interactive terminal coding agent. Local repo
|
|
17
|
+
'Interactive terminal coding agent. Local repo search, file edits, and',
|
|
18
18
|
'shell commands run on your machine. Model inference and server-executed',
|
|
19
19
|
'tools run on the server.',
|
|
20
20
|
'',
|
|
21
21
|
'## Usage',
|
|
22
22
|
'',
|
|
23
|
-
'- `ai`
|
|
24
|
-
'- `ai "<request>"`
|
|
23
|
+
'- `ai` - start an interactive chat session in the current repo',
|
|
24
|
+
'- `ai "<request>"` - start an interactive session with `<request>` as the first message',
|
|
25
25
|
'- Coding sessions require terminal stdin and stdout; piped prompts are not supported.',
|
|
26
26
|
'',
|
|
27
27
|
'## Auth',
|
|
28
28
|
'',
|
|
29
|
-
'- `ai
|
|
30
|
-
'- `ai login
|
|
31
|
-
'-
|
|
32
|
-
'
|
|
33
|
-
'
|
|
29
|
+
'- `ai` - signs you in if you are not already, then starts a session',
|
|
30
|
+
'- `ai login` - the same thing; kept for muscle memory',
|
|
31
|
+
'- Signing in opens your browser. When it cannot open one - over SSH, in a',
|
|
32
|
+
' container, or when the browser you want is on another device - the same',
|
|
33
|
+
' screen prints a URL you can open anywhere and takes the code that page',
|
|
34
|
+
' gives you back. There is no mode to pick and no flag to remember.',
|
|
35
|
+
'- `ai whoami` - show the signed-in account',
|
|
36
|
+
'- `ai --usage` - show account usage percentage and reset times',
|
|
37
|
+
'- `ai logout` - sign out',
|
|
38
|
+
'',
|
|
39
|
+
'## MCP servers',
|
|
40
|
+
'',
|
|
41
|
+
'- `ai mcp add <name> -- <command> [args...]` - connect a local MCP server',
|
|
42
|
+
'- `ai mcp add --transport http <name> <url>` - connect a remote MCP server',
|
|
43
|
+
'- `ai mcp --help` - configuration, headers, environment variables and commands',
|
|
44
|
+
'- Short setup flags: `-t` transport, `-e` environment, `-H` header, `-s user` scope.',
|
|
45
|
+
'- `/mcp` - check connections and available tools; changes apply next turn',
|
|
46
|
+
'- Default mode asks before MCP calls; approvals can cover one tool for the session.',
|
|
47
|
+
'- Bypass mode also approves MCP calls. Plan mode blocks MCP calls.',
|
|
48
|
+
'- Invalid servers are reported individually; chat continues with available tools.',
|
|
49
|
+
'- `/mcp` retries connections; tool lists are cached for one minute.',
|
|
50
|
+
'- MCP supports tools over stdio and Streamable HTTP. OAuth, prompts and resources',
|
|
51
|
+
' are not supported yet. Add only servers you trust.',
|
|
34
52
|
'',
|
|
35
53
|
'## Sessions',
|
|
36
54
|
'',
|
|
37
|
-
'- `ai --list-sessions`
|
|
38
|
-
'- `ai --session <id|name>`
|
|
55
|
+
'- `ai --list-sessions` - list saved sessions for this repo',
|
|
56
|
+
'- `ai --session <id|name>` - resume a saved session by id or name',
|
|
39
57
|
'- Sessions are stored locally and can be listed or resumed in the same repo.',
|
|
40
58
|
' Continuing one requires the TheGitAI account used for that session.',
|
|
41
59
|
'',
|
|
60
|
+
'## Updates',
|
|
61
|
+
'',
|
|
62
|
+
'- On start, `ai` says when a newer release is published and offers to install',
|
|
63
|
+
' it. TheGitAI works best on the latest version, and an older CLI may not',
|
|
64
|
+
' work optimally.',
|
|
65
|
+
'- **Update now** is selected when the offer appears, so **Enter** takes the',
|
|
66
|
+
' update; **↑/↓** moves to **Skip**, and the number keys still jump straight',
|
|
67
|
+
' to a row. The CLI installs the update and asks you to start `ai` again, so',
|
|
68
|
+
' the whole session runs one version.',
|
|
69
|
+
'- Skipping starts the session on the version you have and asks again next',
|
|
70
|
+
' time. A release cannot be silenced for good - that is what keeps a broken',
|
|
71
|
+
' combination from lasting.',
|
|
72
|
+
'- **Ctrl+C** at the prompt quits without installing anything and without',
|
|
73
|
+
' starting the session.',
|
|
74
|
+
'',
|
|
42
75
|
'## Options',
|
|
43
76
|
'',
|
|
44
|
-
'- `-y, --yes`
|
|
45
|
-
'- `-h, --help`
|
|
46
|
-
'- `-v, --version`
|
|
77
|
+
'- `-y, --yes` - start in Bypass all permissions mode',
|
|
78
|
+
'- `-h, --help` - show this help',
|
|
79
|
+
'- `-v, --version` - print the version and exit',
|
|
47
80
|
'',
|
|
48
81
|
'## Modes',
|
|
49
82
|
'',
|
|
50
|
-
'- Default
|
|
51
|
-
'
|
|
52
|
-
'
|
|
83
|
+
'- Default · Ask for Approval - asks before creating, editing or deleting',
|
|
84
|
+
' files, before running commands, and before touching a website. Each answer',
|
|
85
|
+
' can be remembered for the rest of the session, and once it is, Default',
|
|
86
|
+
' stops asking for that action; see Safety & approvals.',
|
|
87
|
+
'- Bypass all permissions - approves every command, file edit, deletion and',
|
|
88
|
+
' browser action for the rest of the session, without asking. Shown in red',
|
|
89
|
+
' in the footer. Blocked commands stay blocked.',
|
|
90
|
+
'- Plan - read-only; the agent can inspect, ask typed questions, and plan,',
|
|
53
91
|
' with file-reading shell commands only. It will not edit files or run tests,',
|
|
54
92
|
' builds, diagnostics, package managers, project code, or network probes.',
|
|
55
|
-
'- In the TUI, Shift+Tab cycles
|
|
93
|
+
'- In the TUI, press **?** on an empty composer for the keyboard-and-mouse panel. Shift+Tab cycles Default → Bypass → Plan (refused while the agent is working), mouse drag copies transcript/footer text, left-click opens rendered links, right-click copies rendered links or pastes in the sticky composer/footer when no selection is active, double-click copies a word, and triple-click copies a row.',
|
|
56
94
|
'',
|
|
57
95
|
'## Keys & clipboard',
|
|
58
96
|
'',
|
|
59
|
-
'-
|
|
97
|
+
'- **?** on an empty composer opens the keyboard-and-mouse panel.',
|
|
98
|
+
'- **Enter** sends • **Shift+Tab** cycles Default → Bypass → Plan (only',
|
|
99
|
+
' between turns) • **Esc** cancels the turn •',
|
|
60
100
|
' **Ctrl+C** clears the composer or the queued message, and quits once there',
|
|
61
101
|
' is nothing left to clear. These are the same on macOS, Linux, and Windows.',
|
|
102
|
+
'- **While the agent is working**, Enter queues your message and locks the',
|
|
103
|
+
' composer. Press **Enter** again to send it into the running turn: the agent',
|
|
104
|
+
' picks it up at its next step instead of waiting for the turn to finish, and',
|
|
105
|
+
' the Your messages panel tracks it from queued to delivered. **↑** brings it',
|
|
106
|
+
' back for editing and **Esc**/**Ctrl+C** discards it; both unlock the',
|
|
107
|
+
' composer for the next message. **Ctrl+V** pastes a screenshot onto the',
|
|
108
|
+
' queued message, and it is delivered into the running turn with the text.',
|
|
109
|
+
'- **Ctrl+G** turns desktop notifications on or off. One is raised when a turn',
|
|
110
|
+
' ends and when a permission prompt or a question is waiting for you, but',
|
|
111
|
+
' only while the terminal is in the background - if you are looking at the',
|
|
112
|
+
' session you are told nothing. Coming back clears it. The choice is',
|
|
113
|
+
' remembered between sessions.',
|
|
62
114
|
`- **Paste** into the composer with your terminal's paste shortcut (\`${PASTE_SHORTCUT}\``,
|
|
63
115
|
' on this system) or by right-clicking the composer.',
|
|
64
116
|
'- **Copy** from the transcript by dragging to select; double-click copies a',
|
|
@@ -67,52 +119,111 @@ const HELP_MARKDOWN = [
|
|
|
67
119
|
? ['- On Mac laptops without dedicated keys, **Home/End** are `Fn+←` / `Fn+→`.']
|
|
68
120
|
: []),
|
|
69
121
|
'',
|
|
122
|
+
'## Questions',
|
|
123
|
+
'',
|
|
124
|
+
'- The agent can pause a turn to ask up to four questions in one form.',
|
|
125
|
+
' **↑/↓** moves, the option number or **Enter** chooses, **←/→** moves',
|
|
126
|
+
' between questions, and the last question has a **Submit answers** row.',
|
|
127
|
+
'- Only the option you are on shows its description, so the whole form fits',
|
|
128
|
+
' on screen. Move to an option to read what it means.',
|
|
129
|
+
'- **Something else / add details** is the numbered final option: focus it',
|
|
130
|
+
' and type. **Enter** commits the note and moves to the next question, or to',
|
|
131
|
+
' Submit on the last one - it never submits the form for you.',
|
|
132
|
+
'- **Esc** closes an open note first, and otherwise cancels the form.',
|
|
133
|
+
'',
|
|
70
134
|
'## Chat commands',
|
|
71
135
|
'',
|
|
72
|
-
'-
|
|
73
|
-
'
|
|
74
|
-
'
|
|
75
|
-
'
|
|
76
|
-
'
|
|
77
|
-
'- `/
|
|
78
|
-
'- `/
|
|
136
|
+
'- Type `/` to open the command picker. It ranks what you type, so a typo or',
|
|
137
|
+
' a stray plural (`/moddel`, `/models`) still finds the command, and a word',
|
|
138
|
+
' from the description does too (`/bug` finds `/report`). It shows the five',
|
|
139
|
+
' best matches and counts the rest; **↑/↓** chooses, **Tab** or **Enter**',
|
|
140
|
+
' accepts, **Esc** closes it.',
|
|
141
|
+
'- `/help` - show this help',
|
|
142
|
+
'- `/mcp` - check MCP connections and list available tools',
|
|
143
|
+
'- `/skills` - list your skills and any that failed to load',
|
|
144
|
+
'- `/skills add <source>` - install a skill from GitHub (`owner/repo/path`',
|
|
145
|
+
' or a GitHub URL) or from a local folder into ~/.thegitai/skills; add',
|
|
146
|
+
' `--project` to put it in this project\'s .thegitai/skills instead',
|
|
147
|
+
'- `/<skill> [what to do]` - run a skill yourself. Skills show up in the',
|
|
148
|
+
' command picker, and the agent also loads a matching skill on its own',
|
|
149
|
+
'- `/about` - show version and platform info',
|
|
150
|
+
'- `/report` - file a bug privately through the TheGitAI website in your',
|
|
151
|
+
' browser (sign in with your existing account)',
|
|
152
|
+
'- `/usage` - show account usage percentage and reset times',
|
|
153
|
+
'- `/model` - ↑/↓ picks a model, ←/→ adjusts effort; Enter saves for this project, Esc cancels',
|
|
154
|
+
'- `/model <id>` - switch the active model without clearing history',
|
|
155
|
+
'- `/resume` - resume a saved session for this repo',
|
|
156
|
+
'- `/jobs` - manage long-running commands like dev servers and watchers:',
|
|
79
157
|
' browse them, press Enter to expand one and read its output, k to stop it',
|
|
80
|
-
'-
|
|
81
|
-
'
|
|
82
|
-
'- `/
|
|
83
|
-
'- `/
|
|
158
|
+
'- Ctrl+B - open the same jobs picker, and the only way in while the agent',
|
|
159
|
+
' is working; press it again or Esc to close without touching the turn',
|
|
160
|
+
'- `/jobs output <id>` - print one job\'s full captured output',
|
|
161
|
+
'- `/jobs kill <id>` - stop one background job',
|
|
162
|
+
'- `/notify` - turn desktop notifications on or off (same as Ctrl+G)',
|
|
163
|
+
'- `/new` - start a new conversation; this session remains saved',
|
|
164
|
+
'- `/logout` - sign out and quit',
|
|
165
|
+
'- `/exit` - quit the session',
|
|
84
166
|
'',
|
|
85
167
|
'## Safety & approvals',
|
|
86
168
|
'',
|
|
87
|
-
'- TheGitAI asks before
|
|
88
|
-
'
|
|
89
|
-
'
|
|
169
|
+
'- In Default mode TheGitAI asks before it creates a file, edits an existing',
|
|
170
|
+
' file, deletes a file, or runs a command. These are four separate',
|
|
171
|
+
' permissions: allowing edits does not allow deletions, and allowing file',
|
|
172
|
+
' changes does not allow commands.',
|
|
173
|
+
'- At each prompt: **↑/↓** moves between choices, **Enter** confirms the',
|
|
174
|
+
' highlighted one, and **Esc** denies. Deny is selected by default.',
|
|
175
|
+
' Single-letter shortcuts were removed on purpose: a prompt can appear',
|
|
176
|
+
' while you are typing, and a stray letter must never approve anything.',
|
|
177
|
+
'- Every prompt offers Approve once, an "Always allow" for that kind of',
|
|
178
|
+
' action, and Deny. A command also offers to remember just its prefix - for',
|
|
179
|
+
' example approving `npm test -- --watch=false` can allow `npm test`.',
|
|
180
|
+
'- A prefix is only offered when the command shows a plain verb, as in',
|
|
181
|
+
' `npm test` or `git status`. Commands with no verb (`ls -la`), interpreters',
|
|
182
|
+
' and wrappers (`bash -c`, `python -c`, `env`, `timeout`, `make`), and',
|
|
183
|
+
' destructive or network binaries (`rm`, `sudo`, `curl`) are never offered',
|
|
184
|
+
' one - a bare binary grant would mean "anything this program can do".',
|
|
185
|
+
' `npm run` must name its script, so the grant is `npm run build`.',
|
|
186
|
+
'- A remembered prefix never covers a command that chains, pipes, redirects,',
|
|
187
|
+
' or substitutes, so allowing `npm test` can never green-light',
|
|
188
|
+
' `npm test && rm -rf build`.',
|
|
189
|
+
'- Everything you allow lasts for the current session only and is forgotten',
|
|
190
|
+
' when it ends. `/new` clears it immediately.',
|
|
90
191
|
'- If an approved `sudo` command needs a password, the TUI shows the exact',
|
|
91
192
|
' command and keeps the password masked and local.',
|
|
92
193
|
'- `-y` / `--yes` at startup auto-approves every shell command and file',
|
|
93
|
-
' edit for the whole session
|
|
194
|
+
' edit for the whole session - use with care.',
|
|
94
195
|
'- Long-running commands (e.g. dev servers) can run as managed background',
|
|
95
196
|
' jobs after the same approval as any other command. Background output',
|
|
96
197
|
' stays quiet once the model has responded; the footer shows only a compact',
|
|
97
198
|
' shell-running indicator, `/jobs` lists, inspects, and kills jobs, and',
|
|
98
|
-
' killed jobs disappear immediately.
|
|
99
|
-
'
|
|
199
|
+
' killed jobs disappear immediately. While a turn is running the indicator',
|
|
200
|
+
' points at Ctrl+B instead, which opens the same picker without cancelling',
|
|
201
|
+
' or interrupting the turn. Every job is killed when the session ends.',
|
|
100
202
|
'- File and shell operations are confined to the target repo root.',
|
|
101
203
|
'- Sensitive directories (`.git`, `node_modules`, build output) are',
|
|
102
|
-
'
|
|
204
|
+
' excluded from search and listing.',
|
|
103
205
|
'',
|
|
104
206
|
'## Troubleshooting',
|
|
105
207
|
'',
|
|
106
|
-
'- "Not logged in" → run `ai login`.',
|
|
107
208
|
'- Auth or permission errors → run `ai whoami` to confirm the signed-in',
|
|
108
209
|
' account.',
|
|
109
210
|
'- Usage or quota errors → run `ai --usage`.',
|
|
110
|
-
'- Signed in with the wrong
|
|
111
|
-
' the account you intended to use.',
|
|
211
|
+
'- Signed in with the wrong account → `/logout` (or `ai logout`), then run',
|
|
212
|
+
' `ai` and sign in as the account you intended to use.',
|
|
213
|
+
'- The browser did not open, or opened on the wrong machine → open the URL',
|
|
214
|
+
' printed on the sign-in screen anywhere you like, choose "On another',
|
|
215
|
+
' computer" on that page, and paste the code back into the terminal.',
|
|
112
216
|
'- A local session was used with a different sign-in → sign in with the',
|
|
113
217
|
' account you used for that session or start a new session.',
|
|
114
|
-
'-
|
|
115
|
-
'
|
|
218
|
+
'- The connection drops mid-turn → nothing to do: the CLI reconnects to the',
|
|
219
|
+
' same turn up to three times, ten seconds apart, without running anything',
|
|
220
|
+
' twice. Esc stops it. If it cannot reconnect it says so; some actions may',
|
|
221
|
+
' already have completed, and a queued message waits in the composer.',
|
|
222
|
+
' If the service restarted mid-turn, the turn continues from the steps that',
|
|
223
|
+
' had finished. Starting `ai` while the service is briefly unavailable waits',
|
|
224
|
+
' the same way.',
|
|
225
|
+
'- For anything else, re-run the command and file the printed error',
|
|
226
|
+
' message with `/report` - there is no client-side debug mode by design.',
|
|
116
227
|
].join('\n');
|
|
117
228
|
export function formatAboutCard() {
|
|
118
229
|
return [
|