zidane-gui 7.0.16 → 7.0.18

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
@@ -1,4 +1,4 @@
1
- import { resolve, join, dirname, delimiter, basename } from "node:path";
1
+ import { resolve, join, dirname, delimiter, basename, isAbsolute } from "node:path";
2
2
  import { config } from "dotenv";
3
3
  import { app, shell, BrowserWindow, ipcMain, dialog, nativeImage } from "electron";
4
4
  import { randomUUID } from "node:crypto";
@@ -6,13 +6,14 @@ import { parseEditorCommand, keybindingsPath, stripJsonComments, ensureKeybindin
6
6
  import { spawn, execFile } from "node:child_process";
7
7
  import { mkdirSync, readFileSync, writeFileSync, readdirSync, existsSync, copyFileSync, rmSync } from "node:fs";
8
8
  import { homedir, userInfo } from "node:os";
9
- import { migrateSessionArtifactDirs, createRingBufferSink, fanoutSink, consoleSink, createLogger, createExtensionBus, createExtensionHostRuntimeBridge, toWireConfigSchema, resolveCompletionSubmit, inlineLoadedExtension, discoverAndBuildExtensionRegistry, disposeExtensionRegistry, installExtensionFromSpec, ExtensionInstallError, updateInstalledExtension, removeInstalledExtension, sanitizeExtensionConfigActionPatch, loginMcpServer, McpOAuthProvider, refreshArtifact, extensionScaffold, resolveInlineSuggestion, createPathAutocompleteProvider, editSessionMetadata, renderArtifactRow, loadSession } from "zidane";
9
+ import { migrateSessionArtifactDirs, createRingBufferSink, fanoutSink, consoleSink, createLogger, mergeArtifact, selectArtifactEvictions, createExtensionBus, createExtensionHostRuntimeBridge, toWireConfigSchema, resolveCompletionSubmit, inlineLoadedExtension, discoverAndBuildExtensionRegistry, disposeExtensionRegistry, installExtensionFromSpec, ExtensionInstallError, updateInstalledExtension, removeInstalledExtension, sanitizeExtensionConfigActionPatch, loginMcpServer, McpOAuthProvider, refreshArtifact, extensionScaffold, resolveInlineSuggestion, createPathAutocompleteProvider, editSessionMetadata, renderArtifactRow, loadSession } from "zidane";
10
10
  import { IPC_BUILD_ID, defaultSocketPath, probeSocket, connectIpcClient, IpcVersionMismatchError } from "zidane/ipc";
11
11
  import { DatabaseSync } from "node:sqlite";
12
12
  import { P as PARENT_USER_TURN, u as usageAssistantDaily$1, b as usageUserDaily$1, a as usageSessionDaily$1 } from "./chunks/usage-sql-BdDLRz11.js";
13
13
  import { installSkillFromSpec, SkillInstallError } from "zidane/skills";
14
14
  import { promisify } from "node:util";
15
15
  import { Worker } from "node:worker_threads";
16
+ import { stat } from "node:fs/promises";
16
17
  import { setImmediate as setImmediate$1 } from "node:timers/promises";
17
18
  import { BASH_CALL_ID_PREFIX } from "zidane/chat/pure";
18
19
  import { tailTruncate } from "zidane/tools";
@@ -382,6 +383,26 @@ function openDb() {
382
383
  }
383
384
  db.exec("CREATE INDEX IF NOT EXISTS idx_turns_session_role ON turns(session_id, role, seq)");
384
385
  db.exec("CREATE INDEX IF NOT EXISTS idx_sessions_updated_at ON sessions(updated_at)");
386
+ db.exec(`
387
+ CREATE TABLE IF NOT EXISTS artifacts (
388
+ id TEXT PRIMARY KEY,
389
+ session_id TEXT NOT NULL,
390
+ run_id TEXT,
391
+ turn_id TEXT,
392
+ kind TEXT NOT NULL,
393
+ uri TEXT NOT NULL,
394
+ label TEXT NOT NULL,
395
+ project_root TEXT,
396
+ meta TEXT,
397
+ created_at INTEGER NOT NULL,
398
+ updated_at INTEGER NOT NULL,
399
+ UNIQUE (session_id, kind, uri),
400
+ FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE
401
+ )
402
+ `);
403
+ db.exec("CREATE INDEX IF NOT EXISTS idx_artifacts_session ON artifacts(session_id, updated_at)");
404
+ db.exec("CREATE INDEX IF NOT EXISTS idx_artifacts_project_kind ON artifacts(project_root, kind, updated_at)");
405
+ db.exec("CREATE INDEX IF NOT EXISTS idx_artifacts_kind_uri ON artifacts(kind, uri)");
385
406
  return db;
386
407
  }
