aegiscode 7.0.26 → 7.0.28

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.
Files changed (118) hide show
  1. package/SOURCE-OFFER.txt +9 -0
  2. package/package.json +4 -7
  3. package/scripts/check.mjs +1 -52
  4. package/scripts/demo.mjs +1 -94
  5. package/scripts/predist.mjs +1 -75
  6. package/scripts/runtests.mjs +1 -56
  7. package/scripts/seal-gate.mjs +1 -74
  8. package/src/agents.js +1 -139
  9. package/src/app.js +1 -2957
  10. package/src/art.js +1 -289
  11. package/src/chatflow.js +1 -3023
  12. package/src/checkpoint.js +1 -90
  13. package/src/clipboard.js +1 -424
  14. package/src/cloudsync.js +1 -528
  15. package/src/commands.js +1 -4089
  16. package/src/config.js +1 -581
  17. package/src/connect.js +1 -349
  18. package/src/credentials.js +1 -33
  19. package/src/deps.js +1 -232
  20. package/src/devrun.js +1 -187
  21. package/src/diff.js +1 -333
  22. package/src/diffview.js +1 -296
  23. package/src/engine.js +1 -297
  24. package/src/entitlement.js +1 -355
  25. package/src/events.js +1 -707
  26. package/src/export.js +1 -67
  27. package/src/filepreview.js +1 -153
  28. package/src/fingerprint.js +1 -592
  29. package/src/format.js +1 -259
  30. package/src/fuzzy.js +1 -119
  31. package/src/history.js +1 -423
  32. package/src/init.js +1 -175
  33. package/src/input.js +1 -139
  34. package/src/keys.js +1 -183
  35. package/src/markdown.js +1 -306
  36. package/src/models.js +1 -507
  37. package/src/naming.js +1 -57
  38. package/src/overlays.js +1 -462
  39. package/src/panels.js +1 -1418
  40. package/src/ping.js +1 -226
  41. package/src/presence.js +1 -238
  42. package/src/render.js +1 -516
  43. package/src/screen.js +1 -518
  44. package/src/screens.js +1 -896
  45. package/src/secret.js +1 -59
  46. package/src/securefs.js +1 -359
  47. package/src/settings.js +1 -155
  48. package/src/shared.js +1 -52
  49. package/src/sharedpaths.js +1 -53
  50. package/src/signup.js +1 -156
  51. package/src/summarize.js +1 -95
  52. package/src/sysdiag.js +1 -585
  53. package/src/system.js +1 -40
  54. package/src/theme.js +1 -570
  55. package/src/title.js +1 -220
  56. package/src/todos.js +1 -115
  57. package/src/tokens.js +1 -263
  58. package/src/topup.js +1 -210
  59. package/src/update.js +1 -191
  60. package/vendor/client/aegis.js +1 -2441
  61. package/vendor/client/attest.js +1 -518
  62. package/vendor/client/authorship-key.js +1 -410
  63. package/vendor/client/auto-provision.js +1 -134
  64. package/vendor/client/brain-catalog.js +1 -268
  65. package/vendor/client/byok-catalog.js +1 -199
  66. package/vendor/client/catalog-client.js +1 -487
  67. package/vendor/client/conversation-export.js +1 -177
  68. package/vendor/client/credentials.js +1 -494
  69. package/vendor/client/device-fingerprint.js +1 -141
  70. package/vendor/client/drive-connect.js +1 -110
  71. package/vendor/client/drive-upload.js +1 -234
  72. package/vendor/client/env-file.js +1 -1273
  73. package/vendor/client/fingerprint.js +1 -1064
  74. package/vendor/client/foreign-memory.js +1 -669
  75. package/vendor/client/google-signin.js +1 -133
  76. package/vendor/client/hooks.js +1 -430
  77. package/vendor/client/model-discovery.js +1 -373
  78. package/vendor/client/naming.js +1 -283
  79. package/vendor/client/platform.js +1 -937
  80. package/vendor/client/prefs.js +1 -351
  81. package/vendor/client/presence-constants.js +1 -107
  82. package/vendor/client/presence.js +1 -438
  83. package/vendor/client/record-vault.js +3 -1055
  84. package/vendor/client/session-store.js +1 -575
  85. package/vendor/client/topup.js +1 -297
  86. package/vendor/client/touch.js +1 -458
  87. package/vendor/client/update.js +1 -763
  88. package/vendor/client/user-models.js +1 -381
  89. package/vendor/desktop/lib/local/agents.js +1 -105
  90. package/vendor/desktop/lib/local/attachments.js +1 -276
  91. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  92. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  93. package/vendor/desktop/lib/local/context.js +1 -125
  94. package/vendor/desktop/lib/local/engine.js +1 -3666
  95. package/vendor/desktop/lib/local/entitlement.js +1 -660
  96. package/vendor/desktop/lib/local/exec-plan.js +1 -269
  97. package/vendor/desktop/lib/local/git-scope.js +1 -228
  98. package/vendor/desktop/lib/local/integrity.js +1 -163
  99. package/vendor/desktop/lib/local/local.js +1 -2145
  100. package/vendor/desktop/lib/local/prompt.js +1 -280
  101. package/vendor/desktop/lib/local/queue.js +1 -560
  102. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  103. package/vendor/desktop/lib/local/shell.js +1 -712
  104. package/vendor/desktop/lib/local/spill.js +1 -75
  105. package/vendor/desktop/lib/local/tools.js +1 -1328
  106. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  107. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  108. package/vendor/desktop/lib/settings.js +1 -890
  109. package/vendor/desktop/main.js +1 -4890
  110. package/vendor/desktop/renderer/usage.js +1 -1239
  111. package/vendor/hosts/install.js +1 -638
  112. package/vendor/hosts/openai-shim.js +1 -515
  113. package/vendor/hosts/spec.js +1 -164
  114. package/vendor/hosts/targets.js +1 -346
  115. package/vendor/mcp/server.js +1 -221
  116. package/vendor/mcp/tools.js +1 -408
  117. package/vendor/one/src/child.js +1 -285
  118. package/vendor/one/src/permissions.js +1 -383
