zidane-gui 7.1.10 → 7.2.3
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/out/main/chunks/context-77_UZfgL.js +61 -0
- package/out/main/index.js +868 -6
- package/out/main/lsp-host.js +598 -0
- package/out/preload/index.mjs +24 -0
- package/out/renderer/assets/index-DuUPTo-E.css +2614 -0
- package/out/renderer/assets/{index-BwjXMrIt.js → index-hdJSwjac.js} +96515 -56760
- package/out/renderer/assets/pierre-dark-BL-l9r39.js +4 -0
- package/out/renderer/assets/pierre-dark-protanopia-deuteranopia-BBjGuJQU.js +4 -0
- package/out/renderer/assets/pierre-dark-soft-B6TBhICr.js +4 -0
- package/out/renderer/assets/pierre-dark-tritanopia-f-j_EX9A.js +4 -0
- package/out/renderer/assets/pierre-dark-vibrant-yElMGqZN.js +4 -0
- package/out/renderer/assets/pierre-light-BUzWTcjO.js +4 -0
- package/out/renderer/assets/pierre-light-protanopia-deuteranopia-DlvVSCaI.js +4 -0
- package/out/renderer/assets/pierre-light-soft-CCMU-Zh0.js +4 -0
- package/out/renderer/assets/pierre-light-tritanopia-v4xacE1C.js +4 -0
- package/out/renderer/assets/pierre-light-vibrant-BRUbQnMc.js +4 -0
- package/out/renderer/assets/worker-BPSdoz7S.js +12636 -0
- package/out/renderer/index.html +2 -2
- package/package.json +6 -6
- package/out/renderer/assets/index-CNGtwsYK.css +0 -2379
package/out/main/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fixPath, IPC_BUILD_ID, defaultSocketPath, probeSocket, ensureDaemonRunning, connectIpcClient, IpcVersionMismatchError } from "zidane/ipc";
|
|
2
|
-
import { resolve, delimiter, join, dirname,
|
|
2
|
+
import { resolve, delimiter, join, dirname, isAbsolute, relative, sep, normalize, basename } from "node:path";
|
|
3
3
|
import { config } from "dotenv";
|
|
4
|
-
import { app, shell, BrowserWindow, ipcMain, dialog, nativeImage, session, nativeTheme } from "electron";
|
|
4
|
+
import { app, shell, BrowserWindow, utilityProcess, ipcMain, dialog, nativeImage, session, nativeTheme } from "electron";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
6
|
import { parseEditorCommand, keybindingsPath, stripJsonComments, ensureKeybindingsFile, readProjects, writeProjects, credentialsPath, applyApiKeyEnv, BUILTIN_PROVIDERS, readCredentials, detectAuth, supportsOAuth, runOAuthLogin, DEFAULT_OAUTH_ACCOUNT_LABEL, setProviderCredential, scopeCwd, resolveConfig, DEFAULT_SETTINGS, enforceSettingsInvariants, mcpsWritePath, upsertMcpServer, discoverProjectMcps, removeMcpServer, loadMcpToolsCache, subscribeMcpToolsCache, refreshMcpToolsCatalog, createFileMcpCredentialStore, createChatHost, toTodosSnapshot, searchSessionHistory, searchableTurnText, deriveSessionTitle, toolCallPreview, modelChainMetadata, sessionModelFallbacks, resolveSessionCwd, modelSupportsReasoning, enabledModelOptions, buildModelCatalog, modelsForDescriptor, getContextWindow, truncateTurnsAt, deleteTurnSafely, generateSessionTitle, writeSessionExport, toolResultText, sumRunCosts, effectiveContextWindow, lastContextSizeFromTurns, fmtTokens, groupArtifacts, selectActiveTodos, setTodosForRun, sanitizeTodoItems, DEFAULT_MAX_TODO_ITEMS, fetchAllProviderUsage, fetchProviderUsage, listProjectFiles, discoverProjectSkills, discoverProjectPlugins, readProviderCredential, removeProviderCredential, setPreferredCredential, removeStoredCredential, setCredentialLabel, hasClaudeCodeSetup, countClaudeSessionFiles, importFromClaudeCode, isMainSession, findGitRoot, restoreModelOptions, modelOptionsFor, eventsFromTurns, watchInstalledVersion, checkForUpdate, upgradeInstalledPackages, performSelfUpdate, compareSemver, findInstalledCompanion } from "zidane/chat";
|
|
7
7
|
import { execFile, spawn } from "node:child_process";
|
|
@@ -14,9 +14,10 @@ import { P as PARENT_USER_TURN, u as usageAssistantDaily$1, b as usageUserDaily$
|
|
|
14
14
|
import { installSkillFromSpec, SkillInstallError } from "zidane/skills";
|
|
15
15
|
import { promisify } from "node:util";
|
|
16
16
|
import { Worker } from "node:worker_threads";
|
|
17
|
-
import { stat } from "node:fs/promises";
|
|
17
|
+
import { stat, readFile, writeFile, rename, unlink, realpath, readdir } from "node:fs/promises";
|
|
18
|
+
import { normalizePaletteItems, normalizePaletteRunResult, normalizePanelContent, BASH_CALL_ID_PREFIX, isPaletteContext } from "zidane/chat/pure";
|
|
18
19
|
import { setImmediate as setImmediate$1 } from "node:timers/promises";
|
|
19
|
-
import {
|
|
20
|
+
import { m as makeToolContext } from "./chunks/context-77_UZfgL.js";
|
|
20
21
|
import { tailTruncate } from "zidane/tools";
|
|
21
22
|
import __cjs_mod__ from "node:module";
|
|
22
23
|
const __filename = import.meta.filename;
|
|
@@ -2332,6 +2333,8 @@ function broadcast(signal) {
|
|
|
2332
2333
|
// debounced "an extension panel has new content" push.
|
|
2333
2334
|
case "extensions:invalidated":
|
|
2334
2335
|
case "panel:changed":
|
|
2336
|
+
case "palette:changed":
|
|
2337
|
+
case "lsp:diagnostics":
|
|
2335
2338
|
sendChatStream(signal);
|
|
2336
2339
|
return;
|
|
2337
2340
|
case "event":
|
|
@@ -2886,6 +2889,112 @@ function tokenizeQuery(query) {
|
|
|
2886
2889
|
}
|
|
2887
2890
|
return tokens;
|
|
2888
2891
|
}
|
|
2892
|
+
const ITEMS_TIMEOUT_MS = 3e3;
|
|
2893
|
+
const RUN_TIMEOUT_MS = 3e4;
|
|
2894
|
+
const CHANGE_DEBOUNCE_MS$1 = 150;
|
|
2895
|
+
const watches$1 = /* @__PURE__ */ new Map();
|
|
2896
|
+
async function providersFor$1(cwd) {
|
|
2897
|
+
const config2 = await getRuntimeConfig(cwd);
|
|
2898
|
+
return config2.extensions.palette;
|
|
2899
|
+
}
|
|
2900
|
+
async function listPaletteItems(cwd, ctx) {
|
|
2901
|
+
const providers = await providersFor$1(cwd);
|
|
2902
|
+
const results = await Promise.all(
|
|
2903
|
+
providers.map(async (provider) => {
|
|
2904
|
+
try {
|
|
2905
|
+
const raw = await withTimeout$1(Promise.resolve(provider.items({ ...ctx, cwd })), ITEMS_TIMEOUT_MS);
|
|
2906
|
+
return normalizePaletteItems(raw, provider.id, provider.group);
|
|
2907
|
+
} catch (err) {
|
|
2908
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2909
|
+
const failed = {
|
|
2910
|
+
id: `${provider.id}#error`,
|
|
2911
|
+
title: `${provider.owner}: palette items failed`,
|
|
2912
|
+
description: message,
|
|
2913
|
+
group: provider.group,
|
|
2914
|
+
source: provider.id,
|
|
2915
|
+
disabled: "This extension could not list its commands."
|
|
2916
|
+
};
|
|
2917
|
+
return [failed];
|
|
2918
|
+
}
|
|
2919
|
+
})
|
|
2920
|
+
);
|
|
2921
|
+
return results.flat();
|
|
2922
|
+
}
|
|
2923
|
+
async function runPaletteItem(cwd, source, itemId, ctx) {
|
|
2924
|
+
const provider = (await providersFor$1(cwd)).find((p) => p.id === source);
|
|
2925
|
+
if (!provider) {
|
|
2926
|
+
return { ok: false, error: "This command is no longer registered." };
|
|
2927
|
+
}
|
|
2928
|
+
try {
|
|
2929
|
+
const raw = await withTimeout$1(Promise.resolve(provider.run(itemId, { ...ctx, cwd })), RUN_TIMEOUT_MS);
|
|
2930
|
+
return { ok: true, result: normalizePaletteRunResult(raw, provider.id, provider.group) };
|
|
2931
|
+
} catch (err) {
|
|
2932
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
async function watchPalette(cwd) {
|
|
2936
|
+
if (watches$1.has(cwd)) {
|
|
2937
|
+
return;
|
|
2938
|
+
}
|
|
2939
|
+
const list = [];
|
|
2940
|
+
watches$1.set(cwd, list);
|
|
2941
|
+
for (const provider of await providersFor$1(cwd)) {
|
|
2942
|
+
if (!provider.subscribe) {
|
|
2943
|
+
continue;
|
|
2944
|
+
}
|
|
2945
|
+
const watch = { unsubscribe: () => {
|
|
2946
|
+
}, timer: null };
|
|
2947
|
+
try {
|
|
2948
|
+
watch.unsubscribe = provider.subscribe(() => {
|
|
2949
|
+
if (watch.timer) {
|
|
2950
|
+
return;
|
|
2951
|
+
}
|
|
2952
|
+
watch.timer = setTimeout(() => {
|
|
2953
|
+
watch.timer = null;
|
|
2954
|
+
broadcast({ kind: "palette:changed", cwd });
|
|
2955
|
+
}, CHANGE_DEBOUNCE_MS$1);
|
|
2956
|
+
});
|
|
2957
|
+
list.push(watch);
|
|
2958
|
+
} catch {
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
function unwatchPalette(cwd) {
|
|
2963
|
+
const list = watches$1.get(cwd);
|
|
2964
|
+
if (!list) {
|
|
2965
|
+
return;
|
|
2966
|
+
}
|
|
2967
|
+
watches$1.delete(cwd);
|
|
2968
|
+
for (const watch of list) {
|
|
2969
|
+
if (watch.timer) {
|
|
2970
|
+
clearTimeout(watch.timer);
|
|
2971
|
+
}
|
|
2972
|
+
try {
|
|
2973
|
+
watch.unsubscribe();
|
|
2974
|
+
} catch {
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
function resetPaletteSubscriptions() {
|
|
2979
|
+
for (const cwd of [...watches$1.keys()]) {
|
|
2980
|
+
unwatchPalette(cwd);
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
function withTimeout$1(p, ms) {
|
|
2984
|
+
return new Promise((resolve2, reject) => {
|
|
2985
|
+
const t = setTimeout(() => reject(new Error(`timed out after ${ms}ms`)), ms);
|
|
2986
|
+
p.then(
|
|
2987
|
+
(v) => {
|
|
2988
|
+
clearTimeout(t);
|
|
2989
|
+
resolve2(v);
|
|
2990
|
+
},
|
|
2991
|
+
(e) => {
|
|
2992
|
+
clearTimeout(t);
|
|
2993
|
+
reject(e);
|
|
2994
|
+
}
|
|
2995
|
+
);
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2889
2998
|
const CHANGE_DEBOUNCE_MS = 150;
|
|
2890
2999
|
const watches = /* @__PURE__ */ new Map();
|
|
2891
3000
|
const watchKey = (cwd, id) => `${cwd}\0${id}`;
|
|
@@ -2991,6 +3100,678 @@ function withTimeout(p, ms) {
|
|
|
2991
3100
|
);
|
|
2992
3101
|
});
|
|
2993
3102
|
}
|
|
3103
|
+
const REQUEST_TIMEOUT_MS = 2e4;
|
|
3104
|
+
class LspProxy {
|
|
3105
|
+
#proc = null;
|
|
3106
|
+
#pending = /* @__PURE__ */ new Map();
|
|
3107
|
+
#nextId = 1;
|
|
3108
|
+
#options = {};
|
|
3109
|
+
#stopping = false;
|
|
3110
|
+
#ensure() {
|
|
3111
|
+
if (this.#proc) return this.#proc;
|
|
3112
|
+
const proc = utilityProcess.fork(join(__dirname, "lsp-host.js"), [], { serviceName: "zidane-lsp" });
|
|
3113
|
+
proc.on(
|
|
3114
|
+
"message",
|
|
3115
|
+
(message) => {
|
|
3116
|
+
if (message.event) {
|
|
3117
|
+
this.#onEvent(message.event);
|
|
3118
|
+
return;
|
|
3119
|
+
}
|
|
3120
|
+
if (typeof message.id !== "number") return;
|
|
3121
|
+
const p = this.#pending.get(message.id);
|
|
3122
|
+
if (!p) return;
|
|
3123
|
+
this.#pending.delete(message.id);
|
|
3124
|
+
if (message.ok) p.resolve(message.result);
|
|
3125
|
+
else p.reject(new Error(message.error ?? "lsp host error"));
|
|
3126
|
+
}
|
|
3127
|
+
);
|
|
3128
|
+
proc.on("exit", () => {
|
|
3129
|
+
if (this.#proc === proc) this.#proc = null;
|
|
3130
|
+
for (const p of this.#pending.values()) p.reject(new Error("lsp host exited"));
|
|
3131
|
+
this.#pending.clear();
|
|
3132
|
+
});
|
|
3133
|
+
this.#proc = proc;
|
|
3134
|
+
if (Object.keys(this.#options).length) void this.#call("configure", [this.#options]).catch(() => void 0);
|
|
3135
|
+
return proc;
|
|
3136
|
+
}
|
|
3137
|
+
#onEvent(event) {
|
|
3138
|
+
if (event.kind === "diagnostics") {
|
|
3139
|
+
broadcast({ kind: "lsp:diagnostics", cwd: event.cwd, path: event.path, diagnostics: event.diagnostics });
|
|
3140
|
+
} else if (event.kind === "log") {
|
|
3141
|
+
console.error(`[zidane-gui] ${event.message}`);
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
#call(method, args) {
|
|
3145
|
+
if (this.#stopping) return Promise.reject(new Error("lsp host stopping"));
|
|
3146
|
+
const proc = this.#ensure();
|
|
3147
|
+
const id = this.#nextId++;
|
|
3148
|
+
return new Promise((resolve2, reject) => {
|
|
3149
|
+
const timer = setTimeout(() => {
|
|
3150
|
+
this.#pending.delete(id);
|
|
3151
|
+
reject(new Error(`${String(method)} timed out`));
|
|
3152
|
+
}, REQUEST_TIMEOUT_MS);
|
|
3153
|
+
this.#pending.set(id, {
|
|
3154
|
+
resolve: (v) => {
|
|
3155
|
+
clearTimeout(timer);
|
|
3156
|
+
resolve2(v);
|
|
3157
|
+
},
|
|
3158
|
+
reject: (e) => {
|
|
3159
|
+
clearTimeout(timer);
|
|
3160
|
+
reject(e);
|
|
3161
|
+
}
|
|
3162
|
+
});
|
|
3163
|
+
proc.postMessage({ id, method, args });
|
|
3164
|
+
});
|
|
3165
|
+
}
|
|
3166
|
+
configure(options) {
|
|
3167
|
+
this.#options = { ...this.#options, ...options };
|
|
3168
|
+
if (this.#proc) void this.#call("configure", [this.#options]).catch(() => void 0);
|
|
3169
|
+
}
|
|
3170
|
+
open(cwd, path, text, changes) {
|
|
3171
|
+
return this.#call("open", [cwd, path, text, changes]).catch(() => []);
|
|
3172
|
+
}
|
|
3173
|
+
close(cwd, path) {
|
|
3174
|
+
return this.#call("close", [cwd, path]).catch(() => void 0);
|
|
3175
|
+
}
|
|
3176
|
+
hover(cwd, path, line, character) {
|
|
3177
|
+
return this.#call("hover", [cwd, path, line, character]).catch(() => null);
|
|
3178
|
+
}
|
|
3179
|
+
definition(cwd, path, line, character) {
|
|
3180
|
+
return this.#call("definition", [cwd, path, line, character]).catch(() => []);
|
|
3181
|
+
}
|
|
3182
|
+
list(cwd) {
|
|
3183
|
+
return this.#call("list", [cwd]).catch(() => []);
|
|
3184
|
+
}
|
|
3185
|
+
/** Which servers are runnable in cwd (for skipping redundant project tools). */
|
|
3186
|
+
readyServerIds(cwd) {
|
|
3187
|
+
return this.list(cwd).then((s) => s.filter((x) => x.status === "ready" || x.status === "running").map((x) => x.id));
|
|
3188
|
+
}
|
|
3189
|
+
async stopAll() {
|
|
3190
|
+
this.#stopping = true;
|
|
3191
|
+
const proc = this.#proc;
|
|
3192
|
+
if (!proc) return;
|
|
3193
|
+
await this.#callRaw("stopAll").catch(() => void 0);
|
|
3194
|
+
proc.kill();
|
|
3195
|
+
this.#proc = null;
|
|
3196
|
+
}
|
|
3197
|
+
#callRaw(method) {
|
|
3198
|
+
const proc = this.#proc;
|
|
3199
|
+
if (!proc) return Promise.resolve();
|
|
3200
|
+
const id = this.#nextId++;
|
|
3201
|
+
return new Promise((resolve2) => {
|
|
3202
|
+
const timer = setTimeout(() => {
|
|
3203
|
+
this.#pending.delete(id);
|
|
3204
|
+
resolve2();
|
|
3205
|
+
}, 3e3);
|
|
3206
|
+
this.#pending.set(id, {
|
|
3207
|
+
resolve: () => {
|
|
3208
|
+
clearTimeout(timer);
|
|
3209
|
+
resolve2();
|
|
3210
|
+
},
|
|
3211
|
+
reject: () => {
|
|
3212
|
+
clearTimeout(timer);
|
|
3213
|
+
resolve2();
|
|
3214
|
+
}
|
|
3215
|
+
});
|
|
3216
|
+
proc.postMessage({ id, method, args: [] });
|
|
3217
|
+
});
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
const lspManager = new LspProxy();
|
|
3221
|
+
function toRel(cwd, p) {
|
|
3222
|
+
const rel = isAbsolute(p) ? relative(cwd, p) : p;
|
|
3223
|
+
return rel.split("\\").join("/").replace(/^\.\//, "");
|
|
3224
|
+
}
|
|
3225
|
+
function only(diags, paths) {
|
|
3226
|
+
if (paths.length === 0) return diags;
|
|
3227
|
+
const set = new Set(paths);
|
|
3228
|
+
return diags.filter((d) => set.has(d.path));
|
|
3229
|
+
}
|
|
3230
|
+
function parseTsc(output, cwd) {
|
|
3231
|
+
const out = [];
|
|
3232
|
+
const re = /^(.+?)\((\d+),(\d+)\): (error|warning) (TS\d+): (.*)$/;
|
|
3233
|
+
let current = null;
|
|
3234
|
+
for (const raw of output.split(/\r?\n/)) {
|
|
3235
|
+
const m = re.exec(raw);
|
|
3236
|
+
if (m) {
|
|
3237
|
+
current = {
|
|
3238
|
+
path: toRel(cwd, m[1]),
|
|
3239
|
+
line: Number(m[2]),
|
|
3240
|
+
column: Number(m[3]),
|
|
3241
|
+
severity: m[4] === "warning" ? "warning" : "error",
|
|
3242
|
+
code: m[5],
|
|
3243
|
+
message: m[6].trim(),
|
|
3244
|
+
source: "tsc"
|
|
3245
|
+
};
|
|
3246
|
+
out.push(current);
|
|
3247
|
+
} else if (current && /^\s+\S/.test(raw)) {
|
|
3248
|
+
current.message += `
|
|
3249
|
+
${raw.trim()}`;
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
return out;
|
|
3253
|
+
}
|
|
3254
|
+
const tsc = {
|
|
3255
|
+
id: "tsc",
|
|
3256
|
+
label: "TypeScript (tsc)",
|
|
3257
|
+
scope: "project",
|
|
3258
|
+
supersededBy: "typescript",
|
|
3259
|
+
extensions: ["ts", "tsx", "mts", "cts"],
|
|
3260
|
+
async detect(ctx) {
|
|
3261
|
+
if (!await ctx.hasFile("tsconfig.json")) return null;
|
|
3262
|
+
const bin = await ctx.resolveBin("tsc");
|
|
3263
|
+
return bin ? { bin } : { missing: "typescript is not installed in node_modules" };
|
|
3264
|
+
},
|
|
3265
|
+
async run(ctx, bin, paths) {
|
|
3266
|
+
const r = await ctx.exec(bin, ["--noEmit", "--pretty", "false"], { timeoutMs: 12e4 });
|
|
3267
|
+
return only(parseTsc(r.stdout + "\n" + r.stderr, ctx.cwd), paths);
|
|
3268
|
+
}
|
|
3269
|
+
};
|
|
3270
|
+
function parseEslint(json, cwd) {
|
|
3271
|
+
let files;
|
|
3272
|
+
try {
|
|
3273
|
+
files = JSON.parse(json);
|
|
3274
|
+
} catch {
|
|
3275
|
+
return [];
|
|
3276
|
+
}
|
|
3277
|
+
const out = [];
|
|
3278
|
+
for (const f of files) {
|
|
3279
|
+
for (const m of f.messages ?? []) {
|
|
3280
|
+
out.push({
|
|
3281
|
+
path: toRel(cwd, f.filePath),
|
|
3282
|
+
line: m.line ?? 1,
|
|
3283
|
+
column: m.column ?? 1,
|
|
3284
|
+
...m.endLine ? { endLine: m.endLine } : {},
|
|
3285
|
+
...m.endColumn ? { endColumn: m.endColumn } : {},
|
|
3286
|
+
severity: m.severity === 2 ? "error" : "warning",
|
|
3287
|
+
message: m.message,
|
|
3288
|
+
source: "eslint",
|
|
3289
|
+
...m.ruleId ? { code: m.ruleId } : {}
|
|
3290
|
+
});
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
return out;
|
|
3294
|
+
}
|
|
3295
|
+
const ESLINT_CONFIGS = [
|
|
3296
|
+
"eslint.config.js",
|
|
3297
|
+
"eslint.config.mjs",
|
|
3298
|
+
"eslint.config.cjs",
|
|
3299
|
+
"eslint.config.ts",
|
|
3300
|
+
"eslint.config.mts",
|
|
3301
|
+
".eslintrc",
|
|
3302
|
+
".eslintrc.js",
|
|
3303
|
+
".eslintrc.cjs",
|
|
3304
|
+
".eslintrc.json",
|
|
3305
|
+
".eslintrc.yml",
|
|
3306
|
+
".eslintrc.yaml"
|
|
3307
|
+
];
|
|
3308
|
+
const eslint = {
|
|
3309
|
+
id: "eslint",
|
|
3310
|
+
label: "ESLint",
|
|
3311
|
+
scope: "files",
|
|
3312
|
+
extensions: ["js", "jsx", "mjs", "cjs", "ts", "tsx", "mts", "cts", "vue", "svelte"],
|
|
3313
|
+
async detect(ctx) {
|
|
3314
|
+
if (!await ctx.hasFile(...ESLINT_CONFIGS)) return null;
|
|
3315
|
+
const bin = await ctx.resolveBin("eslint");
|
|
3316
|
+
return bin ? { bin } : { missing: "eslint is not installed in node_modules" };
|
|
3317
|
+
},
|
|
3318
|
+
async run(ctx, bin, paths) {
|
|
3319
|
+
if (paths.length === 0) return [];
|
|
3320
|
+
const r = await ctx.exec(bin, ["--format", "json", "--no-error-on-unmatched-pattern", "--", ...paths]);
|
|
3321
|
+
return parseEslint(r.stdout, ctx.cwd);
|
|
3322
|
+
}
|
|
3323
|
+
};
|
|
3324
|
+
function offsetToLineCol(source, offset) {
|
|
3325
|
+
let line = 1;
|
|
3326
|
+
let last = 0;
|
|
3327
|
+
for (let i = 0; i < offset && i < source.length; i++) {
|
|
3328
|
+
if (source.charCodeAt(i) === 10) {
|
|
3329
|
+
line++;
|
|
3330
|
+
last = i + 1;
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
return { line, column: offset - last + 1 };
|
|
3334
|
+
}
|
|
3335
|
+
function parseBiome(json, cwd) {
|
|
3336
|
+
let report;
|
|
3337
|
+
try {
|
|
3338
|
+
report = JSON.parse(json);
|
|
3339
|
+
} catch {
|
|
3340
|
+
return [];
|
|
3341
|
+
}
|
|
3342
|
+
const out = [];
|
|
3343
|
+
for (const d of report.diagnostics ?? []) {
|
|
3344
|
+
const file = d.location?.path?.file;
|
|
3345
|
+
if (!file) continue;
|
|
3346
|
+
const src = d.location?.sourceCode ?? "";
|
|
3347
|
+
const span = d.location?.span;
|
|
3348
|
+
const start = span ? offsetToLineCol(src, span[0]) : { line: 1, column: 1 };
|
|
3349
|
+
const end = span ? offsetToLineCol(src, span[1]) : void 0;
|
|
3350
|
+
const sev = d.severity === "error" || d.severity === "fatal" ? "error" : d.severity === "warning" ? "warning" : "info";
|
|
3351
|
+
out.push({
|
|
3352
|
+
path: toRel(cwd, file),
|
|
3353
|
+
line: start.line,
|
|
3354
|
+
column: start.column,
|
|
3355
|
+
...end ? { endLine: end.line, endColumn: end.column } : {},
|
|
3356
|
+
severity: sev,
|
|
3357
|
+
message: d.description ?? d.message?.map((m) => m.content ?? "").join("") ?? "",
|
|
3358
|
+
source: "biome",
|
|
3359
|
+
...d.category ? { code: d.category } : {}
|
|
3360
|
+
});
|
|
3361
|
+
}
|
|
3362
|
+
return out;
|
|
3363
|
+
}
|
|
3364
|
+
const biome = {
|
|
3365
|
+
id: "biome",
|
|
3366
|
+
label: "Biome",
|
|
3367
|
+
scope: "files",
|
|
3368
|
+
extensions: ["js", "jsx", "mjs", "cjs", "ts", "tsx", "mts", "cts", "json", "jsonc", "css"],
|
|
3369
|
+
async detect(ctx) {
|
|
3370
|
+
if (!await ctx.hasFile("biome.json", "biome.jsonc")) return null;
|
|
3371
|
+
const bin = await ctx.resolveBin("biome");
|
|
3372
|
+
return bin ? { bin } : { missing: "@biomejs/biome is not installed in node_modules" };
|
|
3373
|
+
},
|
|
3374
|
+
async run(ctx, bin, paths) {
|
|
3375
|
+
if (paths.length === 0) return [];
|
|
3376
|
+
const r = await ctx.exec(bin, ["lint", "--reporter=json", "--", ...paths]);
|
|
3377
|
+
return parseBiome(r.stdout, ctx.cwd);
|
|
3378
|
+
}
|
|
3379
|
+
};
|
|
3380
|
+
function parseRuff(json, cwd) {
|
|
3381
|
+
let items;
|
|
3382
|
+
try {
|
|
3383
|
+
items = JSON.parse(json);
|
|
3384
|
+
} catch {
|
|
3385
|
+
return [];
|
|
3386
|
+
}
|
|
3387
|
+
return items.map((i) => ({
|
|
3388
|
+
path: toRel(cwd, i.filename),
|
|
3389
|
+
line: i.location.row,
|
|
3390
|
+
column: i.location.column,
|
|
3391
|
+
...i.end_location ? { endLine: i.end_location.row, endColumn: i.end_location.column } : {},
|
|
3392
|
+
// Ruff has no severity; syntax errors (no code) are errors, rules are warnings.
|
|
3393
|
+
severity: i.code ? "warning" : "error",
|
|
3394
|
+
message: i.message,
|
|
3395
|
+
source: "ruff",
|
|
3396
|
+
...i.code ? { code: i.code } : {}
|
|
3397
|
+
}));
|
|
3398
|
+
}
|
|
3399
|
+
const ruff = {
|
|
3400
|
+
id: "ruff",
|
|
3401
|
+
label: "Ruff",
|
|
3402
|
+
scope: "files",
|
|
3403
|
+
extensions: ["py", "pyi"],
|
|
3404
|
+
async detect(ctx) {
|
|
3405
|
+
if (!await ctx.hasFile("ruff.toml", ".ruff.toml", "pyproject.toml")) return null;
|
|
3406
|
+
const bin = await ctx.resolveBin("ruff");
|
|
3407
|
+
return bin ? { bin } : { missing: "ruff is not on PATH" };
|
|
3408
|
+
},
|
|
3409
|
+
async run(ctx, bin, paths) {
|
|
3410
|
+
if (paths.length === 0) return [];
|
|
3411
|
+
const r = await ctx.exec(bin, ["check", "--output-format", "json", "--exit-zero", "--", ...paths]);
|
|
3412
|
+
return parseRuff(r.stdout, ctx.cwd);
|
|
3413
|
+
}
|
|
3414
|
+
};
|
|
3415
|
+
function parseCargo(ndjson, cwd) {
|
|
3416
|
+
const out = [];
|
|
3417
|
+
for (const raw of ndjson.split(/\r?\n/)) {
|
|
3418
|
+
if (!raw.trim()) continue;
|
|
3419
|
+
let m;
|
|
3420
|
+
try {
|
|
3421
|
+
m = JSON.parse(raw);
|
|
3422
|
+
} catch {
|
|
3423
|
+
continue;
|
|
3424
|
+
}
|
|
3425
|
+
if (m.reason !== "compiler-message" || !m.message) continue;
|
|
3426
|
+
const span = m.message.spans?.find((s) => s.is_primary) ?? m.message.spans?.[0];
|
|
3427
|
+
if (!span) continue;
|
|
3428
|
+
const level = m.message.level;
|
|
3429
|
+
const severity = level === "error" ? "error" : level === "warning" ? "warning" : level === "help" ? "hint" : "info";
|
|
3430
|
+
out.push({
|
|
3431
|
+
path: toRel(cwd, span.file_name),
|
|
3432
|
+
line: span.line_start,
|
|
3433
|
+
column: span.column_start,
|
|
3434
|
+
endLine: span.line_end,
|
|
3435
|
+
endColumn: span.column_end,
|
|
3436
|
+
severity,
|
|
3437
|
+
message: m.message.message,
|
|
3438
|
+
source: "cargo",
|
|
3439
|
+
...m.message.code?.code ? { code: m.message.code.code } : {}
|
|
3440
|
+
});
|
|
3441
|
+
}
|
|
3442
|
+
return out;
|
|
3443
|
+
}
|
|
3444
|
+
const cargo = {
|
|
3445
|
+
id: "cargo",
|
|
3446
|
+
label: "Rust (cargo check)",
|
|
3447
|
+
scope: "project",
|
|
3448
|
+
supersededBy: "rust-analyzer",
|
|
3449
|
+
extensions: ["rs"],
|
|
3450
|
+
async detect(ctx) {
|
|
3451
|
+
if (!await ctx.hasFile("Cargo.toml")) return null;
|
|
3452
|
+
const bin = await ctx.resolveBin("cargo");
|
|
3453
|
+
return bin ? { bin } : { missing: "cargo is not on PATH" };
|
|
3454
|
+
},
|
|
3455
|
+
async run(ctx, bin, paths) {
|
|
3456
|
+
const r = await ctx.exec(bin, ["check", "--message-format=json", "--quiet"], { timeoutMs: 18e4 });
|
|
3457
|
+
return only(parseCargo(r.stdout, ctx.cwd), paths);
|
|
3458
|
+
}
|
|
3459
|
+
};
|
|
3460
|
+
function parseGoVet(output, cwd) {
|
|
3461
|
+
const out = [];
|
|
3462
|
+
const re = /^(.+?\.go):(\d+):(\d+): (.*)$/;
|
|
3463
|
+
for (const raw of output.split(/\r?\n/)) {
|
|
3464
|
+
const m = re.exec(raw.trim());
|
|
3465
|
+
if (!m || m[1].startsWith("#")) continue;
|
|
3466
|
+
out.push({
|
|
3467
|
+
path: toRel(cwd, m[1]),
|
|
3468
|
+
line: Number(m[2]),
|
|
3469
|
+
column: Number(m[3]),
|
|
3470
|
+
severity: "warning",
|
|
3471
|
+
message: m[4],
|
|
3472
|
+
source: "go"
|
|
3473
|
+
});
|
|
3474
|
+
}
|
|
3475
|
+
return out;
|
|
3476
|
+
}
|
|
3477
|
+
const govet = {
|
|
3478
|
+
id: "go",
|
|
3479
|
+
label: "Go (go vet)",
|
|
3480
|
+
scope: "project",
|
|
3481
|
+
supersededBy: "gopls",
|
|
3482
|
+
extensions: ["go"],
|
|
3483
|
+
async detect(ctx) {
|
|
3484
|
+
if (!await ctx.hasFile("go.mod")) return null;
|
|
3485
|
+
const bin = await ctx.resolveBin("go");
|
|
3486
|
+
return bin ? { bin } : { missing: "go is not on PATH" };
|
|
3487
|
+
},
|
|
3488
|
+
async run(ctx, bin, paths) {
|
|
3489
|
+
const r = await ctx.exec(bin, ["vet", "./..."], { timeoutMs: 12e4 });
|
|
3490
|
+
return only(parseGoVet(r.stderr, ctx.cwd), paths);
|
|
3491
|
+
}
|
|
3492
|
+
};
|
|
3493
|
+
const BUILTIN_TOOLS = [tsc, eslint, biome, ruff, cargo, govet];
|
|
3494
|
+
function supersededTools(readyServerIds, tools = BUILTIN_TOOLS) {
|
|
3495
|
+
return tools.filter((t) => t.supersededBy && readyServerIds.includes(t.supersededBy)).map((t) => t.id);
|
|
3496
|
+
}
|
|
3497
|
+
function toolsFor(path, tools = BUILTIN_TOOLS) {
|
|
3498
|
+
const ext = path.split(".").pop()?.toLowerCase() ?? "";
|
|
3499
|
+
return tools.filter((t) => t.extensions.includes(ext));
|
|
3500
|
+
}
|
|
3501
|
+
const DETECT_TTL_MS = 6e4;
|
|
3502
|
+
const DEFAULT_TIMEOUT_MS = 6e4;
|
|
3503
|
+
const detectCache = /* @__PURE__ */ new Map();
|
|
3504
|
+
const runCache = /* @__PURE__ */ new Map();
|
|
3505
|
+
const inflight = /* @__PURE__ */ new Map();
|
|
3506
|
+
function confineRel(cwd, rel) {
|
|
3507
|
+
if (isAbsolute(rel)) return null;
|
|
3508
|
+
const full = resolve(cwd, rel);
|
|
3509
|
+
const root = resolve(cwd);
|
|
3510
|
+
if (full !== root && !full.startsWith(root + sep)) return null;
|
|
3511
|
+
return normalize(rel).split("\\").join("/");
|
|
3512
|
+
}
|
|
3513
|
+
async function detect(cwd, ctx, tools) {
|
|
3514
|
+
const hit = detectCache.get(cwd);
|
|
3515
|
+
if (hit && Date.now() - hit.at < DETECT_TTL_MS) return hit;
|
|
3516
|
+
const found = [];
|
|
3517
|
+
for (const tool of tools) {
|
|
3518
|
+
const d = await tool.detect(ctx).catch(() => null);
|
|
3519
|
+
if (!d) continue;
|
|
3520
|
+
found.push("bin" in d ? { tool, bin: d.bin } : { tool, bin: null, missing: d.missing });
|
|
3521
|
+
}
|
|
3522
|
+
const result = { at: Date.now(), tools: found };
|
|
3523
|
+
detectCache.set(cwd, result);
|
|
3524
|
+
return result;
|
|
3525
|
+
}
|
|
3526
|
+
async function listDiagnosticsTools(cwd, tools = BUILTIN_TOOLS) {
|
|
3527
|
+
const ctx = makeToolContext(cwd, DEFAULT_TIMEOUT_MS);
|
|
3528
|
+
const detected = await detect(cwd, ctx, tools);
|
|
3529
|
+
return tools.map((tool) => {
|
|
3530
|
+
const d = detected.tools.find((t) => t.tool.id === tool.id);
|
|
3531
|
+
if (!d) return { id: tool.id, label: tool.label, status: "absent" };
|
|
3532
|
+
return d.bin ? { id: tool.id, label: tool.label, status: "ready", detail: d.bin } : { id: tool.id, label: tool.label, status: "missing", detail: d.missing };
|
|
3533
|
+
});
|
|
3534
|
+
}
|
|
3535
|
+
async function mtimes(cwd, paths) {
|
|
3536
|
+
return Promise.all(
|
|
3537
|
+
paths.map(async (path) => {
|
|
3538
|
+
const s = await stat(join(cwd, path)).catch(() => null);
|
|
3539
|
+
return { path, mtimeMs: s ? s.mtimeMs : null };
|
|
3540
|
+
})
|
|
3541
|
+
);
|
|
3542
|
+
}
|
|
3543
|
+
function mtimeKey(stamps) {
|
|
3544
|
+
return stamps.map((s) => `${s.path}@${s.mtimeMs === null ? "x" : Math.round(s.mtimeMs)}`).sort().join("|");
|
|
3545
|
+
}
|
|
3546
|
+
async function runDiagnostics(cwd, rawPaths, opts = {}) {
|
|
3547
|
+
const tools = opts.tools ?? BUILTIN_TOOLS;
|
|
3548
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
3549
|
+
const paths = rawPaths.map((p) => confineRel(cwd, p)).filter((p) => p !== null);
|
|
3550
|
+
if (paths.length === 0) return { diagnostics: [], ran: [], failed: [] };
|
|
3551
|
+
const ctx = makeToolContext(cwd, timeoutMs);
|
|
3552
|
+
const detected = await detect(cwd, ctx, tools);
|
|
3553
|
+
const disabled = new Set(opts.disabled ?? []);
|
|
3554
|
+
const result = { diagnostics: [], ran: [], failed: [] };
|
|
3555
|
+
const byTool = /* @__PURE__ */ new Map();
|
|
3556
|
+
for (const p of paths) for (const t of toolsFor(p, tools)) byTool.set(t.id, [...byTool.get(t.id) ?? [], p]);
|
|
3557
|
+
await Promise.all(
|
|
3558
|
+
[...byTool.entries()].map(async ([id, toolPaths]) => {
|
|
3559
|
+
const d = detected.tools.find((t) => t.tool.id === id);
|
|
3560
|
+
if (!d?.bin || disabled.has(id)) return;
|
|
3561
|
+
const stamps = await mtimes(cwd, toolPaths);
|
|
3562
|
+
const key = d.tool.scope === "project" ? "project" : mtimeKey(stamps);
|
|
3563
|
+
const cacheId = `${cwd}\0${id}`;
|
|
3564
|
+
const cached2 = runCache.get(cacheId);
|
|
3565
|
+
const stale = cached2 && d.tool.scope === "project" && stamps.some((s) => s.mtimeMs !== null && Math.floor(s.mtimeMs) > cached2.startedAt);
|
|
3566
|
+
let diags;
|
|
3567
|
+
if (cached2 && cached2.key === key && !stale) {
|
|
3568
|
+
diags = cached2.diagnostics;
|
|
3569
|
+
} else {
|
|
3570
|
+
const flightId = `${cacheId}\0${key}`;
|
|
3571
|
+
const startedAt = Date.now();
|
|
3572
|
+
let run = inflight.get(flightId);
|
|
3573
|
+
if (!run) {
|
|
3574
|
+
run = d.tool.run(ctx, d.bin, toolPaths).finally(() => inflight.delete(flightId));
|
|
3575
|
+
inflight.set(flightId, run);
|
|
3576
|
+
}
|
|
3577
|
+
try {
|
|
3578
|
+
diags = await run;
|
|
3579
|
+
runCache.set(cacheId, { key, startedAt, diagnostics: diags });
|
|
3580
|
+
} catch (err) {
|
|
3581
|
+
result.failed.push({ id, reason: err instanceof Error ? err.message : String(err) });
|
|
3582
|
+
return;
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
const wanted = new Set(toolPaths);
|
|
3586
|
+
result.diagnostics.push(...diags.filter((x) => wanted.has(x.path)));
|
|
3587
|
+
result.ran.push(id);
|
|
3588
|
+
})
|
|
3589
|
+
);
|
|
3590
|
+
result.diagnostics.sort((a, b) => a.path.localeCompare(b.path) || a.line - b.line || a.column - b.column);
|
|
3591
|
+
result.ran.sort();
|
|
3592
|
+
return result;
|
|
3593
|
+
}
|
|
3594
|
+
function invalidateDiagnostics(cwd) {
|
|
3595
|
+
for (const k of runCache.keys()) if (k.startsWith(`${cwd}\0`)) runCache.delete(k);
|
|
3596
|
+
}
|
|
3597
|
+
const MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
3598
|
+
const MAX_ENTRIES = 5e3;
|
|
3599
|
+
const MAX_DIFF_BYTES = 4 * 1024 * 1024;
|
|
3600
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules", ".DS_Store"]);
|
|
3601
|
+
async function confine(cwd, rel) {
|
|
3602
|
+
if (!isAbsolute(cwd)) return null;
|
|
3603
|
+
const root = await realpath(cwd).catch(() => null);
|
|
3604
|
+
if (!root) return null;
|
|
3605
|
+
const target = resolve(root, rel);
|
|
3606
|
+
const inside = target === root || target.startsWith(root + sep);
|
|
3607
|
+
if (!inside) return null;
|
|
3608
|
+
const real = await realpath(target).catch(() => null);
|
|
3609
|
+
if (!real || !(real === root || real.startsWith(root + sep))) return null;
|
|
3610
|
+
return real;
|
|
3611
|
+
}
|
|
3612
|
+
async function listWorkspace(cwd, options = {}) {
|
|
3613
|
+
const root = await confine(cwd, ".");
|
|
3614
|
+
if (!root) return [];
|
|
3615
|
+
const isRepo = await stat(resolve(root, ".git")).catch(() => null) !== null;
|
|
3616
|
+
const listed = isRepo ? await gitListed(root) : null;
|
|
3617
|
+
const out = [];
|
|
3618
|
+
const walk = async (dirRel) => {
|
|
3619
|
+
if (out.length >= MAX_ENTRIES) return;
|
|
3620
|
+
const entries = await readdir(resolve(root, dirRel), { withFileTypes: true }).catch(() => []);
|
|
3621
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
3622
|
+
let any = false;
|
|
3623
|
+
for (const e of entries) {
|
|
3624
|
+
if (out.length >= MAX_ENTRIES) return;
|
|
3625
|
+
if (SKIP_DIRS.has(e.name)) continue;
|
|
3626
|
+
const rel = dirRel === "." ? e.name : `${dirRel}/${e.name}`;
|
|
3627
|
+
const ignored = listed !== null && (e.isDirectory() ? !listed.dirs.has(rel) && !await isEmptyDir(resolve(root, rel)) : !listed.files.has(rel));
|
|
3628
|
+
if (ignored && !options.showIgnored) continue;
|
|
3629
|
+
any = true;
|
|
3630
|
+
if (ignored) {
|
|
3631
|
+
out.push({ path: e.isDirectory() ? `${rel}/` : rel, kind: e.isDirectory() ? "dir" : "file", ignored: true });
|
|
3632
|
+
continue;
|
|
3633
|
+
}
|
|
3634
|
+
if (e.isDirectory()) {
|
|
3635
|
+
const before = out.length;
|
|
3636
|
+
await walk(rel);
|
|
3637
|
+
if (out.length === before) out.push({ path: `${rel}/`, kind: "dir" });
|
|
3638
|
+
} else if (e.isFile()) {
|
|
3639
|
+
out.push({ path: rel, kind: "file" });
|
|
3640
|
+
} else if (e.isSymbolicLink()) {
|
|
3641
|
+
const real = await confine(root, rel);
|
|
3642
|
+
if (real && (await stat(real).catch(() => null))?.isFile()) out.push({ path: rel, kind: "file" });
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3645
|
+
if (!any && dirRel !== ".") out.push({ path: `${dirRel}/`, kind: "dir" });
|
|
3646
|
+
};
|
|
3647
|
+
await walk(".");
|
|
3648
|
+
return out;
|
|
3649
|
+
}
|
|
3650
|
+
async function readWorkspaceFile(cwd, rel) {
|
|
3651
|
+
const real = await confine(cwd, rel);
|
|
3652
|
+
if (!real) return null;
|
|
3653
|
+
const s = await stat(real).catch(() => null);
|
|
3654
|
+
if (!s?.isFile()) return null;
|
|
3655
|
+
if (s.size > MAX_FILE_BYTES)
|
|
3656
|
+
return { path: rel, contents: "", truncated: true, size: s.size, binary: false, mtimeMs: s.mtimeMs };
|
|
3657
|
+
const buf = await readFile(real).catch(() => null);
|
|
3658
|
+
if (!buf) return null;
|
|
3659
|
+
const binary = buf.subarray(0, 8192).includes(0);
|
|
3660
|
+
return {
|
|
3661
|
+
path: rel,
|
|
3662
|
+
contents: binary ? "" : buf.toString("utf8"),
|
|
3663
|
+
truncated: false,
|
|
3664
|
+
size: s.size,
|
|
3665
|
+
binary,
|
|
3666
|
+
mtimeMs: s.mtimeMs
|
|
3667
|
+
};
|
|
3668
|
+
}
|
|
3669
|
+
async function writeWorkspaceFile(cwd, rel, contents, expectedMtimeMs) {
|
|
3670
|
+
const real = await confine(cwd, rel);
|
|
3671
|
+
if (!real) return { ok: false, reason: "denied" };
|
|
3672
|
+
const s = await stat(real).catch(() => null);
|
|
3673
|
+
if (!s?.isFile()) return { ok: false, reason: "missing" };
|
|
3674
|
+
if (Math.round(s.mtimeMs) !== Math.round(expectedMtimeMs)) return { ok: false, reason: "changed" };
|
|
3675
|
+
const tmp = `${real}.${process.pid}.${Date.now().toString(36)}.tmp`;
|
|
3676
|
+
try {
|
|
3677
|
+
await writeFile(tmp, contents, "utf8");
|
|
3678
|
+
await rename(tmp, real);
|
|
3679
|
+
} catch {
|
|
3680
|
+
await unlink(tmp).catch(() => void 0);
|
|
3681
|
+
return { ok: false, reason: "denied" };
|
|
3682
|
+
}
|
|
3683
|
+
const after = await stat(real).catch(() => null);
|
|
3684
|
+
return { ok: true, mtimeMs: after?.mtimeMs ?? Date.now() };
|
|
3685
|
+
}
|
|
3686
|
+
function git(cwd, args, maxBuffer = MAX_DIFF_BYTES) {
|
|
3687
|
+
return new Promise((resolveOut) => {
|
|
3688
|
+
execFile("git", args, { cwd, maxBuffer, timeout: 8e3 }, (err, stdout) => resolveOut(err ? null : stdout));
|
|
3689
|
+
});
|
|
3690
|
+
}
|
|
3691
|
+
async function gitListed(root) {
|
|
3692
|
+
const out = await git(root, ["ls-files", "-z", "--cached", "--others", "--exclude-standard"]) ?? "";
|
|
3693
|
+
const files = /* @__PURE__ */ new Set();
|
|
3694
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
3695
|
+
for (const rel of out.split("\0")) {
|
|
3696
|
+
if (!rel) continue;
|
|
3697
|
+
files.add(rel);
|
|
3698
|
+
let i = rel.indexOf("/");
|
|
3699
|
+
while (i !== -1) {
|
|
3700
|
+
dirs.add(rel.slice(0, i));
|
|
3701
|
+
i = rel.indexOf("/", i + 1);
|
|
3702
|
+
}
|
|
3703
|
+
}
|
|
3704
|
+
return { files, dirs };
|
|
3705
|
+
}
|
|
3706
|
+
async function isEmptyDir(abs) {
|
|
3707
|
+
const entries = await readdir(abs).catch(() => null);
|
|
3708
|
+
return entries !== null && entries.every((n) => SKIP_DIRS.has(n));
|
|
3709
|
+
}
|
|
3710
|
+
const STATUS_MAP = {
|
|
3711
|
+
M: "modified",
|
|
3712
|
+
A: "added",
|
|
3713
|
+
D: "deleted",
|
|
3714
|
+
R: "renamed",
|
|
3715
|
+
"?": "untracked",
|
|
3716
|
+
"!": "ignored",
|
|
3717
|
+
U: "modified",
|
|
3718
|
+
C: "added"
|
|
3719
|
+
};
|
|
3720
|
+
async function gitStatus(cwd) {
|
|
3721
|
+
const root = await confine(cwd, ".");
|
|
3722
|
+
if (!root) return [];
|
|
3723
|
+
const out = await git(root, ["status", "--porcelain=v1", "-z"]);
|
|
3724
|
+
if (!out) return [];
|
|
3725
|
+
const entries = [];
|
|
3726
|
+
const recs = out.split("\0");
|
|
3727
|
+
for (let i = 0; i < recs.length; i++) {
|
|
3728
|
+
const rec = recs[i];
|
|
3729
|
+
if (rec.length < 4) continue;
|
|
3730
|
+
const x = rec[0];
|
|
3731
|
+
const y = rec[1];
|
|
3732
|
+
let path = rec.slice(3);
|
|
3733
|
+
if (x === "R" || x === "C") {
|
|
3734
|
+
i++;
|
|
3735
|
+
}
|
|
3736
|
+
const code = x !== " " && x !== "?" ? x : y;
|
|
3737
|
+
const status = STATUS_MAP[code] ?? "modified";
|
|
3738
|
+
path = path.replace(/\/$/, "");
|
|
3739
|
+
entries.push({ path, status });
|
|
3740
|
+
}
|
|
3741
|
+
return entries;
|
|
3742
|
+
}
|
|
3743
|
+
async function gitDiff(cwd, path, context = 3) {
|
|
3744
|
+
const root = await confine(cwd, ".");
|
|
3745
|
+
if (!root) return "";
|
|
3746
|
+
const target = path ? ["--", path] : [];
|
|
3747
|
+
const unified = Number.isFinite(context) ? `-U${Math.max(0, Math.floor(context))}` : "-U999999";
|
|
3748
|
+
const tracked = await git(root, ["diff", "HEAD", "--no-color", "--no-ext-diff", unified, ...target]) ?? "";
|
|
3749
|
+
const untrackedList = await git(root, ["ls-files", "--others", "--exclude-standard", "-z", ...target]) ?? "";
|
|
3750
|
+
const untracked = [];
|
|
3751
|
+
for (const rel of untrackedList.split("\0").filter(Boolean)) {
|
|
3752
|
+
const file = await readWorkspaceFile(root, rel);
|
|
3753
|
+
if (!file || file.binary || file.truncated) continue;
|
|
3754
|
+
const lines = file.contents.split("\n");
|
|
3755
|
+
if (lines.at(-1) === "") lines.pop();
|
|
3756
|
+
untracked.push(
|
|
3757
|
+
[
|
|
3758
|
+
`diff --git a/${rel} b/${rel}`,
|
|
3759
|
+
"new file mode 100644",
|
|
3760
|
+
"--- /dev/null",
|
|
3761
|
+
`+++ b/${rel}`,
|
|
3762
|
+
`@@ -0,0 +1,${lines.length} @@`,
|
|
3763
|
+
...lines.map((l) => `+${l}`)
|
|
3764
|
+
].join("\n")
|
|
3765
|
+
);
|
|
3766
|
+
}
|
|
3767
|
+
const all = [tracked.trimEnd(), ...untracked].filter(Boolean).join("\n");
|
|
3768
|
+
return all.length > MAX_DIFF_BYTES ? all.slice(0, MAX_DIFF_BYTES) : all;
|
|
3769
|
+
}
|
|
3770
|
+
async function gitShowHead(cwd, path) {
|
|
3771
|
+
const root = await confine(cwd, ".");
|
|
3772
|
+
if (!root) return null;
|
|
3773
|
+
return git(root, ["show", `HEAD:${path}`]);
|
|
3774
|
+
}
|
|
2994
3775
|
const EXTENSION_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
2995
3776
|
function validateExtensionName(name) {
|
|
2996
3777
|
const trimmed = name.trim();
|
|
@@ -3290,6 +4071,7 @@ function saveHostState(patch) {
|
|
|
3290
4071
|
function invalidateExtensionsAndNotify() {
|
|
3291
4072
|
invalidateExtensionRegistries();
|
|
3292
4073
|
resetPanelSubscriptions();
|
|
4074
|
+
resetPaletteSubscriptions();
|
|
3293
4075
|
broadcast({ kind: "extensions:invalidated" });
|
|
3294
4076
|
}
|
|
3295
4077
|
const LAST_FOLDER_KEY = "last_folder";
|
|
@@ -4139,7 +4921,12 @@ function registerChatIpc() {
|
|
|
4139
4921
|
}
|
|
4140
4922
|
);
|
|
4141
4923
|
ipcMain.handle("todos:get", async (_e, sessionId) => {
|
|
4142
|
-
|
|
4924
|
+
let state2 = await getTodosSnapshot(sessionId);
|
|
4925
|
+
if (!state2) {
|
|
4926
|
+
const session2 = await loadSession(getSessionStore(), sessionId);
|
|
4927
|
+
const cold = session2 ? selectActiveTodos(session2) : null;
|
|
4928
|
+
state2 = cold?.runId ? cold : null;
|
|
4929
|
+
}
|
|
4143
4930
|
if (!state2) {
|
|
4144
4931
|
return null;
|
|
4145
4932
|
}
|
|
@@ -4166,7 +4953,9 @@ function registerChatIpc() {
|
|
|
4166
4953
|
}
|
|
4167
4954
|
setTodosForRun(session2, runId, sanitizeTodoItems(items, DEFAULT_MAX_TODO_ITEMS), { clearArchive: true });
|
|
4168
4955
|
await session2.save();
|
|
4169
|
-
|
|
4956
|
+
const snapshot = toTodosSnapshot(selectActiveTodos(session2));
|
|
4957
|
+
broadcast({ kind: "todos:snapshot", sessionId, snapshot });
|
|
4958
|
+
return snapshot;
|
|
4170
4959
|
});
|
|
4171
4960
|
ipcMain.handle("usage:fetchAll", async (_e, cwd, opts) => {
|
|
4172
4961
|
return fetchAllProviderUsage(userDataDir(), await providersFor(cwd), opts ?? {});
|
|
@@ -4394,6 +5183,63 @@ function registerChatIpc() {
|
|
|
4394
5183
|
}));
|
|
4395
5184
|
}
|
|
4396
5185
|
);
|
|
5186
|
+
ipcMain.handle(
|
|
5187
|
+
"workspace:list",
|
|
5188
|
+
(_e, cwd, options) => listWorkspace(cwd, options)
|
|
5189
|
+
);
|
|
5190
|
+
ipcMain.handle("workspace:read", (_e, cwd, path) => readWorkspaceFile(cwd, path));
|
|
5191
|
+
ipcMain.handle(
|
|
5192
|
+
"workspace:write",
|
|
5193
|
+
async (_e, cwd, path, contents, expectedMtimeMs) => {
|
|
5194
|
+
if (typeof contents !== "string" || typeof expectedMtimeMs !== "number") {
|
|
5195
|
+
return { ok: false, reason: "denied" };
|
|
5196
|
+
}
|
|
5197
|
+
const result = await writeWorkspaceFile(cwd, path, contents, expectedMtimeMs);
|
|
5198
|
+
if (result.ok) invalidateDiagnostics(cwd);
|
|
5199
|
+
return result;
|
|
5200
|
+
}
|
|
5201
|
+
);
|
|
5202
|
+
ipcMain.handle("workspace:diagnosticsTools", (_e, cwd) => listDiagnosticsTools(cwd));
|
|
5203
|
+
ipcMain.handle("workspace:diagnosticsInvalidate", (_e, cwd) => {
|
|
5204
|
+
if (typeof cwd === "string") invalidateDiagnostics(cwd);
|
|
5205
|
+
});
|
|
5206
|
+
ipcMain.handle("workspace:lspConfigure", (_e, opts) => {
|
|
5207
|
+
lspManager.configure({
|
|
5208
|
+
...typeof opts?.idleMs === "number" ? { idleMs: Math.max(1e4, opts.idleMs) } : {},
|
|
5209
|
+
...opts?.overrides && typeof opts.overrides === "object" ? { overrides: opts.overrides } : {}
|
|
5210
|
+
});
|
|
5211
|
+
});
|
|
5212
|
+
ipcMain.handle("workspace:lspServers", (_e, cwd) => lspManager.list(cwd));
|
|
5213
|
+
ipcMain.handle(
|
|
5214
|
+
"workspace:lspOpen",
|
|
5215
|
+
(_e, cwd, path, text, changes) => typeof text === "string" && typeof path === "string" && !path.startsWith("/") && !path.includes("..") ? lspManager.open(cwd, path, text, Array.isArray(changes) ? changes : void 0) : Promise.resolve([])
|
|
5216
|
+
);
|
|
5217
|
+
ipcMain.handle("workspace:lspClose", (_e, cwd, path) => lspManager.close(cwd, path));
|
|
5218
|
+
ipcMain.handle(
|
|
5219
|
+
"workspace:lspDefinition",
|
|
5220
|
+
(_e, cwd, path, line, column) => typeof line === "number" && typeof column === "number" ? lspManager.definition(cwd, path, line, column) : Promise.resolve([])
|
|
5221
|
+
);
|
|
5222
|
+
ipcMain.handle(
|
|
5223
|
+
"workspace:lspHover",
|
|
5224
|
+
(_e, cwd, path, line, column) => typeof line === "number" && typeof column === "number" ? lspManager.hover(cwd, path, line, column) : Promise.resolve(null)
|
|
5225
|
+
);
|
|
5226
|
+
ipcMain.handle(
|
|
5227
|
+
"workspace:diagnostics",
|
|
5228
|
+
async (_e, cwd, paths, opts) => {
|
|
5229
|
+
const disabled = opts?.disabled?.filter((d) => typeof d === "string") ?? [];
|
|
5230
|
+
if (opts?.lsp) disabled.push(...supersededTools(await lspManager.readyServerIds(cwd)));
|
|
5231
|
+
return runDiagnostics(cwd, Array.isArray(paths) ? paths.filter((p) => typeof p === "string") : [], {
|
|
5232
|
+
disabled,
|
|
5233
|
+
timeoutMs: typeof opts?.timeoutMs === "number" ? opts.timeoutMs : void 0
|
|
5234
|
+
});
|
|
5235
|
+
}
|
|
5236
|
+
);
|
|
5237
|
+
ipcMain.handle("workspace:gitStatus", (_e, cwd) => gitStatus(cwd));
|
|
5238
|
+
ipcMain.handle(
|
|
5239
|
+
"workspace:gitDiff",
|
|
5240
|
+
(_e, cwd, path, context) => gitDiff(cwd, path, context === null ? Infinity : context)
|
|
5241
|
+
);
|
|
5242
|
+
ipcMain.handle("workspace:gitShowHead", (_e, cwd, path) => gitShowHead(cwd, path));
|
|
4397
5243
|
ipcMain.handle("panels:list", (_e, cwd) => listPanels(cwd));
|
|
4398
5244
|
ipcMain.handle(
|
|
4399
5245
|
"panels:load",
|
|
@@ -4407,6 +5253,18 @@ function registerChatIpc() {
|
|
|
4407
5253
|
ipcMain.handle("panels:unwatch", (_e, cwd, panelId) => {
|
|
4408
5254
|
unwatchPanel(cwd, panelId);
|
|
4409
5255
|
});
|
|
5256
|
+
ipcMain.handle(
|
|
5257
|
+
"palette:list",
|
|
5258
|
+
(_e, cwd, ctx) => isPaletteContext(ctx) ? listPaletteItems(cwd, ctx) : []
|
|
5259
|
+
);
|
|
5260
|
+
ipcMain.handle(
|
|
5261
|
+
"palette:run",
|
|
5262
|
+
(_e, cwd, source, itemId, ctx) => isPaletteContext(ctx) ? runPaletteItem(cwd, source, itemId, ctx) : { ok: false, error: "Malformed palette context." }
|
|
5263
|
+
);
|
|
5264
|
+
ipcMain.handle("palette:watch", (_e, cwd) => watchPalette(cwd));
|
|
5265
|
+
ipcMain.handle("palette:unwatch", (_e, cwd) => {
|
|
5266
|
+
unwatchPalette(cwd);
|
|
5267
|
+
});
|
|
4410
5268
|
ipcMain.handle("extensions:themes", async (_e, cwd) => {
|
|
4411
5269
|
const config2 = await getRuntimeConfig(cwd);
|
|
4412
5270
|
return Object.values(config2.extensions.themes).map(toGuiTheme);
|
|
@@ -4982,6 +5840,9 @@ function createWindow() {
|
|
|
4982
5840
|
const win = new BrowserWindow({
|
|
4983
5841
|
width: 1200,
|
|
4984
5842
|
height: 800,
|
|
5843
|
+
// Sidebar minimum (220) + chat minimum (480); see renderer/layout/resolve.ts.
|
|
5844
|
+
minWidth: 700,
|
|
5845
|
+
minHeight: 480,
|
|
4985
5846
|
show: false,
|
|
4986
5847
|
autoHideMenuBar: true,
|
|
4987
5848
|
title: withSuffix("Zidane"),
|
|
@@ -5069,6 +5930,7 @@ app.whenReady().then(() => {
|
|
|
5069
5930
|
});
|
|
5070
5931
|
});
|
|
5071
5932
|
app.on("before-quit", () => {
|
|
5933
|
+
void lspManager.stopAll();
|
|
5072
5934
|
shutdownChat();
|
|
5073
5935
|
cancelAllOAuth();
|
|
5074
5936
|
cancelAllMcpLogins();
|