aegiscode 7.0.13 → 7.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/package.json +3 -2
- package/scripts/check.mjs +1 -52
- package/scripts/demo.mjs +1 -94
- package/scripts/predist.mjs +1 -75
- package/scripts/runtests.mjs +1 -56
- package/scripts/seal-gate.mjs +1 -74
- package/src/agents.js +1 -139
- package/src/app.js +1 -2932
- package/src/art.js +1 -289
- package/src/chatflow.js +1 -3008
- package/src/checkpoint.js +1 -90
- package/src/clipboard.js +1 -424
- package/src/cloudsync.js +1 -528
- package/src/commands.js +1 -3987
- package/src/config.js +1 -581
- package/src/connect.js +1 -349
- package/src/credentials.js +1 -33
- package/src/deps.js +1 -232
- package/src/devrun.js +1 -187
- package/src/diff.js +1 -333
- package/src/diffview.js +1 -296
- package/src/engine.js +1 -297
- package/src/entitlement.js +1 -355
- package/src/events.js +1 -707
- package/src/export.js +1 -67
- package/src/fingerprint.js +1 -592
- package/src/format.js +1 -259
- package/src/fuzzy.js +1 -119
- package/src/history.js +1 -401
- package/src/init.js +1 -175
- package/src/input.js +1 -139
- package/src/keys.js +1 -183
- package/src/markdown.js +1 -306
- package/src/models.js +1 -487
- package/src/naming.js +1 -229
- package/src/overlays.js +1 -461
- package/src/panels.js +1 -1418
- package/src/ping.js +1 -226
- package/src/presence.js +1 -238
- package/src/render.js +1 -515
- package/src/screen.js +1 -518
- package/src/screens.js +1 -896
- package/src/secret.js +1 -59
- package/src/securefs.js +1 -359
- package/src/settings.js +1 -155
- package/src/shared.js +1 -52
- package/src/sharedpaths.js +1 -53
- package/src/signup.js +1 -156
- package/src/summarize.js +1 -95
- package/src/sysdiag.js +1 -585
- package/src/system.js +1 -40
- package/src/theme.js +1 -570
- package/src/title.js +1 -220
- package/src/todos.js +1 -115
- package/src/tokens.js +1 -263
- package/src/topup.js +1 -210
- package/src/update.js +1 -181
- package/vendor/client/aegis.js +1 -2054
- package/vendor/client/attest.js +1 -442
- package/vendor/client/authorship-key.js +1 -410
- package/vendor/client/auto-provision.js +1 -134
- package/vendor/client/brain-catalog.js +1 -268
- package/vendor/client/byok-catalog.js +1 -230
- package/vendor/client/credentials.js +1 -494
- package/vendor/client/device-fingerprint.js +1 -141
- package/vendor/client/drive-connect.js +1 -85
- package/vendor/client/drive-upload.js +1 -174
- package/vendor/client/env-file.js +1 -1273
- package/vendor/client/fingerprint.js +1 -1064
- package/vendor/client/foreign-memory.js +1 -669
- package/vendor/client/google-signin.js +1 -125
- package/vendor/client/hooks.js +1 -430
- package/vendor/client/model-discovery.js +1 -330
- package/vendor/client/platform.js +1 -937
- package/vendor/client/prefs.js +1 -351
- package/vendor/client/presence-constants.js +1 -107
- package/vendor/client/presence.js +1 -438
- package/vendor/client/record-vault.js +3 -1055
- package/vendor/client/session-store.js +1 -548
- package/vendor/client/topup.js +1 -297
- package/vendor/client/touch.js +1 -458
- package/vendor/client/update.js +1 -704
- package/vendor/client/user-models.js +1 -381
- package/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/desktop/lib/local/claude-pro.js +1 -993
- package/vendor/desktop/lib/local/context.js +1 -95
- package/vendor/desktop/lib/local/engine.js +1 -3228
- package/vendor/desktop/lib/local/entitlement.js +1 -654
- package/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/desktop/lib/local/local.js +1 -2135
- package/vendor/desktop/lib/local/prompt.js +1 -275
- package/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/desktop/lib/local/session-rounds.js +1 -208
- package/vendor/desktop/lib/local/shell.js +1 -680
- package/vendor/desktop/lib/local/tools.js +1 -1238
- package/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/desktop/lib/settings.js +1 -890
- package/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/hosts/install.js +1 -638
- package/vendor/hosts/openai-shim.js +1 -515
- package/vendor/hosts/spec.js +1 -164
- package/vendor/hosts/targets.js +1 -346
- package/vendor/mcp/server.js +1 -221
- package/vendor/mcp/tools.js +1 -408
- package/vendor/one/src/child.js +1 -285
- package/vendor/one/src/permissions.js +1 -369
package/src/secret.js
CHANGED
|
@@ -1,61 +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
|
-
* Read a secret from the terminal without echoing it.
|
|
10
|
-
*
|
|
11
|
-
* Extracted from app.js so the non-interactive entry point can use the same
|
|
12
|
-
* prompt as the in-session commands: `aegiscode login` asks for the account key
|
|
13
|
-
* on the same terms `/key` does, and a second copy of this loop would be a
|
|
14
|
-
* second place for a key to end up echoed to the screen or in a shell history.
|
|
15
|
-
*
|
|
16
|
-
* Raw mode when the stream supports it; a stream that cannot mask (no TTY, no
|
|
17
|
-
* setRawMode) resolves to '' rather than silently reading an echoed secret —
|
|
18
|
-
* every caller treats '' as "nothing given" and says so.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const MASK = '\u2022'; // •
|
|
22
|
-
|
|
23
|
-
function readSecret(promptText, o = {}) {
|
|
24
|
-
const stdin = o.stdin || process.stdin;
|
|
25
|
-
const stdout = o.stdout || process.stdout;
|
|
26
|
-
const canMask = !!stdin.isTTY && typeof stdin.setRawMode === 'function';
|
|
27
|
-
if (!canMask) return Promise.resolve('');
|
|
28
|
-
return new Promise((resolve) => {
|
|
29
|
-
stdout.write(promptText);
|
|
30
|
-
let buf = '';
|
|
31
|
-
const done = (value) => {
|
|
32
|
-
try {
|
|
33
|
-
stdin.setRawMode(false);
|
|
34
|
-
} catch {}
|
|
35
|
-
stdin.removeListener('data', onData);
|
|
36
|
-
stdout.write('\n');
|
|
37
|
-
resolve(value);
|
|
38
|
-
};
|
|
39
|
-
const onData = (chunk) => {
|
|
40
|
-
// Drop terminal escape sequences whole: skipping only the ESC leaves the
|
|
41
|
-
// CSI tail ([A, [3~, …) to be appended to the key.
|
|
42
|
-
const text = String(chunk).replace(/\x1b\[[0-9;?]*[A-Za-z~]/g, '').replace(/\x1b./g, '');
|
|
43
|
-
for (const ch of text) {
|
|
44
|
-
if (ch === '\r' || ch === '\n') return done(buf);
|
|
45
|
-
if (ch === '\x03' || ch === '\x04') return done(''); // ctrl+c / ctrl+d
|
|
46
|
-
if (ch === '\u007f' || ch === '\b') {
|
|
47
|
-
buf = buf.slice(0, -1);
|
|
48
|
-
stdout.write('\b \b');
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
buf += ch;
|
|
52
|
-
stdout.write(MASK);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
stdin.setRawMode(true);
|
|
56
|
-
stdin.resume();
|
|
57
|
-
stdin.on('data', onData);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
module.exports = { readSecret, MASK };
|
|
3
|
+
"use strict";const MASK="•";function readSecret(e,t={}){const r=t.stdin||process.stdin,s=t.stdout||process.stdout;return r.isTTY&&"function"==typeof r.setRawMode?new Promise((t=>{s.write(e);let o="";const n=e=>{try{r.setRawMode(!1)}catch{}r.removeListener("data",c),s.write("\n"),t(e)},c=e=>{const t=String(e).replace(/\x1b\[[0-9;?]*[A-Za-z~]/g,"").replace(/\x1b./g,"");for(const e of t){if("\r"===e||"\n"===e)return n(o);if(""===e||""===e)return n("");""!==e&&"\b"!==e?(o+=e,s.write("•")):(o=o.slice(0,-1),s.write("\b \b"))}};r.setRawMode(!0),r.resume(),r.on("data",c)})):Promise.resolve("")}module.exports={readSecret:readSecret,MASK:"•"};
|
package/src/securefs.js
CHANGED
|
@@ -1,361 +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
|
-
* Private files in the data dir (~/.aegiscode) — hardening against a local
|
|
10
|
-
* info-stealer, which is the threat the CLI's own store actually invites.
|
|
11
|
-
*
|
|
12
|
-
* What was wrong: every writer in this CLI used `fs.writeFileSync(p, data)`
|
|
13
|
-
* with no `mode`, and `fs.mkdirSync(dir, { recursive: true })` with no `mode`.
|
|
14
|
-
* Both therefore inherited the process umask, which on a default desktop Linux
|
|
15
|
-
* is 0002 — so the data dir landed at 0775 and every file in it at 0664. On a
|
|
16
|
-
* single-user box that looks harmless. It is not:
|
|
17
|
-
*
|
|
18
|
-
* - 0664 is world-READABLE. history.jsonl is every prompt and every reply the
|
|
19
|
-
* user has ever sent, checkpoints/ is the same in full, and clipboard.txt is
|
|
20
|
-
* verbatim whatever the user last marked and copied. Any other local account
|
|
21
|
-
* — or any process running as one — reads all of it with plain `cat`.
|
|
22
|
-
* - 0664 is group-WRITABLE, and so was the 0775 directory. config.json holds
|
|
23
|
-
* `provider` and `baseURL`, so a second account in the group could repoint
|
|
24
|
-
* the CLI's endpoint at a host it controls and collect the prompts, the
|
|
25
|
-
* completions, and the credentials relayed through it. A writable data dir
|
|
26
|
-
* also lets anyone drop a `permissions.json` that pre-approves the tools
|
|
27
|
-
* they want the next session to run unprompted.
|
|
28
|
-
*
|
|
29
|
-
* Two properties matter beyond the mode bits:
|
|
30
|
-
*
|
|
31
|
-
* - `O_NOFOLLOW` on create. `writeFileSync` follows symlinks, so a symlink
|
|
32
|
-
* planted at `~/.aegiscode/clipboard.txt` pointing at `~/.bashrc` turned a
|
|
33
|
-
* copy gesture into an arbitrary file overwrite. Creating with
|
|
34
|
-
* `O_CREAT|O_EXCL|O_NOFOLLOW` — after unlinking any leftover — fails instead
|
|
35
|
-
* of following, and `O_EXCL` closes the window between the unlink and the
|
|
36
|
-
* open: a symlink raced into place makes the open fail with EEXIST rather
|
|
37
|
-
* than being followed.
|
|
38
|
-
* - `rename`, not truncate, for the atomic path. `renameSync` replaces a
|
|
39
|
-
* planted symlink instead of writing through it, so the atomic writers
|
|
40
|
-
* (config, permissions) are safe even without the O_EXCL dance.
|
|
41
|
-
*
|
|
42
|
-
* Ownership is checked before every chmod and never chmod'ed through a symlink,
|
|
43
|
-
* so a data dir that is deliberately shared (or root-owned) is left alone rather
|
|
44
|
-
* than having its permissions silently rewritten by us. Every helper is
|
|
45
|
-
* best-effort in the same spirit as the rest of this CLI: a hardening step that
|
|
46
|
-
* cannot be applied must not be the reason a session cannot save.
|
|
47
|
-
*
|
|
48
|
-
* Deliberately dependency-free — no `shared.js`, no engine — so it can be
|
|
49
|
-
* required from anything without a cycle, and unit-tested in isolation.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
const fs = require('node:fs');
|
|
53
|
-
const path = require('node:path');
|
|
54
|
-
|
|
55
|
-
// O_NOFOLLOW is POSIX; on Windows the constant is absent, leaving the mode and
|
|
56
|
-
// rename protections (which do not depend on it) in place.
|
|
57
|
-
const NOFOLLOW = fs.constants.O_NOFOLLOW || 0;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Do `fs.stat().mode` permission bits mean anything on this host?
|
|
61
|
-
*
|
|
62
|
-
* Windows: no. libuv has no NTFS ACL to report, so it synthesises the mode from
|
|
63
|
-
* the read-only attribute and returns 0o666 for every writable file and
|
|
64
|
-
* directory. `exposedBits()` below is therefore ALWAYS true there, which made
|
|
65
|
-
* `/doctor` report the entire data directory as group/world-accessible and
|
|
66
|
-
* `/doctor fix` report it as still exposed after "repairing" it — a permanent
|
|
67
|
-
* false alarm with no action that could clear it. The boundary on Windows is the
|
|
68
|
-
* profile directory's ACL (see client/authorship-key.js, which has always
|
|
69
|
-
* skipped its own mode assert there).
|
|
70
|
-
*
|
|
71
|
-
* Duplicated from client/platform.js `hasPosixModes()` rather than imported
|
|
72
|
-
* because this module is deliberately dependency-free (see the header) so it can
|
|
73
|
-
* be required from anything without a cycle. Injectable, so both branches are
|
|
74
|
-
* exercised on one host.
|
|
75
|
-
*/
|
|
76
|
-
function hasPosixModes(platform = process.platform) {
|
|
77
|
-
return platform !== 'win32';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** True when `st` is owned by the current user (always true where getuid is absent). */
|
|
81
|
-
function ownedByUs(st) {
|
|
82
|
-
if (typeof process.getuid !== 'function') return true;
|
|
83
|
-
try { return st.uid === process.getuid(); } catch { return false; }
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Force `p` to `mode`, but only when it is a real file we own.
|
|
88
|
-
* Never follows a symlink (chmod through a link would modify its target) and
|
|
89
|
-
* never returns false for a file that is already correct.
|
|
90
|
-
*/
|
|
91
|
-
function chmodPrivate(p, mode = 0o600) {
|
|
92
|
-
try {
|
|
93
|
-
const st = fs.lstatSync(p);
|
|
94
|
-
if (st.isSymbolicLink()) return false;
|
|
95
|
-
if (!ownedByUs(st)) return false;
|
|
96
|
-
if ((st.mode & 0o777) === mode) return true;
|
|
97
|
-
fs.chmodSync(p, mode);
|
|
98
|
-
return true;
|
|
99
|
-
} catch {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* `mkdir -p` at 0700, and tighten a directory that already exists.
|
|
106
|
-
* `mkdirSync` ignores `mode` for a directory that is already there, so an
|
|
107
|
-
* install that predates this module keeps its 0775 without the explicit chmod.
|
|
108
|
-
*/
|
|
109
|
-
function ensurePrivateDir(dir) {
|
|
110
|
-
try {
|
|
111
|
-
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
112
|
-
} catch {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
const st = fs.lstatSync(dir);
|
|
117
|
-
if (st.isSymbolicLink() || !st.isDirectory()) return false;
|
|
118
|
-
// Guarded on hasPosixModes: on Windows the test is always true, so this
|
|
119
|
-
// chmod'ed the data directory on literally every write and never changed it.
|
|
120
|
-
if (hasPosixModes() && ownedByUs(st) && (st.mode & 0o077) !== 0) fs.chmodSync(dir, 0o700);
|
|
121
|
-
return true;
|
|
122
|
-
} catch {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Write `data` to `file` with mode 0600, creating the parent dir at 0700.
|
|
129
|
-
*
|
|
130
|
-
* atomic (default) writes `file.tmp` and renames over the target, so a crash
|
|
131
|
-
* cannot truncate a live config and a planted symlink is replaced rather than
|
|
132
|
-
* followed. `{ atomic: false }` truncates in place instead, which is the right
|
|
133
|
-
* shape for a scratch file that is never read concurrently — it still refuses
|
|
134
|
-
* to follow a symlink at `file`.
|
|
135
|
-
*
|
|
136
|
-
* Throws on failure; callers already treat a failed save as non-fatal.
|
|
137
|
-
*/
|
|
138
|
-
function writePrivateFile(file, data, opts = {}) {
|
|
139
|
-
const dir = path.dirname(file);
|
|
140
|
-
ensurePrivateDir(dir);
|
|
141
|
-
|
|
142
|
-
const common = fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | NOFOLLOW;
|
|
143
|
-
|
|
144
|
-
if (opts.atomic === false) {
|
|
145
|
-
try { fs.unlinkSync(file); } catch {} // drop a leftover or a planted symlink
|
|
146
|
-
const fd = fs.openSync(file, common, 0o600);
|
|
147
|
-
try {
|
|
148
|
-
fs.fchmodSync(fd, 0o600);
|
|
149
|
-
fs.writeFileSync(fd, data);
|
|
150
|
-
} finally {
|
|
151
|
-
fs.closeSync(fd);
|
|
152
|
-
}
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const tmp = file + '.tmp';
|
|
157
|
-
try { fs.unlinkSync(tmp); } catch {}
|
|
158
|
-
const fd = fs.openSync(tmp, common, 0o600);
|
|
159
|
-
try {
|
|
160
|
-
fs.fchmodSync(fd, 0o600);
|
|
161
|
-
fs.writeFileSync(fd, data);
|
|
162
|
-
} finally {
|
|
163
|
-
fs.closeSync(fd);
|
|
164
|
-
}
|
|
165
|
-
fs.renameSync(tmp, file); // replaces a planted symlink instead of writing through it
|
|
166
|
-
chmodPrivate(file, 0o600);
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* ---------------------------------------------------------------------------
|
|
172
|
-
* Retroactive repair.
|
|
173
|
-
* ---------------------------------------------------------------------------
|
|
174
|
-
*
|
|
175
|
-
* `writePrivateFile` hardens a path only at the moment it is written, so an
|
|
176
|
-
* install that predates this module keeps its 0664/0775 indefinitely: each
|
|
177
|
-
* writer fixes a file the next time that file happens to change, and nothing
|
|
178
|
-
* ever revisits the rest. On the real store that left `~/.aegiscode` at 0775
|
|
179
|
-
* with config.json, permissions.json, history.jsonl, clipboard.txt and every
|
|
180
|
-
* file under checkpoints/ and indexes/ at 0664 — months of transcripts, plus a
|
|
181
|
-
* group-writable endpoint — readable by any other local account.
|
|
182
|
-
*
|
|
183
|
-
* `repairExposure` walks the data dir once and forces it private. Three details
|
|
184
|
-
* are load-bearing rather than incidental:
|
|
185
|
-
*
|
|
186
|
-
* - The exec bit is PRESERVED, not stripped. This directory is not purely
|
|
187
|
-
* data: `oauth-proxy.js` (0775) and `bin/aegis-cli` (0755) are run from
|
|
188
|
-
* here, so the obvious implementation — a blanket `chmod 0600` — would
|
|
189
|
-
* silently break both. The rule is therefore mode-relative: a directory, or
|
|
190
|
-
* a file the owner may execute, becomes 0700; anything else becomes 0600.
|
|
191
|
-
* Nothing loses a permission it needed; everything loses the ones it did
|
|
192
|
-
* not.
|
|
193
|
-
* - Symlinks are never entered and never chmod'ed through, for the same reason
|
|
194
|
-
* `chmodPrivate` refuses them: a planted link would otherwise make the
|
|
195
|
-
* repair itself the write primitive.
|
|
196
|
-
* - The root directory is the high-value step. At 0700 no other account can
|
|
197
|
-
* traverse into it at all, which covers every file inside — including the
|
|
198
|
-
* executables above whose own modes stay permissive. The per-file pass is
|
|
199
|
-
* defence in depth for the case where the directory is later re-shared,
|
|
200
|
-
* restored from a backup, or a file is copied out of it.
|
|
201
|
-
*
|
|
202
|
-
* The read-only (`auditExposure`) and writing (`repairExposure`) entry points
|
|
203
|
-
* are deliberately separate so `/doctor` can report exposure without changing
|
|
204
|
-
* anything, and only act on an explicit `/doctor fix`.
|
|
205
|
-
*/
|
|
206
|
-
|
|
207
|
-
/** Longest path (below the data dir) the repair walk will descend. */
|
|
208
|
-
const MAX_WALK_DEPTH = 4;
|
|
209
|
-
|
|
210
|
-
/** `0775`-style rendering of the permission bits of a `stat`. */
|
|
211
|
-
function fmtMode(mode) {
|
|
212
|
-
return '0' + (mode & 0o777).toString(8).padStart(3, '0');
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* The mode a path should hold: 0700 when the owner needs to traverse or execute
|
|
217
|
-
* it (a directory, or a file carrying an owner-exec bit), 0600 otherwise.
|
|
218
|
-
*/
|
|
219
|
-
function targetMode(st) {
|
|
220
|
-
if (st.isDirectory()) return 0o700;
|
|
221
|
-
return st.mode & 0o100 ? 0o700 : 0o600;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Every non-symlink entry under `root`, depth-first, with its lstat.
|
|
226
|
-
* Unreadable directories are skipped rather than thrown on: a repair that
|
|
227
|
-
* cannot see a subtree must still fix the rest of it.
|
|
228
|
-
*/
|
|
229
|
-
function scanTree(root) {
|
|
230
|
-
const out = [];
|
|
231
|
-
const walk = (dir, rel, depth) => {
|
|
232
|
-
if (depth > MAX_WALK_DEPTH) return;
|
|
233
|
-
let entries;
|
|
234
|
-
try {
|
|
235
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
236
|
-
} catch {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
for (const e of entries) {
|
|
240
|
-
if (e.isSymbolicLink()) continue; // never followed, never chmod'ed through
|
|
241
|
-
const full = path.join(dir, e.name);
|
|
242
|
-
const childRel = rel ? `${rel}/${e.name}` : e.name;
|
|
243
|
-
let st;
|
|
244
|
-
try {
|
|
245
|
-
st = fs.lstatSync(full);
|
|
246
|
-
} catch {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
out.push({ rel: childRel, full, st });
|
|
250
|
-
if (st.isDirectory()) walk(full, childRel, depth + 1);
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
walk(root, '', 0);
|
|
254
|
-
return out;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/** Does `mode` grant anything to group or other? */
|
|
258
|
-
function exposedBits(mode) {
|
|
259
|
-
return (mode & 0o077) !== 0;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Report every path in the data dir that is reachable by group or other.
|
|
264
|
-
*
|
|
265
|
-
* Read-only. Returns `{ root, exists, rootMode, exposed, total }` where each
|
|
266
|
-
* entry of `exposed` is `{ rel, mode, kind }` — `rel` is `.` for the root
|
|
267
|
-
* itself, and `kind` is `'dir'` or `'file'`.
|
|
268
|
-
*/
|
|
269
|
-
function auditExposure(root, options = {}) {
|
|
270
|
-
const platform = options.platform || process.platform;
|
|
271
|
-
const modesMeaningful = hasPosixModes(platform);
|
|
272
|
-
const report = { root, exists: false, rootMode: null, exposed: [], total: 0, modesMeaningful };
|
|
273
|
-
let rst;
|
|
274
|
-
try {
|
|
275
|
-
rst = fs.lstatSync(root);
|
|
276
|
-
} catch {
|
|
277
|
-
return report;
|
|
278
|
-
}
|
|
279
|
-
if (rst.isSymbolicLink() || !rst.isDirectory()) return report;
|
|
280
|
-
report.exists = true;
|
|
281
|
-
report.rootMode = fmtMode(rst.mode);
|
|
282
|
-
// Where the mode is synthesised there is nothing to audit: every path would be
|
|
283
|
-
// listed, none of it true. `modesMeaningful: false` is the honest answer and
|
|
284
|
-
// the caller renders it as "not applicable", never as "all clear".
|
|
285
|
-
if (!modesMeaningful) {
|
|
286
|
-
report.total = scanTree(root).length;
|
|
287
|
-
return report;
|
|
288
|
-
}
|
|
289
|
-
if (exposedBits(rst.mode)) report.exposed.push({ rel: '.', mode: report.rootMode, kind: 'dir' });
|
|
290
|
-
|
|
291
|
-
const items = scanTree(root);
|
|
292
|
-
report.total = items.length;
|
|
293
|
-
for (const it of items) {
|
|
294
|
-
if (!exposedBits(it.st.mode)) continue;
|
|
295
|
-
report.exposed.push({
|
|
296
|
-
rel: it.rel,
|
|
297
|
-
mode: fmtMode(it.st.mode),
|
|
298
|
-
kind: it.st.isDirectory() ? 'dir' : 'file',
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
return report;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Force every group/world-accessible path in the data dir back to 0700/0600,
|
|
306
|
-
* preserving the owner-exec bit (see the block comment above).
|
|
307
|
-
*
|
|
308
|
-
* Best-effort and idempotent: a path that is already private is left untouched,
|
|
309
|
-
* a path we do not own is reported rather than fought over, and a second run
|
|
310
|
-
* fixes nothing. Returns `{ root, exists, fixed, failed, remaining }`, where
|
|
311
|
-
* `remaining` is the exposure audit taken after the pass — non-empty only when
|
|
312
|
-
* something could not be repaired.
|
|
313
|
-
*/
|
|
314
|
-
function repairExposure(root, options = {}) {
|
|
315
|
-
const platform = options.platform || process.platform;
|
|
316
|
-
const modesMeaningful = hasPosixModes(platform);
|
|
317
|
-
const report = { root, exists: false, fixed: [], failed: [], remaining: [], modesMeaningful };
|
|
318
|
-
let rst;
|
|
319
|
-
try {
|
|
320
|
-
rst = fs.lstatSync(root);
|
|
321
|
-
} catch {
|
|
322
|
-
return report;
|
|
323
|
-
}
|
|
324
|
-
if (rst.isSymbolicLink() || !rst.isDirectory()) return report;
|
|
325
|
-
report.exists = true;
|
|
326
|
-
// A chmod here cannot change what stat reports, so the old code "fixed" every
|
|
327
|
-
// path and then re-audited it as still exposed, forever. Report a clean no-op.
|
|
328
|
-
if (!modesMeaningful) return report;
|
|
329
|
-
|
|
330
|
-
const tighten = (full, st, rel) => {
|
|
331
|
-
if (!ownedByUs(st)) {
|
|
332
|
-
report.failed.push({ rel, reason: 'not owned by this user' });
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
const want = targetMode(st);
|
|
336
|
-
try {
|
|
337
|
-
fs.chmodSync(full, want);
|
|
338
|
-
report.fixed.push({ rel, from: fmtMode(st.mode), to: fmtMode(want) });
|
|
339
|
-
} catch (err) {
|
|
340
|
-
report.failed.push({ rel, reason: err.code || String(err) });
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
if (exposedBits(rst.mode)) tighten(root, rst, '.');
|
|
345
|
-
for (const it of scanTree(root)) {
|
|
346
|
-
if (!exposedBits(it.st.mode)) continue;
|
|
347
|
-
tighten(it.full, it.st, it.rel);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
report.remaining = auditExposure(root, { platform }).exposed;
|
|
351
|
-
return report;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
module.exports = {
|
|
355
|
-
ensurePrivateDir,
|
|
356
|
-
writePrivateFile,
|
|
357
|
-
chmodPrivate,
|
|
358
|
-
auditExposure,
|
|
359
|
-
repairExposure,
|
|
360
|
-
fmtMode,
|
|
361
|
-
};
|
|
3
|
+
"use strict";const fs=require("node:fs"),path=require("node:path"),NOFOLLOW=fs.constants.O_NOFOLLOW||0;function hasPosixModes(e=process.platform){return"win32"!==e}function ownedByUs(e){if("function"!=typeof process.getuid)return!0;try{return e.uid===process.getuid()}catch{return!1}}function chmodPrivate(e,t=384){try{const r=fs.lstatSync(e);return!r.isSymbolicLink()&&!!ownedByUs(r)&&((511&r.mode)===t||fs.chmodSync(e,t),!0)}catch{return!1}}function ensurePrivateDir(e){try{fs.mkdirSync(e,{recursive:!0,mode:448})}catch{return!1}try{const t=fs.lstatSync(e);return!(t.isSymbolicLink()||!t.isDirectory()||(hasPosixModes()&&ownedByUs(t)&&0!=(63&t.mode)&&fs.chmodSync(e,448),0))}catch{return!1}}function writePrivateFile(e,t,r={}){ensurePrivateDir(path.dirname(e));const o=fs.constants.O_WRONLY|fs.constants.O_CREAT|fs.constants.O_EXCL|NOFOLLOW;if(!1===r.atomic){try{fs.unlinkSync(e)}catch{}const r=fs.openSync(e,o,384);try{fs.fchmodSync(r,384),fs.writeFileSync(r,t)}finally{fs.closeSync(r)}return!0}const s=e+".tmp";try{fs.unlinkSync(s)}catch{}const n=fs.openSync(s,o,384);try{fs.fchmodSync(n,384),fs.writeFileSync(n,t)}finally{fs.closeSync(n)}return fs.renameSync(s,e),chmodPrivate(e,384),!0}const MAX_WALK_DEPTH=4;function fmtMode(e){return"0"+(511&e).toString(8).padStart(3,"0")}function targetMode(e){return e.isDirectory()||64&e.mode?448:384}function scanTree(e){const t=[],r=(e,o,s)=>{if(s>MAX_WALK_DEPTH)return;let n;try{n=fs.readdirSync(e,{withFileTypes:!0})}catch{return}for(const i of n){if(i.isSymbolicLink())continue;const n=path.join(e,i.name),c=o?`${o}/${i.name}`:i.name;let f;try{f=fs.lstatSync(n)}catch{continue}t.push({rel:c,full:n,st:f}),f.isDirectory()&&r(n,c,s+1)}};return r(e,"",0),t}function exposedBits(e){return 0!=(63&e)}function auditExposure(e,t={}){const r=hasPosixModes(t.platform||process.platform),o={root:e,exists:!1,rootMode:null,exposed:[],total:0,modesMeaningful:r};let s;try{s=fs.lstatSync(e)}catch{return o}if(s.isSymbolicLink()||!s.isDirectory())return o;if(o.exists=!0,o.rootMode=fmtMode(s.mode),!r)return o.total=scanTree(e).length,o;exposedBits(s.mode)&&o.exposed.push({rel:".",mode:o.rootMode,kind:"dir"});const n=scanTree(e);o.total=n.length;for(const e of n)exposedBits(e.st.mode)&&o.exposed.push({rel:e.rel,mode:fmtMode(e.st.mode),kind:e.st.isDirectory()?"dir":"file"});return o}function repairExposure(e,t={}){const r=t.platform||process.platform,o=hasPosixModes(r),s={root:e,exists:!1,fixed:[],failed:[],remaining:[],modesMeaningful:o};let n;try{n=fs.lstatSync(e)}catch{return s}if(n.isSymbolicLink()||!n.isDirectory())return s;if(s.exists=!0,!o)return s;const i=(e,t,r)=>{if(!ownedByUs(t))return void s.failed.push({rel:r,reason:"not owned by this user"});const o=targetMode(t);try{fs.chmodSync(e,o),s.fixed.push({rel:r,from:fmtMode(t.mode),to:fmtMode(o)})}catch(e){s.failed.push({rel:r,reason:e.code||String(e)})}};exposedBits(n.mode)&&i(e,n,".");for(const t of scanTree(e))exposedBits(t.st.mode)&&i(t.full,t.st,t.rel);return s.remaining=auditExposure(e,{platform:r}).exposed,s}module.exports={ensurePrivateDir:ensurePrivateDir,writePrivateFile:writePrivateFile,chmodPrivate:chmodPrivate,auditExposure:auditExposure,repairExposure:repairExposure,fmtMode:fmtMode};
|
package/src/settings.js
CHANGED
|
@@ -1,157 +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
|
-
* /config — read and write every setting from the prompt, over the split store.
|
|
10
|
-
*
|
|
11
|
-
* The upstream engine's version of this (`src/session.js`, `parseConfigValue` /
|
|
12
|
-
* `configRows` / `setConfigValue`) sits on a single config file, so it can list
|
|
13
|
-
* `Object.keys(cfg)` and write whatever it is given. This host cannot: since
|
|
14
|
-
* AEGISONE D5, `cli/src/config.js` keeps host-local keys in `config.json` and
|
|
15
|
-
* *preferences* in the shared `preferences.json` the desktop's settings window
|
|
16
|
-
* writes too (`SHARED_PREF_KEYS`, mirrored in `client/prefs.js`). A `/config`
|
|
17
|
-
* that showed one flat list and wrote it back blind would reintroduce exactly
|
|
18
|
-
* the drift ON8/D8 rule 1 just closed — two stores holding two answers to one
|
|
19
|
-
* question. So the two things this module adds over the port:
|
|
20
|
-
*
|
|
21
|
-
* 1. Every row says which store holds the key, and the write goes through
|
|
22
|
-
* `updateConfig()`, which routes each key to the store that owns it. There
|
|
23
|
-
* is no path here that writes a file directly.
|
|
24
|
-
* 2. Values are SUMMARIZED for the list. `models` is a several-hundred-line
|
|
25
|
-
* model table and `updateCheck` is an object; dumping them is how `/config`
|
|
26
|
-
* becomes unreadable. `/config <key>` still shows one in full, on demand.
|
|
27
|
-
*
|
|
28
|
-
* Typed parsing is the upstream's, unchanged and deliberately narrow: `true` /
|
|
29
|
-
* `false` / `null`, integers, floats, JSON arrays and objects, everything else a
|
|
30
|
-
* string. An unknown key is refused rather than created — a typo that silently
|
|
31
|
-
* grows the config file is a config file nobody can reason about later.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
const { loadConfig, updateConfig, DEFAULT_CONFIG } = require('./config.js');
|
|
35
|
-
// The one list of keys that live in the shared store. Imported rather than
|
|
36
|
-
// re-listed: a second copy here is how the two hosts drift back apart.
|
|
37
|
-
const { prefs } = require('./shared.js');
|
|
38
|
-
|
|
39
|
-
const SHARED_KEYS = new Set(prefs.SHARED_PREF_KEYS);
|
|
40
|
-
|
|
41
|
-
/** Where a key lives: the store both hosts read, or this host's own file. */
|
|
42
|
-
function configStore(key) {
|
|
43
|
-
return SHARED_KEYS.has(key) ? 'shared' : 'host';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Coerce a prompt-ish string into the JSON type the config key wants. */
|
|
47
|
-
function parseConfigValue(raw) {
|
|
48
|
-
const s = String(raw == null ? '' : raw).trim();
|
|
49
|
-
if (s === '') return '';
|
|
50
|
-
if (s === 'true') return true;
|
|
51
|
-
if (s === 'false') return false;
|
|
52
|
-
if (s === 'null') return null;
|
|
53
|
-
if (/^-?\d+$/.test(s)) return Number.parseInt(s, 10);
|
|
54
|
-
if (/^-?\d*\.\d+$/.test(s)) return Number.parseFloat(s);
|
|
55
|
-
if (s.startsWith('[') || s.startsWith('{')) {
|
|
56
|
-
try { return JSON.parse(s); } catch { return s; }
|
|
57
|
-
}
|
|
58
|
-
return s;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* One line for the list. Smaller values print as the value the user would have
|
|
63
|
-
* typed (so `/config <key> <value>` round-trips); anything structured is
|
|
64
|
-
* counted. `''` is shown as `""` because an empty row and a missing row must
|
|
65
|
-
* not look alike.
|
|
66
|
-
*/
|
|
67
|
-
function summarizeValue(value, max = 48) {
|
|
68
|
-
if (value === null) return 'null';
|
|
69
|
-
if (value === undefined) return '(unset)';
|
|
70
|
-
if (Array.isArray(value)) return `[${value.length} item${value.length === 1 ? '' : 's'}]`;
|
|
71
|
-
if (typeof value === 'object') {
|
|
72
|
-
const n = Object.keys(value).length;
|
|
73
|
-
return `{${n} key${n === 1 ? '' : 's'}}`;
|
|
74
|
-
}
|
|
75
|
-
if (typeof value === 'string') {
|
|
76
|
-
if (value === '') return '""';
|
|
77
|
-
return value.length > max ? `${value.slice(0, max - 1)}…` : value;
|
|
78
|
-
}
|
|
79
|
-
return String(value);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Render a value for `/config <key>` — pretty JSON when it is structured. */
|
|
83
|
-
function fullValue(value) {
|
|
84
|
-
if (value && typeof value === 'object') return JSON.stringify(value, null, 2);
|
|
85
|
-
if (value === '') return '""';
|
|
86
|
-
return String(value);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Every key, with its current (defaulted) value and the store that owns it.
|
|
91
|
-
* `defaulted` marks a key still at its shipped value, so "I never changed this"
|
|
92
|
-
* is visible rather than inferred.
|
|
93
|
-
*/
|
|
94
|
-
function configRows(cfg = loadConfig()) {
|
|
95
|
-
return Object.keys(cfg).sort().map((key) => ({
|
|
96
|
-
key,
|
|
97
|
-
value: cfg[key],
|
|
98
|
-
store: configStore(key),
|
|
99
|
-
defaulted: Object.prototype.hasOwnProperty.call(DEFAULT_CONFIG, key)
|
|
100
|
-
&& JSON.stringify(cfg[key]) === JSON.stringify(DEFAULT_CONFIG[key]),
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Panel lines: `key = value [store]`. */
|
|
105
|
-
function formatConfigRows(rows = configRows()) {
|
|
106
|
-
if (!rows.length) return [' No config keys.'];
|
|
107
|
-
const width = Math.max(...rows.map((r) => r.key.length));
|
|
108
|
-
return rows.map((r) => ` ${r.key.padEnd(width)} ${summarizeValue(r.value).padEnd(26)} ${r.store}${r.defaulted ? ' (default)' : ''}`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Set one key. Returns `{ key, value, store }` on success or `{ error }`.
|
|
113
|
-
* The known-key check reads the *merged* config, which is the set of keys a
|
|
114
|
-
* later `loadConfig()` will actually return — so a write can never land on a
|
|
115
|
-
* key the read side would not report.
|
|
116
|
-
*/
|
|
117
|
-
function setConfigValue(key, rawValue) {
|
|
118
|
-
const k = String(key || '').trim();
|
|
119
|
-
if (!k) return { error: 'usage: /config <key> <value>' };
|
|
120
|
-
const cfg = loadConfig();
|
|
121
|
-
if (!Object.prototype.hasOwnProperty.call(cfg, k)) {
|
|
122
|
-
return { error: `unknown config key "${k}" — run /config to list the keys` };
|
|
123
|
-
}
|
|
124
|
-
const value = parseConfigValue(rawValue);
|
|
125
|
-
updateConfig({ [k]: value });
|
|
126
|
-
return { key: k, value, store: configStore(k) };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Put one key back to its shipped value. Returns `{ error }` for an unknown key
|
|
131
|
-
* or for a key this host has no default for (a host-local extra is deleted
|
|
132
|
-
* rather than set to `undefined`, which is not a JSON value).
|
|
133
|
-
*/
|
|
134
|
-
function resetConfigValue(key) {
|
|
135
|
-
const k = String(key || '').trim();
|
|
136
|
-
if (!k) return { error: 'usage: /config reset <key>' };
|
|
137
|
-
if (!Object.prototype.hasOwnProperty.call(loadConfig(), k)) {
|
|
138
|
-
return { error: `unknown config key "${k}" — run /config to list the keys` };
|
|
139
|
-
}
|
|
140
|
-
if (!Object.prototype.hasOwnProperty.call(DEFAULT_CONFIG, k)) {
|
|
141
|
-
return { error: `"${k}" has no shipped default to reset to — /config ${k} <value> sets it directly` };
|
|
142
|
-
}
|
|
143
|
-
updateConfig({ [k]: DEFAULT_CONFIG[k] });
|
|
144
|
-
return { key: k, value: DEFAULT_CONFIG[k], store: configStore(k) };
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
module.exports = {
|
|
148
|
-
SHARED_KEYS,
|
|
149
|
-
configStore,
|
|
150
|
-
parseConfigValue,
|
|
151
|
-
summarizeValue,
|
|
152
|
-
fullValue,
|
|
153
|
-
configRows,
|
|
154
|
-
formatConfigRows,
|
|
155
|
-
setConfigValue,
|
|
156
|
-
resetConfigValue,
|
|
157
|
-
};
|
|
3
|
+
"use strict";const{loadConfig:loadConfig,updateConfig:updateConfig,DEFAULT_CONFIG:DEFAULT_CONFIG}=require("./config.js"),{prefs:prefs}=require("./shared.js"),SHARED_KEYS=new Set(prefs.SHARED_PREF_KEYS);function configStore(e){return SHARED_KEYS.has(e)?"shared":"host"}function parseConfigValue(e){const t=String(null==e?"":e).trim();if(""===t)return"";if("true"===t)return!0;if("false"===t)return!1;if("null"===t)return null;if(/^-?\d+$/.test(t))return Number.parseInt(t,10);if(/^-?\d*\.\d+$/.test(t))return Number.parseFloat(t);if(t.startsWith("[")||t.startsWith("{"))try{return JSON.parse(t)}catch{return t}return t}function summarizeValue(e,t=48){if(null===e)return"null";if(void 0===e)return"(unset)";if(Array.isArray(e))return`[${e.length} item${1===e.length?"":"s"}]`;if("object"==typeof e){const t=Object.keys(e).length;return`{${t} key${1===t?"":"s"}}`}return"string"==typeof e?""===e?'""':e.length>t?`${e.slice(0,t-1)}…`:e:String(e)}function fullValue(e){return e&&"object"==typeof e?JSON.stringify(e,null,2):""===e?'""':String(e)}function configRows(e=loadConfig()){return Object.keys(e).sort().map((t=>({key:t,value:e[t],store:configStore(t),defaulted:Object.prototype.hasOwnProperty.call(DEFAULT_CONFIG,t)&&JSON.stringify(e[t])===JSON.stringify(DEFAULT_CONFIG[t])})))}function formatConfigRows(e=configRows()){if(!e.length)return[" No config keys."];const t=Math.max(...e.map((e=>e.key.length)));return e.map((e=>` ${e.key.padEnd(t)} ${summarizeValue(e.value).padEnd(26)} ${e.store}${e.defaulted?" (default)":""}`))}function setConfigValue(e,t){const r=String(e||"").trim();if(!r)return{error:"usage: /config <key> <value>"};const n=loadConfig();if(!Object.prototype.hasOwnProperty.call(n,r))return{error:`unknown config key "${r}" — run /config to list the keys`};const o=parseConfigValue(t);return updateConfig({[r]:o}),{key:r,value:o,store:configStore(r)}}function resetConfigValue(e){const t=String(e||"").trim();return t?Object.prototype.hasOwnProperty.call(loadConfig(),t)?Object.prototype.hasOwnProperty.call(DEFAULT_CONFIG,t)?(updateConfig({[t]:DEFAULT_CONFIG[t]}),{key:t,value:DEFAULT_CONFIG[t],store:configStore(t)}):{error:`"${t}" has no shipped default to reset to — /config ${t} <value> sets it directly`}:{error:`unknown config key "${t}" — run /config to list the keys`}:{error:"usage: /config reset <key>"}}module.exports={SHARED_KEYS:SHARED_KEYS,configStore:configStore,parseConfigValue:parseConfigValue,summarizeValue:summarizeValue,fullValue:fullValue,configRows:configRows,formatConfigRows:formatConfigRows,setConfigValue:setConfigValue,resetConfigValue:resetConfigValue};
|
package/src/shared.js
CHANGED
|
@@ -1,54 +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
|
-
* Where the CLI finds the modules it shares with the other hosts.
|
|
10
|
-
*
|
|
11
|
-
* `src/deps.js` does this for the transport/engine/registry trio, but it pulls
|
|
12
|
-
* the whole agent loop in at require time — far too heavy for `config.js` and
|
|
13
|
-
* `history.js`, which every command and every launch touches. This module
|
|
14
|
-
* resolves the two *pure* shared modules those files need, with the same
|
|
15
|
-
* two-layout rule and the same by-existence lookup:
|
|
16
|
-
*
|
|
17
|
-
* in-repo <repo>/cli/src/shared.js -> <repo>/client/*.js
|
|
18
|
-
* npm <pkg>/src/shared.js -> <pkg>/vendor/client/*.js
|
|
19
|
-
*
|
|
20
|
-
* A missing module is a loud error rather than a silent fallback to a second
|
|
21
|
-
* copy: a duplicate credential store or session store is exactly the drift this
|
|
22
|
-
* whole arrangement exists to prevent.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const fs = require('node:fs');
|
|
26
|
-
const path = require('node:path');
|
|
27
|
-
|
|
28
|
-
function candidates(name) {
|
|
29
|
-
return [
|
|
30
|
-
path.join(__dirname, '..', '..', 'client', name), // repo checkout
|
|
31
|
-
path.join(__dirname, '..', 'vendor', 'client', name), // staged package
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function resolveClientModule(name) {
|
|
36
|
-
const tried = candidates(name);
|
|
37
|
-
for (const candidate of tried) {
|
|
38
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
39
|
-
}
|
|
40
|
-
throw new Error(
|
|
41
|
-
`aegiscode: cannot find client/${name}. Expected it beside cli/ (in the repo) ` +
|
|
42
|
-
'or under cli/vendor/client/ (installed package). Reinstall the package, or ' +
|
|
43
|
-
'run `node scripts/predist.mjs` from cli/ if this is a source checkout.'
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const credentials = require(resolveClientModule('credentials.js'));
|
|
48
|
-
const sessionStore = require(resolveClientModule('session-store.js'));
|
|
49
|
-
// The one shared non-secret preference store (AEGISONE D5). `config.js` reads
|
|
50
|
-
// and writes it, and the desktop's settings store writes the same file — so it
|
|
51
|
-
// belongs here, resolved by existence, rather than as a second path guess.
|
|
52
|
-
const prefs = require(resolveClientModule('prefs.js'));
|
|
53
|
-
|
|
54
|
-
module.exports = { credentials, sessionStore, prefs, resolveClientModule };
|
|
3
|
+
"use strict";const fs=require("node:fs"),path=require("node:path");function candidates(e){return[path.join(__dirname,"..","..","client",e),path.join(__dirname,"..","vendor","client",e)]}function resolveClientModule(e){const s=candidates(e);for(const e of s)if(fs.existsSync(e))return e;throw new Error(`aegiscode: cannot find client/${e}. Expected it beside cli/ (in the repo) or under cli/vendor/client/ (installed package). Reinstall the package, or run \`node scripts/predist.mjs\` from cli/ if this is a source checkout.`)}const credentials=require(resolveClientModule("credentials.js")),sessionStore=require(resolveClientModule("session-store.js")),prefs=require(resolveClientModule("prefs.js"));module.exports={credentials:credentials,sessionStore:sessionStore,prefs:prefs,resolveClientModule:resolveClientModule};
|