387
408
  function withImmediateTransaction(database, fn) {
@@ -527,6 +548,7 @@ function sidebarMetaSql(where, limit) {
527
548
  (SELECT COUNT(*) FROM turns t WHERE t.session_id = s.id) AS turn_count,
528
549
  (SELECT COUNT(*) FROM turns t WHERE t.session_id = s.id AND t.role = 'user') AS user_count,
529
550
  (SELECT COUNT(*) FROM runs r WHERE r.session_id = s.id) AS run_count,
551
+ (SELECT COUNT(*) FROM artifacts a WHERE a.session_id = s.id) AS artifact_count,
530
552
  CASE WHEN json_valid(s.metadata)
531
553
  AND TRIM(COALESCE(json_extract(s.metadata, '$.title'), '')) <> '' THEN NULL
532
554
  ELSE (SELECT t.data FROM turns t WHERE t.session_id = s.id AND t.role = 'user'
@@ -555,6 +577,7 @@ function rowToSidebarMeta(r) {
555
577
  turnCount: r.turn_count,
556
578
  userMessageCount: r.user_count,
557
579
  runCount: r.run_count,
580
+ artifactCount: r.artifact_count,
558
581
  ...firstUserTurn ? { firstUserTurn } : {}
559
582
  };
560
583
  }
@@ -791,6 +814,7 @@ function getSessionStore() {
791
814
  turnCount: m.turnCount,
792
815
  userMessageCount: m.userMessageCount,
793
816
  runCount: m.runCount,
817
+ artifactCount: m.artifactCount,
794
818
  ...m.firstUserTurn ? { firstUserTurn: m.firstUserTurn } : {}
795
819
  }));
796
820
  },
@@ -807,10 +831,109 @@ function getSessionStore() {
807
831
  },
