@getengram/cli 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +38 -11
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/conversations.d.ts.map +1 -1
- package/dist/commands/conversations.js +8 -2
- package/dist/commands/conversations.js.map +1 -1
- package/dist/commands/exclude.d.ts.map +1 -1
- package/dist/commands/exclude.js +73 -21
- package/dist/commands/exclude.js.map +1 -1
- package/dist/commands/import.d.ts +30 -3
- package/dist/commands/import.d.ts.map +1 -1
- package/dist/commands/import.js +374 -45
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +144 -29
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/search.js +2 -2
- package/dist/commands/search.js.map +1 -1
- package/dist/commands/status.d.ts +16 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +51 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/store.d.ts.map +1 -1
- package/dist/commands/store.js +19 -3
- package/dist/commands/store.js.map +1 -1
- package/dist/commands/upgrade.d.ts +24 -0
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +64 -15
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/usage.d.ts +44 -0
- package/dist/commands/usage.d.ts.map +1 -1
- package/dist/commands/usage.js +79 -19
- package/dist/commands/usage.js.map +1 -1
- package/dist/commands/vault.d.ts +11 -2
- package/dist/commands/vault.d.ts.map +1 -1
- package/dist/commands/vault.js +372 -53
- package/dist/commands/vault.js.map +1 -1
- package/dist/config-file.d.ts +74 -0
- package/dist/config-file.d.ts.map +1 -0
- package/dist/config-file.js +152 -0
- package/dist/config-file.js.map +1 -0
- package/dist/config-guard.d.ts +96 -0
- package/dist/config-guard.d.ts.map +1 -0
- package/dist/config-guard.js +184 -0
- package/dist/config-guard.js.map +1 -0
- package/dist/config.d.ts +48 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +101 -12
- package/dist/config.js.map +1 -1
- package/dist/daemon/as-root.d.ts +46 -0
- package/dist/daemon/as-root.d.ts.map +1 -0
- package/dist/daemon/as-root.js +64 -0
- package/dist/daemon/as-root.js.map +1 -0
- package/dist/daemon/backoff.d.ts +26 -0
- package/dist/daemon/backoff.d.ts.map +1 -0
- package/dist/daemon/backoff.js +37 -0
- package/dist/daemon/backoff.js.map +1 -0
- package/dist/daemon/codex-parser.d.ts +38 -4
- package/dist/daemon/codex-parser.d.ts.map +1 -1
- package/dist/daemon/codex-parser.js +111 -23
- package/dist/daemon/codex-parser.js.map +1 -1
- package/dist/daemon/command-path.d.ts +13 -0
- package/dist/daemon/command-path.d.ts.map +1 -0
- package/dist/daemon/command-path.js +35 -0
- package/dist/daemon/command-path.js.map +1 -0
- package/dist/daemon/commands.d.ts +146 -5
- package/dist/daemon/commands.d.ts.map +1 -1
- package/dist/daemon/commands.js +2766 -316
- package/dist/daemon/commands.js.map +1 -1
- package/dist/daemon/db.d.ts +255 -27
- package/dist/daemon/db.d.ts.map +1 -1
- package/dist/daemon/db.js +749 -53
- package/dist/daemon/db.js.map +1 -1
- package/dist/daemon/exclusions.d.ts +23 -3
- package/dist/daemon/exclusions.d.ts.map +1 -1
- package/dist/daemon/exclusions.js +91 -21
- package/dist/daemon/exclusions.js.map +1 -1
- package/dist/daemon/homebrew.d.ts +26 -0
- package/dist/daemon/homebrew.d.ts.map +1 -0
- package/dist/daemon/homebrew.js +43 -0
- package/dist/daemon/homebrew.js.map +1 -0
- package/dist/daemon/instance.d.ts +427 -0
- package/dist/daemon/instance.d.ts.map +1 -0
- package/dist/daemon/instance.js +1201 -0
- package/dist/daemon/instance.js.map +1 -0
- package/dist/daemon/key-source.d.ts +41 -0
- package/dist/daemon/key-source.d.ts.map +1 -0
- package/dist/daemon/key-source.js +89 -0
- package/dist/daemon/key-source.js.map +1 -0
- package/dist/daemon/launch.d.ts +56 -0
- package/dist/daemon/launch.d.ts.map +1 -0
- package/dist/daemon/launch.js +153 -0
- package/dist/daemon/launch.js.map +1 -0
- package/dist/daemon/launchd.d.ts +215 -0
- package/dist/daemon/launchd.d.ts.map +1 -0
- package/dist/daemon/launchd.js +527 -0
- package/dist/daemon/launchd.js.map +1 -0
- package/dist/daemon/login-start.d.ts +2 -0
- package/dist/daemon/login-start.d.ts.map +1 -0
- package/dist/daemon/login-start.js +25 -0
- package/dist/daemon/login-start.js.map +1 -0
- package/dist/daemon/ownership.d.ts +123 -0
- package/dist/daemon/ownership.d.ts.map +1 -0
- package/dist/daemon/ownership.js +245 -0
- package/dist/daemon/ownership.js.map +1 -0
- package/dist/daemon/package-runner.d.ts +28 -0
- package/dist/daemon/package-runner.d.ts.map +1 -0
- package/dist/daemon/package-runner.js +113 -0
- package/dist/daemon/package-runner.js.map +1 -0
- package/dist/daemon/parser.d.ts +45 -7
- package/dist/daemon/parser.d.ts.map +1 -1
- package/dist/daemon/parser.js +153 -53
- package/dist/daemon/parser.js.map +1 -1
- package/dist/daemon/powershell.d.ts +25 -0
- package/dist/daemon/powershell.d.ts.map +1 -0
- package/dist/daemon/powershell.js +30 -0
- package/dist/daemon/powershell.js.map +1 -0
- package/dist/daemon/preflight.d.ts.map +1 -1
- package/dist/daemon/preflight.js +5 -1
- package/dist/daemon/preflight.js.map +1 -1
- package/dist/daemon/prune.d.ts +101 -0
- package/dist/daemon/prune.d.ts.map +1 -0
- package/dist/daemon/prune.js +287 -0
- package/dist/daemon/prune.js.map +1 -0
- package/dist/daemon/queue-error.d.ts +47 -0
- package/dist/daemon/queue-error.d.ts.map +1 -0
- package/dist/daemon/queue-error.js +59 -0
- package/dist/daemon/queue-error.js.map +1 -0
- package/dist/daemon/root-daemon.d.ts +60 -0
- package/dist/daemon/root-daemon.d.ts.map +1 -0
- package/dist/daemon/root-daemon.js +86 -0
- package/dist/daemon/root-daemon.js.map +1 -0
- package/dist/daemon/scoop.d.ts +52 -0
- package/dist/daemon/scoop.d.ts.map +1 -0
- package/dist/daemon/scoop.js +84 -0
- package/dist/daemon/scoop.js.map +1 -0
- package/dist/daemon/scrubber.d.ts +396 -14
- package/dist/daemon/scrubber.d.ts.map +1 -1
- package/dist/daemon/scrubber.js +915 -52
- package/dist/daemon/scrubber.js.map +1 -1
- package/dist/daemon/status.d.ts +306 -11
- package/dist/daemon/status.d.ts.map +1 -1
- package/dist/daemon/status.js +568 -43
- package/dist/daemon/status.js.map +1 -1
- package/dist/daemon/supervise.d.ts +78 -0
- package/dist/daemon/supervise.d.ts.map +1 -0
- package/dist/daemon/supervise.js +121 -0
- package/dist/daemon/supervise.js.map +1 -0
- package/dist/daemon/supervisor.d.ts +18 -0
- package/dist/daemon/supervisor.d.ts.map +1 -0
- package/dist/daemon/supervisor.js +56 -0
- package/dist/daemon/supervisor.js.map +1 -0
- package/dist/daemon/syncer.d.ts +380 -21
- package/dist/daemon/syncer.d.ts.map +1 -1
- package/dist/daemon/syncer.js +1432 -182
- package/dist/daemon/syncer.js.map +1 -1
- package/dist/daemon/systemd.d.ts +109 -0
- package/dist/daemon/systemd.d.ts.map +1 -0
- package/dist/daemon/systemd.js +363 -0
- package/dist/daemon/systemd.js.map +1 -0
- package/dist/daemon/types.d.ts +58 -6
- package/dist/daemon/types.d.ts.map +1 -1
- package/dist/daemon/vault-changed.d.ts +29 -0
- package/dist/daemon/vault-changed.d.ts.map +1 -0
- package/dist/daemon/vault-changed.js +47 -0
- package/dist/daemon/vault-changed.js.map +1 -0
- package/dist/daemon/vault-key-missing.d.ts +70 -0
- package/dist/daemon/vault-key-missing.d.ts.map +1 -0
- package/dist/daemon/vault-key-missing.js +125 -0
- package/dist/daemon/vault-key-missing.js.map +1 -0
- package/dist/daemon/watcher.d.ts +87 -4
- package/dist/daemon/watcher.d.ts.map +1 -1
- package/dist/daemon/watcher.js +286 -36
- package/dist/daemon/watcher.js.map +1 -1
- package/dist/daemon/worker-main.js +352 -64
- package/dist/daemon/worker-main.js.map +1 -1
- package/dist/daemon/worker.js +19 -1
- package/dist/daemon/worker.js.map +1 -1
- package/dist/import-resume.d.ts +163 -0
- package/dist/import-resume.d.ts.map +1 -0
- package/dist/import-resume.js +267 -0
- package/dist/import-resume.js.map +1 -0
- package/dist/index.js +242 -33
- package/dist/index.js.map +1 -1
- package/dist/message-bounds.d.ts +52 -0
- package/dist/message-bounds.d.ts.map +1 -0
- package/dist/message-bounds.js +157 -0
- package/dist/message-bounds.js.map +1 -0
- package/dist/output.d.ts +14 -0
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +33 -5
- package/dist/output.js.map +1 -1
- package/dist/private-files.d.ts +126 -0
- package/dist/private-files.d.ts.map +1 -0
- package/dist/private-files.js +372 -0
- package/dist/private-files.js.map +1 -0
- package/dist/server-url.d.ts +31 -0
- package/dist/server-url.d.ts.map +1 -0
- package/dist/server-url.js +47 -0
- package/dist/server-url.js.map +1 -0
- package/dist/vault-key.d.ts +122 -0
- package/dist/vault-key.d.ts.map +1 -0
- package/dist/vault-key.js +273 -0
- package/dist/vault-key.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading ~/.engram/config.json without trusting it (engram#673). Shared by
|
|
3
|
+
* the CLI and the daemon, and free of the file's location: callers pass the
|
|
4
|
+
* path, or read the text themselves. vault-key.ts reads ~/.engram/vault-key
|
|
5
|
+
* the same way (engram#677).
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: Node built-ins only. The daemon's exclusions use this module.
|
|
8
|
+
*/
|
|
9
|
+
import { lstatSync, readFileSync } from "node:fs";
|
|
10
|
+
/**
|
|
11
|
+
* config.json is there, but Engram can't use it: it can't be read, or what
|
|
12
|
+
* it holds isn't settings. It holds the API key and the folders excluded
|
|
13
|
+
* from capture, so this fails closed. The daemon holds new messages rather
|
|
14
|
+
* than capture from a folder it can't tell is excluded, and a command that
|
|
15
|
+
* saves the file stops rather than replace what is in it.
|
|
16
|
+
*
|
|
17
|
+
* The message names the problem and never quotes the file: JSON.parse's
|
|
18
|
+
* own messages quote the text around the error, which can be part of the
|
|
19
|
+
* key, and these messages reach daemon.log, status.json and notifications.
|
|
20
|
+
*/
|
|
21
|
+
export class ConfigUnreadable extends Error {
|
|
22
|
+
/** What is wrong, worded to follow "config.json", e.g. "isn't valid JSON". */
|
|
23
|
+
problem;
|
|
24
|
+
/**
|
|
25
|
+
* The file is empty. The daemon holds as for any other problem, since a
|
|
26
|
+
* file being written in place is empty for a moment; a command that
|
|
27
|
+
* saves the file may write it, since there is nothing in it to lose.
|
|
28
|
+
*/
|
|
29
|
+
empty;
|
|
30
|
+
constructor(problem, options = {}) {
|
|
31
|
+
super(`~/.engram/config.json ${problem}`);
|
|
32
|
+
this.name = "ConfigUnreadable";
|
|
33
|
+
this.problem = problem;
|
|
34
|
+
this.empty = options.empty ?? false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** What a read that failed says is wrong: from its error code, not its message. */
|
|
38
|
+
function codeProblem(err) {
|
|
39
|
+
const code = err?.code;
|
|
40
|
+
if (code === "EACCES" || code === "EPERM")
|
|
41
|
+
return "can't be read: permission denied";
|
|
42
|
+
if (code === "EISDIR")
|
|
43
|
+
return "is a folder, not a file";
|
|
44
|
+
if (typeof code === "string" && /^[A-Z0-9_]+$/.test(code))
|
|
45
|
+
return `can't be read (${code})`;
|
|
46
|
+
return "can't be read";
|
|
47
|
+
}
|
|
48
|
+
/** The ConfigUnreadable for a read that failed: from its error code, not its message. */
|
|
49
|
+
export function unreadable(err) {
|
|
50
|
+
return new ConfigUnreadable(codeProblem(err));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* True when a read of `file` failed because there is no config.json, which
|
|
54
|
+
* means no settings, not damaged ones. A link to a file that isn't there
|
|
55
|
+
* is not missing: the settings are somewhere that can't be reached right
|
|
56
|
+
* now, a volume that isn't mounted, say.
|
|
57
|
+
*/
|
|
58
|
+
export function isMissing(err, file) {
|
|
59
|
+
if (err?.code !== "ENOENT")
|
|
60
|
+
return false;
|
|
61
|
+
try {
|
|
62
|
+
lstatSync(file);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* What is wrong with a file a read of it failed on, given it isn't missing
|
|
71
|
+
* (isMissing): ENOENT then means a link to nothing. Worded to follow the
|
|
72
|
+
* file's name, and from the error's code, never its message.
|
|
73
|
+
*/
|
|
74
|
+
export function readProblem(err) {
|
|
75
|
+
return err?.code === "ENOENT"
|
|
76
|
+
? "is a link to a file that isn't there"
|
|
77
|
+
: codeProblem(err);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The ConfigUnreadable for a read of config.json that failed, given the
|
|
81
|
+
* file isn't missing (isMissing).
|
|
82
|
+
*/
|
|
83
|
+
export function readFailure(err) {
|
|
84
|
+
return new ConfigUnreadable(readProblem(err));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* What is wrong with a file a write of it failed on (engram#681), worded
|
|
88
|
+
* to follow the file's name: from the error's code, never its message.
|
|
89
|
+
*/
|
|
90
|
+
export function writeProblem(err) {
|
|
91
|
+
const code = err?.code;
|
|
92
|
+
if (code === "EACCES" || code === "EPERM")
|
|
93
|
+
return "can't be written: permission denied";
|
|
94
|
+
if (code === "EROFS")
|
|
95
|
+
return "can't be written: the disk it's on is read-only";
|
|
96
|
+
if (code === "ENOSPC")
|
|
97
|
+
return "can't be written: the disk it's on is full";
|
|
98
|
+
if (code === "EDQUOT")
|
|
99
|
+
return "can't be written: the disk quota is used up";
|
|
100
|
+
if (typeof code === "string" && /^[A-Z0-9_]+$/.test(code))
|
|
101
|
+
return `can't be written (${code})`;
|
|
102
|
+
return "can't be written";
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* config.json's text as settings: a JSON object. Throws ConfigUnreadable
|
|
106
|
+
* for anything else. A leading byte-order mark, which some Windows editors
|
|
107
|
+
* add, is skipped.
|
|
108
|
+
*/
|
|
109
|
+
export function parseConfigText(text) {
|
|
110
|
+
const body = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
111
|
+
if (body.trim() === "")
|
|
112
|
+
throw new ConfigUnreadable("is empty", { empty: true });
|
|
113
|
+
let parsed;
|
|
114
|
+
try {
|
|
115
|
+
parsed = JSON.parse(body);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
throw new ConfigUnreadable("isn't valid JSON");
|
|
119
|
+
}
|
|
120
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
121
|
+
throw new ConfigUnreadable("isn't a JSON object");
|
|
122
|
+
}
|
|
123
|
+
return parsed;
|
|
124
|
+
}
|
|
125
|
+
/** The settings in `file`, or null when there is no such file. Throws ConfigUnreadable. */
|
|
126
|
+
export function readConfigFileSync(file) {
|
|
127
|
+
let text;
|
|
128
|
+
try {
|
|
129
|
+
text = readFileSync(file, "utf-8");
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
if (isMissing(err, file))
|
|
133
|
+
return null;
|
|
134
|
+
throw readFailure(err);
|
|
135
|
+
}
|
|
136
|
+
return parseConfigText(text);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The excluded folders in `config`, as saved: none when it has no
|
|
140
|
+
* excludePaths. Throws ConfigUnreadable when excludePaths is anything but
|
|
141
|
+
* a list of paths, since then which folders are excluded can't be told.
|
|
142
|
+
*/
|
|
143
|
+
export function excludePathsOf(config) {
|
|
144
|
+
const paths = config.excludePaths;
|
|
145
|
+
if (paths === undefined || paths === null)
|
|
146
|
+
return [];
|
|
147
|
+
if (!Array.isArray(paths) || !paths.every((p) => typeof p === "string")) {
|
|
148
|
+
throw new ConfigUnreadable("has an excludePaths that isn't a list of paths");
|
|
149
|
+
}
|
|
150
|
+
return paths;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=config-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-file.js","sourceRoot":"","sources":["../src/config-file.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAElD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,8EAA8E;IACrE,OAAO,CAAS;IACzB;;;;OAIG;IACM,KAAK,CAAU;IAExB,YAAY,OAAe,EAAE,UAA+B,EAAE;QAC5D,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;IACtC,CAAC;CACF;AAED,mFAAmF;AACnF,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,IAAI,GAAI,GAAoC,EAAE,IAAI,CAAC;IACzD,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,kCAAkC,CAAC;IACrF,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,yBAAyB,CAAC;IACxD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,kBAAkB,IAAI,GAAG,CAAC;IAC5F,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,UAAU,CAAC,GAAY;IACrC,OAAO,IAAI,gBAAgB,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,GAAY,EAAE,IAAY;IAClD,IAAK,GAAoC,EAAE,IAAI,KAAK,Q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AAE,CAAC;QACxE,MAAM,IAAI,gBAAgB,CAAC,gDAAgD,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,KAAiB,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commands, and a ~/.engram/config.json they can't read (engram#673).
|
|
3
|
+
*
|
|
4
|
+
* The file holds the API key and the folders excluded from capture. Read
|
|
5
|
+
* leniently, a file that couldn't be read or parsed read as no settings: a
|
|
6
|
+
* command that saved it then replaced it, and the key and the excluded
|
|
7
|
+
* folders were gone for good; one that used the key said "not signed in",
|
|
8
|
+
* or sent ENGRAM_API_KEY to the default server instead of the configured
|
|
9
|
+
* one (engram#625). These read it strictly and stop instead, saying why.
|
|
10
|
+
*
|
|
11
|
+
* An empty file is the exception. There is nothing in it to lose, so a
|
|
12
|
+
* command reads it as no settings and may save over it, saying that any
|
|
13
|
+
* folders that were excluded have to be added back; the daemon still holds
|
|
14
|
+
* capture for it (exclusions.ts), since a file being written in place is
|
|
15
|
+
* empty for a moment.
|
|
16
|
+
*/
|
|
17
|
+
import { type Config } from "./config.js";
|
|
18
|
+
import { ConfigUnreadable } from "./config-file.js";
|
|
19
|
+
import { type LockedDir } from "./daemon/ownership.js";
|
|
20
|
+
/**
|
|
21
|
+
* A ~/.engram the user can't search (engram#723), when that is why
|
|
22
|
+
* config.json couldn't be read: then the folder is what's wrong, and
|
|
23
|
+
* nothing in the file. Null for an empty file, which was read.
|
|
24
|
+
*/
|
|
25
|
+
export declare function lockedConfigDir(problem: ConfigUnreadable): LockedDir | null;
|
|
26
|
+
/**
|
|
27
|
+
* config.json's settings, or what is wrong with it: what the daemon holds
|
|
28
|
+
* capture for, an excludePaths it can't use among it. A file that isn't
|
|
29
|
+
* there reads as no settings. Never throws.
|
|
30
|
+
*/
|
|
31
|
+
export declare function inspectConfig(): Promise<{
|
|
32
|
+
config: Config;
|
|
33
|
+
problem: null;
|
|
34
|
+
} | {
|
|
35
|
+
config: null;
|
|
36
|
+
problem: ConfigUnreadable;
|
|
37
|
+
}>;
|
|
38
|
+
/** What is wrong with config.json, or null: see inspectConfig. */
|
|
39
|
+
export declare function configProblem(): Promise<ConfigUnreadable | null>;
|
|
40
|
+
/**
|
|
41
|
+
* config.json's settings, for a command that changes one and saves them
|
|
42
|
+
* back. When they can't be read, the command stops with nothing changed.
|
|
43
|
+
* `hints` are said after the fix, e.g. another way to do what was asked.
|
|
44
|
+
* They aren't said when ~/.engram itself is what's in the way (engram#723):
|
|
45
|
+
* a way around the file reaches into the folder too, and once the folder
|
|
46
|
+
* is fixed, the command does what was asked.
|
|
47
|
+
*/
|
|
48
|
+
export declare function loadConfigForUpdate(hints?: string[]): Promise<Config>;
|
|
49
|
+
/**
|
|
50
|
+
* Said on stderr by a command that saves settings into an empty
|
|
51
|
+
* config.json: what the file listed as excluded from capture is gone, and
|
|
52
|
+
* from then on the daemon captures from those folders again.
|
|
53
|
+
*/
|
|
54
|
+
export declare function printEmptyConfigNote(): void;
|
|
55
|
+
/**
|
|
56
|
+
* config.json's settings, for a command that uses the key or the server in
|
|
57
|
+
* them, or what is wrong with the file. With ENGRAM_API_KEY and
|
|
58
|
+
* ENGRAM_BASE_URL both set, the file isn't needed.
|
|
59
|
+
*/
|
|
60
|
+
export declare function configForUse(): Promise<{
|
|
61
|
+
config: Config;
|
|
62
|
+
} | {
|
|
63
|
+
problem: ConfigUnreadable;
|
|
64
|
+
}>;
|
|
65
|
+
/** Say on stderr that a command can't run because config.json can't be read. */
|
|
66
|
+
export declare function printConfigProblemForUse(problem: ConfigUnreadable): void;
|
|
67
|
+
/**
|
|
68
|
+
* config.json's settings, for a command that uses the key or the server in
|
|
69
|
+
* them. When they can't be read, the command stops, saying why.
|
|
70
|
+
*/
|
|
71
|
+
export declare function loadConfigForUse(): Promise<Config>;
|
|
72
|
+
/**
|
|
73
|
+
* Commands, and a config.json they can read but not write (engram#717).
|
|
74
|
+
* A save that failed ended the command with Node's own error, which named
|
|
75
|
+
* the path and nothing else, after `engram login` and `engram signup` had
|
|
76
|
+
* made the API key that the save then lost. These say why it can't be
|
|
77
|
+
* written, what that means for the command, and what fixes it, and the
|
|
78
|
+
* command exits 1.
|
|
79
|
+
*
|
|
80
|
+
* `meaning`: what the command didn't do, said after why. `again`: the
|
|
81
|
+
* command to run once it's fixed; without it, "this", for one whose
|
|
82
|
+
* arguments shouldn't be repeated, such as a key.
|
|
83
|
+
*/
|
|
84
|
+
export declare function exitConfigUnsaved(failure: {
|
|
85
|
+
problem: string;
|
|
86
|
+
fix: string | null;
|
|
87
|
+
}, meaning: string[], again?: string): never;
|
|
88
|
+
/**
|
|
89
|
+
* Stop, as exitConfigUnsaved does, when config.json can't be written now:
|
|
90
|
+
* before a command does what a failed save would waste, such as making an
|
|
91
|
+
* account or an API key. Nothing is written.
|
|
92
|
+
*/
|
|
93
|
+
export declare function requireWritableConfig(meaning: string[], again?: string): void;
|
|
94
|
+
/** Save config.json, or stop as exitConfigUnsaved does. */
|
|
95
|
+
export declare function saveConfigOrExit(config: Config, meaning: string[], again?: string): Promise<void>;
|
|
96
|
+
//# sourceMappingURL=config-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-guard.d.ts","sourceRoot":"","sources":["../src/config-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAgE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAkB,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAA4C,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAQjG;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAI3E;AAED;;;;GAIG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAC5C;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;I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
|
+
* The file holds the API key and the folders excluded from capture. Read
|
|
5
|
+
* leniently, a file that couldn't be read or parsed read as no settings: a
|
|
6
|
+
* command that saved it then replaced it, and the key and the excluded
|
|
7
|
+
* folders were gone for good; one that used the key said "not signed in",
|
|
8
|
+
* or sent ENGRAM_API_KEY to the default server instead of the configured
|
|
9
|
+
* one (engram#625). These read it strictly and stop instead, saying why.
|
|
10
|
+
*
|
|
11
|
+
* An empty file is the exception. There is nothing in it to lose, so a
|
|
12
|
+
* command reads it as no settings and may save over it, saying that any
|
|
13
|
+
* folders that were excluded have to be added back; the daemon still holds
|
|
14
|
+
* capture for it (exclusions.ts), since a file being written in place is
|
|
15
|
+
* empty for a moment.
|
|
16
|
+
*/
|
|
17
|
+
import { configSaveProblem, loadConfigStrict, saveConfig, saveFailure } from "./config.js";
|
|
18
|
+
import { ConfigUnreadable, excludePathsOf } from "./config-file.js";
|
|
19
|
+
import { lockedDir, lockedDirFix, lockedDirReason } from "./daemon/ownership.js";
|
|
20
|
+
import { engramCommand } from "./daemon/package-runner.js";
|
|
21
|
+
import { dim, red } from "./output.js";
|
|
22
|
+
function asProblem(err) {
|
|
23
|
+
return err instanceof ConfigUnreadable ? err : new ConfigUnreadable("can't be read");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A ~/.engram the user can't search (engram#723), when that is why
|
|
27
|
+
* config.json couldn't be read: then the folder is what's wrong, and
|
|
28
|
+
* nothing in the file. Null for an empty file, which was read.
|
|
29
|
+
*/
|
|
30
|
+
export function lockedConfigDir(problem) {
|
|
31
|
+
if (problem.empty)
|
|
32
|
+
return null;
|
|
33
|
+
const locked = lockedDir();
|
|
34
|
+
return locked?.search ? locked : null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* config.json's settings, or what is wrong with it: what the daemon holds
|
|
38
|
+
* capture for, an excludePaths it can't use among it. A file that isn't
|
|
39
|
+
* there reads as no settings. Never throws.
|
|
40
|
+
*/
|
|
41
|
+
export async function inspectConfig() {
|
|
42
|
+
try {
|
|
43
|
+
const config = await loadConfigStrict();
|
|
44
|
+
excludePathsOf(config);
|
|
45
|
+
return { config, problem: null };
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
return { config: null, problem: asProblem(err) };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** What is wrong with config.json, or null: see inspectConfig. */
|
|
52
|
+
export async function configProblem() {
|
|
53
|
+
return (await inspectConfig()).problem;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* config.json's settings, for a command that changes one and saves them
|
|
57
|
+
* back. When they can't be read, the command stops with nothing changed.
|
|
58
|
+
* `hints` are said after the fix, e.g. another way to do what was asked.
|
|
59
|
+
* They aren't said when ~/.engram itself is what's in the way (engram#723):
|
|
60
|
+
* a way around the file reaches into the folder too, and once the folder
|
|
61
|
+
* is fixed, the command does what was asked.
|
|
62
|
+
*/
|
|
63
|
+
export async function loadConfigForUpdate(hints = []) {
|
|
64
|
+
try {
|
|
65
|
+
return await loadConfigStrict();
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
const problem = asProblem(err);
|
|
69
|
+
if (problem.empty) {
|
|
70
|
+
printEmptyConfigNote();
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
const locked = lockedConfigDir(problem);
|
|
74
|
+
if (locked) {
|
|
75
|
+
console.error(red(`Error: ${lockedDirReason("opening config.json")}, so nothing was changed.`));
|
|
76
|
+
console.error(` ${lockedDirFix(locked)}`);
|
|
77
|
+
console.error(" Then run this again.");
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
console.error(red(`Error: ${problem.message}.`));
|
|
81
|
+
console.error(" Saving now would replace everything in it, your API key and the folders you");
|
|
82
|
+
console.error(" excluded from capture among them, so nothing was changed.");
|
|
83
|
+
console.error(" Fix the file, then run this again.");
|
|
84
|
+
for (const hint of hints)
|
|
85
|
+
console.error(` ${hint}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Said on stderr by a command that saves settings into an empty
|
|
91
|
+
* config.json: what the file listed as excluded from capture is gone, and
|
|
92
|
+
* from then on the daemon captures from those folders again.
|
|
93
|
+
*/
|
|
94
|
+
export function printEmptyConfigNote() {
|
|
95
|
+
console.error(dim("Note: ~/.engram/config.json was empty, so any folders you had excluded from"));
|
|
96
|
+
console.error(dim(` capture are lost. Add them back with: ${engramCommand("exclude add <path>")}`));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* config.json's settings, for a command that uses the key or the server in
|
|
100
|
+
* them, or what is wrong with the file. With ENGRAM_API_KEY and
|
|
101
|
+
* ENGRAM_BASE_URL both set, the file isn't needed.
|
|
102
|
+
*/
|
|
103
|
+
export async function configForUse() {
|
|
104
|
+
try {
|
|
105
|
+
return { config: await loadConfigStrict() };
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
const problem = asProblem(err);
|
|
109
|
+
if (problem.empty || (process.env.ENGRAM_API_KEY && process.env.ENGRAM_BASE_URL)) {
|
|
110
|
+
return { config: {} };
|
|
111
|
+
}
|
|
112
|
+
return { problem };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** Say on stderr that a command can't run because config.json can't be read. */
|
|
116
|
+
export function printConfigProblemForUse(problem) {
|
|
117
|
+
const locked = lockedConfigDir(problem);
|
|
118
|
+
if (locked) {
|
|
119
|
+
console.error(red(`Error: ${lockedDirReason("opening config.json")}, so Engram can't tell which account or server to use.`));
|
|
120
|
+
console.error(` ${lockedDirFix(locked)}`);
|
|
121
|
+
console.error(" Then run this again.");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
console.error(red(`Error: ${problem.message}, so Engram can't tell which account or server to use.`));
|
|
125
|
+
console.error(" Fix the file, then run this again.");
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* config.json's settings, for a command that uses the key or the server in
|
|
129
|
+
* them. When they can't be read, the command stops, saying why.
|
|
130
|
+
*/
|
|
131
|
+
export async function loadConfigForUse() {
|
|
132
|
+
const read = await configForUse();
|
|
133
|
+
if ("problem" in read) {
|
|
134
|
+
printConfigProblemForUse(read.problem);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
return read.config;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Commands, and a config.json they can read but not write (engram#717).
|
|
141
|
+
* A save that failed ended the command with Node's own error, which named
|
|
142
|
+
* the path and nothing else, after `engram login` and `engram signup` had
|
|
143
|
+
* made the API key that the save then lost. These say why it can't be
|
|
144
|
+
* written, what that means for the command, and what fixes it, and the
|
|
145
|
+
* command exits 1.
|
|
146
|
+
*
|
|
147
|
+
* `meaning`: what the command didn't do, said after why. `again`: the
|
|
148
|
+
* command to run once it's fixed; without it, "this", for one whose
|
|
149
|
+
* arguments shouldn't be repeated, such as a key.
|
|
150
|
+
*/
|
|
151
|
+
export function exitConfigUnsaved(failure, meaning, again) {
|
|
152
|
+
const command = again === undefined ? "this" : `'${engramCommand(again)}'`;
|
|
153
|
+
console.error(red(`Error: ${failure.problem}.`));
|
|
154
|
+
for (const line of meaning)
|
|
155
|
+
console.error(` ${line}`);
|
|
156
|
+
if (failure.fix) {
|
|
157
|
+
console.error(` To fix it, run: ${failure.fix}`);
|
|
158
|
+
console.error(` Then run ${command} again.`);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
console.error(` Once it's fixed, run ${command} again.`);
|
|
162
|
+
}
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Stop, as exitConfigUnsaved does, when config.json can't be written now:
|
|
167
|
+
* before a command does what a failed save would waste, such as making an
|
|
168
|
+
* account or an API key. Nothing is written.
|
|
169
|
+
*/
|
|
170
|
+
export function requireWritableConfig(meaning, again) {
|
|
171
|
+
const failure = configSaveProblem();
|
|
172
|
+
if (failure)
|
|
173
|
+
exitConfigUnsaved(failure, meaning, again);
|
|
174
|
+
}
|
|
175
|
+
/** Save config.json, or stop as exitConfigUnsaved does. */
|
|
176
|
+
export async function saveConfigOrExit(config, meaning, again) {
|
|
177
|
+
try {
|
|
178
|
+
await saveConfig(config);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
exitConfigUnsaved(saveFailure(err), meaning, again);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=config-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-guard.js","sourceRoot":"","sources":["../src/config-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAe,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAkB,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAEvC,SAAS,SAAS,CAAC,GAAY;IAC7B,OAAO,GAAG,YAAY,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,eAAe,CAAC,CAAC;AACvF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,OAAyB;IACvD,IAAI,OAAO,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAC/B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa;IAGjC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AO,CAAC,KAAK,CAAC,0BAA0B,OAAO,SAAS,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAiB,EAAE,KAAc;IACrE,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,IAAI,OAAO;QAAE,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,2DAA2D;AAC3D,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAc,EAAE,OAAiB,EAAE,KAAc;IACtF,IAAI,CAAC;QACH,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,iBAAiB,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export { resolveBaseUrl } from "./server-url.js";
|
|
2
|
+
export interface Config {
|
|
2
3
|
apiKey?: string;
|
|
3
4
|
baseUrl?: string;
|
|
4
5
|
/** "off" = the user explicitly stopped capture; the CLI must not
|
|
@@ -9,9 +10,52 @@ interface Config {
|
|
|
9
10
|
* this list, no restart needed. */
|
|
10
11
|
excludePaths?: string[];
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The settings in ~/.engram/config.json: none when there is no such file.
|
|
15
|
+
* One that exists and can't be read or parsed THROWS a ConfigUnreadable,
|
|
16
|
+
* never reads as no settings. The daemon re-reads the key every couple of
|
|
17
|
+
* seconds and treats "no key" as a logout (engram#594), so a file caught
|
|
18
|
+
* half-written, or one damaged by hand, must not look like one: that would
|
|
19
|
+
* stop capture for nothing. And a command that saved over it would replace
|
|
20
|
+
* the key and the excluded folders in it (engram#673).
|
|
21
|
+
*
|
|
22
|
+
* There is no lenient version on purpose: reading a damaged file as no
|
|
23
|
+
* settings, then saving, is how the key and the exclusions were lost. The
|
|
24
|
+
* error never quotes the file, which holds the key: the daemon logs it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function loadConfigStrict(): Promise<Config>;
|
|
27
|
+
/**
|
|
28
|
+
* config.json holds the API key, so it and ~/.engram are the user's alone
|
|
29
|
+
* (engram#627), and it is replaced in one step: the daemon reads it every
|
|
30
|
+
* few seconds, and a save cut short leaves the old file whole instead of a
|
|
31
|
+
* truncated one without the key.
|
|
32
|
+
*/
|
|
13
33
|
export declare function saveConfig(config: Config): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Why saveConfig failed, as "~/.engram/config.json can't be written: …",
|
|
36
|
+
* and the command that fixes it, if there is one (engram#681): there is
|
|
37
|
+
* when ~/.engram or config.json is the user's and only lacks its write
|
|
38
|
+
* permission. Files that are another user's are said before the command,
|
|
39
|
+
* with their chown (engram#659). A full or read-only disk, a file locked
|
|
40
|
+
* some other way (EPERM: chmod can't change a locked file), or a
|
|
41
|
+
* config.json that is a link has none. The error's message, which names
|
|
42
|
+
* the path, is never quoted.
|
|
43
|
+
*
|
|
44
|
+
* A ~/.engram the user can't search is said as that (engram#723): nothing
|
|
45
|
+
* is wrong with the file, and a chmod of it can't reach it. Its command
|
|
46
|
+
* gives the folder back all its owner's permissions that are missing.
|
|
47
|
+
*/
|
|
48
|
+
export declare function saveFailure(err: unknown): {
|
|
49
|
+
problem: string;
|
|
50
|
+
fix: string | null;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* What stops config.json being saved now, as saveFailure says it, or null
|
|
54
|
+
* when nothing does that can be found without writing (engram#717).
|
|
55
|
+
*/
|
|
56
|
+
export declare function configSaveProblem(): {
|
|
57
|
+
problem: string;
|
|
58
|
+
fix: string | null;
|
|
59
|
+
} | null;
|
|
14
60
|
export declare function getApiKey(): string;
|
|
15
|
-
export declare function getBaseUrl(): string;
|
|
16
|
-
export {};
|
|
17
61
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAKjD,MAAM,WAAW,MAAM;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;mEAC+D;IAC/D,WAAW,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC;IAC3B;;wCAEoC;IACpC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC,CASxD;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAIjF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,CAOlF;AA4BD,wBAAgB,SAAS,IAAI,MAAM,CAalC"}
|
package/dist/config.js
CHANGED
|
@@ -1,34 +1,123 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { lstatSync, statSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import { join } from "node:path";
|
|
5
|
+
import { checkWritableSync, ensurePrivateDirSync, writePrivateFileSync } from "./private-files.js";
|
|
6
|
+
import { isMissing, parseConfigText, readFailure, writeProblem } from "./config-file.js";
|
|
7
|
+
import { lockedDir, lockedDirReason } from "./daemon/ownership.js";
|
|
8
|
+
import { engramCommand } from "./daemon/package-runner.js";
|
|
9
|
+
// Where it always was, for the commands that import it from here.
|
|
10
|
+
export { resolveBaseUrl } from "./server-url.js";
|
|
4
11
|
const CONFIG_DIR = join(homedir(), ".engram");
|
|
5
12
|
const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
6
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The settings in ~/.engram/config.json: none when there is no such file.
|
|
15
|
+
* One that exists and can't be read or parsed THROWS a ConfigUnreadable,
|
|
16
|
+
* never reads as no settings. The daemon re-reads the key every couple of
|
|
17
|
+
* seconds and treats "no key" as a logout (engram#594), so a file caught
|
|
18
|
+
* half-written, or one damaged by hand, must not look like one: that would
|
|
19
|
+
* stop capture for nothing. And a command that saved over it would replace
|
|
20
|
+
* the key and the excluded folders in it (engram#673).
|
|
21
|
+
*
|
|
22
|
+
* There is no lenient version on purpose: reading a damaged file as no
|
|
23
|
+
* settings, then saving, is how the key and the exclusions were lost. The
|
|
24
|
+
* error never quotes the file, which holds the key: the daemon logs it.
|
|
25
|
+
*/
|
|
26
|
+
export async function loadConfigStrict() {
|
|
27
|
+
let raw;
|
|
7
28
|
try {
|
|
8
|
-
|
|
9
|
-
return JSON.parse(raw);
|
|
29
|
+
raw = await readFile(CONFIG_FILE, "utf-8");
|
|
10
30
|
}
|
|
11
|
-
catch {
|
|
12
|
-
|
|
31
|
+
catch (err) {
|
|
32
|
+
if (isMissing(err, CONFIG_FILE))
|
|
33
|
+
return {};
|
|
34
|
+
throw readFailure(err);
|
|
13
35
|
}
|
|
36
|
+
return parseConfigText(raw);
|
|
14
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* config.json holds the API key, so it and ~/.engram are the user's alone
|
|
40
|
+
* (engram#627), and it is replaced in one step: the daemon reads it every
|
|
41
|
+
* few seconds, and a save cut short leaves the old file whole instead of a
|
|
42
|
+
* truncated one without the key.
|
|
43
|
+
*/
|
|
15
44
|
export async function saveConfig(config) {
|
|
16
|
-
|
|
17
|
-
|
|
45
|
+
ensurePrivateDirSync(CONFIG_DIR);
|
|
46
|
+
writePrivateFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Why saveConfig failed, as "~/.engram/config.json can't be written: …",
|
|
50
|
+
* and the command that fixes it, if there is one (engram#681): there is
|
|
51
|
+
* when ~/.engram or config.json is the user's and only lacks its write
|
|
52
|
+
* permission. Files that are another user's are said before the command,
|
|
53
|
+
* with their chown (engram#659). A full or read-only disk, a file locked
|
|
54
|
+
* some other way (EPERM: chmod can't change a locked file), or a
|
|
55
|
+
* config.json that is a link has none. The error's message, which names
|
|
56
|
+
* the path, is never quoted.
|
|
57
|
+
*
|
|
58
|
+
* A ~/.engram the user can't search is said as that (engram#723): nothing
|
|
59
|
+
* is wrong with the file, and a chmod of it can't reach it. Its command
|
|
60
|
+
* gives the folder back all its owner's permissions that are missing.
|
|
61
|
+
*/
|
|
62
|
+
export function saveFailure(err) {
|
|
63
|
+
const locked = err?.code === "EACCES" ? lockedDir({ dir: CONFIG_DIR }) : null;
|
|
64
|
+
if (locked?.search)
|
|
65
|
+
return { problem: lockedDirReason("saving config.json"), fix: locked.command };
|
|
66
|
+
return { problem: `~/.engram/config.json ${writeProblem(err)}`, fix: writableFix(err) };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* What stops config.json being saved now, as saveFailure says it, or null
|
|
70
|
+
* when nothing does that can be found without writing (engram#717).
|
|
71
|
+
*/
|
|
72
|
+
export function configSaveProblem() {
|
|
73
|
+
try {
|
|
74
|
+
checkWritableSync(CONFIG_FILE);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
return saveFailure(err);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** `chmod u+w` for what lacks its write permission, when that is all that's wrong. */
|
|
82
|
+
function writableFix(err) {
|
|
83
|
+
const code = err?.code;
|
|
84
|
+
if (code !== "EACCES" || process.platform === "win32")
|
|
85
|
+
return null;
|
|
86
|
+
const uid = process.geteuid?.();
|
|
87
|
+
const unwritable = [];
|
|
88
|
+
const looked = [
|
|
89
|
+
[CONFIG_DIR, "~/.engram"],
|
|
90
|
+
[CONFIG_FILE, "~/.engram/config.json"],
|
|
91
|
+
];
|
|
92
|
+
for (const [path, shown] of looked) {
|
|
93
|
+
let st;
|
|
94
|
+
try {
|
|
95
|
+
// Through a link, the file and the folder its new copy is made in are
|
|
96
|
+
// elsewhere.
|
|
97
|
+
if (path === CONFIG_FILE && lstatSync(path).isSymbolicLink())
|
|
98
|
+
return null;
|
|
99
|
+
st = statSync(path);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
continue; // not there, so nothing to make writable
|
|
103
|
+
}
|
|
104
|
+
if (st.uid !== uid)
|
|
105
|
+
return null;
|
|
106
|
+
if ((st.mode & 0o200) === 0)
|
|
107
|
+
unwritable.push(shown);
|
|
108
|
+
}
|
|
109
|
+
return unwritable.length > 0 ? `chmod u+w ${unwritable.join(" ")}` : null;
|
|
18
110
|
}
|
|
19
111
|
export function getApiKey() {
|
|
20
112
|
const key = process.env.ENGRAM_API_KEY;
|
|
21
113
|
if (!key) {
|
|
22
114
|
console.error("Error: No API key found.\n\n" +
|
|
23
115
|
"Set your API key with:\n" +
|
|
24
|
-
"
|
|
116
|
+
` ${engramCommand("auth login")}\n` +
|
|
25
117
|
" # or\n" +
|
|
26
118
|
" export ENGRAM_API_KEY=engram_sk_live_...\n");
|
|
27
119
|
process.exit(1);
|
|
28
120
|
}
|
|
29
121
|
return key;
|
|
30
122
|
}
|
|
31
|
-
export function getBaseUrl() {
|
|
32
|
-
return process.env.ENGRAM_BASE_URL ?? "https://mcp.getengram.app";
|
|
33
|
-
}
|
|
34
123
|
//# sourceMappingURL=config.js.map
|