@@ -1,353 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
- // Conveying a modified copy, or running one as a network service, owes the
5
- // corresponding source under this licence (§5/§13) — see LICENSING.md.
6
- 'use strict';
7
-
8
- /**
9
- * prefs.js — the ONE shared, non-secret preference store (AEGISONE, decision
10
- * D5: "one store for preferences; secrets stay where the OS can decrypt them").
11
- *
12
- * Both faces read and write this file:
13
- *
14
- * the window desktop/lib/settings.js (the memory-persist preference, and the
15
- * CLI-key accessors `getSharedPref`/
16
- * `setSharedPref` the store exposes)
17
- * the shell cli/src/config.js (theme, model/class pin, effort, vim,
18
- * memoryPersist)
19
- *
20
- * and `desktop/lib/sync/persist-gate.js` reads it directly, in the main process,
21
- * before it opens a socket.
22
- *
23
- * WHY A THIRD FILE, when the repo already has credentials.json and sessions.json
24
- * in the same directory: those two are a *secret* store and a *content* store.
25
- * This one is neither. Splitting the desktop's single `<userData>/settings.json`
26
- * along the line D5 already drew for sessions and credentials is what makes the
27
- * split honest:
28
- *
29
- * $AEGISCODE_HOME/preferences.json non-secret preferences (this file)
30
- * <userData>/settings.json host-local: `safeStorage` blobs (a plain
31
- * Node process, i.e. the CLI, cannot decrypt
32
- * those on Linux) + machine/UI state
33
- *
34
- * The boundary is enforced, not documented: `set()` refuses to write anything
35
- * that looks like key material (`scanForSecrets`/`assertNoSecrets` below), so a
36
- * caller that tries to park an API key in the shared store gets a thrown error
37
- * rather than a plaintext secret in a file the other host reads. A preference
38
- * store that *can* carry a key is a second place to leak one; this one cannot.
39
- *
40
- * Adoption of a pre-unification `<userData>/settings.json` is one-way, once and
41
- * idempotent — the pattern `client/session-store.js` already proves and
42
- * `test/shared-store.test.mjs` property D already asserts. There is no merge
43
- * loop and no last-writer-wins ping-pong: shared values are never copied back
44
- * into the legacy file, and a second adoption attempt is refused.
45
- */
46
-
47
- const fs = require('node:fs');
48
- const path = require('node:path');
49
-
50
- // The data dir is defined once, in the shared credential module — the same rule
51
- // cli/src/config.js and desktop/lib/sync/sessions.js follow, so the two faces
52
- // cannot drift about where the store lives (`$AEGISCODE_HOME`, else
53
- // `~/.aegiscode`).
54
- const { aegisHome } = require('./credentials.js');
55
-
56
- const PREFS_FILE = 'preferences.json';
57
- const PREFS_VERSION = 1;
58
-
59
- /**
60
- * The non-secret preference keys the shell's `config.js` keeps in the shared
61
- * store (everything else in its config — `updateCheck`, `lastCwd`, a legacy
62
- * `provider`/`baseURL` row — stays in `config.json`, which is host-local).
63
- *
64
- * This list is also the access-control list for the desktop's generic
65
- * `getSharedPref`/`setSharedPref`, so the window can read exactly the
66
- * preferences the shell owns and not reach into anyone else's state.
67
- */
68
- const SHARED_PREF_KEYS = Object.freeze([
69
- 'themeIndex',
70
- 'model',
71
- 'modelClass',
72
- 'currentModelId',
73
- 'models',
74
- 'effort',
75
- 'vim',
76
- 'memoryPersist',
77
- // ON8 / D8 rule 1: the confirmation gate is a POSTURE, not a surface. The
78
- // window's "confirm before running tools" switch and the shell's rule set
79
- // answer the same question ("may this call run unattended?"), so the switch
80
- // lives beside the rules that gate answers, in the one store both hosts read.
81
- 'confirmMode',
82
- ]);
83
-
84
- /**
85
- * The legacy desktop namespace D5 retires: `<userData>/settings.json`'s
86
- * `__memoryPersist: { enabled }` becomes the shared store's `memoryPersist`
87
- * boolean — the shell's own spelling (`cli/src/config.js` `MEMORY_PERSIST_KEY`),
88
- * so one preference has one representation instead of two that could disagree.
89
- */
90
- const LEGACY_MEMORY_PERSIST_NAMESPACE = '__memoryPersist';
91
-
92
- /**
93
- * The second legacy namespace this store retires (ON8): the window's
94
- * `__confirmMode: { enabled }` becomes the shared `confirmMode` boolean. Same
95
- * rule, same reason as memory-persist above — and it is the one that closes
96
- * D8's rule 1 in the direction that used to be impossible: a posture set in
97
- * the window is now the posture the shell reads.
98
- */
99
- const LEGACY_CONFIRM_MODE_NAMESPACE = '__confirmMode';
100
-
101
- /**
102
- * Key names that mean "secret" wherever they appear in the tree. Deliberately
103
- * conservative: `keyMask`-style *previews* never reach this file (they are not
104
- * preferences), and no legitimate preference is named `token`/`secret`/`auth`.
105
- */
106
- const SECRET_KEY_RE =
107
- /(^|[^a-z0-9])(api[_-]?key|apikey|key|keys|token|secret|password|passwd|credential|credentials|authorization|bearer|private[_-]?key|access[_-]?key|session[_-]?key)([^a-z0-9]|$)/i;
108
-
109
- /**
110
- * Values that are key material whatever they are called. Every shape here is a
111
- * real prefix this product's hosts mint or accept: AEGIS Cloud keys
112
- * (`aegis_…`), OpenAI/BYOK keys (`sk-…`), GitHub/Anthropic strings (`ghp_`,
113
- * `sk-ant-…`), JWTs (`eyJ…`, which is what an OAuth-ish provider returns), and
114
- * a bare long base64 blob (which is what Electron's `safeStorage` ciphertext —
115
- * and a base64-encoded key, the exact fallback `settings.js` uses when
116
- * `safeStorage` is unavailable — looks like).
117
- */
118
- const SECRET_VALUE_RES = [
119
- /\baegis_[A-Za-z0-9_\-]{12,}/,
120
- /\bsk-[A-Za-z0-9_\-]{12,}/,
121
- /\bghp_[A-Za-z0-9_\-]{20,}/,
122
- /\bxox[baprs]-[A-Za-z0-9\-]{10,}/,
123
- /\beyJ[A-Za-z0-9_\-]{16,}\.[A-Za-z0-9_\-]{8,}/,
124
- /^[A-Za-z0-9+/]{48,}={0,2}$/,
125
- ];
126
-
127
- /** The shared dir: an explicit `dir`, else `$AEGISCODE_HOME`/`~/.aegiscode`. */
128
- function prefsDir(opts) {
129
- const o = opts || {};
130
- if (o.dir && String(o.dir).trim()) return path.resolve(String(o.dir).trim());
131
- return aegisHome(o.env);
132
- }
133
-
134
- /** The shared file. `prefsFile({ dir, env })`. */
135
- function prefsFile(opts) {
136
- const o = opts || {};
137
- if (o.file && String(o.file).trim()) return path.resolve(String(o.file).trim());
138
- return path.join(prefsDir(o), PREFS_FILE);
139
- }
140
-
141
- /**
142
- * Every finding in `value` that looks like key material, as dotted paths.
143
- * An empty array means "nothing key-shaped in here" — the property the exit
144
- * criteria assert about the shared file, with a negative control that shows the
145
- * scan can fail.
146
- */
147
- function scanForSecrets(value, atPath = '', found = []) {
148
- if (value == null) return found;
149
- if (typeof value === 'string') {
150
- if (SECRET_VALUE_RES.some((re) => re.test(value))) found.push(atPath || '(root)');
151
- return found;
152
- }
153
- if (typeof value !== 'object') return found;
154
- if (Array.isArray(value)) {
155
- value.forEach((v, i) => scanForSecrets(v, `${atPath}[${i}]`, found));
156
- return found;
157
- }
158
- for (const [k, v] of Object.entries(value)) {
159
- const here = atPath ? `${atPath}.${k}` : k;
160
- // An empty/absent value is not key material — `{ key: null }` is how this
161
- // repo clears a stored credential, and refusing that would be noise.
162
- if (SECRET_KEY_RE.test(k) && v != null && v !== '' && v !== false) {
163
- found.push(here);
164
- continue;
165
- }
166
- scanForSecrets(v, here, found);
167
- }
168
- return found;
169
- }
170
-
171
- /** Throw when `value` carries key material. The writer's fail-closed gate. */
172
- function assertNoSecrets(value, what = 'shared preference store') {
173
- const found = scanForSecrets(value);
174
- if (found.length) {
175
- throw new Error(
176
- `${what} must not carry key material — refusing to write (found: ${found.join(', ')}). ` +
177
- 'Secrets belong in the host-local credential store, where the OS can protect them.'
178
- );
179
- }
180
- return value;
181
- }
182
-
183
- function readJson(file, fallback) {
184
- try {
185
- const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
186
- return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : fallback;
187
- } catch {
188
- return fallback;
189
- }
190
- }
191
-
192
- /** Read the shared store. Never throws: a corrupt file reads as empty. */
193
- function load(opts) {
194
- return readJson(prefsFile(opts), {});
195
- }
196
-
197
- /**
198
- * Write the shared store atomically and 0600.
199
- *
200
- * 0600 rather than 0644 even though nothing secret belongs here: the file
201
- * decides whether a user's turns are persisted to the cloud (`memoryPersist`)
202
- * and which provider row the local class dials, so a writable copy is another
203
- * local account's way to change how this host behaves. The mode is the control;
204
- * the scan above is the boundary.
205
- */
206
- function write(next, opts) {
207
- assertNoSecrets(next);
208
- const file = prefsFile(opts);
209
- fs.mkdirSync(path.dirname(file), { recursive: true });
210
- const tmp = `${file}.tmp-${process.pid}`;
211
- fs.writeFileSync(tmp, JSON.stringify(next, null, 2) + '\n', { mode: 0o600 });
212
- fs.renameSync(tmp, file);
213
- try {
214
- fs.chmodSync(file, 0o600);
215
- } catch {
216
- /* Windows: POSIX modes are a no-op, ACLs are the OS's business */
217
- }
218
- return next;
219
- }
220
-
221
- /** Merge a patch into the shared store and return the merged view. */
222
- function set(patch, opts) {
223
- const next = { ...load(opts), ...(patch || {}) };
224
- // `undefined` in a patch is how callers retire a key (JSON.stringify drops
225
- // it), so drop those before the scan and the write.
226
- for (const k of Object.keys(next)) if (next[k] === undefined) delete next[k];
227
- if (next.version === undefined) next.version = PREFS_VERSION;
228
- return write(next, opts);
229
- }
230
-
231
- /** One shared preference value, or `fallback`. */
232
- function get(key, opts, fallback) {
233
- const v = load(opts)[key];
234
- return v === undefined ? fallback : v;
235
- }
236
-
237
- /** True when the store holds an explicit value for `key`. */
238
- function has(key, opts) {
239
- return load(opts)[key] !== undefined;
240
- }
241
-
242
- /**
243
- * Retire a key. Confined here (read-modify-write) so the two faces never
244
- * clobber each other's namespaces with a whole-file overwrite.
245
- */
246
- function remove(key, opts) {
247
- const next = load(opts);
248
- delete next[key];
249
- return write(next, opts);
250
- }
251
-
252
- /**
253
- * The non-secret half of a legacy `<userData>/settings.json`, in the shared
254
- * store's spellings. Only namespaces THIS store owns are extracted: the other
255
- * app-level namespaces (`__avatar`, `__telemetry`,
256
- * `__autoDrain`, `__autoMint`, `__quickLauncher`) stay host-local until their
257
- * own phase moves them, and the provider rows are never here at all because a
258
- * provider row is where a key lives.
259
- */
260
- function extractNonSecretHalf(legacy) {
261
- const out = {};
262
- const src = (legacy || {})[LEGACY_MEMORY_PERSIST_NAMESPACE];
263
- if (src && typeof src === 'object' && typeof src.enabled === 'boolean') {
264
- out.memoryPersist = src.enabled;
265
- }
266
- // ON8: the confirmation gate adopts the same way. `enabled: true` means the
267
- // gate is UP, which is the shared `confirmMode: true`; the shared key keeps
268
- // the window's own polarity so an adopting install cannot flip its gate.
269
- const gate = (legacy || {})[LEGACY_CONFIRM_MODE_NAMESPACE];
270
- if (gate && typeof gate === 'object' && typeof gate.enabled === 'boolean') {
271
- out.confirmMode = gate.enabled;
272
- }
273
- return out;
274
- }
275
-
276
- /**
277
- * One-way, once, idempotent adoption of the legacy desktop store's non-secret
278
- * half.
279
- *
280
- * `adopt({ dir, env, legacyDir })`:
281
- * - `dir`/`env` locate the SHARED store;
282
- * - `legacyDir` is the old settings directory (Electron's `<userData>`; main
283
- * passes the same dir its store was built with).
284
- *
285
- * One-way: the legacy file is read, never written — a preference that moved to
286
- * the shared store is not mirrored back. Once: a key the shared store already
287
- * carries is never overwritten, so a second run has nothing left to do and
288
- * returns `adopted:false` without touching the file. That is what makes it
289
- * idempotent rather than a periodic merge.
290
- */
291
- function adopt(opts) {
292
- const o = opts || {};
293
- const shared = prefsFile(o);
294
- const legacyDir = o.legacyDir;
295
- const legacyFile = legacyDir ? path.join(String(legacyDir), 'settings.json') : null;
296
- if (legacyFile && path.resolve(legacyFile) === shared) {
297
- return { adopted: false, keys: [], from: legacyFile, reason: 'shared store is the legacy file' };
298
- }
299
- if (!legacyFile || !fs.existsSync(legacyFile)) {
300
- return { adopted: false, keys: [], from: legacyFile, reason: 'no legacy settings file' };
301
- }
302
- const current = load(o);
303
- const half = extractNonSecretHalf(readJson(legacyFile, {}));
304
- // One-way means missing-only: an explicit shared value outranks the legacy
305
- // one and is never clobbered by it.
306
- const keys = Object.keys(half).filter((k) => current[k] === undefined);
307
- if (!keys.length) {
308
- return {
309
- adopted: false,
310
- keys: [],
311
- from: legacyFile,
312
- reason: Object.keys(half).length
313
- ? 'shared store already carries these preferences'
314
- : 'legacy store has no shared preferences',
315
- };
316
- }
317
- const patch = {};
318
- for (const k of keys) patch[k] = half[k];
319
- // `names`, NOT `keys` (AEGISONE ON8): this ledger is written through `write()`
320
- // below, so it is scanned like everything else — and `SECRET_KEY_RE` matches
321
- // `key`/`keys` by design, because a preference named `keys` IS how key material
322
- // would smuggle itself into a file the desktop and the shell both read. Spelled
323
- // `keys`, this field made `assertNoSecrets` refuse the store's own write, so
324
- // EVERY adoption with something to adopt threw — the whole pre-D5 migration was
325
- // dead, silently (settings.js's best-effort catch turned the throw into "no
326
- // adoption" and no one was told). The scanner is the control here, not the bug;
327
- // a field name is free to change.
328
- patch.adopted = {
329
- from: legacyFile,
330
- at: new Date().toISOString(),
331
- names: keys.slice().sort(),
332
- };
333
- write({ ...current, ...patch }, o);
334
- return { adopted: true, keys: keys.slice().sort(), from: legacyFile };
335
- }
336
-
337
- module.exports = {
338
- PREFS_FILE,
339
- PREFS_VERSION,
340
- SHARED_PREF_KEYS,
341
- LEGACY_MEMORY_PERSIST_NAMESPACE,
342
- prefsDir,
343
- prefsFile,
344
- load,
345
- set,
346
- get,
347
- has,
348
- remove,
349
- scanForSecrets,
350
- assertNoSecrets,
351
- extractNonSecretHalf,
352
- adopt,
353
- };
3
+ "use strict";const fs=require("node:fs"),path=require("node:path"),{aegisHome:aegisHome}=require("./credentials.js"),PREFS_FILE="preferences.json",PREFS_VERSION=1,SHARED_PREF_KEYS=Object.freeze(["themeIndex","model","modelClass","currentModelId","models","effort","vim","memoryPersist","confirmMode"]),LEGACY_MEMORY_PERSIST_NAMESPACE="__memoryPersist",LEGACY_CONFIRM_MODE_NAMESPACE="__confirmMode",SECRET_KEY_RE=/(^|[^a-z0-9])(api[_-]?key|apikey|key|keys|token|secret|password|passwd|credential|credentials|authorization|bearer|private[_-]?key|access[_-]?key|session[_-]?key)([^a-z0-9]|$)/i,SECRET_VALUE_RES=[/\baegis_[A-Za-z0-9_\-]{12,}/,/\bsk-[A-Za-z0-9_\-]{12,}/,/\bghp_[A-Za-z0-9_\-]{20,}/,/\bxox[baprs]-[A-Za-z0-9\-]{10,}/,/\beyJ[A-Za-z0-9_\-]{16,}\.[A-Za-z0-9_\-]{8,}/,/^[A-Za-z0-9+/]{48,}={0,2}$/];function prefsDir(e){const r=e||{};return r.dir&&String(r.dir).trim()?path.resolve(String(r.dir).trim()):aegisHome(r.env)}function prefsFile(e){const r=e||{};return r.file&&String(r.file).trim()?path.resolve(String(r.file).trim()):path.join(prefsDir(r),PREFS_FILE)}function scanForSecrets(e,r="",t=[]){if(null==e)return t;if("string"==typeof e)return SECRET_VALUE_RES.some((r=>r.test(e)))&&t.push(r||"(root)"),t;if("object"!=typeof e)return t;if(Array.isArray(e))return e.forEach(((e,o)=>scanForSecrets(e,`${r}[${o}]`,t))),t;for(const[o,s]of Object.entries(e)){const e=r?`${r}.${o}`:o;SECRET_KEY_RE.test(o)&&null!=s&&""!==s&&!1!==s?t.push(e):scanForSecrets(s,e,t)}return t}function assertNoSecrets(e,r="shared preference store"){const t=scanForSecrets(e);if(t.length)throw new Error(`${r} must not carry key material — refusing to write (found: ${t.join(", ")}). Secrets belong in the host-local credential store, where the OS can protect them.`);return e}function readJson(e,r){try{const t=JSON.parse(fs.readFileSync(e,"utf8"));return t&&"object"==typeof t&&!Array.isArray(t)?t:r}catch{return r}}function load(e){return readJson(prefsFile(e),{})}function write(e,r){assertNoSecrets(e);const t=prefsFile(r);fs.mkdirSync(path.dirname(t),{recursive:!0});const o=`${t}.tmp-${process.pid}`;fs.writeFileSync(o,JSON.stringify(e,null,2)+"\n",{mode:384}),fs.renameSync(o,t);try{fs.chmodSync(t,384)}catch{}return e}function set(e,r){const t={...load(r),...e||{}};for(const e of Object.keys(t))void 0===t[e]&&delete t[e];return void 0===t.version&&(t.version=1),write(t,r)}function get(e,r,t){const o=load(r)[e];return void 0===o?t:o}function has(e,r){return void 0!==load(r)[e]}function remove(e,r){const t=load(r);return delete t[e],write(t,r)}function extractNonSecretHalf(e){const r={},t=(e||{})[LEGACY_MEMORY_PERSIST_NAMESPACE];t&&"object"==typeof t&&"boolean"==typeof t.enabled&&(r.memoryPersist=t.enabled);const o=(e||{})[LEGACY_CONFIRM_MODE_NAMESPACE];return o&&"object"==typeof o&&"boolean"==typeof o.enabled&&(r.confirmMode=o.enabled),r}function adopt(e){const r=e||{},t=prefsFile(r),o=r.legacyDir,s=o?path.join(String(o),"settings.json"):null;if(s&&path.resolve(s)===t)return{adopted:!1,keys:[],from:s,reason:"shared store is the legacy file"};if(!s||!fs.existsSync(s))return{adopted:!1,keys:[],from:s,reason:"no legacy settings file"};const n=load(r),a=extractNonSecretHalf(readJson(s,{})),i=Object.keys(a).filter((e=>void 0===n[e]));if(!i.length)return{adopted:!1,keys:[],from:s,reason:Object.keys(a).length?"shared store already carries these preferences":"legacy store has no shared preferences"};const c={};for(const e of i)c[e]=a[e];return c.adopted={from:s,at:(new Date).toISOString(),names:i.slice().sort()},write({...n,...c},r),{adopted:!0,keys:i.slice().sort(),from:s}}module.exports={PREFS_FILE:PREFS_FILE,PREFS_VERSION:1,SHARED_PREF_KEYS:SHARED_PREF_KEYS,LEGACY_MEMORY_PERSIST_NAMESPACE:LEGACY_MEMORY_PERSIST_NAMESPACE,prefsDir:prefsDir,prefsFile:prefsFile,load:load,set:set,get:get,has:has,remove:remove,scanForSecrets:scanForSecrets,assertNoSecrets:assertNoSecrets,extractNonSecretHalf:extractNonSecretHalf,adopt:adopt};
@@ -1,109 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
- // Conveying a modified copy, or running one as a network service, owes the
5
- // corresponding source under this licence (§5/§13) — see LICENSING.md.
6
- 'use strict';
7
-
8
- /**
9
- * The wire contract and the sanitising helpers for the presence beacon
10
- * (client/presence.js).
11
- *
12
- * These live in their own file for one reason: the widths and the app-name
13
- * vocabulary below are not this client's invention, they are aegis1's
14
- * (`_presence_token`, `_presence_app` and `PRESENCE_BEAT_INTERVAL_S` in
15
- * aegis1/app.py, and the `client_presence` table in aegis1/db.py). A test can
16
- * assert them without loading the network module, and if the server widens a
17
- * column the mismatch is visible in one file instead of being spread through
18
- * the beacon's request path.
19
- *
20
- * Kept dependency-free: plain Node, no Electron, no aegis.js — `presence.js`
21
- * requires this, and the tests require both.
22
- */
23
-
24
- /** aegis1: `@app.route("/api/v1/heartbeat", methods=["POST"])`. The v1 path is
25
- * the client beacon; `/api/heartbeat` is the dashboard's own JS ping and is
26
- * deliberately NOT used here — it takes no app/install field and writes no
27
- * presence row. */
28
- const PRESENCE_PATH = '/api/v1/heartbeat';
29
-
30
- /** Fallback cadence, in ms, used until the server answers with its own.
31
- * aegis1's PRESENCE_BEAT_INTERVAL_S is 300 (5 min) as this is written; if the
32
- * two ever disagree the server's value wins at runtime, so this only bounds
33
- * the very first beat. */
34
- const DEFAULT_INTERVAL_MS = 300 * 1000;
35
-
36
- /** One minute. `/api/heartbeat` and `/api/v1/heartbeat` are both
37
- * `@login_required`, and that decorator throttles `_track_request()` to
38
- * 1/min/user — beating faster than this would buy nothing but load. */
39
- const MIN_INTERVAL_MS = 60 * 1000;
40
-
41
- /** One hour: the ceiling the server may ask for, and the ceiling the backoff
42
- * ladder may reach. Past this the panel's "online" window is meaningless. */
43
- const MAX_INTERVAL_MS = 60 * 60 * 1000;
44
-
45
- /** Failures slow the beacon down rather than retrying on the same rhythm. */
46
- const BACKOFF_FACTOR = 2;
47
- const MAX_BACKOFF_MS = 30 * 60 * 1000;
48
-
49
- /** A beacon that has not answered in 20 s is a beacon that is not going to:
50
- * the request body is ~120 bytes. Kept well under MIN_INTERVAL_MS so an
51
- * in-flight beat can never overlap the next scheduled one. */
52
- const REQUEST_TIMEOUT_MS = 20 * 1000;
53
-
54
- /** The app vocabulary, copied EXACTLY from aegis1's `PRESENCE_APPS`
55
- * (aegis1/app.py, right above `_presence_app`). This is not a suggestion: the
56
- * server keeps a name only if it is in that tuple and maps everything else to
57
- * 'other', so a client that sends a name of its own invention is a client the
58
- * operator cannot identify in the panel — silently, with a 200 and no error
59
- * anywhere. `test/cli-presence.test.mjs` parses PRESENCE_APPS out of app.py and
60
- * fails if these two lists drift.
61
- *
62
- * The terminal host sends 'cli' rather than a product name for that reason:
63
- * 'aegiscode' is not in the server's tuple, so it would land as 'other'. */
64
- const APP_NAMES = Object.freeze(['desktop', 'cli', 'mcp', 'extension', 'web']);
65
-
66
- /**
67
- * One wire-safe token: trimmed, control characters and whitespace stripped,
68
- * truncated to the width the server's `_presence_token()` will accept. Returns
69
- * '' for anything that is not a usable string, so a caller can use the empty
70
- * result as "omit this field" rather than sending `null`.
71
- *
72
- * The sanitising is done HERE rather than left to the server on purpose: the
73
- * server sanitises so a bad field cannot 400 the beacon, but a client that
74
- * relies on that ships a body it cannot describe. Truncating at the source
75
- * means what this code sends and what the presence row stores are the same
76
- * string.
77
- */
78
- function saneToken(value, limit) {
79
- try {
80
- if (value == null) return '';
81
- if (typeof value === 'number' && !Number.isFinite(value)) return '';
82
- const text = String(value).replace(/[\u0000-\u001f\u007f\s]+/g, '');
83
- const max = Number.isFinite(Number(limit)) && Number(limit) > 0 ? Math.floor(Number(limit)) : 64;
84
- return text.slice(0, max);
85
- } catch {
86
- return '';
87
- }
88
- }
89
-
90
- /** A non-negative integer queue depth. aegis1 clamps to [0, 100000] itself;
91
- * clamping here too means the two never disagree about what was sent. */
92
- function saneCount(value) {
93
- const n = Number(value);
94
- if (!Number.isFinite(n) || n <= 0) return 0;
95
- return Math.min(100000, Math.floor(n));
96
- }
97
-
98
- module.exports = {
99
- PRESENCE_PATH,
100
- DEFAULT_INTERVAL_MS,
101
- MIN_INTERVAL_MS,
102
- MAX_INTERVAL_MS,
103
- BACKOFF_FACTOR,
104
- MAX_BACKOFF_MS,
105
- REQUEST_TIMEOUT_MS,
106
- APP_NAMES,
107
- saneToken,
108
- saneCount,
109
- };
3
+ "use strict";const PRESENCE_PATH="/api/v1/heartbeat",DEFAULT_INTERVAL_MS=3e5,MIN_INTERVAL_MS=6e4,MAX_INTERVAL_MS=36e5,BACKOFF_FACTOR=2,MAX_BACKOFF_MS=18e5,REQUEST_TIMEOUT_MS=2e4,APP_NAMES=Object.freeze(["desktop","cli","mcp","extension","web"]);function saneToken(e,n){try{if(null==e)return"";if("number"==typeof e&&!Number.isFinite(e))return"";const t=String(e).replace(/[\u0000-\u001f\u007f\s]+/g,""),_=Number.isFinite(Number(n))&&Number(n)>0?Math.floor(Number(n)):64;return t.slice(0,_)}catch{return""}}function saneCount(e){const n=Number(e);return!Number.isFinite(n)||n<=0?0:Math.min(1e5,Math.floor(n))}module.exports={PRESENCE_PATH:PRESENCE_PATH,DEFAULT_INTERVAL_MS:3e5,MIN_INTERVAL_MS:6e4,MAX_INTERVAL_MS:36e5,BACKOFF_FACTOR:2,MAX_BACKOFF_MS:18e5,REQUEST_TIMEOUT_MS:2e4,APP_NAMES:APP_NAMES,saneToken:saneToken,saneCount:saneCount};