aegiscode 7.0.33 → 7.0.35

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.
@@ -756,6 +756,7 @@ function watchTopupCredit(aegis, opts) {
756
756
  */
757
757
  let memoryIndexHandle = null;
758
758
  let memoryIndexOff = false;
759
+ let memoryIndexTries = 0;
759
760
  function memoryIndex(dir) {
760
761
  if (memoryIndexHandle) return memoryIndexHandle;
761
762
  if (memoryIndexOff || !dir) return null;
@@ -763,13 +764,19 @@ function memoryIndex(dir) {
763
764
  const store = new memoryStore.MemoryStore({ dir });
764
765
  const opened = store.open();
765
766
  if (!opened.ok) {
766
- memoryIndexOff = true;
767
+ // `node:sqlite` missing is permanent, so latch on sight. Anything else
768
+ // (EACCES on the dir, EBUSY, a corrupt file) may be transient and must
769
+ // not kill indexing for the whole process — but search runs on every
770
+ // keystroke, so stop attempting a doomed open after a few rather than
771
+ // retrying it per character.
772
+ if (!memoryStore.isAvailable() || ++memoryIndexTries >= 3) memoryIndexOff = true;
767
773
  return null;
768
774
  }
775
+ memoryIndexTries = 0;
769
776
  memoryIndexHandle = store;
770
777
  return memoryIndexHandle;
771
778
  } catch {
772
- memoryIndexOff = true;
779
+ if (!memoryStore.isAvailable() || ++memoryIndexTries >= 3) memoryIndexOff = true;
773
780
  return null;
774
781
  }
775
782
  }
@@ -2711,26 +2718,78 @@ function createSyncDispatch(sessions, dir, aegis, settingsDir, modelDispatch) {
2711
2718
  auto: () => autoPush.auto(),
2712
2719
  memoryPersistState: () => autoPush.gate(),
2713
2720
  listSessions: () => ({ sessions: sessions.listSessions(dir) }),
2714
- // The SESSION search the menu's "Search sessions…" (Cmd/Ctrl+K) runs. It
2715
- // lives here, not in the renderer, for the same reason the list does: the
2716
- // store is a main-process file, and `listSessions()` truncates — it returns
2717
- // title/messages/updatedAt, so a renderer-side filter would be a second,
2718
- // weaker copy of the same read. `searchSessions` takes the query and returns
2719
- // the ranked matches plus WHICH field matched, so the row can say why it is
2720
- // in the list. An empty query returns the newest N unchanged, so the sheet
2721
- // opens on something instead of a blank pane.
2721
+ // The ONE search the menu's "Search" (Cmd/Ctrl+K) runs — sessions AND
2722
+ // memory under a single query box.
2722
2723
  //
2723
- // The ranking is `client/session-search.js` — the same module the CLI's
2724
- // /resume picker filters with, so the two faces cannot order the same
2725
- // conversation differently.
2724
+ // It used to be two sheets on two accelerators: Cmd/Ctrl+K searched
2725
+ // sessions, Cmd/Ctrl+Shift+K opened the memory inspector. Same verb, two
2726
+ // surfaces, and neither could answer "I know I wrote this down somewhere".
2727
+ // This channel now returns both stores in one payload so the renderer can
2728
+ // paint one list; the inspector keeps its own door in the Memory pane.
2729
+ //
2730
+ // Why the ranking is HERE and not in the renderer: both stores are
2731
+ // main-process files (sessions.json, memory.db), and `listSessions()`
2732
+ // truncates — it returns title/messages/updatedAt — so a renderer-side
2733
+ // filter would be a second, weaker copy of the same read.
2734
+ //
2735
+ // The session ranking is `client/session-search.js`, the same module the
2736
+ // CLI's /resume picker filters with, so the two faces cannot order the same
2737
+ // conversation differently. Memory ranks through `memory-store.js`'s own
2738
+ // `search()`, which is FTS5 when the build has it — its tiers are not
2739
+ // comparable to the session tiers, which is exactly why the sheet draws the
2740
+ // two groups as SECTIONS with a flat cursor order rather than one
2741
+ // cross-type column.
2742
+ //
2743
+ // An empty query returns the newest N of each, so the sheet opens on
2744
+ // something instead of a blank pane.
2726
2745
  searchSessions: (payload) => {
2727
2746
  const query = payload && typeof payload.query === 'string' ? payload.query : '';
2728
2747
  const limit = Number.isInteger(payload && payload.limit) ? payload.limit : 50;
2748
+ const cap = Math.max(1, limit);
2729
2749
  const all = sessions.listSessions(dir) || [];
2730
- const ranked = sessionSearch.rankSessions(query, all).slice(0, Math.max(1, limit));
2750
+ const ranked = sessionSearch.rankSessions(query, all).slice(0, cap);
2751
+ // Memory is READ-ONLY here: `search()` is a local index read, never a
2752
+ // cloud round trip, so a keystroke cannot cost the user a metered call.
2753
+ // An unavailable index (no SQLite in this build) is an empty section, not
2754
+ // an error — a search that still works for sessions beats one that fails
2755
+ // because the other store is missing.
2756
+ let memory = [];
2757
+ let memoryTotal = 0;
2758
+ // `ok` | `unavailable` (no SQLite in this build) | `error` (index exists
2759
+ // but could not be read). The renderer must tell these apart: reporting
2760
+ // "0 memories" would claim the store is empty when the truth is that it
2761
+ // was never searched.
2762
+ let memoryStatus = 'ok';
2763
+ try {
2764
+ const index = memoryIndex(dir);
2765
+ if (index) {
2766
+ const found = index.search(query, { limit: cap });
2767
+ if (found && found.ok) {
2768
+ memory = (found.results || []).map((r) => ({
2769
+ id: r.id,
2770
+ content: r.body || '',
2771
+ scope: r.scope || '',
2772
+ tags: Array.isArray(r.tags) ? r.tags : [],
2773
+ updated: r.updated || null,
2774
+ }));
2775
+ memoryTotal = index.count();
2776
+ } else {
2777
+ memoryStatus = 'error';
2778
+ }
2779
+ } else {
2780
+ memoryStatus = memoryStore.isAvailable() && dir ? 'error' : 'unavailable';
2781
+ }
2782
+ } catch {
2783
+ memory = [];
2784
+ memoryTotal = 0;
2785
+ memoryStatus = 'error';
2786
+ }
2731
2787
  return {
2732
2788
  query,
2733
2789
  total: all.length,
2790
+ memoryStatus,
2791
+ memoryTotal,
2792
+ memory,
2734
2793
  sessions: ranked.map((s) => ({
2735
2794
  id: s && s.id,
2736
2795
  title: (s && s.title) || (s && s.id) || 'untitled',
@@ -2756,6 +2815,20 @@ function createSyncDispatch(sessions, dir, aegis, settingsDir, modelDispatch) {
2756
2815
  ),
2757
2816
  delete: (payload) =>
2758
2817
  sessions.deleteSession(dir, payload && payload.sessionId),
2818
+ // Rename a thread by hand (the library pane's Rename button).
2819
+ //
2820
+ // `renameSession`, not `setTitle`: lib/sync/sessions.js explains at length
2821
+ // why the shared store's `setTitle` is deliberately NOT re-exported under
2822
+ // that name (client/naming.js duck-checks it to decide whether to spend a
2823
+ // model round). The write it performs is the same one, marked `named` so
2824
+ // no later naming round can overwrite a name the user typed. An empty
2825
+ // title is refused rather than written — blanking a name is not a rename.
2826
+ rename: (payload) =>
2827
+ sessions.renameSession(
2828
+ dir,
2829
+ payload && payload.sessionId,
2830
+ payload && payload.title
2831
+ ),
2759
2832
  // The naming ladder (client/naming.js), run in the MAIN process.
2760
2833
  //
2761
2834
  // The window used to name a thread `prompt.slice(0, 60)` — in the renderer,
@@ -2794,7 +2867,15 @@ function createSyncDispatch(sessions, dir, aegis, settingsDir, modelDispatch) {
2794
2867
  prompt: text,
2795
2868
  system: opts.system,
2796
2869
  maxTokens: 64,
2797
- sessionId,
2870
+ // NOT the turn's `sessionId`. The engine keys its cancel registry
2871
+ // by that id (lib/local/engine.js `controllers`), and the desktop
2872
+ // reuses the conversation id for the turn it is streaming — so a
2873
+ // naming round sharing it fought the live turn for the Stop
2874
+ // button. The engine now refuses to lose the turn's controller
2875
+ // either way, but a decoration should not be claiming the turn's
2876
+ // identity in the first place: approvals, round counts and
2877
+ // cancellation all hang off this id, and naming is none of them.
2878
+ sessionId: `${sessionId}:naming`,
2798
2879
  // `tools: false` is the engine's own opt-out (a naming round must
2799
2880
  // not run the agent loop); nothing else here is a wire field.
2800
2881
  tools: false,
@@ -2805,8 +2886,20 @@ function createSyncDispatch(sessions, dir, aegis, settingsDir, modelDispatch) {
2805
2886
  return null;
2806
2887
  }
2807
2888
  };
2889
+ // `sessions.namingStore`, not `sessions`: the binding deliberately does
2890
+ // not carry a bare `setTitle`, because naming.js arms itself on that
2891
+ // name and an incidental re-export would turn a model round per
2892
+ // conversation on invisibly (see lib/sync/sessions.js). Passing the
2893
+ // adapter is what arms it, here, on purpose — this ladder was dead for
2894
+ // as long as the binding was handed over directly.
2808
2895
  try {
2809
- return await namingLib.nameSession(sessions, dir, sessionId, prompt, { callModel });
2896
+ return await namingLib.nameSession(
2897
+ sessions.namingStore,
2898
+ dir,
2899
+ sessionId,
2900
+ prompt,
2901
+ { callModel }
2902
+ );
2810
2903
  } catch {
2811
2904
  return null;
2812
2905
  }
@@ -4221,8 +4314,7 @@ function sendDeepLinkToWindow(win, parsed) {
4221
4314
 
4222
4315
  /** Application menu: the platform defaults (Edit roles, mac's app/quit
4223
4316
  * items) plus the native-shell accelerators this plan adds — New Chat
4224
- * (Cmd/Ctrl+N), Search sessions… (Cmd/Ctrl+K), Search memory…
4225
- * (Cmd/Ctrl+Shift+K), Reload (Cmd/Ctrl+R) and Toggle DevTools
4317
+ * (Cmd/Ctrl+N), Search (Cmd/Ctrl+K), Reload (Cmd/Ctrl+R) and Toggle DevTools
4226
4318
  * (Cmd/Ctrl+Shift+I) are plain Electron roles that already carry the right
4227
4319
  * accelerator on every platform — plus a manual "Check for Updates…" entry,
4228
4320
  * since the automatic checks in createUpdateManager.start() only run on ready
@@ -4234,8 +4326,9 @@ function sendDeepLinkToWindow(win, parsed) {
4234
4326
  *
4235
4327
  * * Cmd/Ctrl+K opened the MEMORY inspector while the item said "Search…", so
4236
4328
  * the label named neither the sheet nor the thing the user wanted. The
4237
- * chord now goes to a real session search (client/session-search.js); the
4238
- * inspector keeps its own item on its own chord instead of sharing one.
4329
+ * chord now goes to one search over sessions AND memory (sessions ranked by
4330
+ * client/session-search.js, memory by memory-store.js), and the two are
4331
+ * drawn as sections of a single list rather than as two sheets.
4239
4332
  * * There was no licence surface anywhere in the app. `Help` is now on every
4240
4333
  * platform and leads with Credits & Licence, which renders
4241
4334
  * client/credits.js — the licence, the program notice and every vendored
@@ -4270,25 +4363,33 @@ function buildAppMenu({ app, Menu, BrowserWindow, updateManager, loggedIn }) {
4270
4363
  accelerator: 'CmdOrCtrl+N',
4271
4364
  click: () => sendToAppWindow(BrowserWindow, MENU_NEW_CHAT_CHANNEL),
4272
4365
  };
4273
- // View > Search sessions… (Cmd/Ctrl+K).
4366
+ // View > Search (Cmd/Ctrl+K).
4274
4367
  //
4275
- // This item used to be labelled `Search…` and opened the MEMORY inspector — the
4276
- // accelerator, the label and the sheet disagreed about what they were for, and
4277
- // nothing in the app searched conversations at all. A session search is now a
4278
- // thing that exists (renderer/openSessionSearch in app.js, ranked by
4279
- // client/session-search.js), so the plain accelerator goes to the thing the
4280
- // label promises; the inspector keeps a menu item of its own below.
4368
+ // Two corrections live in this item's history. It once said `Search…` and
4369
+ // opened the MEMORY inspector, so the accelerator, the label and the sheet
4370
+ // disagreed. It then said `Search sessions…` and searched only conversations,
4371
+ // while memory kept a parallel sheet on Cmd/Ctrl+Shift+K — one verb, two
4372
+ // surfaces, and no way to answer "I know I wrote this down somewhere".
4373
+ // It is now one sheet over both stores (see `searchSessions` above), so the
4374
+ // label promises exactly what the sheet does and stops naming one store.
4281
4375
  const searchItem = {
4282
- label: 'Search sessions…',
4376
+ label: 'Search',
4283
4377
  accelerator: 'CmdOrCtrl+K',
4284
4378
  click: () => sendToAppWindow(BrowserWindow, MENU_SEARCH_CHANNEL),
4285
4379
  };
4286
- // View > Search memory… — the inspector that Cmd/Ctrl+K used to open. Shift
4287
- // because the plain chord is the session search now; the two are separate
4288
- // sheets, so they cannot share a keystroke.
4380
+ // Cmd/Ctrl+Shift+K still opens the same sheet, pre-scoped to memory — the
4381
+ // chord people already learned keeps working, and it lands them in the one
4382
+ // search rather than a second one.
4383
+ //
4384
+ // `visible: false` is deliberate. Electron registers the accelerator of a
4385
+ // hidden item, so the key survives; what goes away is the MENU ROW that
4386
+ // advertised a separate memory search. Removing the item entirely would have
4387
+ // silently killed a chord users have muscle memory for; leaving it visible
4388
+ // would keep advertising the split this change exists to remove.
4289
4389
  const searchMemoryItem = {
4290
- label: 'Search memory…',
4390
+ label: 'Search memory',
4291
4391
  accelerator: 'CmdOrCtrl+Shift+K',
4392
+ visible: false,
4292
4393
  click: () => sendToAppWindow(BrowserWindow, MENU_SEARCH_MEMORY_CHANNEL),
4293
4394
  };
4294
4395
  // Help > Credits & licence — the AGPL licence, the program notice, and every