zidane-gui 7.0.30 → 7.0.32

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 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, 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 } from "zidane/chat";
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 resolveDaemonSpawnCommand(options = {}) {
241
- const directories = options.directories ?? [
242
- ...(process.env.PATH ?? "").split(delimiter).filter(Boolean),
243
- join(homedir(), ".bun", "bin"),
244
- join(homedir(), ".local", "bin"),
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(state) {
1111
- const loaded = state.settings ?? {};
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 state = stateStore.load();
1133
- const prev = mergedFrom(state);
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({ ...state, settings: next });
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 state = stateStore.load();
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, state.settings ?? {})) {
1181
- stateStore.save({ ...state, settings: slice });
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 state = await getChatHost().setTodos(sessionId, items);
2614
- return state ? toTodosSnapshot(state) : null;
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();
@@ -3975,16 +3984,16 @@ function registerChatIpc() {
3975
3984
  }
3976
3985
  );
3977
3986
  ipcMain.handle("todos:get", async (_e, sessionId) => {
3978
- const state = await getTodosSnapshot(sessionId);
3979
- if (!state) {
3987
+ const state2 = await getTodosSnapshot(sessionId);
3988
+ if (!state2) {
3980
3989
  return null;
3981
3990
  }
3982
3991
  return {
3983
- runId: state.runId,
3984
- todos: [...state.todos],
3985
- archive: [...state.archive],
3986
- inProgress: state.inProgress,
3987
- tally: state.tally
3992
+ runId: state2.runId,
3993
+ todos: [...state2.todos],
3994
+ archive: [...state2.archive],
3995
+ inProgress: state2.inProgress,
3996
+ tally: state2.tally
3988
3997
  };
3989
3998
  });
3990
3999
  ipcMain.handle("todos:set", async (_e, sessionId, items) => {
@@ -4539,6 +4548,191 @@ function registerChatIpc() {
4539
4548
  }));
4540
4549
  });
4541
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
+ }
4542
4736
  function registerIpc() {
4543
4737
  ipcMain.handle("folder:pick", async (e) => {
4544
4738
  const win = BrowserWindow.fromWebContents(e.sender);
@@ -4551,6 +4745,7 @@ function registerIpc() {
4551
4745
  return result.filePaths[0];
4552
4746
  });
4553
4747
  registerChatIpc();
4748
+ registerUpdateIpc();
4554
4749
  }
4555
4750
  config({ path: join(import.meta.dirname, "../../.env"), quiet: true });
4556
4751
  const ICON_PATH = join(import.meta.dirname, "../../resources/icon.png");
@@ -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),