@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
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { discoverSkills } from './skills/discovery.js';
|
|
4
|
+
import { BUNDLED_SKILLS } from './skills/types.js';
|
|
5
|
+
export const SKILLS_ADD_USAGE = '/skills add <owner/repo/path, GitHub URL, or folder> [--project]';
|
|
6
|
+
function displayPath(target, rootDir) {
|
|
7
|
+
const relative = path.relative(rootDir, target);
|
|
8
|
+
if (relative && !relative.startsWith('..') && !path.isAbsolute(relative))
|
|
9
|
+
return relative.split(path.sep).join('/');
|
|
10
|
+
const home = os.homedir();
|
|
11
|
+
if (target === home)
|
|
12
|
+
return '~';
|
|
13
|
+
if (target.startsWith(`${home}${path.sep}`))
|
|
14
|
+
return `~/${target.slice(home.length + 1).split(path.sep).join('/')}`;
|
|
15
|
+
return target;
|
|
16
|
+
}
|
|
17
|
+
export const SKILLS_PICKER_GROUP_TITLES = {
|
|
18
|
+
personal: 'Personal',
|
|
19
|
+
project: 'Project',
|
|
20
|
+
bundled: 'Built in',
|
|
21
|
+
'not-loaded': 'Not loaded',
|
|
22
|
+
};
|
|
23
|
+
export const SKILLS_PICKER_ADD_HINT = '/skills add <source> installs one from GitHub or a folder';
|
|
24
|
+
export function buildSkillsPickerItems(rootDir, env, builtinCommands, discovery = discoverSkills(rootDir, env)) {
|
|
25
|
+
const builtins = new Set(builtinCommands);
|
|
26
|
+
const local = (skill) => {
|
|
27
|
+
const clashes = builtins.has(`/${skill.name}`);
|
|
28
|
+
const notes = [];
|
|
29
|
+
if (skill.typedOnly)
|
|
30
|
+
notes.push('runs only when you type it');
|
|
31
|
+
if (clashes)
|
|
32
|
+
notes.push(`/${skill.name} opens the built-in command; the agent can still use it`);
|
|
33
|
+
return {
|
|
34
|
+
name: skill.name,
|
|
35
|
+
group: skill.scope,
|
|
36
|
+
description: skill.description,
|
|
37
|
+
path: displayPath(skill.dir, rootDir),
|
|
38
|
+
notes,
|
|
39
|
+
usable: !clashes,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const localNames = new Set(discovery.skills.map((skill) => skill.name));
|
|
43
|
+
return [
|
|
44
|
+
...discovery.skills.filter((skill) => skill.scope === 'personal').map(local),
|
|
45
|
+
...discovery.skills.filter((skill) => skill.scope === 'project').map(local),
|
|
46
|
+
...BUNDLED_SKILLS.filter((skill) => !localNames.has(skill.name)).map((skill) => ({
|
|
47
|
+
name: skill.name,
|
|
48
|
+
group: 'bundled',
|
|
49
|
+
description: skill.description,
|
|
50
|
+
path: null,
|
|
51
|
+
notes: [],
|
|
52
|
+
usable: true,
|
|
53
|
+
})),
|
|
54
|
+
...discovery.problems.map((problem) => ({
|
|
55
|
+
name: path.basename(problem.dir),
|
|
56
|
+
group: 'not-loaded',
|
|
57
|
+
description: problem.message,
|
|
58
|
+
path: displayPath(problem.dir, rootDir),
|
|
59
|
+
notes: [],
|
|
60
|
+
usable: false,
|
|
61
|
+
})),
|
|
62
|
+
...discovery.shadowed.map((skill) => ({
|
|
63
|
+
name: skill.name,
|
|
64
|
+
group: 'not-loaded',
|
|
65
|
+
description: 'Hidden by your personal skill with the same name.',
|
|
66
|
+
path: displayPath(skill.dir, rootDir),
|
|
67
|
+
notes: [],
|
|
68
|
+
usable: false,
|
|
69
|
+
})),
|
|
70
|
+
];
|
|
71
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { isMcpToolName } from './mcp-types.js';
|
|
2
|
+
import { sessionMcp } from './mcp-client.js';
|
|
1
3
|
import { drainBackgroundJobNotifications, getBackgroundJob, } from './background-jobs.js';
|
|
2
4
|
import { canStoreEditSnapshot, isEditToolName, isGitWorkTree, MAX_EDIT_JOURNAL_RECORDS, operationFromSnapshots, readFileEditSnapshot, } from './edit-journal.js';
|
|
3
5
|
import { clearEditFailure, collectCommandMutations, captureMutationBaseline, ensureActiveCheckpoint, recordEditFailure, recordSessionEdit, rememberCheckpointFiles, } from './session-safety.js';
|
|
4
6
|
import { buildAgentModeToolBlockedResult, } from './agent-mode.js';
|
|
5
7
|
import { classifyProjectPath } from './patcher.js';
|
|
6
8
|
import { dispatchTool } from './tools/index.js';
|
|
7
|
-
import { syncIndexFromDisk } from './project-index.js';
|
|
8
9
|
import { PATH_REPAIRING_EDIT_TOOLS, repairFilePath } from './tools/path-suggest.js';
|
|
9
|
-
import { invalidateShellDiagnosticsCache, runShellDiagnostics, } from './tools/shell-diagnostics.js';
|
|
10
|
+
import { invalidateShellDiagnosticsCache, runBatchDiagnostics, runShellDiagnostics, } from './tools/shell-diagnostics.js';
|
|
10
11
|
import { extractTodosArg } from './todo-list.js';
|
|
11
12
|
const EDIT_FILE_PATH_ARG_ALIASES = [
|
|
12
13
|
'filePath',
|
|
@@ -43,9 +44,9 @@ function toolCallSummary(call) {
|
|
|
43
44
|
return args.query.slice(0, 120);
|
|
44
45
|
return '';
|
|
45
46
|
}
|
|
46
|
-
export function formatToolCallForStatus(call) {
|
|
47
|
+
export function formatToolCallForStatus(call, label = call.name) {
|
|
47
48
|
const summary = toolCallSummary(call);
|
|
48
|
-
return summary ? `Tool: ${
|
|
49
|
+
return summary ? `Tool: ${label} ${summary}` : `Tool: ${label}`;
|
|
49
50
|
}
|
|
50
51
|
function getEditToolFilePath(call) {
|
|
51
52
|
const args = call.args && typeof call.args === 'object' ? call.args : {};
|
|
@@ -69,7 +70,7 @@ function editToolWritesSeparateOutput(call) {
|
|
|
69
70
|
const output = args.outputPath ?? args.output_path;
|
|
70
71
|
return typeof output === 'string' && output.trim().length > 0;
|
|
71
72
|
}
|
|
72
|
-
async function collectTrackedCommandMutations({ session,
|
|
73
|
+
async function collectTrackedCommandMutations({ session, result, tracker, toolName, toolCallId, turnId, }) {
|
|
73
74
|
const checkpoint = ensureActiveCheckpoint(session.clientState.safety, turnId);
|
|
74
75
|
const records = collectCommandMutations({
|
|
75
76
|
state: session.clientState.safety,
|
|
@@ -84,40 +85,11 @@ async function collectTrackedCommandMutations({ session, projectIndex, result, t
|
|
|
84
85
|
return;
|
|
85
86
|
invalidateShellDiagnosticsCache(session.rootDir);
|
|
86
87
|
rememberCheckpointFiles(session.clientState.safety, session.rootDir, records.map((record) => record.filePath), turnId);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
removed: records.filter((record) => record.operation === 'delete').length,
|
|
93
|
-
indexedChunks: 0,
|
|
94
|
-
retrievalTokensUsed: 0,
|
|
95
|
-
};
|
|
96
|
-
if (priorSync?.error) {
|
|
97
|
-
result.repoSync = {
|
|
98
|
-
...mutationCounts,
|
|
99
|
-
indexSyncError: priorSync.error,
|
|
100
|
-
skipped: true,
|
|
101
|
-
reason: 'local index sync failed after command execution',
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
try {
|
|
106
|
-
const repoSync = await syncIndexFromDisk(projectIndex);
|
|
107
|
-
result.repoSync = {
|
|
108
|
-
...repoSync,
|
|
109
|
-
added: Math.max(repoSync.added, mutationCounts.added),
|
|
110
|
-
modified: Math.max(repoSync.modified, mutationCounts.modified),
|
|
111
|
-
removed: Math.max(repoSync.removed, mutationCounts.removed),
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
const indexSyncError = error instanceof Error ? error.message : String(error);
|
|
116
|
-
result.repoSync = { ...mutationCounts, indexSyncError };
|
|
117
|
-
session.onStatus(`Repository changes were recorded, but local index sync failed: ${indexSyncError}`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
88
|
+
result.repoSync = {
|
|
89
|
+
added: records.filter((record) => record.operation === 'create').length,
|
|
90
|
+
modified: records.filter((record) => record.operation === 'update').length,
|
|
91
|
+
removed: records.filter((record) => record.operation === 'delete').length,
|
|
92
|
+
};
|
|
121
93
|
result.sessionEdits = records.map((record) => ({
|
|
122
94
|
id: record.id,
|
|
123
95
|
filePath: record.filePath,
|
|
@@ -125,9 +97,9 @@ async function collectTrackedCommandMutations({ session, projectIndex, result, t
|
|
|
125
97
|
beforeHash: record.beforeHash,
|
|
126
98
|
afterHash: record.afterHash,
|
|
127
99
|
}));
|
|
128
|
-
result.diagnostics = runShellDiagnostics(session.rootDir);
|
|
100
|
+
result.diagnostics = await runShellDiagnostics(session.rootDir);
|
|
129
101
|
}
|
|
130
|
-
export async function collectBackgroundJobUiKillMutations({ session,
|
|
102
|
+
export async function collectBackgroundJobUiKillMutations({ session, jobId, result, }) {
|
|
131
103
|
const normalizedJobId = String(jobId ?? result.snapshot?.id ?? '').trim();
|
|
132
104
|
if (!normalizedJobId || !result.ok)
|
|
133
105
|
return;
|
|
@@ -137,7 +109,6 @@ export async function collectBackgroundJobUiKillMutations({ session, projectInde
|
|
|
137
109
|
const mutationResult = result;
|
|
138
110
|
await collectTrackedCommandMutations({
|
|
139
111
|
session,
|
|
140
|
-
projectIndex,
|
|
141
112
|
result: mutationResult,
|
|
142
113
|
tracker: tracked.tracker,
|
|
143
114
|
toolName: tracked.toolName,
|
|
@@ -151,7 +122,7 @@ export async function collectBackgroundJobUiKillMutations({ session, projectInde
|
|
|
151
122
|
backgroundCommandTrackers.delete(normalizedJobId);
|
|
152
123
|
}
|
|
153
124
|
}
|
|
154
|
-
export async function collectBackgroundJobUiOutputMutations({ session,
|
|
125
|
+
export async function collectBackgroundJobUiOutputMutations({ session, jobId, }) {
|
|
155
126
|
const normalizedJobId = String(jobId ?? '').trim();
|
|
156
127
|
if (!normalizedJobId)
|
|
157
128
|
return;
|
|
@@ -165,7 +136,6 @@ export async function collectBackgroundJobUiOutputMutations({ session, projectIn
|
|
|
165
136
|
return;
|
|
166
137
|
await collectTrackedCommandMutations({
|
|
167
138
|
session,
|
|
168
|
-
projectIndex,
|
|
169
139
|
result: {},
|
|
170
140
|
tracker: tracked.tracker,
|
|
171
141
|
toolName: tracked.toolName,
|
|
@@ -244,8 +214,9 @@ function recordAssistantEdit(session, call, result, before) {
|
|
|
244
214
|
});
|
|
245
215
|
clearEditFailure(session.clientState.safety, filePath);
|
|
246
216
|
}
|
|
247
|
-
export async function executeLocalToolCall(
|
|
248
|
-
session.
|
|
217
|
+
export async function executeLocalToolCall(session, call, diagnosticsPlan) {
|
|
218
|
+
session.turnAbortSignal?.throwIfAborted();
|
|
219
|
+
session.onStatus(formatToolCallForStatus(call, session.mcp?.label(call.name)));
|
|
249
220
|
try {
|
|
250
221
|
const agentModeBlocked = buildAgentModeToolBlockedResult(session.agentMode, call);
|
|
251
222
|
if (agentModeBlocked) {
|
|
@@ -253,6 +224,11 @@ export async function executeLocalToolCall(toolContext, session, call) {
|
|
|
253
224
|
session.onToolEvent?.({ call, result });
|
|
254
225
|
return result;
|
|
255
226
|
}
|
|
227
|
+
if (isMcpToolName(call.name)) {
|
|
228
|
+
const result = await sessionMcp(session).execute(session, call);
|
|
229
|
+
session.onToolEvent?.({ call, result });
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
256
232
|
const rawEditFilePath = isEditToolName(call.name)
|
|
257
233
|
? getEditToolFilePath(call)
|
|
258
234
|
: '';
|
|
@@ -275,17 +251,21 @@ export async function executeLocalToolCall(toolContext, session, call) {
|
|
|
275
251
|
const context = {
|
|
276
252
|
rootDir: session.rootDir,
|
|
277
253
|
sessionId: session.sessionId,
|
|
278
|
-
projectIndex: toolContext.projectIndex,
|
|
279
254
|
autoYes: session.autoYes,
|
|
280
|
-
|
|
281
|
-
|
|
255
|
+
agentMode: session.agentMode,
|
|
256
|
+
grants: session.grants,
|
|
257
|
+
requestPermission: session.requestPermission,
|
|
282
258
|
requestSudoPassword: session.requestSudoPassword,
|
|
259
|
+
requestUserInput: session.requestUserInput
|
|
260
|
+
? (request) => session.requestUserInput(request, session.turnAbortSignal)
|
|
261
|
+
: null,
|
|
283
262
|
onStatus: session.onStatus,
|
|
284
263
|
editJournal: session.clientState.editJournal,
|
|
285
264
|
safety: session.clientState.safety,
|
|
286
265
|
currentTurnId: session.turnState.id,
|
|
287
266
|
currentToolCallId: call.id,
|
|
288
267
|
env: session.env,
|
|
268
|
+
diagnosticsPlan,
|
|
289
269
|
markEditReverted: (editId, toolCallId) => {
|
|
290
270
|
const record = session.clientState.editJournal.find((entry) => entry.id === editId);
|
|
291
271
|
if (record) {
|
|
@@ -295,11 +275,11 @@ export async function executeLocalToolCall(toolContext, session, call) {
|
|
|
295
275
|
},
|
|
296
276
|
};
|
|
297
277
|
const result = await dispatchTool(context, call);
|
|
278
|
+
await checkBatchWhenLastEditDidNot(session, result, diagnosticsPlan);
|
|
298
279
|
recordAssistantEdit(session, call, result, beforeEditSnapshot);
|
|
299
280
|
if (result && typeof result === 'object' && commandTracker) {
|
|
300
281
|
await collectTrackedCommandMutations({
|
|
301
282
|
session,
|
|
302
|
-
projectIndex: toolContext.projectIndex,
|
|
303
283
|
result,
|
|
304
284
|
tracker: commandTracker,
|
|
305
285
|
toolName: call.name,
|
|
@@ -326,7 +306,6 @@ export async function executeLocalToolCall(toolContext, session, call) {
|
|
|
326
306
|
if (tracked) {
|
|
327
307
|
await collectTrackedCommandMutations({
|
|
328
308
|
session,
|
|
329
|
-
projectIndex: toolContext.projectIndex,
|
|
330
309
|
result,
|
|
331
310
|
tracker: tracked.tracker,
|
|
332
311
|
toolName: tracked.toolName,
|
|
@@ -363,7 +342,18 @@ export async function executeLocalToolCall(toolContext, session, call) {
|
|
|
363
342
|
},
|
|
364
343
|
error: error instanceof Error ? error.message : String(error),
|
|
365
344
|
};
|
|
345
|
+
await checkBatchWhenLastEditDidNot(session, result, diagnosticsPlan);
|
|
366
346
|
session.onToolEvent?.({ call, result });
|
|
367
347
|
return result;
|
|
368
348
|
}
|
|
369
349
|
}
|
|
350
|
+
export async function checkBatchWhenLastEditDidNot(session, result, plan) {
|
|
351
|
+
if (!plan?.files?.length || !result || typeof result !== 'object')
|
|
352
|
+
return;
|
|
353
|
+
if (session.turnAbortSignal?.aborted)
|
|
354
|
+
return;
|
|
355
|
+
const existing = result.diagnostics;
|
|
356
|
+
if (existing && typeof existing.available === 'boolean')
|
|
357
|
+
return;
|
|
358
|
+
result.diagnostics = await runBatchDiagnostics(session.rootDir, plan.files);
|
|
359
|
+
}
|