aegis-desktop 1.0.5 → 1.0.6

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.
@@ -55,4 +55,9 @@ function createAccountKey({ aegis, credentials, persistKey, provision, onChange
55
55
  return { status, recordStartup, registerAccount };
56
56
  }
57
57
 
58
- module.exports = { createAccountKey, provisionFailureText };
58
+ // A key this host saved on purpose outranks one minted for a fresh device at startup.
59
+ function startupKeyOverride({ mintedKey, hostKey }) {
60
+ return mintedKey && hostKey && hostKey !== mintedKey ? hostKey : null;
61
+ }
62
+
63
+ module.exports = { createAccountKey, provisionFailureText, startupKeyOverride };
package/main.js CHANGED
@@ -152,7 +152,7 @@ try {
152
152
  // backed by transport-only modules in desktop/lib/. No brain logic enters here.
153
153
  const os = require('node:os');
154
154
  const { createLocalEngine } = require('./lib/local/engine.js');
155
- const { createAccountKey } = require('./lib/account-key.js');
155
+ const { createAccountKey, startupKeyOverride } = require('./lib/account-key.js');
156
156
  const { createSettingsStore, isReservedNamespace } = require('./lib/settings.js');
157
157
  const sessionStore = require('./lib/sync/sessions.js');
158
158
  const memoryQueue = require('./lib/sync/memory-queue.js');
@@ -3333,6 +3333,7 @@ function bootstrap() {
3333
3333
  provision: autoProvision.autoProvisionApiKey,
3334
3334
  onChange: (state) => broadcastAccountStatus(state),
3335
3335
  });
3336
+ const keyPresentAtStart = Boolean(aegis.apiKey);
3336
3337
  const earlyKeyProvision = autoProvision.autoProvisionApiKey(aegis, credentials).then((result) => {
3337
3338
  accountKey.recordStartup(result);
3338
3339
  if (!result.key && !aegis.apiKey) {
@@ -3910,13 +3911,25 @@ function bootstrap() {
3910
3911
  // registration attempt, and earlyKeyProvision's own .then() already
3911
3912
  // warns on failure, so there is nothing further to report if it
3912
3913
  // didn't land.
3913
- await earlyKeyProvision;
3914
- const chosen = credentials.preferNewest(settings.aegisRawKey(), settings.aegisKeySavedAt());
3915
- if (chosen.key) {
3916
- aegis.setApiKey(chosen.key);
3917
- // The shared store is the newer write: bring this host's encrypted copy
3918
- // up to date so a CLI rotation does not have to be redone in Settings.
3919
- if (chosen.source === 'shared') settings.setAegisKey(chosen.key);
3914
+ const early = await earlyKeyProvision;
3915
+ // A key minted just now only means "no key was saved yet" — a key the user
3916
+ // saved in Settings before the shared store mirrored it would otherwise be
3917
+ // overwritten by the device's fresh account on this first start.
3918
+ const override = startupKeyOverride({
3919
+ mintedKey: keyPresentAtStart ? '' : early.key,
3920
+ hostKey: credentials.normalizeApiKey(settings.aegisRawKey()),
3921
+ });
3922
+ if (override) {
3923
+ credentials.saveApiKey(override);
3924
+ aegis.setApiKey(override);
3925
+ } else {
3926
+ const chosen = credentials.preferNewest(settings.aegisRawKey(), settings.aegisKeySavedAt());
3927
+ if (chosen.key) {
3928
+ aegis.setApiKey(chosen.key);
3929
+ // The shared store is the newer write: bring this host's encrypted copy
3930
+ // up to date so a CLI rotation does not have to be redone in Settings.
3931
+ if (chosen.source === 'shared') settings.setAegisKey(chosen.key);
3932
+ }
3920
3933
  }
3921
3934
  }
3922
3935
  // ── presence beacon ───────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegis-desktop",
3
3
  "productName": "AEGIS Desktop",
4
- "version": "1.0.5",
4
+ "version": "1.0.6",
5
5
  "description": "Thin Electron host for AEGIS — a local chat UI over the shared client/aegis.js transport. Ships transport + UI only; engine logic stays server-side.",
6
6
  "author": {
7
7
  "name": "AEGIS Code",