@getengram/cli 0.6.0 → 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/LICENSE +112 -0
- 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 +153 -3
- package/dist/daemon/commands.d.ts.map +1 -1
- package/dist/daemon/commands.js +2775 -235
- 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 +50 -5
- package/dist/daemon/parser.d.ts.map +1 -1
- package/dist/daemon/parser.js +224 -47
- 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 +0 -17
- package/dist/daemon/preflight.d.ts.map +1 -1
- package/dist/daemon/preflight.js +32 -6
- 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 +456 -0
- package/dist/daemon/scrubber.d.ts.map +1 -0
- package/dist/daemon/scrubber.js +994 -0
- package/dist/daemon/scrubber.js.map +1 -0
- 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 +382 -21
- package/dist/daemon/syncer.d.ts.map +1 -1
- package/dist/daemon/syncer.js +1448 -178
- 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 +363 -51
- 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 +11 -12
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { accessSync, chmodSync, constants, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { commandFailure, commandPath } from "./command-path.js";
|
|
7
|
+
import { pinnedToKeg } from "./homebrew.js";
|
|
8
|
+
import { logProblem } from "./launch.js";
|
|
9
|
+
import { runnerCacheOf } from "./package-runner.js";
|
|
10
|
+
// Start at login on macOS: a launchd agent,
|
|
11
|
+
// ~/Library/LaunchAgents/app.getengram.daemon.plist. launchd loads the
|
|
12
|
+
// agents there when the user logs in, and starts the daemon (RunAtLoad), and
|
|
13
|
+
// again after a crash (KeepAlive). `engram install` loads it there and then.
|
|
14
|
+
export const PLIST_LABEL = "app.getengram.daemon";
|
|
15
|
+
// Bump when generatePlist() changes in a way existing installs must pick up.
|
|
16
|
+
// A plist is written once at install time and never revisited, so upgrading
|
|
17
|
+
// the CLI alone does NOT fix a defect that lives in the plist — the stale file
|
|
18
|
+
// keeps launching the old thing. Every machine installed before v2 is still
|
|
19
|
+
// pointing launchd at `worker-main.js`, the pre-0.4.2 entry point that has no
|
|
20
|
+
// ABI preflight, which is why the self-heal shipped in 0.4.2 has never once
|
|
21
|
+
// run on them (engram#469).
|
|
22
|
+
//
|
|
23
|
+
// v2: launch `worker.js` (preflight bootstrap) and give the job a PATH.
|
|
24
|
+
export const PLIST_VERSION = 2;
|
|
25
|
+
/** What marks which version of the plist an install has: a variable in the job's environment. */
|
|
26
|
+
const VERSION_ENV = "ENGRAM_PLIST_VERSION";
|
|
27
|
+
/** Each launchctl call; one that hangs counts as one that failed. */
|
|
28
|
+
const LAUNCHCTL_TIMEOUT_MS = 15_000;
|
|
29
|
+
/** How long a reload waits for launchd to let go of the job it unloads. */
|
|
30
|
+
const UNLOAD_WAIT_MS = 5_000;
|
|
31
|
+
export function plistDir() {
|
|
32
|
+
return join(homedir(), "Library", "LaunchAgents");
|
|
33
|
+
}
|
|
34
|
+
export function plistPath() {
|
|
35
|
+
return join(plistDir(), `${PLIST_LABEL}.plist`);
|
|
36
|
+
}
|
|
37
|
+
const ESCAPES = { "&": "&", "<": "<", ">": ">" };
|
|
38
|
+
/** Half of a UTF-16 pair without the other half: no file name has one, and launchd can't read one. */
|
|
39
|
+
const LONE_SURROGATE = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
|
|
40
|
+
/**
|
|
41
|
+
* A value as the text of a <string>, which launchd reads back exactly
|
|
42
|
+
* (engram#616): `&`, `<` and `>` escaped, as macOS's own plist writer
|
|
43
|
+
* escapes them. A raw `<` made a plist launchd couldn't load, so start at
|
|
44
|
+
* login quietly did nothing; a raw `&`, one launchd loads but plutil and
|
|
45
|
+
* every other tool that reads plists through CoreFoundation refuses.
|
|
46
|
+
*
|
|
47
|
+
* A control character is refused instead, as in a systemd unit: XML 1.0
|
|
48
|
+
* forbids most of them. Exported for tests.
|
|
49
|
+
*/
|
|
50
|
+
export function xmlText(s) {
|
|
51
|
+
if (/[\x00-\x1f\x7f]/.test(s))
|
|
52
|
+
throw new Error(`a path with a control character in it: ${JSON.stringify(s)}`);
|
|
53
|
+
if (LONE_SURROGATE.test(s))
|
|
54
|
+
throw new Error(`a path that isn't valid Unicode: ${JSON.stringify(s)}`);
|
|
55
|
+
return s.replace(/[&<>]/g, (c) => ESCAPES[c]);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The plist for the paths given. Pure: tests pass made-up paths.
|
|
59
|
+
*
|
|
60
|
+
* KeepAlive SuccessfulExit=false: a daemon that crashes is started again,
|
|
61
|
+
* one that stops (`engram stop`, or another daemon already running) is not.
|
|
62
|
+
* HOME is the CLI's own. launchd hands a job a bare PATH
|
|
63
|
+
* (/usr/bin:/bin:/usr/sbin:/sbin), without npm, which the ABI self-heal in
|
|
64
|
+
* preflight.ts runs (`npm rebuild better-sqlite3`): the caller puts Node's
|
|
65
|
+
* own directory, where npm is, first.
|
|
66
|
+
*/
|
|
67
|
+
export function generatePlist(p) {
|
|
68
|
+
return render({
|
|
69
|
+
node: xmlText(p.node),
|
|
70
|
+
worker: xmlText(p.worker),
|
|
71
|
+
log: p.log === null ? null : xmlText(p.log),
|
|
72
|
+
home: xmlText(p.home),
|
|
73
|
+
path: xmlText(p.path),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The plist with each value's text in place. Every v2 plist has this text,
|
|
78
|
+
* but for the values, and for the log, which one without a log leaves out.
|
|
79
|
+
*/
|
|
80
|
+
function render(v) {
|
|
81
|
+
const log = v.log === null
|
|
82
|
+
? ""
|
|
83
|
+
: `
|
|
84
|
+
<key>StandardOutPath</key>
|
|
85
|
+
<string>${v.log}</string>
|
|
86
|
+
<key>StandardErrorPath</key>
|
|
87
|
+
<string>${v.log}</string>`;
|
|
88
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
89
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
90
|
+
<plist version="1.0">
|
|
91
|
+
<dict>
|
|
92
|
+
<key>Label</key>
|
|
93
|
+
<string>${PLIST_LABEL}</string>
|
|
94
|
+
<key>ProgramArguments</key>
|
|
95
|
+
<array>
|
|
96
|
+
<string>${v.node}</string>
|
|
97
|
+
<string>${v.worker}</string>
|
|
98
|
+
</array>
|
|
99
|
+
<key>RunAtLoad</key>
|
|
100
|
+
<true/>
|
|
101
|
+
<key>KeepAlive</key>
|
|
102
|
+
<dict>
|
|
103
|
+
<key>SuccessfulExit</key>
|
|
104
|
+
<false/>
|
|
105
|
+
</dict>${log}
|
|
106
|
+
<key>ThrottleInterval</key>
|
|
107
|
+
<integer>10</integer>
|
|
108
|
+
<key>EnvironmentVariables</key>
|
|
109
|
+
<dict>
|
|
110
|
+
<key>HOME</key>
|
|
111
|
+
<string>${v.home}</string>
|
|
112
|
+
<key>PATH</key>
|
|
113
|
+
<string>${v.path}</string>
|
|
114
|
+
<key>${VERSION_ENV}</key>
|
|
115
|
+
<string>${PLIST_VERSION}</string>
|
|
116
|
+
</dict>
|
|
117
|
+
</dict>
|
|
118
|
+
</plist>`;
|
|
119
|
+
}
|
|
120
|
+
const UNESCAPES = { "&": "&", "<": "<", ">": ">" };
|
|
121
|
+
let templatePatterns;
|
|
122
|
+
/**
|
|
123
|
+
* render()'s text as patterns, each value a capture: the plist with a log,
|
|
124
|
+
* and the one without. A value never holds a `<` (xmlText escapes it), and
|
|
125
|
+
* the log, there twice, is the same both times.
|
|
126
|
+
*/
|
|
127
|
+
function templates() {
|
|
128
|
+
return (templatePatterns ??= [template("\0log\0"), template(null)]);
|
|
129
|
+
}
|
|
130
|
+
function template(log) {
|
|
131
|
+
const seen = new Set();
|
|
132
|
+
const source = render({ node: "\0node\0", worker: "\0worker\0", log, home: "\0home\0", path: "\0path\0" })
|
|
133
|
+
.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&")
|
|
134
|
+
.replace(/\0(\w+)\0/g, (_, name) => {
|
|
135
|
+
if (seen.has(name))
|
|
136
|
+
return `\\k<${name}>`;
|
|
137
|
+
seen.add(name);
|
|
138
|
+
return `(?<${name}>[^<]*)`;
|
|
139
|
+
});
|
|
140
|
+
return new RegExp(`^${source}$`);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The paths in a plist exactly as generatePlist() writes one; null for any
|
|
144
|
+
* other text. Exported for tests.
|
|
145
|
+
*
|
|
146
|
+
* Not read as a plist in general, because no reader here could read one as
|
|
147
|
+
* launchd does: launchd parses plists with libxpc's own reader, not with
|
|
148
|
+
* CoreFoundation's, which plutil and the rest of macOS use, and the two
|
|
149
|
+
* disagree on much of what isn't plain XML. libxpc takes a raw `&` as it
|
|
150
|
+
* is, for one, where CoreFoundation refuses the file. What generatePlist()
|
|
151
|
+
* writes is plain XML, which both read back as the paths it was made from.
|
|
152
|
+
*/
|
|
153
|
+
export function pathsIn(text) {
|
|
154
|
+
let v;
|
|
155
|
+
for (const pattern of templates()) {
|
|
156
|
+
v = pattern.exec(text)?.groups;
|
|
157
|
+
if (v)
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
if (!v)
|
|
161
|
+
return null;
|
|
162
|
+
const unescape = (s) => s.replace(/&(?:amp|lt|gt);/g, (e) => UNESCAPES[e]);
|
|
163
|
+
const paths = {
|
|
164
|
+
node: unescape(v.node),
|
|
165
|
+
worker: unescape(v.worker),
|
|
166
|
+
log: v.log === undefined ? null : unescape(v.log),
|
|
167
|
+
home: unescape(v.home),
|
|
168
|
+
path: unescape(v.path),
|
|
169
|
+
};
|
|
170
|
+
try {
|
|
171
|
+
// Escaped just as xmlText escapes, and nothing else: not a raw `&`, not `&`.
|
|
172
|
+
return generatePlist(paths) === text ? paths : null;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return null; // a value xmlText refuses
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** The version a plist says it is; 1 for one from before the stamp. */
|
|
179
|
+
function stampIn(text) {
|
|
180
|
+
const m = new RegExp(`<key>${VERSION_ENV}</key>\\s*<string>([0-9]+)</string>`).exec(text);
|
|
181
|
+
return m ? Number(m[1]) : 1;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* launchd won't load an agent that others can write, or that someone other
|
|
185
|
+
* than the user or root owns. Unknowable without POSIX owners (Windows, in
|
|
186
|
+
* tests). Exported for tests.
|
|
187
|
+
*/
|
|
188
|
+
export function refusedByLaunchd(st) {
|
|
189
|
+
const uid = process.getuid?.();
|
|
190
|
+
if (uid === undefined)
|
|
191
|
+
return false;
|
|
192
|
+
return (st.mode & 0o022) !== 0 || (st.uid !== uid && st.uid !== 0);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The plist at plistPath(). The label is Engram's, so whatever is there is
|
|
196
|
+
* ours to repair.
|
|
197
|
+
*/
|
|
198
|
+
export function readPlist() {
|
|
199
|
+
let st;
|
|
200
|
+
let text;
|
|
201
|
+
try {
|
|
202
|
+
st = statSync(plistPath());
|
|
203
|
+
// A byte order mark is dropped: launchd reads past one, so the plist
|
|
204
|
+
// after it is the one launchd loads.
|
|
205
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(readFileSync(plistPath()));
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
const code = err.code;
|
|
209
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
210
|
+
return { kind: "none" };
|
|
211
|
+
// Unreadable, or not UTF-8 as every plist of ours is.
|
|
212
|
+
return { kind: "ours", broken: true, version: 1, outdated: true };
|
|
213
|
+
}
|
|
214
|
+
const version = stampIn(text);
|
|
215
|
+
let broken = refusedByLaunchd(st);
|
|
216
|
+
let outdated = version < PLIST_VERSION;
|
|
217
|
+
// An older version's is rewritten anyway, by `engram start`, and a newer
|
|
218
|
+
// one's is a later CLI's to judge, not this one's.
|
|
219
|
+
if (version === PLIST_VERSION) {
|
|
220
|
+
const paths = pathsIn(text);
|
|
221
|
+
broken ||=
|
|
222
|
+
paths === null ||
|
|
223
|
+
!existsSync(paths.node) ||
|
|
224
|
+
!existsSync(paths.worker) ||
|
|
225
|
+
// launchd would never start the job (engram#679).
|
|
226
|
+
(paths.log !== null && logProblem(paths.log) !== null);
|
|
227
|
+
outdated =
|
|
228
|
+
paths !== null &&
|
|
229
|
+
(pinnedToKeg(paths.node) ||
|
|
230
|
+
pinnedToKeg(paths.worker) ||
|
|
231
|
+
runnerCacheOf(paths.worker) !== null ||
|
|
232
|
+
(paths.log === null && logProblem() === null));
|
|
233
|
+
}
|
|
234
|
+
return { kind: "ours", broken, version, outdated };
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Makes ~/Library/LaunchAgents the user's again (engram#678). The folder
|
|
238
|
+
* only: the other agents in it are theirs to look at, and Engram needs no
|
|
239
|
+
* more than to write in it.
|
|
240
|
+
*/
|
|
241
|
+
export const LAUNCH_AGENTS_FIX = 'sudo chown "$(id -un)" ~/Library/LaunchAgents';
|
|
242
|
+
function ownerOfPath(path) {
|
|
243
|
+
try {
|
|
244
|
+
return statSync(path).uid;
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function writableDir(path) {
|
|
251
|
+
try {
|
|
252
|
+
accessSync(path, constants.W_OK | constants.X_OK);
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* ~/Library/LaunchAgents is another user's, and Engram can't write in it
|
|
261
|
+
* (engram#678, engram#715): whether that user is root. Run with sudo, a CLI
|
|
262
|
+
* from before engram#653 made the folder as root when it wasn't there yet:
|
|
263
|
+
* macOS keeps HOME under sudo. The plist can't be written, replaced or
|
|
264
|
+
* removed then, as each is a change to the folder. Null when the folder is
|
|
265
|
+
* the user's, isn't there, or can be written in all the same.
|
|
266
|
+
*
|
|
267
|
+
* A plist that root owns, in the user's own folder, is no problem: launchd
|
|
268
|
+
* loads one (refusedByLaunchd), and it is replaced and removed like any
|
|
269
|
+
* other.
|
|
270
|
+
*/
|
|
271
|
+
export function launchAgentsNotYours({ euid = process.geteuid?.(), ownerOf = ownerOfPath, canWriteIn = writableDir, } = {}) {
|
|
272
|
+
// Root can write in any folder, and is refused before this (engram#653).
|
|
273
|
+
if (euid === undefined || euid === 0)
|
|
274
|
+
return null;
|
|
275
|
+
const dir = plistDir();
|
|
276
|
+
const uid = ownerOf(dir);
|
|
277
|
+
if (uid === null || uid === euid || canWriteIn(dir))
|
|
278
|
+
return null;
|
|
279
|
+
return { root: uid === 0 };
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Write the plist in one step: a temporary file beside it, renamed over it,
|
|
283
|
+
* so launchd never reads half of one. 0644: launchd won't load an agent that
|
|
284
|
+
* others can write. A link in its place is replaced, not written through.
|
|
285
|
+
*/
|
|
286
|
+
export function writePlistFile(text) {
|
|
287
|
+
mkdirSync(plistDir(), { recursive: true });
|
|
288
|
+
const temp = join(plistDir(), `.${PLIST_LABEL}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`);
|
|
289
|
+
try {
|
|
290
|
+
writeFileSync(temp, text, { flag: "wx", mode: 0o644 });
|
|
291
|
+
chmodSync(temp, 0o644);
|
|
292
|
+
renameSync(temp, plistPath());
|
|
293
|
+
}
|
|
294
|
+
catch (err) {
|
|
295
|
+
rmSync(temp, { force: true });
|
|
296
|
+
throw err;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/** launchctl, from an absolute directory on PATH; null when there is none. */
|
|
300
|
+
export function launchctlPath() {
|
|
301
|
+
return commandPath("launchctl");
|
|
302
|
+
}
|
|
303
|
+
/** Arguments, never a shell command line: a path is only ever one argument. */
|
|
304
|
+
function launchctl(args) {
|
|
305
|
+
const file = launchctlPath();
|
|
306
|
+
if (file === null)
|
|
307
|
+
throw new Error("launchctl isn't on PATH");
|
|
308
|
+
return execFileSync(file, args, {
|
|
309
|
+
encoding: "utf-8",
|
|
310
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
311
|
+
timeout: LAUNCHCTL_TIMEOUT_MS,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* The job in launchd's system domain, where it runs as root (engram#680).
|
|
316
|
+
* `launchctl load` run as root loads a plist there, wherever the plist is:
|
|
317
|
+
* `sudo engram install` did, and `sudo engram start` reloading a stale
|
|
318
|
+
* plist, before engram#653.
|
|
319
|
+
*/
|
|
320
|
+
export const SYSTEM_JOB = `system/${PLIST_LABEL}`;
|
|
321
|
+
/** How to unload SYSTEM_JOB, which stops the daemon it runs. */
|
|
322
|
+
export const SYSTEM_JOB_UNLOAD = `sudo launchctl bootout ${SYSTEM_JOB}`;
|
|
323
|
+
/**
|
|
324
|
+
* The system-domain job in `launchctl print` output, when it was loaded
|
|
325
|
+
* from `plist`: this user's own plist, so its daemon runs in their
|
|
326
|
+
* ~/.engram. A job loaded from anywhere else isn't this user's. The job's
|
|
327
|
+
* own keys are indented by one tab; what is nested in them, by more.
|
|
328
|
+
* Pure: the tests pass made-up output.
|
|
329
|
+
*/
|
|
330
|
+
export function parseSystemJob(output, plist) {
|
|
331
|
+
const path = /^\tpath = (.*)$/m.exec(output)?.[1];
|
|
332
|
+
if (path !== plist)
|
|
333
|
+
return null;
|
|
334
|
+
const pid = /^\tpid = (\d+)$/m.exec(output)?.[1];
|
|
335
|
+
return { pid: pid === undefined ? null : Number(pid) };
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Engram's job in launchd's system domain, loaded from this user's plist;
|
|
339
|
+
* null when there is none, or it can't be told. `launchctl print` needs no
|
|
340
|
+
* root to look. macOS only.
|
|
341
|
+
*/
|
|
342
|
+
export function systemJob() {
|
|
343
|
+
if (process.platform !== "darwin")
|
|
344
|
+
return null;
|
|
345
|
+
try {
|
|
346
|
+
return parseSystemJob(launchctl(["print", SYSTEM_JOB]), plistPath());
|
|
347
|
+
}
|
|
348
|
+
catch {
|
|
349
|
+
return null; // none loaded (launchctl exits 113), or launchctl failed
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/** The user's login session, where agents run. */
|
|
353
|
+
function guiDomain() {
|
|
354
|
+
return `gui/${process.getuid?.() ?? 0}`;
|
|
355
|
+
}
|
|
356
|
+
/** The PID of the daemon launchd runs for the agent; null when there is none. */
|
|
357
|
+
export function agentPid() {
|
|
358
|
+
let output;
|
|
359
|
+
try {
|
|
360
|
+
output = launchctl(["list", PLIST_LABEL]);
|
|
361
|
+
}
|
|
362
|
+
catch {
|
|
363
|
+
return null; // not loaded
|
|
364
|
+
}
|
|
365
|
+
const match = /"PID"\s*=\s*(\d+)/.exec(output);
|
|
366
|
+
if (match)
|
|
367
|
+
return parseInt(match[1], 10);
|
|
368
|
+
// Also check the tabular format: PID\tStatus\tLabel
|
|
369
|
+
for (const line of output.trim().split("\n")) {
|
|
370
|
+
const pid = parseInt(line.split("\t")[0], 10);
|
|
371
|
+
if (!isNaN(pid) && pid > 0)
|
|
372
|
+
return pid;
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
/** launchd has the job loaded: it is in the user's session now. */
|
|
377
|
+
export function agentLoaded() {
|
|
378
|
+
try {
|
|
379
|
+
launchctl(["list", PLIST_LABEL]);
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
catch {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Whether `launchctl print-disabled` output has the job switched off: true
|
|
388
|
+
* for `"<label>" => disabled` (`=> true` on older macOS), false for enabled,
|
|
389
|
+
* or for a job it doesn't list, which launchd was never told to switch off.
|
|
390
|
+
* null when it can't tell: no "disabled services" list, or a value it
|
|
391
|
+
* doesn't know for the job. Only the label itself counts, never one that
|
|
392
|
+
* starts with it.
|
|
393
|
+
* Exported for tests.
|
|
394
|
+
*/
|
|
395
|
+
export function disabledIn(output, label = PLIST_LABEL) {
|
|
396
|
+
let listed = false;
|
|
397
|
+
let inList = false;
|
|
398
|
+
for (const line of output.split("\n")) {
|
|
399
|
+
const text = line.trim();
|
|
400
|
+
if (text === "disabled services = {") {
|
|
401
|
+
listed = inList = true;
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (text === "}") {
|
|
405
|
+
inList = false;
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (!inList)
|
|
409
|
+
continue;
|
|
410
|
+
const entry = /^"(.*)"\s*=>\s*(.*)$/.exec(text);
|
|
411
|
+
if (entry === null || entry[1] !== label)
|
|
412
|
+
continue;
|
|
413
|
+
if (entry[2] === "disabled" || entry[2] === "true")
|
|
414
|
+
return true;
|
|
415
|
+
if (entry[2] === "enabled" || entry[2] === "false")
|
|
416
|
+
return false;
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
return listed ? false : null;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* launchd has the job switched off: with `launchctl disable`, or `unload -w`.
|
|
423
|
+
* It then loads it at no login, and won't bootstrap it, until it is switched
|
|
424
|
+
* back on, and it remembers that after the plist is gone (engram#654). null
|
|
425
|
+
* when launchctl couldn't say.
|
|
426
|
+
*/
|
|
427
|
+
export function agentDisabled() {
|
|
428
|
+
try {
|
|
429
|
+
return disabledIn(launchctl(["print-disabled", guiDomain()]));
|
|
430
|
+
}
|
|
431
|
+
catch {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Switch the job back on in launchd, for `engram install` only: the user
|
|
437
|
+
* asking for start at login (engram#654). Whether launchd took it.
|
|
438
|
+
*/
|
|
439
|
+
export function enableAgent() {
|
|
440
|
+
try {
|
|
441
|
+
launchctl(["enable", `${guiDomain()}/${PLIST_LABEL}`]);
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
catch {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function sleepSync(ms) {
|
|
449
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Load the agent: launchd starts the daemon now and at every login. bootstrap
|
|
453
|
+
* where macOS has it; `load` where that fails, as on older ones. Neither
|
|
454
|
+
* loads a job the user switched off. `turnOn`: `load -w`, which switches it
|
|
455
|
+
* back on too: for `engram install` only, never a repair or auto-capture
|
|
456
|
+
* (engram#654). The error when it couldn't.
|
|
457
|
+
*/
|
|
458
|
+
export function loadAgent({ turnOn = false } = {}) {
|
|
459
|
+
try {
|
|
460
|
+
launchctl(["bootstrap", guiDomain(), plistPath()]);
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
// older macOS, or switched off
|
|
465
|
+
}
|
|
466
|
+
try {
|
|
467
|
+
launchctl(turnOn ? ["load", "-w", plistPath()] : ["load", plistPath()]);
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
catch (err) {
|
|
471
|
+
return commandFailure(err);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Have launchd start the daemon now: `launchctl kickstart`, which runs the
|
|
476
|
+
* job whatever its launch conditions, as after `engram stop`, whose exit 0
|
|
477
|
+
* KeepAlive doesn't restart (engram#641). launchd starts the daemon again
|
|
478
|
+
* after a crash then, as it does the one it starts at login. A job that
|
|
479
|
+
* runs already is left running: never `-k`, which would kill it first. The
|
|
480
|
+
* error when launchd wouldn't.
|
|
481
|
+
*/
|
|
482
|
+
export function kickstartAgent() {
|
|
483
|
+
try {
|
|
484
|
+
launchctl(["kickstart", `${guiDomain()}/${PLIST_LABEL}`]);
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
catch (err) {
|
|
488
|
+
return commandFailure(err);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Unload the agent, which stops a daemon launchd runs for it. Quiet when it
|
|
493
|
+
* isn't loaded. Whether launchctl took the bootout, or the unload after it:
|
|
494
|
+
* false when it took neither, as when the job isn't loaded, when launchd
|
|
495
|
+
* refuses, or when bootout gives up waiting for the daemon to exit
|
|
496
|
+
* ("Operation now in progress") and launchd lets go of the job after.
|
|
497
|
+
*/
|
|
498
|
+
export function unloadAgent() {
|
|
499
|
+
try {
|
|
500
|
+
launchctl(["bootout", `${guiDomain()}/${PLIST_LABEL}`]);
|
|
501
|
+
return true;
|
|
502
|
+
}
|
|
503
|
+
catch {
|
|
504
|
+
// not loaded, or older macOS
|
|
505
|
+
}
|
|
506
|
+
try {
|
|
507
|
+
launchctl(["unload", plistPath()]);
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
catch {
|
|
511
|
+
return false; // not loaded
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Load the plist as it is now. launchd keeps the job it loaded, whatever the
|
|
516
|
+
* file says since, until the job is unloaded; and it can still be letting go
|
|
517
|
+
* of one when bootout returns, when a bootstrap straight after fails.
|
|
518
|
+
* `turnOn`: as for loadAgent. The error when it couldn't load it.
|
|
519
|
+
*/
|
|
520
|
+
export function reloadAgent({ turnOn = false } = {}) {
|
|
521
|
+
unloadAgent();
|
|
522
|
+
const deadline = Date.now() + UNLOAD_WAIT_MS;
|
|
523
|
+
while (agentLoaded() && Date.now() < deadline)
|
|
524
|
+
sleepSync(100);
|
|
525
|
+
return loadAgent({ turnOn });
|
|
526
|
+
}
|
|
527
|
+
//# sourceMappingURL=launchd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launchd.js","sourceRoot":"","sources":["../../src/daemon/launchd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,EACR,aAAa,GAEd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,4CAA4C;AAC5C,uEAAuE;AACvE,6EAA6E;AAC7E,6EAA6E;AAE7E,MAAM,CAAC,MAAM,WAAW,GAAG,sBAAsB,CAAC;AAElD,6EAA6E;AAC7E,4EAA4E;AAC5E,+EAA+E;AAC/E,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,4BAA4B;AAC5B,EAAE;AACF,wEAAwE;AACxE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAE/B,iGAAiG;AACjG,MAAM,WAAW,GAAG,sBAAsB,CAAC;AAE3C,qEAAqE;AACrE,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAEpC,2EAA2E;AAC3E,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,MAAM,UAAU,QAAQ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C;QACH,SAAS,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW;IACzB,IAAI,CAAC;QACH,SAAS,CAAC,CAAC,SAAS,EAAE,GAAG,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,6BAA6B;IAC/B,CAAC;IACD,IAAI,CAAC;QACH,SAAS,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC,CAAC,aAAa;IAC7B,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,MAAM,GAAG,KAAK,KAA2B,EAAE;IACvE,WAAW,EAAE,CAAC;IACd,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,CAAC;IAC7C,OAAO,WAAW,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ;QAAE,SAAS,CAAC,GAAG,CAAC,CAAC;IAC9D,OAAO,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-start.d.ts","sourceRoot":"","sources":["../../src/daemon/login-start.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Windows runs at sign-in once start at login is on (engram#602). The
|
|
3
|
+
* per-user Run entry is `"…\node.exe" "…\dist\daemon\login-start.js"`.
|
|
4
|
+
*
|
|
5
|
+
* node.exe is a console program, so whatever it runs at sign-in gets a
|
|
6
|
+
* console window, and closing that window would end the daemon. So this
|
|
7
|
+
* starts the supervisor detached and hidden, as `engram start` does, and
|
|
8
|
+
* exits: the window only flashes. The supervisor starts the worker, and
|
|
9
|
+
* starts it again if it exits with an error (engram#613; see supervise.ts).
|
|
10
|
+
*
|
|
11
|
+
* It starts them without checking for a daemon. The worker does that
|
|
12
|
+
* itself (engram#612): if a daemon already answers on its named pipe, it
|
|
13
|
+
* exits at once. The PID file is never taken as a sign of one here.
|
|
14
|
+
* Signing out ends every program the user was running, so a file left from
|
|
15
|
+
* the last session names a PID that may since have gone to another program;
|
|
16
|
+
* the new worker writes its own PID over it.
|
|
17
|
+
*
|
|
18
|
+
* It never touches config. Like the macOS launchd agent, the entry runs at
|
|
19
|
+
* every sign-in until `engram uninstall` removes it.
|
|
20
|
+
*
|
|
21
|
+
* Import-light, like worker.ts: see launch.ts.
|
|
22
|
+
*/
|
|
23
|
+
import { spawnSupervisor } from "./launch.js";
|
|
24
|
+
spawnSupervisor();
|
|
25
|
+
//# sourceMappingURL=login-start.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-start.js","sourceRoot":"","sources":["../../src/daemon/login-start.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAe,EAAE,CAAC"}
|