zidane-gui 7.0.29 → 7.0.31
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/index.js +273 -39
- package/out/preload/index.mjs +7 -0
- package/out/renderer/assets/index-DIbhi3RE.css +2078 -0
- package/out/renderer/assets/{index-Dz5Ybpow.js → index-LXtHDMLr.js} +1664 -1468
- package/out/renderer/index.html +2 -2
- package/package.json +2 -2
- package/out/renderer/assets/index-D3KopBrL.css +0 -2078
package/out/main/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { resolve, delimiter, join, dirname, basename, isAbsolute } from "node:pa
|
|
|
2
2
|
import { config } from "dotenv";
|
|
3
3
|
import { app, shell, BrowserWindow, ipcMain, dialog, nativeImage } from "electron";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
-
import { parseEditorCommand, keybindingsPath, stripJsonComments, ensureKeybindingsFile, readProjects, writeProjects, credentialsPath, applyApiKeyEnv, BUILTIN_PROVIDERS, readCredentials, detectAuth, supportsOAuth, runOAuthLogin, setProviderCredential, scopeCwd, resolveConfig, DEFAULT_SETTINGS, enforceSettingsInvariants, mcpsWritePath, upsertMcpServer, discoverProjectMcps, removeMcpServer, loadMcpToolsCache, subscribeMcpToolsCache, refreshMcpToolsCatalog, createFileMcpCredentialStore, createChatHost, toTodosSnapshot, searchSessionHistory, searchableTurnText, deriveSessionTitle, toolCallPreview, modelChainMetadata, sessionModelFallbacks, enabledModelOptions, buildModelCatalog, modelsForDescriptor,
|
|
5
|
+
import { parseEditorCommand, keybindingsPath, stripJsonComments, ensureKeybindingsFile, readProjects, writeProjects, credentialsPath, applyApiKeyEnv, BUILTIN_PROVIDERS, readCredentials, detectAuth, supportsOAuth, runOAuthLogin, 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, hasClaudeCodeSetup, countClaudeSessionFiles, importFromClaudeCode, isMainSession, findGitRoot, restoreModelOptions, modelOptionsFor, eventsFromTurns, watchInstalledVersion, checkForUpdate, upgradeInstalledPackages, performSelfUpdate, compareSemver, findInstalledCompanion } from "zidane/chat";
|
|
6
6
|
import { spawn, execFile } from "node:child_process";
|
|
7
7
|
import { mkdirSync, readFileSync, writeFileSync, existsSync, accessSync, constants, statSync, readdirSync, copyFileSync, rmSync } from "node:fs";
|
|
8
8
|
import { homedir, userInfo } from "node:os";
|
|
@@ -237,14 +237,23 @@ function cancelAllOAuth() {
|
|
|
237
237
|
}
|
|
238
238
|
oauthFlights.clear();
|
|
239
239
|
}
|
|
240
|
-
function
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
join(
|
|
240
|
+
function launcherSearchDirectories(env = process.env) {
|
|
241
|
+
const home = homedir();
|
|
242
|
+
return [
|
|
243
|
+
...(env.PATH ?? "").split(delimiter).filter(Boolean),
|
|
244
|
+
join(home, ".bun", "bin"),
|
|
245
|
+
join(home, ".volta", "bin"),
|
|
246
|
+
join(home, ".local", "bin"),
|
|
247
|
+
...env.PNPM_HOME ? [env.PNPM_HOME] : [],
|
|
245
248
|
"/opt/homebrew/bin",
|
|
246
249
|
"/usr/local/bin"
|
|
247
250
|
];
|
|
251
|
+
}
|
|
252
|
+
function launcherSearchPath(env = process.env) {
|
|
253
|
+
return launcherSearchDirectories(env).join(delimiter);
|
|
254
|
+
}
|
|
255
|
+
function resolveDaemonSpawnCommand(options = {}) {
|
|
256
|
+
const directories = options.directories ?? launcherSearchDirectories();
|
|
248
257
|
const executable = (name) => {
|
|
249
258
|
for (const directory of directories) {
|
|
250
259
|
const path = join(directory, name);
|
|
@@ -1107,8 +1116,8 @@ function invalidateConfig() {
|
|
|
1107
1116
|
}
|
|
1108
1117
|
const LEGACY_SQLITE_KEY = "chat_settings";
|
|
1109
1118
|
const LEGACY_SQLITE_BACKUP_KEY = "chat_settings_migrated_backup";
|
|
1110
|
-
function mergedFrom(
|
|
1111
|
-
const loaded =
|
|
1119
|
+
function mergedFrom(state2) {
|
|
1120
|
+
const loaded = state2.settings ?? {};
|
|
1112
1121
|
const interactionMode = loaded.interactionMode === "ask" || loaded.interactionMode === "skip" || loaded.interactionMode === "disabled" ? loaded.interactionMode : loaded.allowInteraction === false ? "disabled" : "ask";
|
|
1113
1122
|
const merged = {
|
|
1114
1123
|
...DEFAULT_SETTINGS,
|
|
@@ -1129,8 +1138,8 @@ function foreignConfigFlags(settings = readSettings()) {
|
|
|
1129
1138
|
}
|
|
1130
1139
|
function writeSettingsPatch(patch) {
|
|
1131
1140
|
const { stateStore } = getResolvedConfig();
|
|
1132
|
-
const
|
|
1133
|
-
const prev = mergedFrom(
|
|
1141
|
+
const state2 = stateStore.load();
|
|
1142
|
+
const prev = mergedFrom(state2);
|
|
1134
1143
|
const actualPatch = {};
|
|
1135
1144
|
const changed = /* @__PURE__ */ new Set();
|
|
1136
1145
|
for (const key of Object.keys(patch)) {
|
|
@@ -1150,12 +1159,12 @@ function writeSettingsPatch(patch) {
|
|
|
1150
1159
|
changed.add(key);
|
|
1151
1160
|
}
|
|
1152
1161
|
}
|
|
1153
|
-
stateStore.save({ ...
|
|
1162
|
+
stateStore.save({ ...state2, settings: next });
|
|
1154
1163
|
return { next, changed };
|
|
1155
1164
|
}
|
|
1156
1165
|
function initSettings() {
|
|
1157
1166
|
const { stateStore, initialSettings } = getResolvedConfig();
|
|
1158
|
-
const
|
|
1167
|
+
const state2 = stateStore.load();
|
|
1159
1168
|
const slice = { ...initialSettings };
|
|
1160
1169
|
const raw = settingsRepo.get(LEGACY_SQLITE_KEY);
|
|
1161
1170
|
if (raw !== null) {
|
|
@@ -1177,8 +1186,8 @@ function initSettings() {
|
|
|
1177
1186
|
settingsRepo.delete(LEGACY_SQLITE_KEY);
|
|
1178
1187
|
console.log(`[zidane-gui] migrated sqlite chat settings into state.json (backup: ${LEGACY_SQLITE_BACKUP_KEY})`);
|
|
1179
1188
|
}
|
|
1180
|
-
if (!settingsValueEqual(slice,
|
|
1181
|
-
stateStore.save({ ...
|
|
1189
|
+
if (!settingsValueEqual(slice, state2.settings ?? {})) {
|
|
1190
|
+
stateStore.save({ ...state2, settings: slice });
|
|
1182
1191
|
}
|
|
1183
1192
|
}
|
|
1184
1193
|
function settingsValueEqual(a, b) {
|
|
@@ -1776,7 +1785,7 @@ function cancelAllMcpLogins() {
|
|
|
1776
1785
|
flights.clear();
|
|
1777
1786
|
latestFlightByName.clear();
|
|
1778
1787
|
}
|
|
1779
|
-
const CACHE_TTL_MS = 6e4;
|
|
1788
|
+
const CACHE_TTL_MS$1 = 6e4;
|
|
1780
1789
|
let bucketCache = null;
|
|
1781
1790
|
let bucketLoad = null;
|
|
1782
1791
|
function invalidateUsageSummaryCache() {
|
|
@@ -1826,7 +1835,7 @@ async function loadBucketsInProcess() {
|
|
|
1826
1835
|
return { assistant, user, sessions };
|
|
1827
1836
|
}
|
|
1828
1837
|
async function loadBuckets(now) {
|
|
1829
|
-
if (bucketCache && now - bucketCache.loadedAt < CACHE_TTL_MS) {
|
|
1838
|
+
if (bucketCache && now - bucketCache.loadedAt < CACHE_TTL_MS$1) {
|
|
1830
1839
|
return bucketCache;
|
|
1831
1840
|
}
|
|
1832
1841
|
bucketLoad ??= (async () => {
|
|
@@ -2610,8 +2619,8 @@ async function setSessionTodos(sessionId, items) {
|
|
|
2610
2619
|
if (daemon) {
|
|
2611
2620
|
return daemon.request("todos.set", { sessionId, items });
|
|
2612
2621
|
}
|
|
2613
|
-
const
|
|
2614
|
-
return
|
|
2622
|
+
const state2 = await getChatHost().setTodos(sessionId, items);
|
|
2623
|
+
return state2 ? toTodosSnapshot(state2) : null;
|
|
2615
2624
|
}
|
|
2616
2625
|
function getContextBreakdown(sessionId) {
|
|
2617
2626
|
const daemon = getDaemonClient();
|
|
@@ -3142,6 +3151,22 @@ const LAST_FOLDER_KEY = "last_folder";
|
|
|
3142
3151
|
function announceSessionsTouch(sessionId) {
|
|
3143
3152
|
getDaemonClient()?.notify("sessions.touch", { sessionId });
|
|
3144
3153
|
}
|
|
3154
|
+
async function patchSessionMetaSafely(sessionId, patch, rpc) {
|
|
3155
|
+
const daemon = getDaemonClient();
|
|
3156
|
+
if (daemon && rpc) {
|
|
3157
|
+
try {
|
|
3158
|
+
await rpc(daemon);
|
|
3159
|
+
return;
|
|
3160
|
+
} catch (err) {
|
|
3161
|
+
guiLog.warn("daemon metadata RPC failed; falling back to the in-process host", {
|
|
3162
|
+
scope: "daemon",
|
|
3163
|
+
error: err?.message ?? String(err)
|
|
3164
|
+
});
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
await getChatHost().patchSessionMeta(sessionId, patch);
|
|
3168
|
+
announceSessionsTouch(sessionId);
|
|
3169
|
+
}
|
|
3145
3170
|
async function disposeOrRebuild(sessionId) {
|
|
3146
3171
|
const daemon = getDaemonClient();
|
|
3147
3172
|
if (daemon) {
|
|
@@ -3497,6 +3522,7 @@ function registerChatIpc() {
|
|
|
3497
3522
|
} catch {
|
|
3498
3523
|
}
|
|
3499
3524
|
}
|
|
3525
|
+
await getChatHost().setLiveSessionAgentId(id, agentId);
|
|
3500
3526
|
patchSessionScope(id, { agentId });
|
|
3501
3527
|
await disposeOrRebuild(id);
|
|
3502
3528
|
announceSessionsTouch(id);
|
|
@@ -3519,32 +3545,54 @@ function registerChatIpc() {
|
|
|
3519
3545
|
announceSessionsTouch(id);
|
|
3520
3546
|
invalidateGitRepoCache();
|
|
3521
3547
|
});
|
|
3522
|
-
ipcMain.handle("sessions:setEffort", (_e, id, effort) => {
|
|
3523
|
-
|
|
3524
|
-
|
|
3548
|
+
ipcMain.handle("sessions:setEffort", async (_e, id, effort) => {
|
|
3549
|
+
await patchSessionMetaSafely(
|
|
3550
|
+
id,
|
|
3551
|
+
{ effort },
|
|
3552
|
+
(daemon) => daemon.request("sessions.setEffort", { sessionId: id, effort })
|
|
3553
|
+
);
|
|
3525
3554
|
});
|
|
3526
3555
|
ipcMain.handle(
|
|
3527
3556
|
"sessions:setModel",
|
|
3528
3557
|
async (_e, id, providerKey, modelId, fallbacks) => {
|
|
3529
|
-
|
|
3558
|
+
const data = await getSessionStore().load(id);
|
|
3559
|
+
const providers = await providersFor(data ? resolveSessionCwd(data) : void 0);
|
|
3560
|
+
const descriptor = descriptorFor(providerKey, providers);
|
|
3561
|
+
const priorEffort = data?.metadata?.effort;
|
|
3562
|
+
const effort = typeof priorEffort === "string" && descriptor && modelSupportsReasoning(descriptor, modelId) ? priorEffort : void 0;
|
|
3563
|
+
const pick = {
|
|
3530
3564
|
providerKey,
|
|
3531
3565
|
modelId,
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
}
|
|
3535
|
-
|
|
3566
|
+
...fallbacks && fallbacks.length > 0 ? { fallbacks: [...fallbacks] } : {},
|
|
3567
|
+
...effort ? { effort } : {}
|
|
3568
|
+
};
|
|
3569
|
+
const daemon = getDaemonClient();
|
|
3570
|
+
if (daemon) {
|
|
3571
|
+
try {
|
|
3572
|
+
await daemon.request("sessions.setModel", { sessionId: id, ...pick });
|
|
3573
|
+
return;
|
|
3574
|
+
} catch (err) {
|
|
3575
|
+
guiLog.warn("sessions.setModel RPC failed; falling back to the in-process host", {
|
|
3576
|
+
scope: "daemon",
|
|
3577
|
+
error: err?.message ?? String(err)
|
|
3578
|
+
});
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
await getChatHost().setSessionModel(id, pick);
|
|
3536
3582
|
announceSessionsTouch(id);
|
|
3537
3583
|
}
|
|
3538
3584
|
);
|
|
3539
3585
|
ipcMain.handle("sessions:setModelOptions", async (_e, id, options) => {
|
|
3540
3586
|
const data = await getSessionStore().load(id);
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
modelOptions: enabledModelOptions(options)
|
|
3545
|
-
})
|
|
3587
|
+
const modelOptions = modelOptionsForSession({
|
|
3588
|
+
...data?.metadata ?? {},
|
|
3589
|
+
modelOptions: enabledModelOptions(options)
|
|
3546
3590
|
});
|
|
3547
|
-
|
|
3591
|
+
await patchSessionMetaSafely(
|
|
3592
|
+
id,
|
|
3593
|
+
{ modelOptions },
|
|
3594
|
+
(daemon) => daemon.request("sessions.setModelOptions", { sessionId: id, options: modelOptions })
|
|
3595
|
+
);
|
|
3548
3596
|
});
|
|
3549
3597
|
ipcMain.handle("sessions:listModels", async (_e, cwd) => {
|
|
3550
3598
|
applyAuthEnv();
|
|
@@ -3936,16 +3984,16 @@ function registerChatIpc() {
|
|
|
3936
3984
|
}
|
|
3937
3985
|
);
|
|
3938
3986
|
ipcMain.handle("todos:get", async (_e, sessionId) => {
|
|
3939
|
-
const
|
|
3940
|
-
if (!
|
|
3987
|
+
const state2 = await getTodosSnapshot(sessionId);
|
|
3988
|
+
if (!state2) {
|
|
3941
3989
|
return null;
|
|
3942
3990
|
}
|
|
3943
3991
|
return {
|
|
3944
|
-
runId:
|
|
3945
|
-
todos: [...
|
|
3946
|
-
archive: [...
|
|
3947
|
-
inProgress:
|
|
3948
|
-
tally:
|
|
3992
|
+
runId: state2.runId,
|
|
3993
|
+
todos: [...state2.todos],
|
|
3994
|
+
archive: [...state2.archive],
|
|
3995
|
+
inProgress: state2.inProgress,
|
|
3996
|
+
tally: state2.tally
|
|
3949
3997
|
};
|
|
3950
3998
|
});
|
|
3951
3999
|
ipcMain.handle("todos:set", async (_e, sessionId, items) => {
|
|
@@ -4500,6 +4548,191 @@ function registerChatIpc() {
|
|
|
4500
4548
|
}));
|
|
4501
4549
|
});
|
|
4502
4550
|
}
|
|
4551
|
+
const PACKAGE_NAME = "zidane-gui";
|
|
4552
|
+
const TARGETS = [{ packageName: PACKAGE_NAME }, { packageName: "zidane-tui", binName: "zidane" }];
|
|
4553
|
+
const FIRST_CHECK_DELAY_MS = 3e3;
|
|
4554
|
+
const RECHECK_INTERVAL_MS = 6 * 60 * 6e4;
|
|
4555
|
+
const CACHE_TTL_MS = 60 * 6e4;
|
|
4556
|
+
let state = {
|
|
4557
|
+
running: app.getVersion(),
|
|
4558
|
+
latest: null,
|
|
4559
|
+
hasUpdate: false,
|
|
4560
|
+
installed: null,
|
|
4561
|
+
restartRequired: false,
|
|
4562
|
+
phase: "idle",
|
|
4563
|
+
progress: null,
|
|
4564
|
+
error: null,
|
|
4565
|
+
checkedAt: null
|
|
4566
|
+
};
|
|
4567
|
+
let watcher = null;
|
|
4568
|
+
let installing = null;
|
|
4569
|
+
let checking = null;
|
|
4570
|
+
function updaterEnabled() {
|
|
4571
|
+
return process.env.ZIDANE_GUI_NO_UPDATE !== "1" && !process.env.ELECTRON_RENDERER_URL;
|
|
4572
|
+
}
|
|
4573
|
+
function toolEnv() {
|
|
4574
|
+
return { ...process.env, PATH: launcherSearchPath() };
|
|
4575
|
+
}
|
|
4576
|
+
function findInstalled(spec) {
|
|
4577
|
+
return findInstalledCompanion(spec, { env: toolEnv() });
|
|
4578
|
+
}
|
|
4579
|
+
function checksEnabled() {
|
|
4580
|
+
return updaterEnabled() && readSettings().checkForUpdates !== false;
|
|
4581
|
+
}
|
|
4582
|
+
function publish(patch) {
|
|
4583
|
+
state = { ...state, ...patch };
|
|
4584
|
+
for (const win of BrowserWindow.getAllWindows()) {
|
|
4585
|
+
win.webContents.send("update:changed", state);
|
|
4586
|
+
}
|
|
4587
|
+
return state;
|
|
4588
|
+
}
|
|
4589
|
+
function checkForAppUpdate(opts = {}) {
|
|
4590
|
+
if (checking) {
|
|
4591
|
+
return checking;
|
|
4592
|
+
}
|
|
4593
|
+
if (!checksEnabled()) {
|
|
4594
|
+
return Promise.resolve(publish({ latest: null, hasUpdate: false }));
|
|
4595
|
+
}
|
|
4596
|
+
watcher?.check();
|
|
4597
|
+
if (state.phase === "idle") {
|
|
4598
|
+
publish({ phase: "checking" });
|
|
4599
|
+
}
|
|
4600
|
+
checking = checkForUpdate({
|
|
4601
|
+
packageName: PACKAGE_NAME,
|
|
4602
|
+
currentVersion: state.running,
|
|
4603
|
+
cacheDir: getResolvedConfig().paths.cacheDir,
|
|
4604
|
+
cacheTtlMs: CACHE_TTL_MS,
|
|
4605
|
+
force: opts.force,
|
|
4606
|
+
timeoutMs: 8e3
|
|
4607
|
+
}).then(
|
|
4608
|
+
(status) => publish({
|
|
4609
|
+
latest: status.latest,
|
|
4610
|
+
hasUpdate: status.hasUpdate,
|
|
4611
|
+
checkedAt: status.checkedAt,
|
|
4612
|
+
...state.phase === "checking" ? { phase: "idle" } : {}
|
|
4613
|
+
})
|
|
4614
|
+
).catch((err) => {
|
|
4615
|
+
guiLog.warn("update check failed", { scope: "update", error: err?.message ?? String(err) });
|
|
4616
|
+
return publish(state.phase === "checking" ? { phase: "idle" } : {});
|
|
4617
|
+
}).finally(() => {
|
|
4618
|
+
checking = null;
|
|
4619
|
+
});
|
|
4620
|
+
return checking;
|
|
4621
|
+
}
|
|
4622
|
+
function installAppUpdate() {
|
|
4623
|
+
if (installing) {
|
|
4624
|
+
return installing;
|
|
4625
|
+
}
|
|
4626
|
+
if (!updaterEnabled()) {
|
|
4627
|
+
return Promise.resolve(state);
|
|
4628
|
+
}
|
|
4629
|
+
publish({ phase: "updating", progress: "checking…", error: null });
|
|
4630
|
+
const cacheDir = getResolvedConfig().paths.cacheDir;
|
|
4631
|
+
const onProgress = (event) => {
|
|
4632
|
+
switch (event.kind) {
|
|
4633
|
+
case "check":
|
|
4634
|
+
publish({ progress: `checking ${event.packageName}…` });
|
|
4635
|
+
break;
|
|
4636
|
+
case "install":
|
|
4637
|
+
publish({ progress: `$ ${event.command.join(" ")}` });
|
|
4638
|
+
guiLog.info("installing update", { scope: "update", packageName: event.packageName, from: event.from, to: event.to, command: event.command.join(" ") });
|
|
4639
|
+
break;
|
|
4640
|
+
case "log":
|
|
4641
|
+
publish({ progress: event.line });
|
|
4642
|
+
break;
|
|
4643
|
+
case "done":
|
|
4644
|
+
guiLog.info("update step finished", { scope: "update", ...event.result });
|
|
4645
|
+
break;
|
|
4646
|
+
}
|
|
4647
|
+
};
|
|
4648
|
+
installing = upgradeInstalledPackages({
|
|
4649
|
+
targets: [...TARGETS],
|
|
4650
|
+
cacheDir,
|
|
4651
|
+
onProgress,
|
|
4652
|
+
findInstalled,
|
|
4653
|
+
performSelfUpdate: (opts) => performSelfUpdate({ ...opts, env: { ...opts.env, PATH: launcherSearchPath() } })
|
|
4654
|
+
}).then((report) => {
|
|
4655
|
+
const disk = watcher?.check();
|
|
4656
|
+
const failures = report.results.filter((r) => r.status === "failed" || r.status === "unavailable");
|
|
4657
|
+
if (failures.length > 0) {
|
|
4658
|
+
const error = failures.map((f) => `${f.packageName}: ${f.error ?? f.status}`).join("\n");
|
|
4659
|
+
guiLog.warn("update failed", { scope: "update", error });
|
|
4660
|
+
return publish({ phase: "failed", progress: null, error, ...disk ? { installed: disk.installed, restartRequired: disk.restartRequired } : {} });
|
|
4661
|
+
}
|
|
4662
|
+
if (report.results.every((r) => r.status === "not-installed")) {
|
|
4663
|
+
const error = "no zidane packages found on PATH";
|
|
4664
|
+
guiLog.warn("update failed", { scope: "update", error, path: launcherSearchPath() });
|
|
4665
|
+
return publish({ phase: "failed", progress: null, error });
|
|
4666
|
+
}
|
|
4667
|
+
const self = report.results.find((r) => r.packageName === PACKAGE_NAME);
|
|
4668
|
+
return publish({
|
|
4669
|
+
phase: "idle",
|
|
4670
|
+
progress: null,
|
|
4671
|
+
error: null,
|
|
4672
|
+
// The registry told us `latest`; once it is on disk there is nothing left to install.
|
|
4673
|
+
hasUpdate: false,
|
|
4674
|
+
...disk ? { installed: disk.installed, restartRequired: disk.restartRequired } : self?.status === "updated" && self.to ? { installed: self.to, restartRequired: compareSemver(self.to, state.running) > 0 } : {}
|
|
4675
|
+
});
|
|
4676
|
+
}).catch((err) => {
|
|
4677
|
+
const error = err?.message ?? String(err);
|
|
4678
|
+
guiLog.error("update crashed", { scope: "update", error });
|
|
4679
|
+
return publish({ phase: "failed", progress: null, error });
|
|
4680
|
+
}).finally(() => {
|
|
4681
|
+
installing = null;
|
|
4682
|
+
});
|
|
4683
|
+
return installing;
|
|
4684
|
+
}
|
|
4685
|
+
async function restartForUpdate(win) {
|
|
4686
|
+
const target = state.installed ? `v${state.installed}` : "the new version";
|
|
4687
|
+
const { response } = await dialog.showMessageBox(win ?? void 0, {
|
|
4688
|
+
type: "info",
|
|
4689
|
+
buttons: ["Restart now", "Later"],
|
|
4690
|
+
defaultId: 0,
|
|
4691
|
+
cancelId: 1,
|
|
4692
|
+
message: `Restart Zidane to finish updating to ${target}?`,
|
|
4693
|
+
detail: "Running work is not interrupted — the daemon keeps sessions alive. Unsaved composer text is kept as a draft."
|
|
4694
|
+
});
|
|
4695
|
+
if (response !== 0) {
|
|
4696
|
+
return false;
|
|
4697
|
+
}
|
|
4698
|
+
guiLog.info("relaunching for update", { scope: "update", installed: state.installed, running: state.running });
|
|
4699
|
+
app.relaunch();
|
|
4700
|
+
app.quit();
|
|
4701
|
+
return true;
|
|
4702
|
+
}
|
|
4703
|
+
function registerUpdateIpc() {
|
|
4704
|
+
ipcMain.handle("update:state", () => state);
|
|
4705
|
+
ipcMain.handle("update:check", () => checkForAppUpdate());
|
|
4706
|
+
ipcMain.handle("update:install", () => installAppUpdate());
|
|
4707
|
+
ipcMain.handle("update:restart", (e) => restartForUpdate(BrowserWindow.fromWebContents(e.sender)));
|
|
4708
|
+
if (!updaterEnabled()) {
|
|
4709
|
+
return;
|
|
4710
|
+
}
|
|
4711
|
+
watcher = watchInstalledVersion({
|
|
4712
|
+
spec: { packageName: PACKAGE_NAME },
|
|
4713
|
+
currentVersion: state.running,
|
|
4714
|
+
cacheDir: getResolvedConfig().paths.cacheDir,
|
|
4715
|
+
probe: findInstalled,
|
|
4716
|
+
onChange: (next) => {
|
|
4717
|
+
guiLog.info("installed version changed", { scope: "update", installed: next.installed, restartRequired: next.restartRequired });
|
|
4718
|
+
publish({ installed: next.installed, restartRequired: next.restartRequired });
|
|
4719
|
+
}
|
|
4720
|
+
});
|
|
4721
|
+
const initial = watcher.current();
|
|
4722
|
+
publish({ installed: initial.installed, restartRequired: initial.restartRequired });
|
|
4723
|
+
const first = setTimeout(() => void checkForAppUpdate(), FIRST_CHECK_DELAY_MS);
|
|
4724
|
+
const recheck = setInterval(() => void checkForAppUpdate(), RECHECK_INTERVAL_MS);
|
|
4725
|
+
app.on("browser-window-focus", () => {
|
|
4726
|
+
watcher?.check();
|
|
4727
|
+
void checkForAppUpdate();
|
|
4728
|
+
});
|
|
4729
|
+
app.on("will-quit", () => {
|
|
4730
|
+
clearTimeout(first);
|
|
4731
|
+
clearInterval(recheck);
|
|
4732
|
+
watcher?.close();
|
|
4733
|
+
watcher = null;
|
|
4734
|
+
});
|
|
4735
|
+
}
|
|
4503
4736
|
function registerIpc() {
|
|
4504
4737
|
ipcMain.handle("folder:pick", async (e) => {
|
|
4505
4738
|
const win = BrowserWindow.fromWebContents(e.sender);
|
|
@@ -4512,6 +4745,7 @@ function registerIpc() {
|
|
|
4512
4745
|
return result.filePaths[0];
|
|
4513
4746
|
});
|
|
4514
4747
|
registerChatIpc();
|
|
4748
|
+
registerUpdateIpc();
|
|
4515
4749
|
}
|
|
4516
4750
|
config({ path: join(import.meta.dirname, "../../.env"), quiet: true });
|
|
4517
4751
|
const ICON_PATH = join(import.meta.dirname, "../../resources/icon.png");
|
package/out/preload/index.mjs
CHANGED
|
@@ -53,6 +53,13 @@ const api = {
|
|
|
53
53
|
// Synchronous — webFrame lives in this process; no IPC roundtrip.
|
|
54
54
|
getZoomFactor: () => webFrame.getZoomFactor()
|
|
55
55
|
},
|
|
56
|
+
update: {
|
|
57
|
+
state: () => ipcRenderer.invoke("update:state"),
|
|
58
|
+
check: () => ipcRenderer.invoke("update:check"),
|
|
59
|
+
install: () => ipcRenderer.invoke("update:install"),
|
|
60
|
+
restart: () => ipcRenderer.invoke("update:restart"),
|
|
61
|
+
onChanged: (cb) => subscribe("update:changed", cb)
|
|
62
|
+
},
|
|
56
63
|
chat: {
|
|
57
64
|
send: (opts) => ipcRenderer.invoke("chat:send", opts),
|
|
58
65
|
interrupt: (sessionId) => ipcRenderer.invoke("chat:interrupt", sessionId),
|