aegiscode 6.8.30 → 6.8.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/README.md +2 -2
- package/bin/aegiscode.js +31 -0
- package/package.json +1 -1
- package/scripts/predist.mjs +32 -328
- package/src/app.js +30 -0
- package/src/commands.js +95 -0
- package/src/config.js +148 -11
- package/src/permissions.js +92 -0
- package/src/shared.js +5 -1
- package/src/topup.js +207 -0
- package/vendor/client/platform.js +7 -0
- package/vendor/client/prefs.js +318 -0
- package/vendor/client/topup.js +294 -0
- package/vendor/client/update.js +141 -3
- package/vendor/desktop/lib/local/context.js +92 -0
- package/vendor/desktop/lib/local/engine.js +13 -0
- package/vendor/desktop/lib/local/local.js +1410 -46
- package/vendor/desktop/lib/settings.js +141 -14
|
@@ -13,12 +13,52 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Pure Node + injectable storage dir / safeStorage so it unit-tests without
|
|
15
15
|
* an Electron binary.
|
|
16
|
+
*
|
|
17
|
+
* AEGISONE D5 splits this store in two, along the line the repo already drew
|
|
18
|
+
* for sessions and credentials:
|
|
19
|
+
*
|
|
20
|
+
* <userData>/settings.json HOST-LOCAL — provider rows and the AEGIS key
|
|
21
|
+
* (`safeStorage` blobs a plain Node process
|
|
22
|
+
* cannot decrypt on Linux), plus machine/UI
|
|
23
|
+
* state. `SETTINGS_FILE`, below.
|
|
24
|
+
* $AEGISCODE_HOME/preferences.json SHARED, NON-SECRET — the preferences both
|
|
25
|
+
* faces must agree about. Owned by
|
|
26
|
+
* `client/prefs.js`; `sharedDir` (an
|
|
27
|
+
* injectable seam, defaulting to
|
|
28
|
+
* `credentials.aegisHome()`) locates it.
|
|
29
|
+
*
|
|
30
|
+
* So `getSharedPref`/`setSharedPref` and the memory-persist preference read and
|
|
31
|
+
* write the SHARED file, a legacy `<userData>` `__memoryPersist` namespace is
|
|
32
|
+
* adopted once and then only read as a fallback, and everything key-bearing
|
|
33
|
+
* stays here in `<userData>`. The shared store refuses key material outright
|
|
34
|
+
* (`client/prefs.js` `assertNoSecrets`), which is what keeps the split honest.
|
|
16
35
|
*/
|
|
17
36
|
|
|
18
37
|
const fs = require('node:fs');
|
|
19
38
|
const path = require('node:path');
|
|
20
39
|
const { execFileSync } = require('node:child_process');
|
|
21
40
|
|
|
41
|
+
// The shared, non-secret preference store (AEGISONE D5) and the data-dir
|
|
42
|
+
// helper, resolved the same two ways lib/sync/sessions.js resolves the other
|
|
43
|
+
// cross-host modules: in-repo `<repo>/client/*.js`, packaged
|
|
44
|
+
// `desktop/vendor/*.js`. A missing module is a loud error rather than a second
|
|
45
|
+
// implementation — the drift this arrangement exists to prevent.
|
|
46
|
+
const prefs = (() => {
|
|
47
|
+
try {
|
|
48
|
+
return require('../../client/prefs.js');
|
|
49
|
+
} catch {
|
|
50
|
+
return require('../vendor/prefs.js');
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
53
|
+
|
|
54
|
+
const credentials = (() => {
|
|
55
|
+
try {
|
|
56
|
+
return require('../../client/credentials.js');
|
|
57
|
+
} catch {
|
|
58
|
+
return require('../vendor/credentials.js');
|
|
59
|
+
}
|
|
60
|
+
})();
|
|
61
|
+
|
|
22
62
|
// The local-model transport. Required for ONE function: `remoteRefusal`, the
|
|
23
63
|
// fail-closed check that keeps a non-local base URL out of the `local` row. The
|
|
24
64
|
// module owns that policy so this store, the engine and the CLI cannot drift
|
|
@@ -207,10 +247,68 @@ function restrictFile(file) {
|
|
|
207
247
|
}
|
|
208
248
|
}
|
|
209
249
|
|
|
210
|
-
function createSettingsStore({ dir, safeStorage } = {}) {
|
|
250
|
+
function createSettingsStore({ dir, safeStorage, prefsDir, env } = {}) {
|
|
211
251
|
if (!dir) throw new Error('createSettingsStore requires a storage dir');
|
|
212
252
|
const file = path.join(dir, SETTINGS_FILE);
|
|
213
253
|
|
|
254
|
+
// --- the shared, non-secret preference store (AEGISONE D5) --------------
|
|
255
|
+
//
|
|
256
|
+
// `prefsDir` is the injectable seam (tests point it at a temp dir); the
|
|
257
|
+
// default is the same `$AEGISCODE_HOME` / `~/.aegiscode` directory the
|
|
258
|
+
// session store and the credential store already use, so an install has one
|
|
259
|
+
// answer to "where does this host keep its data".
|
|
260
|
+
const sharedDir = (() => {
|
|
261
|
+
const explicit = prefsDir === undefined || prefsDir === null ? '' : String(prefsDir).trim();
|
|
262
|
+
return explicit ? path.resolve(explicit) : credentials.aegisHome(env);
|
|
263
|
+
})();
|
|
264
|
+
|
|
265
|
+
// One-way, once, idempotent adoption of a pre-D5 `<userData>/settings.json`
|
|
266
|
+
// non-secret half (D5, step 2): an existing user's preference survives the
|
|
267
|
+
// upgrade. Best-effort — a store must still open when the legacy file is
|
|
268
|
+
// unreadable or the shared dir is unwritable.
|
|
269
|
+
const adoption = (() => {
|
|
270
|
+
try {
|
|
271
|
+
return prefs.adopt({ dir: sharedDir, legacyDir: dir });
|
|
272
|
+
} catch (err) {
|
|
273
|
+
return { adopted: false, keys: [], reason: `adoption failed: ${err.message}` };
|
|
274
|
+
}
|
|
275
|
+
})();
|
|
276
|
+
|
|
277
|
+
/** The shared preference file this store reads and writes (never a secret). */
|
|
278
|
+
function sharedFile() {
|
|
279
|
+
return prefs.prefsFile({ dir: sharedDir });
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function loadShared() {
|
|
283
|
+
try {
|
|
284
|
+
return prefs.load({ dir: sharedDir });
|
|
285
|
+
} catch {
|
|
286
|
+
return {};
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* One shared preference, as the CLI's `config.js` stores it. Restricted to
|
|
292
|
+
* `SHARED_PREF_KEYS` — the window may read exactly the preferences the shell
|
|
293
|
+
* owns, not reach into arbitrary state in a file another host reads.
|
|
294
|
+
*/
|
|
295
|
+
function getSharedPref(key) {
|
|
296
|
+
if (!prefs.SHARED_PREF_KEYS.includes(key)) {
|
|
297
|
+
throw new Error(`"${key}" is not a shared preference (see client/prefs.js SHARED_PREF_KEYS)`);
|
|
298
|
+
}
|
|
299
|
+
const value = loadShared()[key];
|
|
300
|
+
return value === undefined ? null : value;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Write one shared preference. Key material is refused by the store itself. */
|
|
304
|
+
function setSharedPref(key, value) {
|
|
305
|
+
if (!prefs.SHARED_PREF_KEYS.includes(key)) {
|
|
306
|
+
throw new Error(`"${key}" is not a shared preference (see client/prefs.js SHARED_PREF_KEYS)`);
|
|
307
|
+
}
|
|
308
|
+
prefs.set({ [key]: value }, { dir: sharedDir });
|
|
309
|
+
return getSharedPref(key);
|
|
310
|
+
}
|
|
311
|
+
|
|
214
312
|
const safeAvailable = () =>
|
|
215
313
|
Boolean(
|
|
216
314
|
safeStorage &&
|
|
@@ -297,13 +395,21 @@ function createSettingsStore({ dir, safeStorage } = {}) {
|
|
|
297
395
|
*/
|
|
298
396
|
function set(provider, { baseURL, key } = {}) {
|
|
299
397
|
assertNotReserved(provider);
|
|
398
|
+
let nextBaseURL = baseURL;
|
|
300
399
|
if (provider === LOCAL_NAMESPACE && baseURL) {
|
|
301
400
|
const refusal = localTransport.remoteRefusal(baseURL);
|
|
302
401
|
if (refusal) throw refusal;
|
|
402
|
+
// Persist the DIALABLE spelling, not the typed one: `localhost:11434` is
|
|
403
|
+
// how a user writes the address, and `http://localhost:11434` is what the
|
|
404
|
+
// probe and the chat call must dial (local.js `normalizeBase`, whose
|
|
405
|
+
// header explains why a scheme-less string is the common case rather than
|
|
406
|
+
// an edge one). Storing the raw form left every consumer to normalize for
|
|
407
|
+
// itself — and a consumer that forgot read the URL as a remote host.
|
|
408
|
+
nextBaseURL = localTransport.normalizeBase(baseURL);
|
|
303
409
|
}
|
|
304
410
|
const data = load();
|
|
305
411
|
const cfg = data[provider] || {};
|
|
306
|
-
if (
|
|
412
|
+
if (nextBaseURL !== undefined) cfg.baseURL = nextBaseURL;
|
|
307
413
|
if (key !== undefined) cfg.key = key ? encrypt(key) : null;
|
|
308
414
|
data[provider] = cfg;
|
|
309
415
|
save(data);
|
|
@@ -463,33 +569,49 @@ function createSettingsStore({ dir, safeStorage } = {}) {
|
|
|
463
569
|
return getTelemetryOptIn();
|
|
464
570
|
}
|
|
465
571
|
|
|
466
|
-
// --- Persisting memory:
|
|
572
|
+
// --- Persisting memory: SHARED preference (AEGISONE D5) -----------------
|
|
467
573
|
// The desktop's half of "persisting memory for every account": whether a
|
|
468
574
|
// finished turn is pushed to cloud memory automatically. ON when unset —
|
|
469
575
|
// an install that never touched the toggle behaves like cli/, whose
|
|
470
576
|
// `memoryPersist` also defaults to on. `memoryPersistState()` reports the
|
|
471
|
-
// SOURCE as well as the value so "off" and "never set" stay distinguishable
|
|
472
|
-
//
|
|
473
|
-
// the
|
|
577
|
+
// SOURCE as well as the value so "off" and "never set" stay distinguishable.
|
|
578
|
+
//
|
|
579
|
+
// This preference is the seam D5 closes: it lives in the SHARED store under
|
|
580
|
+
// the shell's own key (`memoryPersist`), so `/cloud memory off` in the
|
|
581
|
+
// terminal and the Settings toggle in the window are one value, not two that
|
|
582
|
+
// can disagree. The pre-D5 `__memoryPersist` namespace in `<userData>` is
|
|
583
|
+
// adopted once (above) and still read as a fallback, never written — a second
|
|
584
|
+
// writer is exactly the split-brain this replaced. lib/sync/persist-gate.js
|
|
585
|
+
// reads the same shared key straight off disk, in the main process, and the
|
|
586
|
+
// two must agree on the default.
|
|
474
587
|
|
|
475
588
|
function getMemoryPersist() {
|
|
476
|
-
|
|
477
|
-
return cfg.enabled === undefined ? true : Boolean(cfg.enabled);
|
|
589
|
+
return memoryPersistState().enabled;
|
|
478
590
|
}
|
|
479
591
|
|
|
480
592
|
/** `{ enabled, source }` — mirrors cli/src/cloudsync.js memoryPersistState(). */
|
|
481
593
|
function memoryPersistState() {
|
|
594
|
+
const shared = loadShared();
|
|
595
|
+
if (typeof shared.memoryPersist === 'boolean') {
|
|
596
|
+
return { enabled: shared.memoryPersist, source: 'config' };
|
|
597
|
+
}
|
|
598
|
+
// Pre-D5 install, or one whose adoption had nothing to move: the legacy
|
|
599
|
+
// namespace still answers until the first write retires it.
|
|
482
600
|
const cfg = load()[MEMORY_PERSIST_NAMESPACE] || {};
|
|
483
|
-
return {
|
|
484
|
-
|
|
485
|
-
source: cfg.enabled === undefined ? 'default' : 'config',
|
|
486
|
-
};
|
|
601
|
+
if (cfg.enabled === undefined) return { enabled: true, source: 'default' };
|
|
602
|
+
return { enabled: Boolean(cfg.enabled), source: 'config' };
|
|
487
603
|
}
|
|
488
604
|
|
|
489
605
|
function setMemoryPersist(enabled) {
|
|
606
|
+
prefs.set({ memoryPersist: Boolean(enabled) }, { dir: sharedDir });
|
|
607
|
+
// One-way: drop the legacy copy in the same breath so the preference exists
|
|
608
|
+
// in exactly one place from here on (the same retirement
|
|
609
|
+
// cli/src/config.js's setMemoryPersist() does for the pre-flip `cloudSync`).
|
|
490
610
|
const data = load();
|
|
491
|
-
data[MEMORY_PERSIST_NAMESPACE]
|
|
492
|
-
|
|
611
|
+
if (data[MEMORY_PERSIST_NAMESPACE] !== undefined) {
|
|
612
|
+
delete data[MEMORY_PERSIST_NAMESPACE];
|
|
613
|
+
save(data);
|
|
614
|
+
}
|
|
493
615
|
return memoryPersistState();
|
|
494
616
|
}
|
|
495
617
|
|
|
@@ -629,6 +751,11 @@ function createSettingsStore({ dir, safeStorage } = {}) {
|
|
|
629
751
|
|
|
630
752
|
return {
|
|
631
753
|
file,
|
|
754
|
+
sharedDir,
|
|
755
|
+
adoption,
|
|
756
|
+
sharedFile,
|
|
757
|
+
getSharedPref,
|
|
758
|
+
setSharedPref,
|
|
632
759
|
get,
|
|
633
760
|
set,
|
|
634
761
|
rawKey,
|