@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import chalk from '../colors.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { ensurePermission } from '../permissions.js';
|
|
4
4
|
import { isTuiMode } from '../runtime-mode.js';
|
|
5
5
|
import { buildDeferredShellDiagnostics, invalidateShellDiagnosticsCache, } from './shell-diagnostics.js';
|
|
6
6
|
import { ensureSessionScratchDir } from '../scratch-dir.js';
|
|
@@ -56,29 +56,6 @@ function buildOutput(stdout, stderr, exitCode) {
|
|
|
56
56
|
return trimOutput(stdout.trim());
|
|
57
57
|
return trimOutput([stdout, stderr].filter(Boolean).join('\n').trim());
|
|
58
58
|
}
|
|
59
|
-
function emptyRepoSync(reason) {
|
|
60
|
-
return {
|
|
61
|
-
added: 0,
|
|
62
|
-
modified: 0,
|
|
63
|
-
removed: 0,
|
|
64
|
-
indexedChunks: 0,
|
|
65
|
-
retrievalTokensUsed: 0,
|
|
66
|
-
skipped: true,
|
|
67
|
-
...(reason ? { reason } : {}),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function readGitStatusSignature(rootDir) {
|
|
71
|
-
try {
|
|
72
|
-
return execFileSync('git', ['-C', rootDir, 'status', '--porcelain=v1', '--untracked-files=all'], {
|
|
73
|
-
encoding: 'utf-8',
|
|
74
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
75
|
-
timeout: 10_000,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
59
|
function executeNodeScript(rootDir, script, timeout) {
|
|
83
60
|
const effectiveTimeout = typeof timeout === 'number' && timeout > 0
|
|
84
61
|
? timeout
|
|
@@ -148,7 +125,7 @@ function executeNodeScript(rootDir, script, timeout) {
|
|
|
148
125
|
});
|
|
149
126
|
}
|
|
150
127
|
export async function runNodeScript(context, args) {
|
|
151
|
-
const { rootDir
|
|
128
|
+
const { rootDir } = context;
|
|
152
129
|
const script = typeof args.script === 'string' ? args.script : '';
|
|
153
130
|
if (!script.trim()) {
|
|
154
131
|
return { ok: false, error: 'script is required' };
|
|
@@ -158,65 +135,21 @@ export async function runNodeScript(context, args) {
|
|
|
158
135
|
console.log(chalk.bold.yellow(`\n ⚡ Node script:\n${commandForApproval}\n`));
|
|
159
136
|
console.log(chalk.dim(` in: ${rootDir}\n`));
|
|
160
137
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const approved = await confirmCommand(commandForApproval);
|
|
170
|
-
if (!approved) {
|
|
171
|
-
if (!isTuiMode()) {
|
|
172
|
-
console.log(chalk.dim(` ⏭ Skipped: ${COMMAND_LABEL}`));
|
|
173
|
-
}
|
|
174
|
-
return {
|
|
175
|
-
ok: false,
|
|
176
|
-
skipped: true,
|
|
177
|
-
command: COMMAND_LABEL,
|
|
178
|
-
failureCategory: 'user_declined',
|
|
179
|
-
failureDetails: {
|
|
180
|
-
category: 'user_declined',
|
|
181
|
-
tool: 'run_node_script',
|
|
182
|
-
action: '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.',
|
|
183
|
-
},
|
|
184
|
-
error: 'The real user rejected this proposed script. Nothing was executed; this was not a tool failure or an automated system skip.',
|
|
185
|
-
};
|
|
138
|
+
const denied = await ensurePermission(context, {
|
|
139
|
+
bucket: 'run',
|
|
140
|
+
title: 'Approve node script?',
|
|
141
|
+
body: commandForApproval,
|
|
142
|
+
}, 'run_node_script', { command: COMMAND_LABEL });
|
|
143
|
+
if (denied) {
|
|
144
|
+
if (!isTuiMode()) {
|
|
145
|
+
console.log(chalk.dim(` ⏭ Skipped: ${COMMAND_LABEL}`));
|
|
186
146
|
}
|
|
147
|
+
return denied;
|
|
187
148
|
}
|
|
188
|
-
const beforeGitStatus = readGitStatusSignature(rootDir);
|
|
189
149
|
const result = await executeNodeScript(rootDir, script, typeof args.timeout_ms === 'number' && args.timeout_ms > 0
|
|
190
150
|
? args.timeout_ms
|
|
191
151
|
: undefined);
|
|
192
|
-
const afterGitStatus = readGitStatusSignature(rootDir);
|
|
193
|
-
const gitStatusCleanBeforeAndAfter = beforeGitStatus === '' && afterGitStatus === '';
|
|
194
|
-
const shouldSync = context.projectIndex.initialized && !gitStatusCleanBeforeAndAfter;
|
|
195
|
-
let repoSync;
|
|
196
|
-
if (shouldSync) {
|
|
197
|
-
try {
|
|
198
|
-
repoSync = await syncIndexFromDisk(context.projectIndex);
|
|
199
|
-
}
|
|
200
|
-
catch (error) {
|
|
201
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
202
|
-
context.onStatus(`Node script completed, but local index sync failed: ${message}`);
|
|
203
|
-
repoSync = {
|
|
204
|
-
...emptyRepoSync('local index sync failed after Node script execution'),
|
|
205
|
-
error: message,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
repoSync = emptyRepoSync(!context.projectIndex.initialized
|
|
211
|
-
? 'project index not initialized'
|
|
212
|
-
: gitStatusCleanBeforeAndAfter
|
|
213
|
-
? 'git status clean before and after'
|
|
214
|
-
: 'sync not needed');
|
|
215
|
-
}
|
|
216
152
|
invalidateShellDiagnosticsCache(rootDir);
|
|
217
|
-
if (repoSync.added || repoSync.modified || repoSync.removed) {
|
|
218
|
-
context.onStatus(`Synced repo state after Node script (${repoSync.added} added, ${repoSync.modified} modified, ${repoSync.removed} removed).`);
|
|
219
|
-
}
|
|
220
153
|
return {
|
|
221
154
|
ok: result.exitCode === 0,
|
|
222
155
|
command: COMMAND_LABEL,
|
|
@@ -225,8 +158,6 @@ export async function runNodeScript(context, args) {
|
|
|
225
158
|
stdout: result.stdout,
|
|
226
159
|
stderr: result.stderr,
|
|
227
160
|
output: result.output,
|
|
228
|
-
repoSync,
|
|
229
|
-
retrievalTokensUsed: repoSync.retrievalTokensUsed,
|
|
230
161
|
diagnostics: buildDeferredShellDiagnostics('run_node_script'),
|
|
231
162
|
};
|
|
232
163
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getClientStateDir } from '../client-state.js';
|
|
4
|
+
import { MAX_IMAGE_SIZE_BYTES, sniffImageMimeType, } from '../core/image-limits.js';
|
|
5
|
+
const IMAGE_FILE_MODE = 0o600;
|
|
6
|
+
const IMAGE_DIR_MODE = 0o700;
|
|
7
|
+
export const GENERATED_IMAGES_SUBDIR = 'generated_images';
|
|
8
|
+
export const GENERATED_IMAGE_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
9
|
+
export function getGeneratedImagesDir(env = process.env) {
|
|
10
|
+
return path.join(getClientStateDir(env), GENERATED_IMAGES_SUBDIR);
|
|
11
|
+
}
|
|
12
|
+
export function sanitizeGeneratedImageBasename(raw) {
|
|
13
|
+
const trimmed = String(raw ?? '').trim();
|
|
14
|
+
const base = trimmed
|
|
15
|
+
.replace(/\\/g, '/')
|
|
16
|
+
.split('/')
|
|
17
|
+
.pop()
|
|
18
|
+
?.replace(/^\.+/, '')
|
|
19
|
+
.replace(/[^\w.\-]+/g, '-')
|
|
20
|
+
.replace(/-+/g, '-')
|
|
21
|
+
.replace(/^-+|-+$/g, '')
|
|
22
|
+
.replace(/-\.|\.-/g, '.')
|
|
23
|
+
.replace(/^-+|-+$/g, '')
|
|
24
|
+
.slice(0, 80);
|
|
25
|
+
if (!base || base === '.' || base === '..') {
|
|
26
|
+
return `generated-${Date.now()}.png`;
|
|
27
|
+
}
|
|
28
|
+
if (/\.png$/i.test(base)) {
|
|
29
|
+
return base.replace(/\.png$/i, '.png');
|
|
30
|
+
}
|
|
31
|
+
const withoutExt = base.replace(/\.[^.]+$/, '').replace(/-+$/g, '');
|
|
32
|
+
return `${withoutExt || 'generated'}.png`;
|
|
33
|
+
}
|
|
34
|
+
function uniquePath(dir, basename) {
|
|
35
|
+
const candidate = path.join(dir, basename);
|
|
36
|
+
if (!existsSync(candidate)) {
|
|
37
|
+
return candidate;
|
|
38
|
+
}
|
|
39
|
+
const ext = path.extname(basename) || '.png';
|
|
40
|
+
const stem = path.basename(basename, ext);
|
|
41
|
+
for (let i = 2; i < 10_000; i += 1) {
|
|
42
|
+
const next = path.join(dir, `${stem}-${i}${ext}`);
|
|
43
|
+
if (!existsSync(next)) {
|
|
44
|
+
return next;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return path.join(dir, `${stem}-${Date.now()}${ext}`);
|
|
48
|
+
}
|
|
49
|
+
export function sweepGeneratedImages({ maxAgeMs = GENERATED_IMAGE_MAX_AGE_MS, env = process.env, now = Date.now(), } = {}) {
|
|
50
|
+
const dir = getGeneratedImagesDir(env);
|
|
51
|
+
if (!existsSync(dir))
|
|
52
|
+
return 0;
|
|
53
|
+
let removed = 0;
|
|
54
|
+
let entries;
|
|
55
|
+
try {
|
|
56
|
+
entries = readdirSync(dir);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
for (const entry of entries) {
|
|
62
|
+
const filePath = path.join(dir, entry);
|
|
63
|
+
try {
|
|
64
|
+
if (now - statSync(filePath).mtimeMs < maxAgeMs)
|
|
65
|
+
continue;
|
|
66
|
+
rmSync(filePath, { force: true });
|
|
67
|
+
removed += 1;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return removed;
|
|
73
|
+
}
|
|
74
|
+
export function saveGeneratedImage(args) {
|
|
75
|
+
const base64Data = String(args.base64Data ?? '').trim();
|
|
76
|
+
if (!base64Data) {
|
|
77
|
+
return {
|
|
78
|
+
ok: false,
|
|
79
|
+
error: 'This CLI build cannot generate images without server-supplied image bytes. Update TheGitAI CLI.',
|
|
80
|
+
failureCategory: 'tool_exception',
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
let bytes;
|
|
84
|
+
try {
|
|
85
|
+
bytes = Buffer.from(base64Data, 'base64');
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return {
|
|
89
|
+
ok: false,
|
|
90
|
+
error: 'Generated image bytes are invalid.',
|
|
91
|
+
failureCategory: 'invalid_argument',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (bytes.length === 0 || bytes.length > MAX_IMAGE_SIZE_BYTES) {
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
error: 'Generated image exceeded the allowed size limit.',
|
|
98
|
+
failureCategory: 'invalid_argument',
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const sniffed = sniffImageMimeType(bytes);
|
|
102
|
+
if (sniffed !== 'image/png') {
|
|
103
|
+
return {
|
|
104
|
+
ok: false,
|
|
105
|
+
error: 'Generated image must be a PNG.',
|
|
106
|
+
failureCategory: 'invalid_argument',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const env = args.env ?? process.env;
|
|
110
|
+
const dir = getGeneratedImagesDir(env);
|
|
111
|
+
mkdirSync(dir, { recursive: true, mode: IMAGE_DIR_MODE });
|
|
112
|
+
const basename = sanitizeGeneratedImageBasename(args.suggestedFilename ?? args.filename);
|
|
113
|
+
const target = uniquePath(dir, basename);
|
|
114
|
+
writeFileSync(target, bytes, { mode: IMAGE_FILE_MODE });
|
|
115
|
+
return {
|
|
116
|
+
ok: true,
|
|
117
|
+
path: target,
|
|
118
|
+
message: `Image saved to ${target}`,
|
|
119
|
+
};
|
|
120
|
+
}
|