@thegitai/cli 1.0.0-preview.63 → 1.0.0-preview.65
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/src/api/chat.js +2 -1
- package/dist/src/api/http.js +8 -1
- package/dist/src/install-id.js +32 -0
- package/dist/src/tool-executor.js +16 -3
- package/dist/src/tools/browser.js +73 -17
- package/dist/src/tools/delete-file.js +1 -1
- package/dist/src/tools/patch-file.js +2 -3
- package/dist/src/tools/restore-checkpoint.js +1 -1
- package/dist/src/tools/shell-diagnostics.js +245 -71
- package/dist/src/tools/str-replace.js +2 -3
- package/dist/src/tools/undo-edit.js +1 -1
- package/dist/src/tools/write-file.js +2 -3
- package/package.json +6 -6
package/dist/src/api/chat.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createPromptCheckpoint, sanitizeSessionSafetyForServer, } from '../sess
|
|
|
7
7
|
import { applySessionSnapshot, saveSessionState, snapshotFromSession, } from '../session-store.js';
|
|
8
8
|
import { executeLocalToolCall } from '../tool-executor.js';
|
|
9
9
|
import { saveGeneratedImage } from '../tools/save-generated-image.js';
|
|
10
|
+
import { readEditDiagnosticsPlan } from '../tools/shell-diagnostics.js';
|
|
10
11
|
import { isUserInputQuestionArray } from './contracts.js';
|
|
11
12
|
import { createTraceContext, gatewayFailureCategory, normalizeServerUrl, QUOTA_EXCEEDED_CODE, PLAN_REQUIRED_CODE, failureDetails, isTurnRefusal, readErrorResponse, ServerApiError, transportFailureDetail, } from './http.js';
|
|
12
13
|
import { createTurnRecovery, fetchTurnAttempt, interruptedStream, isRetryableTurnStatus, isTurnRecoveryExhausted, readTurnChunk, } from './turn-recovery.js';
|
|
@@ -405,7 +406,7 @@ async function executeAndPostToolResult({ config, session, event, input, request
|
|
|
405
406
|
suggestedFilename: event.generatedImage.suggestedFilename ||
|
|
406
407
|
String(call.args?.filename ?? call.args?.file_name ?? ''),
|
|
407
408
|
})
|
|
408
|
-
: await executeLocalToolCall(session, call);
|
|
409
|
+
: await executeLocalToolCall(session, call, readEditDiagnosticsPlan(event.diagnostics));
|
|
409
410
|
preserveCancelledTurnToolResult(session, input, { ...event, call }, rawResult);
|
|
410
411
|
executed();
|
|
411
412
|
signal.throwIfAborted();
|
package/dist/src/api/http.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { DEFAULT_THEGITAI_HOST } from './default-host.js';
|
|
3
|
+
import { getInstallId } from '../install-id.js';
|
|
3
4
|
export const TRACE_ID_HEADER = 'x-thegitai-trace-id';
|
|
4
5
|
export const CLIENT_HEADER = 'x-thegitai-client';
|
|
5
6
|
export const CLIENT_PLATFORM_HEADER = 'x-thegitai-client-platform';
|
|
7
|
+
export const INSTALL_ID_HEADER = 'x-thegitai-install-id';
|
|
6
8
|
export class ServerApiError extends Error {
|
|
7
9
|
status;
|
|
8
10
|
traceId;
|
|
@@ -21,12 +23,14 @@ export function createTraceId() {
|
|
|
21
23
|
return `tr_${randomUUID().replace(/-/g, '')}`;
|
|
22
24
|
}
|
|
23
25
|
export function createTraceContext(traceId = createTraceId()) {
|
|
26
|
+
const installId = getInstallId();
|
|
24
27
|
return {
|
|
25
28
|
traceId,
|
|
26
29
|
headers: {
|
|
27
30
|
[TRACE_ID_HEADER]: traceId,
|
|
28
31
|
[CLIENT_HEADER]: 'cli',
|
|
29
32
|
[CLIENT_PLATFORM_HEADER]: `${process.platform}/${process.arch}`,
|
|
33
|
+
...(installId ? { [INSTALL_ID_HEADER]: installId } : {}),
|
|
30
34
|
},
|
|
31
35
|
};
|
|
32
36
|
}
|
|
@@ -251,8 +255,11 @@ export const PLAN_REQUIRED_CODE = 'PLAN_REQUIRED';
|
|
|
251
255
|
export function isPlanRequiredError(error) {
|
|
252
256
|
return error instanceof ServerApiError && error.code === PLAN_REQUIRED_CODE;
|
|
253
257
|
}
|
|
258
|
+
const ACCOUNT_REFUSAL_CODES = new Set(['ACCOUNT_ACTIVITY_REVIEW', 'PHONE_VERIFICATION_REQUIRED']);
|
|
254
259
|
export function isTurnRefusal(error) {
|
|
255
|
-
return isPlanRequiredError(error) ||
|
|
260
|
+
return (isPlanRequiredError(error) ||
|
|
261
|
+
isQuotaExceededError(error) ||
|
|
262
|
+
(error instanceof ServerApiError && ACCOUNT_REFUSAL_CODES.has(error.code)));
|
|
256
263
|
}
|
|
257
264
|
export function isAuthenticationError(error) {
|
|
258
265
|
return error instanceof ServerApiError && error.status === 401;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { getClientStateDir } from './client-state.js';
|
|
5
|
+
const INSTALL_ID_PATTERN = /^[a-f0-9]{32}$/;
|
|
6
|
+
let cached;
|
|
7
|
+
function readInstallId(file) {
|
|
8
|
+
try {
|
|
9
|
+
const value = readFileSync(file, 'utf8').trim();
|
|
10
|
+
return INSTALL_ID_PATTERN.test(value) ? value : null;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function getInstallId(env = process.env) {
|
|
17
|
+
if (cached !== undefined)
|
|
18
|
+
return cached;
|
|
19
|
+
const file = path.join(getClientStateDir(env), 'install-id');
|
|
20
|
+
const existing = readInstallId(file);
|
|
21
|
+
if (existing)
|
|
22
|
+
return (cached = existing);
|
|
23
|
+
try {
|
|
24
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
25
|
+
const id = randomBytes(16).toString('hex');
|
|
26
|
+
writeFileSync(file, `${id}\n`, { mode: 0o600, flag: 'wx' });
|
|
27
|
+
return (cached = id);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return (cached = readInstallId(file));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -7,7 +7,7 @@ import { buildAgentModeToolBlockedResult, } from './agent-mode.js';
|
|
|
7
7
|
import { classifyProjectPath } from './patcher.js';
|
|
8
8
|
import { dispatchTool } from './tools/index.js';
|
|
9
9
|
import { PATH_REPAIRING_EDIT_TOOLS, repairFilePath } from './tools/path-suggest.js';
|
|
10
|
-
import { invalidateShellDiagnosticsCache, runShellDiagnostics, } from './tools/shell-diagnostics.js';
|
|
10
|
+
import { invalidateShellDiagnosticsCache, runBatchDiagnostics, runShellDiagnostics, } from './tools/shell-diagnostics.js';
|
|
11
11
|
import { extractTodosArg } from './todo-list.js';
|
|
12
12
|
const EDIT_FILE_PATH_ARG_ALIASES = [
|
|
13
13
|
'filePath',
|
|
@@ -97,7 +97,7 @@ async function collectTrackedCommandMutations({ session, result, tracker, toolNa
|
|
|
97
97
|
beforeHash: record.beforeHash,
|
|
98
98
|
afterHash: record.afterHash,
|
|
99
99
|
}));
|
|
100
|
-
result.diagnostics = runShellDiagnostics(session.rootDir);
|
|
100
|
+
result.diagnostics = await runShellDiagnostics(session.rootDir);
|
|
101
101
|
}
|
|
102
102
|
export async function collectBackgroundJobUiKillMutations({ session, jobId, result, }) {
|
|
103
103
|
const normalizedJobId = String(jobId ?? result.snapshot?.id ?? '').trim();
|
|
@@ -214,7 +214,7 @@ function recordAssistantEdit(session, call, result, before) {
|
|
|
214
214
|
});
|
|
215
215
|
clearEditFailure(session.clientState.safety, filePath);
|
|
216
216
|
}
|
|
217
|
-
export async function executeLocalToolCall(session, call) {
|
|
217
|
+
export async function executeLocalToolCall(session, call, diagnosticsPlan) {
|
|
218
218
|
session.turnAbortSignal?.throwIfAborted();
|
|
219
219
|
session.onStatus(formatToolCallForStatus(call, session.mcp?.label(call.name)));
|
|
220
220
|
try {
|
|
@@ -265,6 +265,7 @@ export async function executeLocalToolCall(session, call) {
|
|
|
265
265
|
currentTurnId: session.turnState.id,
|
|
266
266
|
currentToolCallId: call.id,
|
|
267
267
|
env: session.env,
|
|
268
|
+
diagnosticsPlan,
|
|
268
269
|
markEditReverted: (editId, toolCallId) => {
|
|
269
270
|
const record = session.clientState.editJournal.find((entry) => entry.id === editId);
|
|
270
271
|
if (record) {
|
|
@@ -274,6 +275,7 @@ export async function executeLocalToolCall(session, call) {
|
|
|
274
275
|
},
|
|
275
276
|
};
|
|
276
277
|
const result = await dispatchTool(context, call);
|
|
278
|
+
await checkBatchWhenLastEditDidNot(session, result, diagnosticsPlan);
|
|
277
279
|
recordAssistantEdit(session, call, result, beforeEditSnapshot);
|
|
278
280
|
if (result && typeof result === 'object' && commandTracker) {
|
|
279
281
|
await collectTrackedCommandMutations({
|
|
@@ -340,7 +342,18 @@ export async function executeLocalToolCall(session, call) {
|
|
|
340
342
|
},
|
|
341
343
|
error: error instanceof Error ? error.message : String(error),
|
|
342
344
|
};
|
|
345
|
+
await checkBatchWhenLastEditDidNot(session, result, diagnosticsPlan);
|
|
343
346
|
session.onToolEvent?.({ call, result });
|
|
344
347
|
return result;
|
|
345
348
|
}
|
|
346
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
|
+
}
|
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { normalizeProjectRelativePath } from '../artifact-policy.js';
|
|
4
4
|
import { BrowserBridgeError } from '../browser/bridge.js';
|
|
5
5
|
import { chromeProfileLabel } from '../browser/chrome-profiles.js';
|
|
6
|
+
import { isSupportedImageMimeType } from '../core/image-limits.js';
|
|
6
7
|
import { storeSessionImageBytes } from '../core/session-image-store.js';
|
|
7
8
|
import { browserAvailability, drainBrowserEvents, ensureBrowserBridge, resyncBrowserBridge, } from '../browser/session-bridge.js';
|
|
8
9
|
import { getClientStateDir } from '../client-state.js';
|
|
@@ -528,31 +529,33 @@ export async function browserComputer(context, args) {
|
|
|
528
529
|
}
|
|
529
530
|
function reshapeScreenshot(context, result, args) {
|
|
530
531
|
const { base64Data, mimeType, geometry, ...rest } = result;
|
|
532
|
+
const imageMimeType = isSupportedImageMimeType(String(mimeType)) ? mimeType : 'image/png';
|
|
531
533
|
const payload = {
|
|
532
534
|
...rest,
|
|
533
535
|
viewport: geometry,
|
|
534
536
|
coordinateSpace: geometry?.scale === 1 && !geometry?.offsetX && !geometry?.offsetY
|
|
535
537
|
? 'Image pixels are viewport CSS pixels. Use coordinates directly.'
|
|
536
538
|
: 'Convert image pixels to viewport CSS coordinates: x = imageX / viewport.scale + viewport.offsetX; y = imageY / viewport.scale + viewport.offsetY.',
|
|
537
|
-
imageBytes: { base64Data, mimeType:
|
|
539
|
+
imageBytes: { base64Data, mimeType: imageMimeType },
|
|
538
540
|
};
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
541
|
+
const wantsFile = args.save_to_disk === true || args.saveToDisk === true;
|
|
542
|
+
const sessionId = context.sessionId;
|
|
543
|
+
if (sessionId) {
|
|
544
|
+
try {
|
|
545
|
+
const stored = storeSessionImageBytes({
|
|
546
|
+
sessionId,
|
|
547
|
+
base64Data,
|
|
548
|
+
mimeType: imageMimeType,
|
|
549
|
+
env: context.env,
|
|
550
|
+
});
|
|
551
|
+
if (wantsFile)
|
|
549
552
|
payload.savedPath = stored.cachePath;
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
553
|
+
payload.imageBytes.cachePath = stored.cachePath;
|
|
554
|
+
payload.imageBytes.index = stored.index;
|
|
555
|
+
}
|
|
556
|
+
catch (error) {
|
|
557
|
+
if (wantsFile)
|
|
554
558
|
payload.saveError = String(error?.message ?? error);
|
|
555
|
-
}
|
|
556
559
|
}
|
|
557
560
|
}
|
|
558
561
|
return payload;
|
|
@@ -689,7 +692,40 @@ export async function browserDownloads(context, args) {
|
|
|
689
692
|
});
|
|
690
693
|
return { ok: true, ...result };
|
|
691
694
|
}
|
|
695
|
+
const RESTORE_MIN_EXTENSION_VERSION = [0, 1, 7];
|
|
696
|
+
export function extensionPredates(version, minimum) {
|
|
697
|
+
if (!version)
|
|
698
|
+
return false;
|
|
699
|
+
const parts = version.split('.').map((part) => Number.parseInt(part, 10) || 0);
|
|
700
|
+
for (let index = 0; index < minimum.length; index += 1) {
|
|
701
|
+
const have = parts[index] ?? 0;
|
|
702
|
+
if (have !== minimum[index])
|
|
703
|
+
return have < minimum[index];
|
|
704
|
+
}
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
function connectedExtensionVersion(context) {
|
|
708
|
+
const availability = browserAvailability({ cwd: context.rootDir, env: context.env });
|
|
709
|
+
const key = profileChoiceFor(context)?.key ?? availability.selected;
|
|
710
|
+
return availability.browsers.find((browser) => browser.key === key)?.extensionVersion;
|
|
711
|
+
}
|
|
692
712
|
export function browserResize(context, args) {
|
|
713
|
+
if (args.restore === true) {
|
|
714
|
+
const version = connectedExtensionVersion(context);
|
|
715
|
+
if (extensionPredates(version, RESTORE_MIN_EXTENSION_VERSION)) {
|
|
716
|
+
return Promise.resolve({
|
|
717
|
+
ok: false,
|
|
718
|
+
error: `Restoring the window needs the TheGitAI Chrome extension ${RESTORE_MIN_EXTENSION_VERSION.join('.')} or later; this browser has ${version}. Resize it back with the width and height it had before, and tell the user the extension has an update.`,
|
|
719
|
+
failureCategory: 'invalid_argument',
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
return gatedTabCall(context, {
|
|
723
|
+
tool: 'browser_resize',
|
|
724
|
+
op: 'resize',
|
|
725
|
+
args: { tabId: args.tabId ?? args.tab_id, restore: true },
|
|
726
|
+
summary: () => 'Put the browser window back to its size before resizing.',
|
|
727
|
+
});
|
|
728
|
+
}
|
|
693
729
|
const width = Number(args.width);
|
|
694
730
|
const height = Number(args.height);
|
|
695
731
|
if (!Number.isFinite(width) || !Number.isFinite(height)) {
|
|
@@ -700,7 +736,27 @@ export function browserResize(context, args) {
|
|
|
700
736
|
op: 'resize',
|
|
701
737
|
args: { tabId: args.tabId ?? args.tab_id, width, height },
|
|
702
738
|
summary: () => `Resize the browser window to ${width}x${height}.`,
|
|
703
|
-
});
|
|
739
|
+
}).then((result) => withResizeWarning(result, width, height));
|
|
740
|
+
}
|
|
741
|
+
const RESIZE_TOLERANCE_PX = 24;
|
|
742
|
+
export function withResizeWarning(result, width, height) {
|
|
743
|
+
const viewport = result.viewport;
|
|
744
|
+
if (result.ok === false || !viewport)
|
|
745
|
+
return result;
|
|
746
|
+
const actualWidth = Number(viewport.cssWidth);
|
|
747
|
+
const actualHeight = Number(viewport.cssHeight);
|
|
748
|
+
if (!Number.isFinite(actualWidth) || !Number.isFinite(actualHeight))
|
|
749
|
+
return result;
|
|
750
|
+
if (Math.abs(actualWidth - width) <= RESIZE_TOLERANCE_PX &&
|
|
751
|
+
Math.abs(actualHeight - height) <= RESIZE_TOLERANCE_PX) {
|
|
752
|
+
return result;
|
|
753
|
+
}
|
|
754
|
+
return {
|
|
755
|
+
...result,
|
|
756
|
+
warning: `The page is ${Math.round(actualWidth)}x${Math.round(actualHeight)} CSS pixels, not the ${width}x${height} you asked for. ` +
|
|
757
|
+
'The window may be maximized, tiled or full screen in a way this system does not let a program change, or the size may be outside what the screen and Chrome allow. ' +
|
|
758
|
+
'Do not assume the layout changed. If the user needs this size, ask them to un-maximize the window; otherwise check the page at the size it has.',
|
|
759
|
+
};
|
|
704
760
|
}
|
|
705
761
|
export async function browserFileUpload(context, args) {
|
|
706
762
|
const guard = await notConnected(context, { tabId: args.tabId ?? args.tab_id });
|
|
@@ -56,6 +56,6 @@ export async function deleteFile(context, args) {
|
|
|
56
56
|
? {}
|
|
57
57
|
: { contentOmitted: result.contentOmitted }),
|
|
58
58
|
...(result.content === undefined ? {} : { content: result.content }),
|
|
59
|
-
diagnostics: result.deleted && !scratchPath ? runShellDiagnostics(rootDir) : undefined,
|
|
59
|
+
diagnostics: result.deleted && !scratchPath ? await runShellDiagnostics(rootDir) : undefined,
|
|
60
60
|
};
|
|
61
61
|
}
|
|
@@ -5,7 +5,7 @@ import { applyUnifiedPatch, classifyProjectPath, readProjectFile, renderDiffPrev
|
|
|
5
5
|
import { repairFilePath } from './path-suggest.js';
|
|
6
6
|
import { isTuiMode } from '../runtime-mode.js';
|
|
7
7
|
import { getCurrentFileHash, resolveRedactionTokens } from '../session-safety.js';
|
|
8
|
-
import {
|
|
8
|
+
import { diagnoseEditedFile } from './shell-diagnostics.js';
|
|
9
9
|
import { ensurePermission } from '../permissions.js';
|
|
10
10
|
const DOCUMENT_EXTENSIONS = new Set(['.pdf', '.xlsx', '.docx']);
|
|
11
11
|
export async function patchFile(context, args) {
|
|
@@ -91,8 +91,7 @@ export async function patchFile(context, args) {
|
|
|
91
91
|
const { changed } = writeProjectFile(rootDir, filePath, patchedContent);
|
|
92
92
|
let diagnostics;
|
|
93
93
|
if (!scratchPath) {
|
|
94
|
-
|
|
95
|
-
diagnostics = runShellDiagnostics(rootDir, filePath);
|
|
94
|
+
diagnostics = await diagnoseEditedFile(rootDir, filePath, 'patch_file', context.diagnosticsPlan);
|
|
96
95
|
}
|
|
97
96
|
const originalLines = originalContent.split('\n').length;
|
|
98
97
|
const patchedLines = patchedContent.split('\n').length;
|
|
@@ -80,7 +80,7 @@ export async function restoreToCheckpoint(context, args) {
|
|
|
80
80
|
return {
|
|
81
81
|
...result,
|
|
82
82
|
operation: 'restore_to_checkpoint',
|
|
83
|
-
diagnostics: runShellDiagnostics(context.rootDir),
|
|
83
|
+
diagnostics: await runShellDiagnostics(context.rootDir),
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
export async function restoreFilesToCheckpoint(context, args) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
3
3
|
import { builtinModules } from 'node:module';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
const CHECK_TIMEOUT = 60000;
|
|
@@ -36,37 +36,34 @@ function detectLanguageFromProject(rootDir) {
|
|
|
36
36
|
return 'python';
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
stdio: 'pipe',
|
|
39
|
+
function execCheck(cmd, args, options) {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
execFile(cmd, args, {
|
|
42
|
+
cwd: options.cwd,
|
|
44
43
|
encoding: 'utf-8',
|
|
44
|
+
maxBuffer: MAX_RAW_OUTPUT,
|
|
45
|
+
timeout: options.timeout,
|
|
46
|
+
}, (error, stdout, stderr) => {
|
|
47
|
+
const code = error?.code;
|
|
48
|
+
resolve({
|
|
49
|
+
stdout: String(stdout ?? ''),
|
|
50
|
+
stderr: String(stderr ?? ''),
|
|
51
|
+
exitCode: error ? (typeof code === 'number' ? code : 1) : 0,
|
|
52
|
+
});
|
|
45
53
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const commandChecks = new Map();
|
|
57
|
+
function commandExists(cmd) {
|
|
58
|
+
let check = commandChecks.get(cmd);
|
|
59
|
+
if (!check) {
|
|
60
|
+
check = execCheck(cmd, ['--version'], { timeout: 5000 }).then((result) => result.exitCode === 0);
|
|
61
|
+
commandChecks.set(cmd, check);
|
|
50
62
|
}
|
|
63
|
+
return check;
|
|
51
64
|
}
|
|
52
65
|
function runCheck(cmd, args, rootDir) {
|
|
53
|
-
|
|
54
|
-
const stdout = execFileSync(cmd, args, {
|
|
55
|
-
cwd: rootDir,
|
|
56
|
-
encoding: 'utf-8',
|
|
57
|
-
maxBuffer: MAX_RAW_OUTPUT,
|
|
58
|
-
timeout: CHECK_TIMEOUT,
|
|
59
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
60
|
-
});
|
|
61
|
-
return { stdout, stderr: '', exitCode: 0 };
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
return {
|
|
65
|
-
stdout: err.stdout ?? '',
|
|
66
|
-
stderr: err.stderr ?? '',
|
|
67
|
-
exitCode: err.status ?? 1,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
66
|
+
return execCheck(cmd, args, { cwd: rootDir, timeout: CHECK_TIMEOUT });
|
|
70
67
|
}
|
|
71
68
|
function parseRustDiagnostics(stdout, rootDir) {
|
|
72
69
|
const diagnostics = [];
|
|
@@ -114,12 +111,12 @@ function parseRustDiagnostics(stdout, rootDir) {
|
|
|
114
111
|
}
|
|
115
112
|
return diagnostics;
|
|
116
113
|
}
|
|
117
|
-
function runRustCheck(rootDir) {
|
|
114
|
+
async function runRustCheck(rootDir) {
|
|
118
115
|
if (!existsSync(path.join(rootDir, 'Cargo.toml')))
|
|
119
116
|
return null;
|
|
120
|
-
if (!commandExists('cargo'))
|
|
117
|
+
if (!(await commandExists('cargo')))
|
|
121
118
|
return null;
|
|
122
|
-
const result = runCheck('cargo', ['check', '--message-format=json', '--quiet'], rootDir);
|
|
119
|
+
const result = await runCheck('cargo', ['check', '--message-format=json', '--quiet'], rootDir);
|
|
123
120
|
return parseRustDiagnostics(`${result.stdout}\n${result.stderr}`, rootDir);
|
|
124
121
|
}
|
|
125
122
|
const GO_DIAG_RE = /^(.+?):(\d+):(\d+):\s*(.+)$/;
|
|
@@ -149,12 +146,12 @@ function parseGoDiagnostics(output, rootDir) {
|
|
|
149
146
|
}
|
|
150
147
|
return diagnostics;
|
|
151
148
|
}
|
|
152
|
-
function runGoCheck(rootDir) {
|
|
149
|
+
async function runGoCheck(rootDir) {
|
|
153
150
|
if (!existsSync(path.join(rootDir, 'go.mod')))
|
|
154
151
|
return null;
|
|
155
|
-
if (!commandExists('go'))
|
|
152
|
+
if (!(await commandExists('go')))
|
|
156
153
|
return null;
|
|
157
|
-
const result = runCheck('go', ['build', './...'], rootDir);
|
|
154
|
+
const result = await runCheck('go', ['build', './...'], rootDir);
|
|
158
155
|
return parseGoDiagnostics(`${result.stdout}\n${result.stderr}`, rootDir);
|
|
159
156
|
}
|
|
160
157
|
function parseRuffDiagnostics(stdout, rootDir) {
|
|
@@ -214,14 +211,14 @@ function parsePyCompileDiagnostics(stderr, rootDir, filePath) {
|
|
|
214
211
|
},
|
|
215
212
|
];
|
|
216
213
|
}
|
|
217
|
-
function runPythonCheck(rootDir, filePath) {
|
|
218
|
-
if (commandExists('ruff')) {
|
|
214
|
+
async function runPythonCheck(rootDir, filePath) {
|
|
215
|
+
if (await commandExists('ruff')) {
|
|
219
216
|
const target = filePath || '.';
|
|
220
|
-
const result = runCheck('ruff', ['check', '--output-format=json', '--', target], rootDir);
|
|
217
|
+
const result = await runCheck('ruff', ['check', '--output-format=json', '--', target], rootDir);
|
|
221
218
|
return parseRuffDiagnostics(result.stdout, rootDir);
|
|
222
219
|
}
|
|
223
220
|
if (filePath) {
|
|
224
|
-
const result = runCheck('python', ['-m', 'py_compile', filePath], rootDir);
|
|
221
|
+
const result = await runCheck('python', ['-m', 'py_compile', filePath], rootDir);
|
|
225
222
|
if (result.exitCode !== 0) {
|
|
226
223
|
return parsePyCompileDiagnostics(result.stderr, rootDir, filePath);
|
|
227
224
|
}
|
|
@@ -253,10 +250,10 @@ function parseTscDiagnostics(output, rootDir) {
|
|
|
253
250
|
}
|
|
254
251
|
return diagnostics;
|
|
255
252
|
}
|
|
256
|
-
function runTypeScriptCheck(rootDir) {
|
|
253
|
+
async function runTypeScriptCheck(rootDir) {
|
|
257
254
|
if (!existsSync(path.join(rootDir, 'tsconfig.json')))
|
|
258
255
|
return null;
|
|
259
|
-
const result = runCheck('npx', ['tsc', '--noEmit', '--pretty', 'false'], rootDir);
|
|
256
|
+
const result = await runCheck('npx', ['tsc', '--noEmit', '--pretty', 'false'], rootDir);
|
|
260
257
|
return parseTscDiagnostics(`${result.stdout}\n${result.stderr}`, rootDir);
|
|
261
258
|
}
|
|
262
259
|
const JS_IMPORT_RE = /import\s+(?:type\s+)?([^'"]+?)\s+from\s+['"]([^'"]+)['"]/g;
|
|
@@ -415,12 +412,136 @@ function runJavaScriptStaticCheck(rootDir, filePath) {
|
|
|
415
412
|
}
|
|
416
413
|
return diagnostics;
|
|
417
414
|
}
|
|
418
|
-
|
|
419
|
-
|
|
415
|
+
const NODE_CHECKABLE_EXTENSIONS = new Set(['.js', '.mjs', '.cjs']);
|
|
416
|
+
function stripJsonComments(text) {
|
|
417
|
+
let out = '';
|
|
418
|
+
let inString = false;
|
|
419
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
420
|
+
const char = text[index];
|
|
421
|
+
const next = text[index + 1];
|
|
422
|
+
if (inString) {
|
|
423
|
+
out += char;
|
|
424
|
+
if (char === '\\') {
|
|
425
|
+
out += next ?? '';
|
|
426
|
+
index += 1;
|
|
427
|
+
}
|
|
428
|
+
else if (char === '"') {
|
|
429
|
+
inString = false;
|
|
430
|
+
}
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
if (char === '"') {
|
|
434
|
+
inString = true;
|
|
435
|
+
out += char;
|
|
436
|
+
}
|
|
437
|
+
else if (char === '/' && next === '/') {
|
|
438
|
+
while (index < text.length && text[index] !== '\n')
|
|
439
|
+
index += 1;
|
|
440
|
+
out += '\n';
|
|
441
|
+
}
|
|
442
|
+
else if (char === '/' && next === '*') {
|
|
443
|
+
index += 2;
|
|
444
|
+
while (index < text.length && !(text[index] === '*' && text[index + 1] === '/'))
|
|
445
|
+
index += 1;
|
|
446
|
+
index += 1;
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
out += char;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return out.replace(/,(\s*[}\]])/g, '$1');
|
|
453
|
+
}
|
|
454
|
+
function readTsconfig(file) {
|
|
455
|
+
try {
|
|
456
|
+
return JSON.parse(stripJsonComments(readFileSync(file, 'utf-8')));
|
|
457
|
+
}
|
|
458
|
+
catch {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
function isFile(candidate) {
|
|
463
|
+
try {
|
|
464
|
+
return statSync(candidate).isFile();
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function resolveTsconfigExtends(fromFile, spec) {
|
|
471
|
+
const fromDir = path.dirname(fromFile);
|
|
472
|
+
const bases = [];
|
|
473
|
+
if (spec.startsWith('.') || path.isAbsolute(spec)) {
|
|
474
|
+
bases.push(path.resolve(fromDir, spec));
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
for (let dir = fromDir;; dir = path.dirname(dir)) {
|
|
478
|
+
bases.push(path.join(dir, 'node_modules', spec));
|
|
479
|
+
if (path.dirname(dir) === dir)
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
for (const base of bases) {
|
|
484
|
+
for (const candidate of [base, `${base}.json`, path.join(base, 'tsconfig.json')]) {
|
|
485
|
+
if (isFile(candidate))
|
|
486
|
+
return candidate;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
function effectiveCompilerFlag(configFile, name, seen = new Set()) {
|
|
492
|
+
if (seen.has(configFile) || seen.size > 16)
|
|
493
|
+
return undefined;
|
|
494
|
+
seen.add(configFile);
|
|
495
|
+
const config = readTsconfig(configFile);
|
|
496
|
+
if (!config || typeof config !== 'object')
|
|
497
|
+
return undefined;
|
|
498
|
+
const own = config.compilerOptions?.[name];
|
|
499
|
+
if (typeof own === 'boolean')
|
|
500
|
+
return own;
|
|
501
|
+
const parents = Array.isArray(config.extends)
|
|
502
|
+
? config.extends
|
|
503
|
+
: typeof config.extends === 'string'
|
|
504
|
+
? [config.extends]
|
|
505
|
+
: [];
|
|
506
|
+
for (const spec of [...parents].reverse()) {
|
|
507
|
+
if (typeof spec !== 'string')
|
|
508
|
+
continue;
|
|
509
|
+
const parent = resolveTsconfigExtends(configFile, spec);
|
|
510
|
+
const value = parent ? effectiveCompilerFlag(parent, name, seen) : undefined;
|
|
511
|
+
if (value !== undefined)
|
|
512
|
+
return value;
|
|
513
|
+
}
|
|
514
|
+
return undefined;
|
|
515
|
+
}
|
|
516
|
+
function hasTsCheckPragma(rootDir, filePath) {
|
|
517
|
+
try {
|
|
518
|
+
const head = readFileSync(path.join(rootDir, filePath), 'utf-8').slice(0, 2000);
|
|
519
|
+
return /^(?:\s*(?:\/\/[^\n]*\n|\/\*[\s\S]*?\*\/))*\s*\/\/\s*@ts-check\b/.test(head);
|
|
520
|
+
}
|
|
521
|
+
catch {
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
function typeScriptChecksJavaScript(rootDir, filePath) {
|
|
526
|
+
const tsconfig = path.join(rootDir, 'tsconfig.json');
|
|
527
|
+
if (effectiveCompilerFlag(tsconfig, 'checkJs') === true)
|
|
528
|
+
return true;
|
|
529
|
+
return effectiveCompilerFlag(tsconfig, 'allowJs') === true && hasTsCheckPragma(rootDir, filePath);
|
|
530
|
+
}
|
|
531
|
+
function javaScriptUsesProjectCheck(rootDir, filePath) {
|
|
532
|
+
if (!existsSync(path.join(rootDir, 'tsconfig.json')))
|
|
533
|
+
return false;
|
|
534
|
+
if (!filePath || !NODE_CHECKABLE_EXTENSIONS.has(path.extname(filePath).toLowerCase())) {
|
|
535
|
+
return true;
|
|
536
|
+
}
|
|
537
|
+
return typeScriptChecksJavaScript(rootDir, filePath);
|
|
538
|
+
}
|
|
539
|
+
async function runJavaScriptCheck(rootDir, filePath) {
|
|
540
|
+
if (javaScriptUsesProjectCheck(rootDir, filePath)) {
|
|
420
541
|
return runTypeScriptCheck(rootDir);
|
|
421
542
|
}
|
|
422
543
|
if (filePath) {
|
|
423
|
-
const result = runCheck('node', ['--check', filePath], rootDir);
|
|
544
|
+
const result = await runCheck('node', ['--check', filePath], rootDir);
|
|
424
545
|
const staticDiagnostics = runJavaScriptStaticCheck(rootDir, filePath);
|
|
425
546
|
if (result.exitCode !== 0) {
|
|
426
547
|
const msg = (result.stderr || result.stdout).trim();
|
|
@@ -430,7 +551,7 @@ function runJavaScriptCheck(rootDir, filePath) {
|
|
|
430
551
|
{
|
|
431
552
|
filePath,
|
|
432
553
|
severity: 'error',
|
|
433
|
-
message: msg.split('\n').pop() ?? 'Syntax error',
|
|
554
|
+
message: msg.match(/^\w*Error\b.*$/m)?.[0] ?? msg.split('\n').pop() ?? 'Syntax error',
|
|
434
555
|
source: 'node',
|
|
435
556
|
startLine: lineNum,
|
|
436
557
|
startColumn: 1,
|
|
@@ -515,6 +636,7 @@ function cloneDiagnostics(diagnostics) {
|
|
|
515
636
|
return diagnostics.map((diagnostic) => ({ ...diagnostic }));
|
|
516
637
|
}
|
|
517
638
|
export function invalidateShellDiagnosticsCache(rootDir, filePath) {
|
|
639
|
+
diagnosticsGeneration += 1;
|
|
518
640
|
const prefix = `${rootDir}::`;
|
|
519
641
|
if (!filePath) {
|
|
520
642
|
for (const key of shellDiagnosticsCache.keys()) {
|
|
@@ -552,12 +674,21 @@ function commandScopeFor(language, rootDir, filePath) {
|
|
|
552
674
|
case 'typescript':
|
|
553
675
|
return 'project';
|
|
554
676
|
case 'javascript':
|
|
555
|
-
return
|
|
677
|
+
return javaScriptUsesProjectCheck(rootDir, filePath) ? 'project' : 'file';
|
|
556
678
|
case 'python':
|
|
557
679
|
return filePath ? 'file' : 'project';
|
|
558
680
|
}
|
|
559
681
|
}
|
|
560
|
-
export function buildDeferredShellDiagnostics(trigger, filePath) {
|
|
682
|
+
export function buildDeferredShellDiagnostics(trigger, filePath, reason) {
|
|
683
|
+
if (reason === 'batch') {
|
|
684
|
+
return {
|
|
685
|
+
provider: 'shell',
|
|
686
|
+
deferred: true,
|
|
687
|
+
trigger,
|
|
688
|
+
filePath: filePath ?? undefined,
|
|
689
|
+
output: `Diagnostics for this edit run with the last edit in this batch, which checks every file the batch changed.`,
|
|
690
|
+
};
|
|
691
|
+
}
|
|
561
692
|
if (trigger === 'run_command' || trigger === 'run_node_script') {
|
|
562
693
|
return {
|
|
563
694
|
provider: 'shell',
|
|
@@ -577,6 +708,32 @@ export function buildDeferredShellDiagnostics(trigger, filePath) {
|
|
|
577
708
|
`Batch related edits first, then call get_diagnostics (without a filePath for project-wide errors${filePath ? `, or with filePath="${filePath}" for this file only` : ''}) before declaring success.`,
|
|
578
709
|
};
|
|
579
710
|
}
|
|
711
|
+
export function readEditDiagnosticsPlan(value) {
|
|
712
|
+
if (!value || typeof value !== 'object')
|
|
713
|
+
return undefined;
|
|
714
|
+
const raw = value;
|
|
715
|
+
if (raw.defer === true)
|
|
716
|
+
return { defer: true };
|
|
717
|
+
if (!Array.isArray(raw.files))
|
|
718
|
+
return undefined;
|
|
719
|
+
const files = raw.files
|
|
720
|
+
.filter((file) => typeof file === 'string' && file.trim() !== '')
|
|
721
|
+
.slice(0, 50);
|
|
722
|
+
return files.length ? { files } : undefined;
|
|
723
|
+
}
|
|
724
|
+
export async function diagnoseEditedFile(rootDir, filePath, trigger, plan) {
|
|
725
|
+
invalidateShellDiagnosticsCache(rootDir, filePath);
|
|
726
|
+
if (plan?.defer)
|
|
727
|
+
return buildDeferredShellDiagnostics(trigger, filePath, 'batch');
|
|
728
|
+
return runShellDiagnostics(rootDir, filePath, 50, projectRelativeFiles(rootDir, plan?.files ?? []));
|
|
729
|
+
}
|
|
730
|
+
function projectRelativeFiles(rootDir, files) {
|
|
731
|
+
return files.map((file) => (path.isAbsolute(file) ? path.relative(rootDir, file) : file));
|
|
732
|
+
}
|
|
733
|
+
export async function runBatchDiagnostics(rootDir, files) {
|
|
734
|
+
const [first, ...rest] = projectRelativeFiles(rootDir, files);
|
|
735
|
+
return runShellDiagnostics(rootDir, first, 50, rest);
|
|
736
|
+
}
|
|
580
737
|
function buildUnavailableResult(filePath, command, reason) {
|
|
581
738
|
return {
|
|
582
739
|
ok: true,
|
|
@@ -591,17 +748,16 @@ function buildUnavailableResult(filePath, command, reason) {
|
|
|
591
748
|
output: reason,
|
|
592
749
|
};
|
|
593
750
|
}
|
|
594
|
-
function applyFilePathFilter(diagnostics, filePath) {
|
|
751
|
+
function applyFilePathFilter(diagnostics, filePath, alsoFiles = []) {
|
|
595
752
|
if (!filePath) {
|
|
596
753
|
return { focused: diagnostics, otherFileErrorCount: 0 };
|
|
597
754
|
}
|
|
598
|
-
const
|
|
755
|
+
const normalizedTargets = [filePath, ...alsoFiles].map((target) => target.replace(/^\.\//, ''));
|
|
599
756
|
const focused = [];
|
|
600
757
|
let otherFileErrorCount = 0;
|
|
601
758
|
for (const diagnostic of diagnostics) {
|
|
602
759
|
const normalizedDiag = diagnostic.filePath.replace(/^\.\//, '');
|
|
603
|
-
if (normalizedDiag ===
|
|
604
|
-
normalizedDiag.endsWith(`/${normalizedTarget}`)) {
|
|
760
|
+
if (normalizedTargets.some((target) => normalizedDiag === target || normalizedDiag.endsWith(`/${target}`))) {
|
|
605
761
|
focused.push(diagnostic);
|
|
606
762
|
}
|
|
607
763
|
else if (diagnostic.severity === 'error') {
|
|
@@ -610,40 +766,42 @@ function applyFilePathFilter(diagnostics, filePath) {
|
|
|
610
766
|
}
|
|
611
767
|
return { focused, otherFileErrorCount };
|
|
612
768
|
}
|
|
613
|
-
function runDiagnosticsCommand(language, rootDir, filePath) {
|
|
769
|
+
async function runDiagnosticsCommand(language, rootDir, filePath) {
|
|
614
770
|
switch (language) {
|
|
615
771
|
case 'rust':
|
|
616
772
|
return {
|
|
617
773
|
command: 'cargo check --message-format=json --quiet',
|
|
618
|
-
diagnostics: runRustCheck(rootDir),
|
|
774
|
+
diagnostics: await runRustCheck(rootDir),
|
|
619
775
|
};
|
|
620
776
|
case 'go':
|
|
621
777
|
return {
|
|
622
778
|
command: 'go build ./...',
|
|
623
|
-
diagnostics: runGoCheck(rootDir),
|
|
779
|
+
diagnostics: await runGoCheck(rootDir),
|
|
624
780
|
};
|
|
625
781
|
case 'python':
|
|
626
782
|
return {
|
|
627
|
-
command: commandExists('ruff')
|
|
783
|
+
command: (await commandExists('ruff'))
|
|
628
784
|
? `ruff check ${filePath || '.'}`
|
|
629
785
|
: `python -m py_compile ${filePath || ''}`,
|
|
630
|
-
diagnostics: runPythonCheck(rootDir, filePath),
|
|
786
|
+
diagnostics: await runPythonCheck(rootDir, filePath),
|
|
631
787
|
};
|
|
632
788
|
case 'typescript':
|
|
633
789
|
return {
|
|
634
790
|
command: 'npx tsc --noEmit',
|
|
635
|
-
diagnostics: runTypeScriptCheck(rootDir),
|
|
791
|
+
diagnostics: await runTypeScriptCheck(rootDir),
|
|
636
792
|
};
|
|
637
793
|
case 'javascript':
|
|
638
794
|
return {
|
|
639
|
-
command:
|
|
795
|
+
command: javaScriptUsesProjectCheck(rootDir, filePath)
|
|
640
796
|
? 'npx tsc --noEmit'
|
|
641
797
|
: `node --check ${filePath || ''}`,
|
|
642
|
-
diagnostics: runJavaScriptCheck(rootDir, filePath),
|
|
798
|
+
diagnostics: await runJavaScriptCheck(rootDir, filePath),
|
|
643
799
|
};
|
|
644
800
|
}
|
|
645
801
|
}
|
|
646
|
-
|
|
802
|
+
const diagnosticsRuns = new Map();
|
|
803
|
+
let diagnosticsGeneration = 0;
|
|
804
|
+
export async function runShellDiagnostics(rootDir, filePath, limit = 50, alsoFiles = []) {
|
|
647
805
|
const language = filePath
|
|
648
806
|
? detectLanguageFromFile(filePath)
|
|
649
807
|
: detectLanguageFromProject(rootDir);
|
|
@@ -665,7 +823,21 @@ export function runShellDiagnostics(rootDir, filePath, limit = 50) {
|
|
|
665
823
|
available = cached.available;
|
|
666
824
|
}
|
|
667
825
|
else {
|
|
668
|
-
const
|
|
826
|
+
const generation = diagnosticsGeneration;
|
|
827
|
+
let run = diagnosticsRuns.get(cacheKey);
|
|
828
|
+
if (!run || run.generation !== generation) {
|
|
829
|
+
const started = {
|
|
830
|
+
generation,
|
|
831
|
+
outcome: runDiagnosticsCommand(language, rootDir, filePath),
|
|
832
|
+
};
|
|
833
|
+
run = started;
|
|
834
|
+
diagnosticsRuns.set(cacheKey, started);
|
|
835
|
+
void started.outcome.finally(() => {
|
|
836
|
+
if (diagnosticsRuns.get(cacheKey) === started)
|
|
837
|
+
diagnosticsRuns.delete(cacheKey);
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
const outcome = await run.outcome;
|
|
669
841
|
command = outcome.command;
|
|
670
842
|
if (outcome.diagnostics === null) {
|
|
671
843
|
available = false;
|
|
@@ -675,21 +847,23 @@ export function runShellDiagnostics(rootDir, filePath, limit = 50) {
|
|
|
675
847
|
available = true;
|
|
676
848
|
rawDiagnostics = outcome.diagnostics;
|
|
677
849
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
(
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
850
|
+
if (generation === diagnosticsGeneration) {
|
|
851
|
+
shellDiagnosticsCache.set(cacheKey, {
|
|
852
|
+
expiresAt: Date.now() +
|
|
853
|
+
(scope === 'project'
|
|
854
|
+
? PROJECT_DIAGNOSTICS_CACHE_TTL_MS
|
|
855
|
+
: FILE_DIAGNOSTICS_CACHE_TTL_MS),
|
|
856
|
+
scope,
|
|
857
|
+
command,
|
|
858
|
+
available,
|
|
859
|
+
diagnostics: rawDiagnostics,
|
|
860
|
+
});
|
|
861
|
+
}
|
|
688
862
|
}
|
|
689
863
|
if (!available) {
|
|
690
864
|
return buildUnavailableResult(filePath, command, `No build check command available${filePath ? ` for ${filePath}` : ''} (no project configuration found).`);
|
|
691
865
|
}
|
|
692
|
-
const { focused, otherFileErrorCount } = applyFilePathFilter(rawDiagnostics, filePath);
|
|
866
|
+
const { focused, otherFileErrorCount } = applyFilePathFilter(rawDiagnostics, filePath, alsoFiles);
|
|
693
867
|
const limited = focused.slice(0, limit);
|
|
694
868
|
const counts = countBySeverity(limited);
|
|
695
869
|
return {
|
|
@@ -5,7 +5,7 @@ import { classifyProjectPath, readProjectFile, writeProjectFile, } from '../patc
|
|
|
5
5
|
import { repairFilePath } from './path-suggest.js';
|
|
6
6
|
import { isTuiMode } from '../runtime-mode.js';
|
|
7
7
|
import { getCurrentFileHash, resolveRedactionTokens } from '../session-safety.js';
|
|
8
|
-
import {
|
|
8
|
+
import { diagnoseEditedFile } from './shell-diagnostics.js';
|
|
9
9
|
import { ensurePermission } from '../permissions.js';
|
|
10
10
|
const DOCUMENT_EXTENSIONS = new Set(['.pdf', '.xlsx', '.docx']);
|
|
11
11
|
function countOccurrences(haystack, needle) {
|
|
@@ -194,8 +194,7 @@ export async function strReplace(context, args) {
|
|
|
194
194
|
const replacements = changed ? (replaceAll ? n : 1) : 0;
|
|
195
195
|
let diagnostics;
|
|
196
196
|
if (!scratchPath) {
|
|
197
|
-
|
|
198
|
-
diagnostics = runShellDiagnostics(rootDir, filePath);
|
|
197
|
+
diagnostics = await diagnoseEditedFile(rootDir, filePath, 'str_replace', context.diagnosticsPlan);
|
|
199
198
|
}
|
|
200
199
|
const originalLines = originalContent.split('\n').length;
|
|
201
200
|
const nextLines = nextContent.split('\n').length;
|
|
@@ -194,6 +194,6 @@ export async function undoEdit(context, args) {
|
|
|
194
194
|
previewed,
|
|
195
195
|
reverted,
|
|
196
196
|
gitWorkTree: selected.some((record) => record.gitWorkTree),
|
|
197
|
-
diagnostics: dryRun ? undefined : runShellDiagnostics(context.rootDir),
|
|
197
|
+
diagnostics: dryRun ? undefined : await runShellDiagnostics(context.rootDir),
|
|
198
198
|
};
|
|
199
199
|
}
|
|
@@ -5,7 +5,7 @@ import { classifyProjectPath, writeProjectFile } from '../patcher.js';
|
|
|
5
5
|
import { readFileEditSnapshot } from '../edit-journal.js';
|
|
6
6
|
import { isTuiMode } from '../runtime-mode.js';
|
|
7
7
|
import { getCurrentFileHash, hasFreshFullReadCoverage, resolveRedactionTokens, } from '../session-safety.js';
|
|
8
|
-
import {
|
|
8
|
+
import { diagnoseEditedFile } from './shell-diagnostics.js';
|
|
9
9
|
import { ensurePermission } from '../permissions.js';
|
|
10
10
|
const DOCUMENT_EXTENSIONS = new Set(['.pdf', '.xlsx', '.docx']);
|
|
11
11
|
const MAX_WRITE_PREVIEW_LINES = 400;
|
|
@@ -128,8 +128,7 @@ export async function writeFile(context, args) {
|
|
|
128
128
|
const { changed } = writeProjectFile(rootDir, filePath, content);
|
|
129
129
|
let diagnostics;
|
|
130
130
|
if (!scratchPath) {
|
|
131
|
-
|
|
132
|
-
diagnostics = runShellDiagnostics(rootDir, filePath);
|
|
131
|
+
diagnostics = await diagnoseEditedFile(rootDir, filePath, 'write_file', context.diagnosticsPlan);
|
|
133
132
|
}
|
|
134
133
|
if (!isTuiMode()) {
|
|
135
134
|
const icon = changed ? '✨' : '📝';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thegitai/cli",
|
|
3
|
-
"version": "1.0.0-preview.
|
|
3
|
+
"version": "1.0.0-preview.65",
|
|
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.0.0-preview.
|
|
49
|
-
"@thegitai/tui-darwin-x64": "1.0.0-preview.
|
|
50
|
-
"@thegitai/tui-linux-arm64": "1.0.0-preview.
|
|
51
|
-
"@thegitai/tui-linux-x64": "1.0.0-preview.
|
|
52
|
-
"@thegitai/tui-win32-x64": "1.0.0-preview.
|
|
48
|
+
"@thegitai/tui-darwin-arm64": "1.0.0-preview.65",
|
|
49
|
+
"@thegitai/tui-darwin-x64": "1.0.0-preview.65",
|
|
50
|
+
"@thegitai/tui-linux-arm64": "1.0.0-preview.65",
|
|
51
|
+
"@thegitai/tui-linux-x64": "1.0.0-preview.65",
|
|
52
|
+
"@thegitai/tui-win32-x64": "1.0.0-preview.65",
|
|
53
53
|
"@vscode/ripgrep": "1.18.0"
|
|
54
54
|
},
|
|
55
55
|
"repository": {
|