@thegitai/cli 1.0.0-preview.9 → 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 +139 -111
- 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 +77 -34
- package/dist/src/api/chat.js +700 -173
- 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 +71 -10
- 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/repl.js +1141 -299
- 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 +858 -303
- 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 +4 -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
package/dist/src/agent-mode.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
export const AGENT_MODES = ['default', 'auto-accept', 'plan'];
|
|
2
2
|
const PLAN_MODE_TOOL_NAMES = new Set([
|
|
3
|
-
'search_code',
|
|
4
3
|
'list_files',
|
|
5
4
|
'list_directories',
|
|
6
5
|
'read_file',
|
|
7
6
|
'grep_code',
|
|
8
|
-
'find_symbol',
|
|
9
|
-
'list_symbols',
|
|
10
|
-
'hover_symbol',
|
|
11
|
-
'signature_help',
|
|
12
7
|
'read_document',
|
|
13
8
|
'analyze_image',
|
|
14
9
|
'run_command',
|
|
15
10
|
'shell_job_output',
|
|
16
11
|
'update_todos',
|
|
12
|
+
'use_skill',
|
|
13
|
+
'browser',
|
|
14
|
+
'browser_tabs',
|
|
15
|
+
'browser_read_page',
|
|
16
|
+
'browser_get_page_text',
|
|
17
|
+
'browser_find',
|
|
18
|
+
'browser_console',
|
|
19
|
+
'browser_downloads',
|
|
20
|
+
'browser_network',
|
|
21
|
+
'browser_screenshot',
|
|
22
|
+
'browser_batch',
|
|
17
23
|
]);
|
|
18
24
|
const PLAN_MODE_RUN_COMMAND_NAMES = new Set([
|
|
19
25
|
'pwd',
|
|
@@ -46,7 +52,7 @@ export function nextAgentMode(mode) {
|
|
|
46
52
|
export function agentModeAllowsTool(mode, toolName) {
|
|
47
53
|
return mode !== 'plan' || PLAN_MODE_TOOL_NAMES.has(toolName);
|
|
48
54
|
}
|
|
49
|
-
function getUnquotedShellText(command) {
|
|
55
|
+
export function getUnquotedShellText(command) {
|
|
50
56
|
let quote = null;
|
|
51
57
|
let escaped = false;
|
|
52
58
|
let text = '';
|
|
@@ -140,8 +146,28 @@ export function buildPlanModeToolBlockedResult(toolName, action = 'Plan mode is
|
|
|
140
146
|
}
|
|
141
147
|
export function agentModeLabel(mode) {
|
|
142
148
|
if (mode === 'auto-accept')
|
|
143
|
-
return '
|
|
149
|
+
return 'Bypass all permissions';
|
|
144
150
|
if (mode === 'plan')
|
|
145
151
|
return 'Plan · read-only';
|
|
152
|
+
return 'Default · Ask for Approval';
|
|
153
|
+
}
|
|
154
|
+
export function agentModeLabelTiers(mode) {
|
|
155
|
+
return [agentModeLabel(mode)];
|
|
156
|
+
}
|
|
157
|
+
export function agentModeShortLabel(mode) {
|
|
158
|
+
if (mode === 'auto-accept')
|
|
159
|
+
return 'Bypass';
|
|
160
|
+
if (mode === 'plan')
|
|
161
|
+
return 'Plan';
|
|
146
162
|
return 'Default';
|
|
147
163
|
}
|
|
164
|
+
export function agentModeColor(mode) {
|
|
165
|
+
if (mode === 'auto-accept')
|
|
166
|
+
return 'red';
|
|
167
|
+
if (mode === 'plan')
|
|
168
|
+
return 'yellow';
|
|
169
|
+
return 'cyan';
|
|
170
|
+
}
|
|
171
|
+
export function agentModeCycleSequence() {
|
|
172
|
+
return AGENT_MODES.map(agentModeShortLabel).join(' → ');
|
|
173
|
+
}
|
package/dist/src/api/auth.js
CHANGED
|
@@ -50,20 +50,26 @@ export async function fetchWhoami({ config, fetchImpl = globalThis.fetch, }) {
|
|
|
50
50
|
const data = await fetchWhoamiResponse({ config, fetchImpl });
|
|
51
51
|
return data.customer;
|
|
52
52
|
}
|
|
53
|
-
export async function fetchWhoamiResponse({ config, fetchImpl = globalThis.fetch, }) {
|
|
53
|
+
export async function fetchWhoamiResponse({ config, fetchImpl = globalThis.fetch, budget = {}, }) {
|
|
54
|
+
const { timeoutMs, ...ladder } = budget;
|
|
54
55
|
const data = (await retryTransient(() => authorizedJson({
|
|
55
56
|
config,
|
|
56
57
|
path: '/v1/auth/whoami',
|
|
57
58
|
fetchImpl,
|
|
58
|
-
|
|
59
|
+
...(timeoutMs == null ? {} : { timeoutMs }),
|
|
60
|
+
}), ladder));
|
|
59
61
|
if (!data?.customer?.email) {
|
|
60
62
|
throw new Error('Server returned an invalid whoami response.');
|
|
61
63
|
}
|
|
64
|
+
const latestVersion = data.release?.latestVersion;
|
|
62
65
|
return {
|
|
63
66
|
customer: data.customer,
|
|
64
67
|
debugUi: {
|
|
65
68
|
showSessionId: data.debugUi?.showSessionId === true,
|
|
66
69
|
},
|
|
70
|
+
...(typeof latestVersion === 'string' && latestVersion
|
|
71
|
+
? { release: { latestVersion } }
|
|
72
|
+
: {}),
|
|
67
73
|
...(data.usage ? { usage: data.usage } : {}),
|
|
68
74
|
};
|
|
69
75
|
}
|
|
@@ -5,15 +5,24 @@ import http from 'node:http';
|
|
|
5
5
|
import os from 'node:os';
|
|
6
6
|
import { openUrl } from '../core/open-url.js';
|
|
7
7
|
import { ServerApiError, createTraceContext, failureCode, failureMessage, normalizeServerUrl, readJsonResponse, } from './http.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const DEFAULT_TIMEOUT_MS =
|
|
8
|
+
import { DEFAULT_THEGITAI_HOST } from './default-host.js';
|
|
9
|
+
import { isAbortError } from '../utils.js';
|
|
10
|
+
const DEFAULT_TIMEOUT_MS = 10 * 60 * 1000;
|
|
11
11
|
function shutDownServer(server) {
|
|
12
12
|
server.closeAllConnections?.();
|
|
13
13
|
server.close();
|
|
14
14
|
}
|
|
15
|
+
export class SignInCancelledError extends Error {
|
|
16
|
+
constructor() {
|
|
17
|
+
super('Sign-in cancelled.');
|
|
18
|
+
this.name = 'SignInCancelledError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function isSignInCancelled(error) {
|
|
22
|
+
return error instanceof SignInCancelledError;
|
|
23
|
+
}
|
|
15
24
|
export function resolveWebsiteUrl() {
|
|
16
|
-
return
|
|
25
|
+
return DEFAULT_THEGITAI_HOST.replace(/\/+$/, '');
|
|
17
26
|
}
|
|
18
27
|
function defaultDeviceName() {
|
|
19
28
|
try {
|
|
@@ -102,12 +111,8 @@ function buildAuthUrl(websiteUrl, params) {
|
|
|
102
111
|
const url = new URL(`${websiteUrl}/cli-auth`);
|
|
103
112
|
url.searchParams.set('code_challenge', params.codeChallenge);
|
|
104
113
|
url.searchParams.set('device_name', params.deviceName);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (params.state)
|
|
108
|
-
url.searchParams.set('state', params.state);
|
|
109
|
-
if (params.paste)
|
|
110
|
-
url.searchParams.set('mode', 'paste');
|
|
114
|
+
url.searchParams.set('redirect_uri', params.redirectUri);
|
|
115
|
+
url.searchParams.set('state', params.state);
|
|
111
116
|
return url.toString();
|
|
112
117
|
}
|
|
113
118
|
const RESULT_PAGE = (heading, detail) => `<!doctype html><html><head><meta charset="utf-8"><title>TheGitAI CLI</title>` +
|
|
@@ -140,36 +145,38 @@ async function exchangeCodeForToken({ serverUrl, code, codeVerifier, fetchImpl,
|
|
|
140
145
|
customer,
|
|
141
146
|
};
|
|
142
147
|
}
|
|
148
|
+
async function readPastedResult({ promptCode, signal, serverUrl, codeVerifier, fetchImpl, onPasteRejected, }) {
|
|
149
|
+
while (!signal.aborted) {
|
|
150
|
+
const code = (await promptCode(signal)).trim();
|
|
151
|
+
if (code) {
|
|
152
|
+
try {
|
|
153
|
+
return await exchangeCodeForToken({ serverUrl, code, codeVerifier, fetchImpl });
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if (signal.aborted)
|
|
157
|
+
break;
|
|
158
|
+
onPasteRejected?.(error.message);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
162
|
+
}
|
|
163
|
+
return await new Promise(() => { });
|
|
164
|
+
}
|
|
143
165
|
export async function loginViaBrowser(options) {
|
|
144
|
-
const serverUrl = normalizeServerUrl(options.serverUrl ??
|
|
166
|
+
const serverUrl = normalizeServerUrl(options.serverUrl ?? DEFAULT_THEGITAI_HOST);
|
|
145
167
|
const websiteUrl = resolveWebsiteUrl();
|
|
146
168
|
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
147
169
|
const openBrowser = options.openBrowser ?? openUrl;
|
|
148
170
|
const onUrl = options.onUrl ?? (() => { });
|
|
149
171
|
const deviceName = withOperatingSystemInfo(options.deviceName ?? defaultDeviceName());
|
|
150
172
|
const { verifier, challenge } = generatePkce();
|
|
151
|
-
if (options.noBrowser) {
|
|
152
|
-
const authUrl = buildAuthUrl(websiteUrl, {
|
|
153
|
-
codeChallenge: challenge,
|
|
154
|
-
deviceName,
|
|
155
|
-
paste: true,
|
|
156
|
-
});
|
|
157
|
-
onUrl(authUrl);
|
|
158
|
-
if (!options.promptCode) {
|
|
159
|
-
throw new Error('No way to read the authorization code in this context.');
|
|
160
|
-
}
|
|
161
|
-
const code = (await options.promptCode()).trim();
|
|
162
|
-
if (!code) {
|
|
163
|
-
throw new Error('No authorization code was entered.');
|
|
164
|
-
}
|
|
165
|
-
return exchangeCodeForToken({ serverUrl, code, codeVerifier: verifier, fetchImpl });
|
|
166
|
-
}
|
|
167
173
|
const state = crypto.randomBytes(16).toString('base64url');
|
|
168
174
|
const server = http.createServer();
|
|
175
|
+
let timer;
|
|
169
176
|
const codePromise = new Promise((resolve, reject) => {
|
|
170
|
-
|
|
177
|
+
timer = setTimeout(() => {
|
|
171
178
|
shutDownServer(server);
|
|
172
|
-
reject(new Error('
|
|
179
|
+
reject(new Error('Sign-in timed out. Authorization codes last 10 minutes - run `ai` again to start over.'));
|
|
173
180
|
}, options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
174
181
|
server.on('request', (req, res) => {
|
|
175
182
|
const requestUrl = new URL(req.url ?? '/', 'http://127.0.0.1');
|
|
@@ -182,7 +189,7 @@ export async function loginViaBrowser(options) {
|
|
|
182
189
|
const returnedState = requestUrl.searchParams.get('state') ?? '';
|
|
183
190
|
if (!code || returnedState !== state) {
|
|
184
191
|
res.writeHead(400, { 'content-type': 'text/html', connection: 'close' });
|
|
185
|
-
res.end(RESULT_PAGE('Login failed', 'The request could not be verified. Please run ai
|
|
192
|
+
res.end(RESULT_PAGE('Login failed', 'The request could not be verified. Please run `ai` again.'));
|
|
186
193
|
clearTimeout(timer);
|
|
187
194
|
shutDownServer(server);
|
|
188
195
|
reject(new Error('The login callback could not be verified.'));
|
|
@@ -212,8 +219,44 @@ export async function loginViaBrowser(options) {
|
|
|
212
219
|
state,
|
|
213
220
|
});
|
|
214
221
|
onUrl(authUrl);
|
|
215
|
-
await openBrowser(authUrl).catch(() => false);
|
|
216
|
-
options.
|
|
217
|
-
|
|
218
|
-
|
|
222
|
+
const opened = await openBrowser(authUrl).catch(() => false);
|
|
223
|
+
options.onBrowserOpen?.(opened);
|
|
224
|
+
let raceSettled = false;
|
|
225
|
+
const untilSettled = (promise) => promise.catch((error) => {
|
|
226
|
+
if (raceSettled)
|
|
227
|
+
return new Promise(() => { });
|
|
228
|
+
throw error;
|
|
229
|
+
});
|
|
230
|
+
const pasteAbort = new AbortController();
|
|
231
|
+
const routes = [
|
|
232
|
+
untilSettled(codePromise.then((code) => exchangeCodeForToken({ serverUrl, code, codeVerifier: verifier, fetchImpl }))),
|
|
233
|
+
];
|
|
234
|
+
if (options.promptCode) {
|
|
235
|
+
const pasted = readPastedResult({
|
|
236
|
+
promptCode: options.promptCode,
|
|
237
|
+
signal: pasteAbort.signal,
|
|
238
|
+
serverUrl,
|
|
239
|
+
codeVerifier: verifier,
|
|
240
|
+
fetchImpl,
|
|
241
|
+
onPasteRejected: options.onPasteRejected,
|
|
242
|
+
}).catch((error) => {
|
|
243
|
+
if (!raceSettled && isAbortError(error))
|
|
244
|
+
throw new SignInCancelledError();
|
|
245
|
+
if (!raceSettled) {
|
|
246
|
+
return new Promise(() => { });
|
|
247
|
+
}
|
|
248
|
+
throw error;
|
|
249
|
+
});
|
|
250
|
+
routes.push(untilSettled(pasted));
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
return await Promise.race(routes);
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
raceSettled = true;
|
|
257
|
+
pasteAbort.abort();
|
|
258
|
+
if (timer)
|
|
259
|
+
clearTimeout(timer);
|
|
260
|
+
shutDownServer(server);
|
|
261
|
+
}
|
|
219
262
|
}
|