808
832
  async updateStatus(id, status) {
809
833
  withImmediateTransaction(database, () => updateStatusTxn(id, status));
834
+ },
835
+ // --- artifacts (see docs/ARTIFACTS.md) -------------------------------
836
+ async upsertArtifact(artifact) {
837
+ let stored = null;
838
+ withImmediateTransaction(database, () => {
839
+ if (!database.prepare("SELECT id FROM sessions WHERE id = ?").get(artifact.sessionId)) return;
840
+ const existing = database.prepare(`SELECT ${ARTIFACT_COLUMNS} FROM artifacts WHERE session_id = ? AND kind = ? AND uri = ?`).get(artifact.sessionId, artifact.kind, artifact.uri);
841
+ if (existing) {
842
+ const merged = mergeArtifact(rowToArtifact(existing), artifact);
843
+ database.prepare("UPDATE artifacts SET label = ?, project_root = ?, meta = ?, updated_at = ? WHERE id = ?").run(
844
+ merged.label,
845
+ merged.projectRoot ?? null,
846
+ merged.meta !== void 0 ? JSON.stringify(merged.meta) : null,
847
+ merged.updatedAt,
848
+ merged.id
849
+ );
850
+ stored = merged;
851
+ return;
852
+ }
853
+ const current = database.prepare(`SELECT ${ARTIFACT_COLUMNS} FROM artifacts WHERE session_id = ? ORDER BY created_at, rowid`).all(artifact.sessionId).map(rowToArtifact);
854
+ for (const id of selectArtifactEvictions(current)) {
855
+ database.prepare("DELETE FROM artifacts WHERE session_id = ? AND id = ?").run(artifact.sessionId, id);
856
+ }
857
+ database.prepare(`INSERT INTO artifacts (${ARTIFACT_COLUMNS}) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(
858
+ artifact.id,
859
+ artifact.sessionId,
860
+ artifact.runId ?? null,
861
+ artifact.turnId ?? null,
862
+ artifact.kind,
863
+ artifact.uri,
864
+ artifact.label,
865
+ artifact.projectRoot ?? null,
866
+ artifact.meta !== void 0 ? JSON.stringify(artifact.meta) : null,
867
+ artifact.createdAt,
868
+ artifact.updatedAt
869
+ );
870
+ stored = artifact;
871
+ });
872
+ return stored;
873
+ },
874
+ async listArtifacts(filter) {
875
+ const conditions = [];
876
+ const params = [];
877
+ if (filter?.sessionId !== void 0) {
878
+ conditions.push("session_id = ?");
879
+ params.push(filter.sessionId);
880
+ }
881
+ if (filter?.kind !== void 0) {
882
+ conditions.push("kind = ?");
883
+ params.push(filter.kind);
884
+ }
885
+ if (filter?.uri !== void 0) {
886
+ conditions.push("uri = ?");
887
+ params.push(filter.uri);
888
+ }
889
+ if (filter && "projectRoot" in filter) {
890
+ if (filter.projectRoot === null) conditions.push("project_root IS NULL");
891
+ else if (typeof filter.projectRoot === "string") {
892
+ conditions.push("project_root = ?");
893
+ params.push(filter.projectRoot);
894
+ }
895
+ }
896
+ if (typeof filter?.since === "number") {
897
+ conditions.push("updated_at >= ?");
898
+ params.push(filter.since);
899
+ }
900
+ const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
901
+ const limit = typeof filter?.limit === "number" && filter.limit > 0 ? `LIMIT ${filter.limit}` : "";
902
+ const rows = database.prepare(
903
+ `SELECT ${ARTIFACT_COLUMNS} FROM artifacts ${where} ORDER BY updated_at DESC, created_at DESC, id ${limit}`.replace(/\s+/g, " ").trim()
904
+ ).all(...params);
905
+ return rows.map(rowToArtifact);
906
+ },
907
+ async deleteArtifact(sessionId, artifactId) {
908
+ database.prepare("DELETE FROM artifacts WHERE session_id = ? AND id = ?").run(sessionId, artifactId);
810
909
  }
811
910
  };
812
911
  return store;
813
912
  }
913
+ const ARTIFACT_COLUMNS = "id, session_id, run_id, turn_id, kind, uri, label, project_root, meta, created_at, updated_at";
914
+ function rowToArtifact(r) {
915
+ let meta;
916
+ if (r.meta) {
917
+ try {
918
+ meta = JSON.parse(r.meta);
919
+ } catch {
920
+ meta = void 0;
921
+ }
922
+ }
923
+ return {
924
+ id: r.id,
925
+ sessionId: r.session_id,
926
+ ...r.run_id ? { runId: r.run_id } : {},
927
+ ...r.turn_id ? { turnId: r.turn_id } : {},
928
+ kind: r.kind,
929
+ uri: r.uri,
930
+ label: r.label,
931
+ ...r.project_root ? { projectRoot: r.project_root } : {},
932
+ ...meta !== void 0 ? { meta } : {},
933
+ createdAt: r.created_at,
934
+ updatedAt: r.updated_at
935
+ };
936
+ }
814
937
  function patchSessionMetadata(id, patch, opts = {}) {
815
938
  const database = openDb();
816
939
  const header = database.prepare("SELECT metadata FROM sessions WHERE id = ?").get(id);
@@ -2109,6 +2232,7 @@ function broadcast(signal) {
2109
2232
  case "cache:break":
2110
2233
  case "system-md":
2111
2234
  case "compacting:progress":
2235
+ case "stream:progress":
2112
2236
  case "stream:retry:cleared":
2113
2237
  case "prompt-turns":
2114
2238
  // GUI-local: main-side extension registry invalidation push.
@@ -2392,8 +2516,8 @@ async function deleteArtifact(sessionId, artifactId) {
2392
2516
  broadcast({ kind: "artifact:changed", sessionId, op: "delete", artifactId });
2393
2517
  return true;
2394
2518
  }
2395
- async function refreshSessionArtifact(artifact) {
2396
- const updated = await refreshArtifact(artifact);
2519
+ async function refreshSessionArtifact(artifact, opts) {
2520
+ const updated = await refreshArtifact(artifact, void 0, opts);
2397
2521
  if (!updated) {
2398
2522
  return null;
2399
2523
  }
@@ -2406,7 +2530,10 @@ async function refreshSessionArtifact(artifact) {
2406
2530
  }
2407
2531
  }
2408
2532
  const store2 = getSessionStore();
2409
- const stored = await store2.upsertArtifact?.(updated) ?? updated;
2533
+ const stored = await store2.upsertArtifact?.(updated) ?? null;
2534
+ if (!stored) {
2535
+ return null;
2536
+ }
2410
2537
  broadcast({
2411
2538
  kind: "artifact:changed",
2412
2539
  sessionId: stored.sessionId,
@@ -3625,6 +3752,22 @@ function registerChatIpc() {
3625
3752
  return sendPrompt(opts);
3626
3753
  });
3627
3754
  ipcMain.handle("chat:interrupt", (_e, sessionId) => interruptChat(sessionId));
3755
+ ipcMain.handle("system:revealPath", async (_e, raw) => {
3756
+ const path = typeof raw === "string" ? raw.replace(/^file:\/\//, "") : "";
3757
+ if (!isAbsolute(path)) return false;
3758
+ let stat$1;
3759
+ try {
3760
+ stat$1 = await stat(path);
3761
+ } catch {
3762
+ return false;
3763
+ }
3764
+ if (stat$1.isDirectory()) {
3765
+ const err = await shell.openPath(path);
3766
+ return err === "";
3767
+ }
3768
+ shell.showItemInFolder(path);
3769
+ return true;
3770
+ });
3628
3771
  ipcMain.handle("shell:run", async (_e, sessionId, command) => {
3629
3772
  const store2 = getSessionStore();
3630
3773
  const data = await store2.load(sessionId);
@@ -3710,13 +3853,16 @@ function registerChatIpc() {
3710
3853
  "artifacts:delete",
3711
3854
  (_e, sessionId, artifactId) => deleteArtifact(String(sessionId), String(artifactId))
3712
3855
  );
3713
- ipcMain.handle("artifacts:refresh", async (_e, artifact) => {
3714
- const updated = await refreshSessionArtifact(artifact);
3715
- if (!updated) {
3716
- return null;
3856
+ ipcMain.handle(
3857
+ "artifacts:refresh",
3858
+ async (_e, artifact, opts) => {
3859
+ const updated = await refreshSessionArtifact(artifact, opts?.force ? { force: true } : void 0);
3860
+ if (!updated) {
3861
+ return null;
3862
+ }
3863
+ return { artifact: updated, row: renderArtifactRow(updated) };
3717
3864
  }
3718
- return { artifact: updated, row: renderArtifactRow(updated) };
3719
- });
3865
+ );
3720
3866
  ipcMain.handle("todos:get", async (_e, sessionId) => {
3721
3867
  const state = await getTodosSnapshot(sessionId);
3722
3868
  if (!state) {
@@ -4309,12 +4455,14 @@ function createWindow() {
4309
4455
  if (process.platform === "darwin" && !icon.isEmpty()) {
4310
4456
  app.dock?.setIcon(icon);
4311
4457
  }
4458
+ const titleSuffix = app.isPackaged ? "" : " (dev)";
4459
+ const withSuffix = (title) => title.endsWith(titleSuffix) ? title : `${title}${titleSuffix}`;
4312
4460
  const win = new BrowserWindow({
4313
4461
  width: 1200,
4314
4462
  height: 800,
4315
4463
  show: false,
4316
4464
  autoHideMenuBar: true,
4317
- title: "Zidane",
4465
+ title: withSuffix("Zidane"),
4318
4466
  backgroundColor: "#0f0f10",
4319
4467
  icon: icon.isEmpty() ? void 0 : icon,
4320
4468
  /**
@@ -4354,6 +4502,12 @@ function createWindow() {
4354
4502
  }
4355
4503
  return { action: "deny" };
4356
4504
  });
4505
+ if (titleSuffix) {
4506
+ win.on("page-title-updated", (event, title) => {
4507
+ event.preventDefault();
4508
+ win.setTitle(withSuffix(title));
4509
+ });
4510
+ }
4357
4511
  if (process.env.ELECTRON_RENDERER_URL) {
4358
4512
  win.loadURL(process.env.ELECTRON_RENDERER_URL);
4359
4513
  } else {
@@ -95,6 +95,9 @@ const api = {
95
95
  searchSession: (sessionId, query, limit) => ipcRenderer.invoke("history:searchSession", sessionId, query, limit),
96
96
  searchAll: (query, sessionIds, excerptLimit) => ipcRenderer.invoke("history:searchAll", query, sessionIds, excerptLimit)
97
97
  },
98
+ system: {
99
+ revealPath: (path) => ipcRenderer.invoke("system:revealPath", path)
100
+ },
98
101
  shell: {
99
102
  run: (sessionId, command) => ipcRenderer.invoke("shell:run", sessionId, command),
100
103
  cancel: (sessionId, runId) => ipcRenderer.invoke("shell:cancel", sessionId, runId)
@@ -106,7 +109,7 @@ const api = {
106
109
  artifacts: {
107
110
  list: (query) => ipcRenderer.invoke("artifacts:list", query),
108
111
  delete: (sessionId, artifactId) => ipcRenderer.invoke("artifacts:delete", sessionId, artifactId),
109
- refresh: (artifact) => ipcRenderer.invoke("artifacts:refresh", artifact)
112
+ refresh: (artifact, opts) => ipcRenderer.invoke("artifacts:refresh", artifact, opts)
110
113
  },
111
114
  providerUsage: {
112
115
  fetchAll: (cwd, opts) => ipcRenderer.invoke("usage:fetchAll", cwd, opts),