aegis-desktop 1.0.13 → 1.0.15
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/SOURCE-OFFER.txt +9 -0
- package/bin/aegis.js +1 -32
- package/lib/account-key.js +1 -56
- package/lib/auto.js +1 -430
- package/lib/avatar/companion.js +1 -698
- package/lib/avatar/cosmetics.js +1 -532
- package/lib/avatar/events.js +1 -344
- package/lib/avatar/holder-turn.js +1 -350
- package/lib/avatar/holders.js +1 -612
- package/lib/avatar/identity.js +1 -641
- package/lib/avatar/level.js +1 -368
- package/lib/avatar/mirror.js +1 -524
- package/lib/avatar/persona.js +1 -388
- package/lib/avatar/profile.js +1 -977
- package/lib/avatar/register.js +1 -307
- package/lib/avatar/store.js +1 -472
- package/lib/avatar/tiers.js +1 -38
- package/lib/avatar/transfer.js +1 -415
- package/lib/avatar/turn.js +1 -216
- package/lib/avatar/voice.js +1 -328
- package/lib/avatar/xp.js +1 -404
- package/lib/deep-link.js +1 -120
- package/lib/fingerprint.js +2 -347
- package/lib/google-connect.js +1 -169
- package/lib/local/agents.js +1 -105
- package/lib/local/autonomous.js +1 -1045
- package/lib/local/claude-pro.js +1 -993
- package/lib/local/context.js +1 -95
- package/lib/local/engine.js +1 -3228
- package/lib/local/entitlement.js +1 -654
- package/lib/local/git-scope.js +1 -228
- package/lib/local/local.js +1 -2135
- package/lib/local/prompt.js +1 -275
- package/lib/local/queue.js +1 -560
- package/lib/local/session-rounds.js +1 -208
- package/lib/local/shell.js +1 -680
- package/lib/local/telemetry.js +1 -470
- package/lib/local/tools.js +1 -1238
- package/lib/local/turn-guard.js +1 -300
- package/lib/local/worktree-lock.js +1 -235
- package/lib/provider-key-mirror.js +1 -252
- package/lib/quick-launcher.js +1 -84
- package/lib/settings.js +1 -890
- package/lib/sync/memory-queue.js +1 -60
- package/lib/sync/persist-gate.js +1 -148
- package/lib/sync/sessions.js +1 -106
- package/lib/window-state.js +1 -66
- package/main.js +3 -4390
- package/package.json +3 -5
- package/preload.js +3 -628
- package/renderer/app.js +1 -6560
- package/renderer/avatar/assemble.js +1 -335
- package/renderer/avatar/avatar.js +1 -380
- package/renderer/avatar/cards.js +1 -141
- package/renderer/avatar/hud.js +1 -206
- package/renderer/avatar/machine.js +1 -213
- package/renderer/avatar/pane.js +1 -439
- package/renderer/avatar/parts.js +1 -437
- package/renderer/budget.js +1 -168
- package/renderer/companion.js +1 -223
- package/renderer/diff.js +1 -359
- package/renderer/diffview.js +1 -336
- package/renderer/fingerprint.js +3 -720
- package/renderer/markdown.js +1 -168
- package/renderer/provider-toolbar.js +1 -134
- package/renderer/providers.js +1 -259
- package/renderer/quick.js +1 -191
- package/renderer/stream-policy.js +1 -306
- package/renderer/transcript-view.js +1 -323
- package/renderer/usage.js +1 -1239
- package/vendor/aegis.js +1 -2054
- package/vendor/attest.js +1 -442
- package/vendor/authorship-key.js +1 -410
- package/vendor/auto-provision.js +1 -134
- package/vendor/brain-catalog.js +1 -268
- package/vendor/byok-catalog.js +1 -230
- package/vendor/credentials.js +1 -494
- package/vendor/device-fingerprint.js +1 -141
- package/vendor/drive-connect.js +1 -85
- package/vendor/drive-upload.js +1 -174
- package/vendor/env-file.js +1 -1273
- package/vendor/fingerprint.js +1 -1064
- package/vendor/foreign-memory.js +1 -669
- package/vendor/google-signin.js +1 -125
- package/vendor/hooks.js +1 -430
- package/vendor/model-discovery.js +1 -330
- package/vendor/platform.js +1 -937
- package/vendor/prefs.js +1 -351
- package/vendor/presence-constants.js +1 -107
- package/vendor/presence.js +1 -438
- package/vendor/record-vault.js +3 -1055
- package/vendor/session-store.js +1 -548
- package/vendor/topup.js +1 -297
- package/vendor/touch.js +1 -458
- package/vendor/update.js +1 -704
- package/vendor/user-models.js +1 -381
package/lib/sync/memory-queue.js
CHANGED
|
@@ -1,62 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
-
* memory-queue.js — local retry queue for cloud memory saves (plan P3 §7).
|
|
10
|
-
* When `aegis.memorySave()` fails (no key configured, offline), the entry is
|
|
11
|
-
* appended to <dir>/memory-queue.json instead of being dropped, so a later
|
|
12
|
-
* "Sync now" or heartbeat retry can flush it once the cloud is reachable.
|
|
13
|
-
* Pure Node + injectable dir, mirrors desktop/lib/sync/sessions.js.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const fs = require('node:fs');
|
|
17
|
-
const path = require('node:path');
|
|
18
|
-
|
|
19
|
-
function queueFile(dir) {
|
|
20
|
-
return path.join(dir, 'memory-queue.json');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function load(dir) {
|
|
24
|
-
try {
|
|
25
|
-
const data = JSON.parse(fs.readFileSync(queueFile(dir), 'utf8'));
|
|
26
|
-
return Array.isArray(data) ? data : [];
|
|
27
|
-
} catch {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function atomicWrite(file, data) {
|
|
33
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
34
|
-
const tmp = `${file}.tmp-${process.pid}`;
|
|
35
|
-
fs.writeFileSync(tmp, JSON.stringify(data, null, 2));
|
|
36
|
-
fs.renameSync(tmp, file);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function save(dir, entries) {
|
|
40
|
-
atomicWrite(queueFile(dir), entries);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Queue a memory entry that a cloud save couldn't reach right now. */
|
|
44
|
-
function enqueue(dir, entry) {
|
|
45
|
-
const entries = load(dir);
|
|
46
|
-
const queued = { ...entry, queuedAt: Date.now() };
|
|
47
|
-
entries.push(queued);
|
|
48
|
-
save(dir, entries);
|
|
49
|
-
return queued;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function listQueued(dir) {
|
|
53
|
-
return load(dir);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = {
|
|
57
|
-
queueFile,
|
|
58
|
-
load,
|
|
59
|
-
save,
|
|
60
|
-
enqueue,
|
|
61
|
-
listQueued,
|
|
62
|
-
};
|
|
3
|
+
"use strict";const fs=require("node:fs"),path=require("node:path");function queueFile(e){return path.join(e,"memory-queue.json")}function load(e){try{const u=JSON.parse(fs.readFileSync(queueFile(e),"utf8"));return Array.isArray(u)?u:[]}catch{return[]}}function atomicWrite(e,u){fs.mkdirSync(path.dirname(e),{recursive:!0});const n=`${e}.tmp-${process.pid}`;fs.writeFileSync(n,JSON.stringify(u,null,2)),fs.renameSync(n,e)}function save(e,u){atomicWrite(queueFile(e),u)}function enqueue(e,u){const n=load(e),t={...u,queuedAt:Date.now()};return n.push(t),save(e,n),t}function listQueued(e){return load(e)}module.exports={queueFile:queueFile,load:load,save:save,enqueue:enqueue,listQueued:listQueued};
|
package/lib/sync/persist-gate.js
CHANGED
|
@@ -1,150 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
-
* persist-gate.js — the desktop half of "persisting memory for every account".
|
|
10
|
-
*
|
|
11
|
-
* `cli/` stores the preference in the shared non-secret store as `memoryPersist`
|
|
12
|
-
* (`cli/src/config.js`, migrated off the legacy `cloudSync` key). Since AEGIS
|
|
13
|
-
* ONE D5 that store is `$AEGISCODE_HOME/preferences.json` (`client/prefs.js`),
|
|
14
|
-
* which the shell and the window both write — so this gate reads the SAME value
|
|
15
|
-
* the Settings pane writes, and there is no second copy to disagree with.
|
|
16
|
-
*
|
|
17
|
-
* Two reasons the gate is not taken from the renderer:
|
|
18
|
-
*
|
|
19
|
-
* 1. The decision has to be enforceable in the main process whatever the
|
|
20
|
-
* renderer believes. A renderer-held flag is a suggestion; the process
|
|
21
|
-
* that opens the socket decides.
|
|
22
|
-
* 2. `createSyncDispatch()` / createAutoPush() are unit-tested in plain Node,
|
|
23
|
-
* where no renderer and no Electron exist.
|
|
24
|
-
*
|
|
25
|
-
* Default is ON, matching cli/. `source` keeps "the user turned this off" and
|
|
26
|
-
* "nobody has been asked yet" tellable apart — the whole point of shipping a
|
|
27
|
-
* default is that the absence of a stored key is not the same as a stored no.
|
|
28
|
-
*
|
|
29
|
-
* A pre-D5 `<userData>/settings.json` `__memoryPersist` namespace is still read
|
|
30
|
-
* as a FALLBACK (`readSettings` below, `source: 'config'`) so a gate that runs
|
|
31
|
-
* before adoption lands cannot read "default" over a user's explicit `false`.
|
|
32
|
-
* It is never written: the store retires it on the first write.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
const fs = require('node:fs');
|
|
36
|
-
const path = require('node:path');
|
|
37
|
-
|
|
38
|
-
const { MEMORY_PERSIST_NAMESPACE, SETTINGS_FILE } = require('../settings.js');
|
|
39
|
-
|
|
40
|
-
// The shared, non-secret preference store (D5), resolved the same two ways the
|
|
41
|
-
// other cross-host modules are: in-repo `client/*.js`, packaged `vendor/*.js`.
|
|
42
|
-
const prefs = (() => {
|
|
43
|
-
try {
|
|
44
|
-
return require('../../../client/prefs.js');
|
|
45
|
-
} catch {
|
|
46
|
-
return require('../../vendor/prefs.js');
|
|
47
|
-
}
|
|
48
|
-
})();
|
|
49
|
-
|
|
50
|
-
/** The settings file the store writes (`createSettingsStore` uses the same
|
|
51
|
-
* `path.join(dir, SETTINGS_FILE)`, so both agree on one source of truth).
|
|
52
|
-
* A caller that already holds the file path may pass it directly. */
|
|
53
|
-
function settingsFile(dir) {
|
|
54
|
-
const p = dir || '';
|
|
55
|
-
return p.endsWith(SETTINGS_FILE) ? p : path.join(p, SETTINGS_FILE);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function readSettings(dir) {
|
|
59
|
-
try {
|
|
60
|
-
const data = JSON.parse(fs.readFileSync(settingsFile(dir), 'utf8'));
|
|
61
|
-
return data && typeof data === 'object' ? data : {};
|
|
62
|
-
} catch {
|
|
63
|
-
return {};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* `{ enabled, source }`, read from the SHARED store the Settings pane writes.
|
|
69
|
-
*
|
|
70
|
-
* `source` is 'config' only when a file actually carries an explicit value — an
|
|
71
|
-
* explicit `false` survives, an absent preference is ON. `dir` is the legacy
|
|
72
|
-
* settings directory (Electron's `<userData>`), consulted only when the shared
|
|
73
|
-
* store has no opinion; `opts.prefsDir`/`opts.env` locate the shared store for
|
|
74
|
-
* callers that hold their own seam (tests).
|
|
75
|
-
*/
|
|
76
|
-
function gateState(dir, opts) {
|
|
77
|
-
const o = opts || {};
|
|
78
|
-
const shared = prefs.load({ dir: o.prefsDir, env: o.env });
|
|
79
|
-
if (typeof shared.memoryPersist === 'boolean') {
|
|
80
|
-
return { enabled: shared.memoryPersist, source: 'config' };
|
|
81
|
-
}
|
|
82
|
-
const cfg = readSettings(dir)[MEMORY_PERSIST_NAMESPACE];
|
|
83
|
-
if (!cfg || cfg.enabled === undefined) return { enabled: true, source: 'default' };
|
|
84
|
-
return { enabled: Boolean(cfg.enabled), source: 'config' };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* The post-turn push, gated.
|
|
89
|
-
*
|
|
90
|
-
* `push` is `createSyncDispatch`'s own drain, so this inherits the queue
|
|
91
|
-
* fallback for free: a push flushes `memory-queue.json` before it touches the
|
|
92
|
-
* session list, which is exactly the "offline now, sync later" behaviour the
|
|
93
|
-
* manual button had and the automatic path must not lose.
|
|
94
|
-
*
|
|
95
|
-
* Coalesced: a turn that ends while a drain is still in flight does not open a
|
|
96
|
-
* second one. `push()` snapshots `sessions.listPending(dir)`, so a concurrent
|
|
97
|
-
* call would race the same rows; the newest session instead goes out on the
|
|
98
|
-
* next trigger (the following turn's auto push, or "Sync now"). One turn of
|
|
99
|
-
* delay is the correct trade against two writers marking the same session
|
|
100
|
-
* synced.
|
|
101
|
-
*/
|
|
102
|
-
function createAutoPush({ push, dir, gate, prefsDir, env } = {}) {
|
|
103
|
-
if (typeof push !== 'function') throw new Error('createAutoPush requires a push()');
|
|
104
|
-
const readGate = typeof gate === 'function' ? gate : () => gateState(dir, { prefsDir, env });
|
|
105
|
-
let inFlight = null;
|
|
106
|
-
|
|
107
|
-
async function run() {
|
|
108
|
-
const state = readGate();
|
|
109
|
-
if (!state.enabled) {
|
|
110
|
-
return {
|
|
111
|
-
ok: true,
|
|
112
|
-
skipped: true,
|
|
113
|
-
gate: state,
|
|
114
|
-
reason: 'persisting memory is off',
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
try {
|
|
118
|
-
const result = await push();
|
|
119
|
-
return Object.assign({}, result, { skipped: false, gate: state });
|
|
120
|
-
} catch (err) {
|
|
121
|
-
// A chat turn must never fail because a background push did. `push()`
|
|
122
|
-
// already resolves `{ ok:false, … }` for its expected failures; this
|
|
123
|
-
// catches the unexpected so the caller's fire-and-forget cannot become
|
|
124
|
-
// an unhandled rejection.
|
|
125
|
-
return {
|
|
126
|
-
ok: false,
|
|
127
|
-
skipped: false,
|
|
128
|
-
gate: state,
|
|
129
|
-
reason: (err && err.message) || String(err),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function auto() {
|
|
135
|
-
if (inFlight) return inFlight;
|
|
136
|
-
inFlight = run().finally(() => {
|
|
137
|
-
inFlight = null;
|
|
138
|
-
});
|
|
139
|
-
return inFlight;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return { auto, gate: () => readGate(), state: () => readGate() };
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
module.exports = {
|
|
146
|
-
settingsFile,
|
|
147
|
-
readSettings,
|
|
148
|
-
gateState,
|
|
149
|
-
createAutoPush,
|
|
150
|
-
};
|
|
3
|
+
"use strict";const fs=require("node:fs"),path=require("node:path"),{MEMORY_PERSIST_NAMESPACE:MEMORY_PERSIST_NAMESPACE,SETTINGS_FILE:SETTINGS_FILE}=require("../settings.js"),prefs=(()=>{try{return require("../../../client/prefs.js")}catch{return require("../../vendor/prefs.js")}})();function settingsFile(e){const t=e||"";return t.endsWith(SETTINGS_FILE)?t:path.join(t,SETTINGS_FILE)}function readSettings(e){try{const t=JSON.parse(fs.readFileSync(settingsFile(e),"utf8"));return t&&"object"==typeof t?t:{}}catch{return{}}}function gateState(e,t){const r=t||{},n=prefs.load({dir:r.prefsDir,env:r.env});if("boolean"==typeof n.memoryPersist)return{enabled:n.memoryPersist,source:"config"};const s=readSettings(e)[MEMORY_PERSIST_NAMESPACE];return s&&void 0!==s.enabled?{enabled:Boolean(s.enabled),source:"config"}:{enabled:!0,source:"default"}}function createAutoPush({push:e,dir:t,gate:r,prefsDir:n,env:s}={}){if("function"!=typeof e)throw new Error("createAutoPush requires a push()");const i="function"==typeof r?r:()=>gateState(t,{prefsDir:n,env:s});let o=null;return{auto:function(){return o||(o=async function(){const t=i();if(!t.enabled)return{ok:!0,skipped:!0,gate:t,reason:"persisting memory is off"};try{const r=await e();return Object.assign({},r,{skipped:!1,gate:t})}catch(e){return{ok:!1,skipped:!1,gate:t,reason:e&&e.message||String(e)}}}().finally((()=>{o=null})),o)},gate:()=>i(),state:()=>i()}}module.exports={settingsFile:settingsFile,readSettings:readSettings,gateState:gateState,createAutoPush:createAutoPush};
|
package/lib/sync/sessions.js
CHANGED
|
@@ -1,108 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
-
* sessions.js — the desktop's session store, now a thin binding over the
|
|
10
|
-
* SHARED store in `client/session-store.js`.
|
|
11
|
-
*
|
|
12
|
-
* This file used to be the implementation. It was the desktop's private
|
|
13
|
-
* `sessions.json`, while the terminal host kept `~/.aegiscode/history.jsonl`
|
|
14
|
-
* and the MCP plugin could see neither — three hosts, one account, three
|
|
15
|
-
* disjoint views of the conversation. The implementation now lives in
|
|
16
|
-
* `client/session-store.js`, which is the tree every host already bundles,
|
|
17
|
-
* and every call here forwards to it.
|
|
18
|
-
*
|
|
19
|
-
* Two things that matter are deliberately unchanged:
|
|
20
|
-
*
|
|
21
|
-
* * the public API and its argument order (`(dir, …)` first) — `main.js`, the
|
|
22
|
-
* sync dispatch and `test/sync-sessions.test.mjs` call it by those names;
|
|
23
|
-
* * the record shape — `pending`, `seq`, `updatedAt`, `remoteId`,
|
|
24
|
-
* `lastSyncedAt`, `__seq` all keep their meaning, because cloud sync and
|
|
25
|
-
* the renderer's session list read them.
|
|
26
|
-
*
|
|
27
|
-
* The only real change is *where* `dir` points: main.js now passes the shared
|
|
28
|
-
* data dir (see `resolveStoreDir`), so a session typed in the terminal appears
|
|
29
|
-
* in the desktop's list without a network round trip.
|
|
30
|
-
*
|
|
31
|
-
* Resolution mirrors main.js's own pattern for the shared client: `client/` in
|
|
32
|
-
* a source checkout, `vendor/` in the packaged app (electron-builder cannot
|
|
33
|
-
* reach outside the app dir, so predist.mjs stages the file).
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
const shared = (() => {
|
|
37
|
-
try {
|
|
38
|
-
return require('../../../client/session-store.js');
|
|
39
|
-
} catch {
|
|
40
|
-
return require('../../vendor/session-store.js');
|
|
41
|
-
}
|
|
42
|
-
})();
|
|
43
|
-
|
|
44
|
-
const credentials = (() => {
|
|
45
|
-
try {
|
|
46
|
-
return require('../../../client/credentials.js');
|
|
47
|
-
} catch {
|
|
48
|
-
return require('../../vendor/credentials.js');
|
|
49
|
-
}
|
|
50
|
-
})();
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The directory the shared store lives in: `$AEGISCODE_HOME` or `~/.aegiscode`.
|
|
54
|
-
* `legacyDir` (Electron's userData) is only used to adopt a pre-unification
|
|
55
|
-
* store, never to read sessions from afterwards.
|
|
56
|
-
*/
|
|
57
|
-
function resolveStoreDir(legacyDir) {
|
|
58
|
-
const dir = credentials.aegisHome();
|
|
59
|
-
if (legacyDir && legacyDir !== dir) adopt(dir, legacyDir);
|
|
60
|
-
return dir;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const {
|
|
64
|
-
storeFile,
|
|
65
|
-
load,
|
|
66
|
-
save,
|
|
67
|
-
upsertSession,
|
|
68
|
-
appendMessage,
|
|
69
|
-
recordExchange,
|
|
70
|
-
listSessions,
|
|
71
|
-
getSession,
|
|
72
|
-
deleteSession,
|
|
73
|
-
markSynced,
|
|
74
|
-
markPending,
|
|
75
|
-
listPending,
|
|
76
|
-
mergeRemoteSessions,
|
|
77
|
-
listSummaries,
|
|
78
|
-
readTranscript,
|
|
79
|
-
adopt,
|
|
80
|
-
toMarkdown,
|
|
81
|
-
toJson,
|
|
82
|
-
} = shared;
|
|
83
|
-
|
|
84
|
-
/** Kept under its old name — main.js and the tests call `sessionsFile`. */
|
|
85
|
-
const sessionsFile = storeFile;
|
|
86
|
-
|
|
87
|
-
module.exports = {
|
|
88
|
-
sessionsFile,
|
|
89
|
-
storeFile,
|
|
90
|
-
resolveStoreDir,
|
|
91
|
-
load,
|
|
92
|
-
save,
|
|
93
|
-
upsertSession,
|
|
94
|
-
appendMessage,
|
|
95
|
-
recordExchange,
|
|
96
|
-
listSessions,
|
|
97
|
-
getSession,
|
|
98
|
-
deleteSession,
|
|
99
|
-
markSynced,
|
|
100
|
-
markPending,
|
|
101
|
-
listPending,
|
|
102
|
-
mergeRemoteSessions,
|
|
103
|
-
listSummaries,
|
|
104
|
-
readTranscript,
|
|
105
|
-
adopt,
|
|
106
|
-
toMarkdown,
|
|
107
|
-
toJson,
|
|
108
|
-
};
|
|
3
|
+
"use strict";const shared=(()=>{try{return require("../../../client/session-store.js")}catch{return require("../../vendor/session-store.js")}})(),credentials=(()=>{try{return require("../../../client/credentials.js")}catch{return require("../../vendor/credentials.js")}})();function resolveStoreDir(e){const s=credentials.aegisHome();return e&&e!==s&&adopt(s,e),s}const{storeFile:storeFile,load:load,save:save,upsertSession:upsertSession,appendMessage:appendMessage,recordExchange:recordExchange,listSessions:listSessions,getSession:getSession,deleteSession:deleteSession,markSynced:markSynced,markPending:markPending,listPending:listPending,mergeRemoteSessions:mergeRemoteSessions,listSummaries:listSummaries,readTranscript:readTranscript,adopt:adopt,toMarkdown:toMarkdown,toJson:toJson}=shared,sessionsFile=storeFile;module.exports={sessionsFile:sessionsFile,storeFile:storeFile,resolveStoreDir:resolveStoreDir,load:load,save:save,upsertSession:upsertSession,appendMessage:appendMessage,recordExchange:recordExchange,listSessions:listSessions,getSession:getSession,deleteSession:deleteSession,markSynced:markSynced,markPending:markPending,listPending:listPending,mergeRemoteSessions:mergeRemoteSessions,listSummaries:listSummaries,readTranscript:readTranscript,adopt:adopt,toMarkdown:toMarkdown,toJson:toJson};
|
package/lib/window-state.js
CHANGED
|
@@ -1,68 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
-
* window-state.js — persisted BrowserWindow bounds (native desktop plumbing).
|
|
10
|
-
* Pure Node + injectable dir, mirrors desktop/lib/sync/memory-queue.js: reads
|
|
11
|
-
* and writes <dir>/window-state.json, no Electron import, so it unit-tests
|
|
12
|
-
* without the Electron binary.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const fs = require('node:fs');
|
|
16
|
-
const path = require('node:path');
|
|
17
|
-
|
|
18
|
-
function stateFile(dir) {
|
|
19
|
-
return path.join(dir, 'window-state.json');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function load(dir) {
|
|
23
|
-
try {
|
|
24
|
-
const data = JSON.parse(fs.readFileSync(stateFile(dir), 'utf8'));
|
|
25
|
-
return data && typeof data === 'object' ? data : null;
|
|
26
|
-
} catch {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function save(dir, state) {
|
|
32
|
-
const file = stateFile(dir);
|
|
33
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
34
|
-
const tmp = `${file}.tmp-${process.pid}`;
|
|
35
|
-
fs.writeFileSync(tmp, JSON.stringify(state, null, 2));
|
|
36
|
-
fs.renameSync(tmp, file);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Clamp a saved rectangle so it always intersects at least one connected
|
|
41
|
-
* display's work area. A saved position from a monitor that has since been
|
|
42
|
-
* unplugged, or from a resolution that shrank, would otherwise place the
|
|
43
|
-
* window off every visible screen — it "opens" but is unreachable. `displays`
|
|
44
|
-
* takes plain `{ workArea: {x,y,width,height} }` objects (electron.screen's
|
|
45
|
-
* shape) so this stays pure and Electron-free for testing.
|
|
46
|
-
*/
|
|
47
|
-
function clampToDisplay(bounds, displays, fallback) {
|
|
48
|
-
if (!bounds || typeof bounds !== 'object') return { ...fallback };
|
|
49
|
-
const { x, y, width, height } = bounds;
|
|
50
|
-
if (![x, y, width, height].every((n) => Number.isFinite(n))) return { ...fallback };
|
|
51
|
-
|
|
52
|
-
const w = Math.max(1, width);
|
|
53
|
-
const h = Math.max(1, height);
|
|
54
|
-
const list = Array.isArray(displays) ? displays : [];
|
|
55
|
-
|
|
56
|
-
const visible = list.some((d) => {
|
|
57
|
-
const wa = d && d.workArea;
|
|
58
|
-
if (!wa) return false;
|
|
59
|
-
return x < wa.x + wa.width && x + w > wa.x && y < wa.y + wa.height && y + h > wa.y;
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (visible) return { x, y, width: w, height: h };
|
|
63
|
-
// Position is off every screen: keep the saved size but drop x/y so the
|
|
64
|
-
// caller's default centering (no x/y passed to BrowserWindow) takes over.
|
|
65
|
-
return { ...fallback, width: w, height: h };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
module.exports = { stateFile, load, save, clampToDisplay };
|
|
3
|
+
"use strict";const fs=require("node:fs"),path=require("node:path");function stateFile(t){return path.join(t,"window-state.json")}function load(t){try{const e=JSON.parse(fs.readFileSync(stateFile(t),"utf8"));return e&&"object"==typeof e?e:null}catch{return null}}function save(t,e){const i=stateFile(t);fs.mkdirSync(path.dirname(i),{recursive:!0});const r=`${i}.tmp-${process.pid}`;fs.writeFileSync(r,JSON.stringify(e,null,2)),fs.renameSync(r,i)}function clampToDisplay(t,e,i){if(!t||"object"!=typeof t)return{...i};const{x:r,y:n,width:s,height:a}=t;if(![r,n,s,a].every((t=>Number.isFinite(t))))return{...i};const o=Math.max(1,s),c=Math.max(1,a);return(Array.isArray(e)?e:[]).some((t=>{const e=t&&t.workArea;return!!e&&r<e.x+e.width&&r+o>e.x&&n<e.y+e.height&&n+c>e.y}))?{x:r,y:n,width:o,height:c}:{...i,width:o,height:c}}module.exports={stateFile:stateFile,load:load,save:save,clampToDisplay:clampToDisplay};
|