@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.
Files changed (206) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/auth.d.ts.map +1 -1
  3. package/dist/commands/auth.js +38 -11
  4. package/dist/commands/auth.js.map +1 -1
  5. package/dist/commands/conversations.d.ts.map +1 -1
  6. package/dist/commands/conversations.js +8 -2
  7. package/dist/commands/conversations.js.map +1 -1
  8. package/dist/commands/exclude.d.ts.map +1 -1
  9. package/dist/commands/exclude.js +73 -21
  10. package/dist/commands/exclude.js.map +1 -1
  11. package/dist/commands/import.d.ts +30 -3
  12. package/dist/commands/import.d.ts.map +1 -1
  13. package/dist/commands/import.js +374 -45
  14. package/dist/commands/import.js.map +1 -1
  15. package/dist/commands/login.d.ts.map +1 -1
  16. package/dist/commands/login.js +144 -29
  17. package/dist/commands/login.js.map +1 -1
  18. package/dist/commands/search.js +2 -2
  19. package/dist/commands/search.js.map +1 -1
  20. package/dist/commands/status.d.ts +16 -0
  21. package/dist/commands/status.d.ts.map +1 -0
  22. package/dist/commands/status.js +51 -0
  23. package/dist/commands/status.js.map +1 -0
  24. package/dist/commands/store.d.ts.map +1 -1
  25. package/dist/commands/store.js +19 -3
  26. package/dist/commands/store.js.map +1 -1
  27. package/dist/commands/upgrade.d.ts +24 -0
  28. package/dist/commands/upgrade.d.ts.map +1 -1
  29. package/dist/commands/upgrade.js +64 -15
  30. package/dist/commands/upgrade.js.map +1 -1
  31. package/dist/commands/usage.d.ts +44 -0
  32. package/dist/commands/usage.d.ts.map +1 -1
  33. package/dist/commands/usage.js +79 -19
  34. package/dist/commands/usage.js.map +1 -1
  35. package/dist/commands/vault.d.ts +11 -2
  36. package/dist/commands/vault.d.ts.map +1 -1
  37. package/dist/commands/vault.js +372 -53
  38. package/dist/commands/vault.js.map +1 -1
  39. package/dist/config-file.d.ts +74 -0
  40. package/dist/config-file.d.ts.map +1 -0
  41. package/dist/config-file.js +152 -0
  42. package/dist/config-file.js.map +1 -0
  43. package/dist/config-guard.d.ts +96 -0
  44. package/dist/config-guard.d.ts.map +1 -0
  45. package/dist/config-guard.js +184 -0
  46. package/dist/config-guard.js.map +1 -0
  47. package/dist/config.d.ts +48 -4
  48. package/dist/config.d.ts.map +1 -1
  49. package/dist/config.js +101 -12
  50. package/dist/config.js.map +1 -1
  51. package/dist/daemon/as-root.d.ts +46 -0
  52. package/dist/daemon/as-root.d.ts.map +1 -0
  53. package/dist/daemon/as-root.js +64 -0
  54. package/dist/daemon/as-root.js.map +1 -0
  55. package/dist/daemon/backoff.d.ts +26 -0
  56. package/dist/daemon/backoff.d.ts.map +1 -0
  57. package/dist/daemon/backoff.js +37 -0
  58. package/dist/daemon/backoff.js.map +1 -0
  59. package/dist/daemon/codex-parser.d.ts +38 -4
  60. package/dist/daemon/codex-parser.d.ts.map +1 -1
  61. package/dist/daemon/codex-parser.js +111 -23
  62. package/dist/daemon/codex-parser.js.map +1 -1
  63. package/dist/daemon/command-path.d.ts +13 -0
  64. package/dist/daemon/command-path.d.ts.map +1 -0
  65. package/dist/daemon/command-path.js +35 -0
  66. package/dist/daemon/command-path.js.map +1 -0
  67. package/dist/daemon/commands.d.ts +146 -5
  68. package/dist/daemon/commands.d.ts.map +1 -1
  69. package/dist/daemon/commands.js +2766 -316
  70. package/dist/daemon/commands.js.map +1 -1
  71. package/dist/daemon/db.d.ts +255 -27
  72. package/dist/daemon/db.d.ts.map +1 -1
  73. package/dist/daemon/db.js +749 -53
  74. package/dist/daemon/db.js.map +1 -1
  75. package/dist/daemon/exclusions.d.ts +23 -3
  76. package/dist/daemon/exclusions.d.ts.map +1 -1
  77. package/dist/daemon/exclusions.js +91 -21
  78. package/dist/daemon/exclusions.js.map +1 -1
  79. package/dist/daemon/homebrew.d.ts +26 -0
  80. package/dist/daemon/homebrew.d.ts.map +1 -0
  81. package/dist/daemon/homebrew.js +43 -0
  82. package/dist/daemon/homebrew.js.map +1 -0
  83. package/dist/daemon/instance.d.ts +427 -0
  84. package/dist/daemon/instance.d.ts.map +1 -0
  85. package/dist/daemon/instance.js +1201 -0
  86. package/dist/daemon/instance.js.map +1 -0
  87. package/dist/daemon/key-source.d.ts +41 -0
  88. package/dist/daemon/key-source.d.ts.map +1 -0
  89. package/dist/daemon/key-source.js +89 -0
  90. package/dist/daemon/key-source.js.map +1 -0
  91. package/dist/daemon/launch.d.ts +56 -0
  92. package/dist/daemon/launch.d.ts.map +1 -0
  93. package/dist/daemon/launch.js +153 -0
  94. package/dist/daemon/launch.js.map +1 -0
  95. package/dist/daemon/launchd.d.ts +215 -0
  96. package/dist/daemon/launchd.d.ts.map +1 -0
  97. package/dist/daemon/launchd.js +527 -0
  98. package/dist/daemon/launchd.js.map +1 -0
  99. package/dist/daemon/login-start.d.ts +2 -0
  100. package/dist/daemon/login-start.d.ts.map +1 -0
  101. package/dist/daemon/login-start.js +25 -0
  102. package/dist/daemon/login-start.js.map +1 -0
  103. package/dist/daemon/ownership.d.ts +123 -0
  104. package/dist/daemon/ownership.d.ts.map +1 -0
  105. package/dist/daemon/ownership.js +245 -0
  106. package/dist/daemon/ownership.js.map +1 -0
  107. package/dist/daemon/package-runner.d.ts +28 -0
  108. package/dist/daemon/package-runner.d.ts.map +1 -0
  109. package/dist/daemon/package-runner.js +113 -0
  110. package/dist/daemon/package-runner.js.map +1 -0
  111. package/dist/daemon/parser.d.ts +45 -7
  112. package/dist/daemon/parser.d.ts.map +1 -1
  113. package/dist/daemon/parser.js +153 -53
  114. package/dist/daemon/parser.js.map +1 -1
  115. package/dist/daemon/powershell.d.ts +25 -0
  116. package/dist/daemon/powershell.d.ts.map +1 -0
  117. package/dist/daemon/powershell.js +30 -0
  118. package/dist/daemon/powershell.js.map +1 -0
  119. package/dist/daemon/preflight.d.ts.map +1 -1
  120. package/dist/daemon/preflight.js +5 -1
  121. package/dist/daemon/preflight.js.map +1 -1
  122. package/dist/daemon/prune.d.ts +101 -0
  123. package/dist/daemon/prune.d.ts.map +1 -0
  124. package/dist/daemon/prune.js +287 -0
  125. package/dist/daemon/prune.js.map +1 -0
  126. package/dist/daemon/queue-error.d.ts +47 -0
  127. package/dist/daemon/queue-error.d.ts.map +1 -0
  128. package/dist/daemon/queue-error.js +59 -0
  129. package/dist/daemon/queue-error.js.map +1 -0
  130. package/dist/daemon/root-daemon.d.ts +60 -0
  131. package/dist/daemon/root-daemon.d.ts.map +1 -0
  132. package/dist/daemon/root-daemon.js +86 -0
  133. package/dist/daemon/root-daemon.js.map +1 -0
  134. package/dist/daemon/scoop.d.ts +52 -0
  135. package/dist/daemon/scoop.d.ts.map +1 -0
  136. package/dist/daemon/scoop.js +84 -0
  137. package/dist/daemon/scoop.js.map +1 -0
  138. package/dist/daemon/scrubber.d.ts +396 -14
  139. package/dist/daemon/scrubber.d.ts.map +1 -1
  140. package/dist/daemon/scrubber.js +915 -52
  141. package/dist/daemon/scrubber.js.map +1 -1
  142. package/dist/daemon/status.d.ts +306 -11
  143. package/dist/daemon/status.d.ts.map +1 -1
  144. package/dist/daemon/status.js +568 -43
  145. package/dist/daemon/status.js.map +1 -1
  146. package/dist/daemon/supervise.d.ts +78 -0
  147. package/dist/daemon/supervise.d.ts.map +1 -0
  148. package/dist/daemon/supervise.js +121 -0
  149. package/dist/daemon/supervise.js.map +1 -0
  150. package/dist/daemon/supervisor.d.ts +18 -0
  151. package/dist/daemon/supervisor.d.ts.map +1 -0
  152. package/dist/daemon/supervisor.js +56 -0
  153. package/dist/daemon/supervisor.js.map +1 -0
  154. package/dist/daemon/syncer.d.ts +380 -21
  155. package/dist/daemon/syncer.d.ts.map +1 -1
  156. package/dist/daemon/syncer.js +1432 -182
  157. package/dist/daemon/syncer.js.map +1 -1
  158. package/dist/daemon/systemd.d.ts +109 -0
  159. package/dist/daemon/systemd.d.ts.map +1 -0
  160. package/dist/daemon/systemd.js +363 -0
  161. package/dist/daemon/systemd.js.map +1 -0
  162. package/dist/daemon/types.d.ts +58 -6
  163. package/dist/daemon/types.d.ts.map +1 -1
  164. package/dist/daemon/vault-changed.d.ts +29 -0
  165. package/dist/daemon/vault-changed.d.ts.map +1 -0
  166. package/dist/daemon/vault-changed.js +47 -0
  167. package/dist/daemon/vault-changed.js.map +1 -0
  168. package/dist/daemon/vault-key-missing.d.ts +70 -0
  169. package/dist/daemon/vault-key-missing.d.ts.map +1 -0
  170. package/dist/daemon/vault-key-missing.js +125 -0
  171. package/dist/daemon/vault-key-missing.js.map +1 -0
  172. package/dist/daemon/watcher.d.ts +87 -4
  173. package/dist/daemon/watcher.d.ts.map +1 -1
  174. package/dist/daemon/watcher.js +286 -36
  175. package/dist/daemon/watcher.js.map +1 -1
  176. package/dist/daemon/worker-main.js +352 -64
  177. package/dist/daemon/worker-main.js.map +1 -1
  178. package/dist/daemon/worker.js +19 -1
  179. package/dist/daemon/worker.js.map +1 -1
  180. package/dist/import-resume.d.ts +163 -0
  181. package/dist/import-resume.d.ts.map +1 -0
  182. package/dist/import-resume.js +267 -0
  183. package/dist/import-resume.js.map +1 -0
  184. package/dist/index.js +242 -33
  185. package/dist/index.js.map +1 -1
  186. package/dist/message-bounds.d.ts +52 -0
  187. package/dist/message-bounds.d.ts.map +1 -0
  188. package/dist/message-bounds.js +157 -0
  189. package/dist/message-bounds.js.map +1 -0
  190. package/dist/output.d.ts +14 -0
  191. package/dist/output.d.ts.map +1 -1
  192. package/dist/output.js +33 -5
  193. package/dist/output.js.map +1 -1
  194. package/dist/private-files.d.ts +126 -0
  195. package/dist/private-files.d.ts.map +1 -0
  196. package/dist/private-files.js +372 -0
  197. package/dist/private-files.js.map +1 -0
  198. package/dist/server-url.d.ts +31 -0
  199. package/dist/server-url.d.ts.map +1 -0
  200. package/dist/server-url.js +47 -0
  201. package/dist/server-url.js.map +1 -0
  202. package/dist/vault-key.d.ts +122 -0
  203. package/dist/vault-key.d.ts.map +1 -0
  204. package/dist/vault-key.js +273 -0
  205. package/dist/vault-key.js.map +1 -0
  206. package/package.json +2 -2
@@ -0,0 +1,287 @@
1
+ /**
2
+ * Clears sent messages out of the local queue (engram#598).
3
+ *
4
+ * daemon.db holds what the watcher reads until the server has it. When the
5
+ * server confirms it has stored a batch, the batch's rows are marked sent,
6
+ * and until now they stayed: the file kept a copy of every message ever
7
+ * captured, growing without end. Nothing reads a sent row again. The
8
+ * transcript it was read from is still where it was, and the server has it.
9
+ *
10
+ * Once an hour (the first time a couple of minutes after the daemon
11
+ * starts), rows sent more than SENT_RETENTION_DAYS days ago are deleted, a
12
+ * few hundred at a time with pauses in between, so capture and sending
13
+ * carry on as usual. A row that hasn't been sent is never deleted, however
14
+ * old it is. The days in between leave time to look into a problem with
15
+ * the local queue while its rows are still there.
16
+ *
17
+ * What is deleted leaves the file as well. secure_delete (see db.ts)
18
+ * writes zeros over it, the space it took goes back to the disk, and each
19
+ * pass ends by emptying the write-ahead log. A daemon.db made before this
20
+ * is rewritten once (DaemonDb.compact), when the disks it writes to have
21
+ * room for that, which also clears what earlier deletes left in its free
22
+ * pages.
23
+ */
24
+ import * as fs from "node:fs";
25
+ import { tmpdir } from "node:os";
26
+ import { dirname } from "node:path";
27
+ import { plural } from "../output.js";
28
+ const DAY_MS = 24 * 60 * 60 * 1000;
29
+ /** How long a sent message stays in the local queue. */
30
+ export const SENT_RETENTION_DAYS = 30;
31
+ export const SENT_RETENTION_MS = SENT_RETENTION_DAYS * DAY_MS;
32
+ /** The first pass waits this long after the daemon starts, past the busy
33
+ * first reads of the transcripts. */
34
+ export const FIRST_PASS_MS = 2 * 60 * 1000;
35
+ /** Then a pass every hour. */
36
+ export const PASS_INTERVAL_MS = 60 * 60 * 1000;
37
+ /** Rows deleted in one transaction. */
38
+ export const PRUNE_BATCH = 200;
39
+ /** Free pages given back to the disk in one step (8 MB of 4 KB pages). */
40
+ export const RELEASE_STEP_PAGES = 2048;
41
+ /** The pause between batches and steps, so the queue isn't held for long. */
42
+ export const STEP_PAUSE_MS = 50;
43
+ /** Compacting that was skipped or failed is tried again a day later. */
44
+ export const COMPACT_RETRY_MS = DAY_MS;
45
+ /** Compacting writes a copy of the live data to a temporary file and
46
+ * again to the write-ahead log. It starts only when each disk it writes
47
+ * to has three times that free, and this much more. */
48
+ export const COMPACT_SPARE_BYTES = 64 * 1024 * 1024;
49
+ /**
50
+ * The directory SQLite writes the temporary copy a VACUUM makes to: the
51
+ * first of these it can use, picked as SQLite itself picks it (os_unix.c,
52
+ * unixTempFileDir; on Windows, GetTempPathW's order). Null when none is.
53
+ */
54
+ export function sqliteTempDir(env = process.env, platform = process.platform) {
55
+ if (platform === "win32") {
56
+ return env.TMP || env.TEMP || env.USERPROFILE || tmpdir();
57
+ }
58
+ for (const dir of [env.SQLITE_TMPDIR, env.TMPDIR, "/var/tmp", "/usr/tmp", "/tmp", "."]) {
59
+ if (!dir)
60
+ continue;
61
+ try {
62
+ if (!fs.statSync(dir).isDirectory())
63
+ continue;
64
+ fs.accessSync(dir, fs.constants.W_OK | fs.constants.X_OK);
65
+ return dir;
66
+ }
67
+ catch {
68
+ // Not usable: SQLite goes on to the next one.
69
+ }
70
+ }
71
+ return null;
72
+ }
73
+ /** Bytes free to this user on the disk that holds `path`; null when that
74
+ * can't be told (fs.statfsSync came in Node 18.15). */
75
+ export function freeBytesAt(path) {
76
+ const statfs = fs.statfsSync;
77
+ if (typeof statfs !== "function")
78
+ return null;
79
+ try {
80
+ const s = statfs(path);
81
+ return Number(s.bavail) * Number(s.bsize);
82
+ }
83
+ catch {
84
+ return null;
85
+ }
86
+ }
87
+ function errorText(err) {
88
+ return err instanceof Error ? err.message : String(err);
89
+ }
90
+ function mb(bytes) {
91
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
92
+ }
93
+ export class Pruner {
94
+ db;
95
+ dbPath;
96
+ log;
97
+ now;
98
+ pause;
99
+ freeBytes;
100
+ tempDir;
101
+ timer = null;
102
+ running = null;
103
+ stopped = false;
104
+ /** Compacting isn't tried again before this time. */
105
+ compactAfter = 0;
106
+ /** The last problem logged: the same one again isn't logged every hour. */
107
+ lastProblem = null;
108
+ problemThisPass = false;
109
+ constructor(db, dbPath, opts) {
110
+ this.db = db;
111
+ this.dbPath = dbPath;
112
+ this.log = opts.log;
113
+ this.now = opts.now ?? Date.now;
114
+ this.pause = opts.pause ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
115
+ this.freeBytes = opts.freeBytes ?? freeBytesAt;
116
+ this.tempDir = opts.tempDir ?? (() => sqliteTempDir());
117
+ }
118
+ start() {
119
+ if (this.stopped || this.timer || this.running)
120
+ return;
121
+ this.schedule(FIRST_PASS_MS);
122
+ }
123
+ /** No pass starts after this, and a pass in progress stops at its next
124
+ * step without touching the database again: close it after this. */
125
+ stop() {
126
+ this.stopped = true;
127
+ if (this.timer)
128
+ clearTimeout(this.timer);
129
+ this.timer = null;
130
+ }
131
+ /** Settles when no pass is running. */
132
+ idle() {
133
+ return this.running ?? Promise.resolve();
134
+ }
135
+ schedule(ms) {
136
+ if (this.stopped)
137
+ return;
138
+ const timer = setTimeout(() => {
139
+ this.timer = null;
140
+ this.running = this.pass()
141
+ .catch((err) => {
142
+ // pass() handles its own errors. Anything else (a log line that
143
+ // can't be written to a full disk) mustn't stop the daemon: an
144
+ // unhandled rejection would.
145
+ try {
146
+ this.log(`clearing sent messages failed: ${errorText(err)}`);
147
+ }
148
+ catch {
149
+ // Nowhere to say it.
150
+ }
151
+ })
152
+ .finally(() => {
153
+ this.running = null;
154
+ this.schedule(PASS_INTERVAL_MS);
155
+ });
156
+ }, ms);
157
+ // The daemon's watchers keep it running; this timer alone shouldn't.
158
+ timer.unref?.();
159
+ this.timer = timer;
160
+ }
161
+ /** One pass: delete the rows that are due, give the space they took
162
+ * back to the disk, and empty the write-ahead log. Never throws. */
163
+ async pass() {
164
+ this.problemThisPass = false;
165
+ const removed = await this.prune();
166
+ if (removed > 0) {
167
+ this.log(`removed ${plural(removed, "message")} sent over ${SENT_RETENTION_DAYS} days ago from the local queue (the server keeps them)`);
168
+ }
169
+ if (!this.stopped)
170
+ await this.reclaim();
171
+ if (!this.stopped) {
172
+ try {
173
+ // Busy (another process reading daemon.db) is fine: the next one.
174
+ this.db.checkpoint();
175
+ }
176
+ catch (err) {
177
+ this.problem("emptying daemon.db's write-ahead log failed", err);
178
+ }
179
+ }
180
+ if (!this.problemThisPass)
181
+ this.lastProblem = null;
182
+ }
183
+ /** Deletes the sent rows that are due, PRUNE_BATCH at a time, and
184
+ * returns how many went. */
185
+ async prune() {
186
+ // Fixed for the pass: rows sent while it runs are never due, so it ends.
187
+ const before = new Date(this.now() - SENT_RETENTION_MS);
188
+ let removed = 0;
189
+ for (;;) {
190
+ if (this.stopped)
191
+ break;
192
+ let deleted;
193
+ try {
194
+ deleted = this.db.pruneSent(before, PRUNE_BATCH);
195
+ }
196
+ catch (err) {
197
+ this.problem("removing sent messages from daemon.db failed", err);
198
+ break;
199
+ }
200
+ removed += deleted;
201
+ if (deleted < PRUNE_BATCH)
202
+ break;
203
+ await this.pause(STEP_PAUSE_MS);
204
+ }
205
+ return removed;
206
+ }
207
+ /** Gives the space that deleted rows took back to the disk. */
208
+ async reclaim() {
209
+ let storage;
210
+ try {
211
+ storage = this.db.storage();
212
+ }
213
+ catch (err) {
214
+ this.problem("reading daemon.db's size failed", err);
215
+ return;
216
+ }
217
+ if (storage.incremental) {
218
+ await this.release(storage.freePages);
219
+ }
220
+ else if (this.now() >= this.compactAfter) {
221
+ this.compact(storage);
222
+ }
223
+ }
224
+ async release(freePages) {
225
+ let left = freePages;
226
+ while (left > 0) {
227
+ if (this.stopped)
228
+ return;
229
+ let released;
230
+ try {
231
+ released = this.db.releaseFreePages(RELEASE_STEP_PAGES);
232
+ }
233
+ catch (err) {
234
+ this.problem("giving daemon.db's free space back to the disk failed", err);
235
+ return;
236
+ }
237
+ if (released <= 0)
238
+ return;
239
+ left -= released;
240
+ if (left > 0)
241
+ await this.pause(STEP_PAUSE_MS);
242
+ }
243
+ }
244
+ /** Rewrites a daemon.db made before engram#598, once, when the disks it
245
+ * writes to have room. Tried at most once a day. */
246
+ compact(storage) {
247
+ this.compactAfter = this.now() + COMPACT_RETRY_MS;
248
+ const live = (storage.pages - storage.freePages) * storage.pageSize;
249
+ const needed = 3 * live + COMPACT_SPARE_BYTES;
250
+ for (const dir of [dirname(this.dbPath), this.tempDir()]) {
251
+ const free = dir === null ? null : this.freeBytes(dir);
252
+ if (free === null) {
253
+ this.problem(`not compacting daemon.db yet: couldn't tell how much space is free ${dir === null ? "for SQLite's temporary files" : `in ${dir}`}`);
254
+ return;
255
+ }
256
+ if (free < needed) {
257
+ this.problem(`not compacting daemon.db yet: it needs ${mb(needed)} free in ${dir}, which has ${mb(free)}`);
258
+ return;
259
+ }
260
+ }
261
+ const size = storage.pages * storage.pageSize;
262
+ try {
263
+ this.db.compact();
264
+ }
265
+ catch (err) {
266
+ this.problem("compacting daemon.db failed (it is as it was)", err);
267
+ return;
268
+ }
269
+ try {
270
+ const after = this.db.storage();
271
+ this.log(`compacted daemon.db from ${mb(size)} to ${mb(after.pages * after.pageSize)}; space it frees goes back to the disk from now on`);
272
+ }
273
+ catch {
274
+ this.log("compacted daemon.db; space it frees goes back to the disk from now on");
275
+ }
276
+ }
277
+ /** Logs a problem, unless it's the one logged last. */
278
+ problem(what, err) {
279
+ this.problemThisPass = true;
280
+ const text = err === undefined ? what : `${what}: ${errorText(err)}`;
281
+ if (text === this.lastProblem)
282
+ return;
283
+ this.lastProblem = text;
284
+ this.log(text);
285
+ }
286
+ }
287
+ //# sourceMappingURL=prune.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prune.js","sourceRoot":"","sources":["../../src/daemon/prune.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MA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,GAAG,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;QACrE,IAAI,IAAI,KAAK,IAAI,CAAC,WAAW;YAAE,OAAO;QACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Messages read from a transcript could not be queued in daemon.db
3
+ * (engram#584): the disk is full, an I/O error, a locked or damaged
4
+ * database. Unlike a line the parser can't make sense of, this says nothing
5
+ * about the line itself: the same line queues fine once the disk has room.
6
+ * So the watcher stops at the line, keeps its place, and tries again later,
7
+ * where a bad line is skipped.
8
+ *
9
+ * It used to be logged and dropped: the daemon called the syncer as
10
+ * `onMessages(...).catch(log)`, the watcher had already moved on, and it
11
+ * saved the file's resume offset past the line. The message was never
12
+ * queued, and nothing ever read that line again.
13
+ */
14
+ export declare class QueueWriteError extends Error {
15
+ /** What daemon.db said, e.g. "database or disk is full". */
16
+ readonly reason: string;
17
+ readonly kind: "queue" | "config";
18
+ constructor(cause: unknown);
19
+ }
20
+ /**
21
+ * ~/.engram/config.json is there, but which folders it excludes from
22
+ * capture can't be told (engram#673): it can't be read, or isn't settings.
23
+ * Like a failed queue write, this says nothing about the line: the watcher
24
+ * holds the file at it and tries again later. Captured meanwhile, a
25
+ * session in an excluded folder would be queued and sent, and an
26
+ * exclusion can't be taken back once it has.
27
+ *
28
+ * `reason` names the problem and never quotes the file, which holds the
29
+ * API key: it reaches daemon.log, status.json and a notification.
30
+ */
31
+ export declare class ExclusionsUnreadable extends Error {
32
+ /** What is wrong with the file, e.g. "~/.engram/config.json isn't valid JSON". */
33
+ readonly reason: string;
34
+ readonly kind: "queue" | "config";
35
+ constructor(reason: string);
36
+ }
37
+ /**
38
+ * Why the watcher holds a transcript at a line rather than read on: the
39
+ * line is fine, but it can't be captured safely yet. Anything else thrown
40
+ * while capturing a line is about the line, and it is skipped.
41
+ */
42
+ export type CaptureHold = QueueWriteError | ExclusionsUnreadable;
43
+ /** True for an error the watcher holds a transcript for, rather than skip the line. */
44
+ export declare function isCaptureHold(err: unknown): err is CaptureHold;
45
+ /** Runs one daemon.db step of queuing, turning its failure into a QueueWriteError. */
46
+ export declare function queueing<T>(step: () => T): T;
47
+ //# sourceMappingURL=queue-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-error.d.ts","sourceRoot":"","sources":["../../src/daemon/queue-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAW;gBAEhC,KAAK,EAAE,OAAO;CAM3B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,kFAAkF;IAClF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAY;gBAEjC,MAAM,EAAE,MAAM;CAK3B;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,oBAAoB,CAAC;AAEjE,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW,CAE9D;AAED,sFAAsF;AACtF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAM5C"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Messages read from a transcript could not be queued in daemon.db
3
+ * (engram#584): the disk is full, an I/O error, a locked or damaged
4
+ * database. Unlike a line the parser can't make sense of, this says nothing
5
+ * about the line itself: the same line queues fine once the disk has room.
6
+ * So the watcher stops at the line, keeps its place, and tries again later,
7
+ * where a bad line is skipped.
8
+ *
9
+ * It used to be logged and dropped: the daemon called the syncer as
10
+ * `onMessages(...).catch(log)`, the watcher had already moved on, and it
11
+ * saved the file's resume offset past the line. The message was never
12
+ * queued, and nothing ever read that line again.
13
+ */
14
+ export class QueueWriteError extends Error {
15
+ /** What daemon.db said, e.g. "database or disk is full". */
16
+ reason;
17
+ kind = "queue";
18
+ constructor(cause) {
19
+ const reason = cause instanceof Error ? cause.message : String(cause);
20
+ super(`couldn't queue messages in daemon.db: ${reason}`, { cause });
21
+ this.name = "QueueWriteError";
22
+ this.reason = reason;
23
+ }
24
+ }
25
+ /**
26
+ * ~/.engram/config.json is there, but which folders it excludes from
27
+ * capture can't be told (engram#673): it can't be read, or isn't settings.
28
+ * Like a failed queue write, this says nothing about the line: the watcher
29
+ * holds the file at it and tries again later. Captured meanwhile, a
30
+ * session in an excluded folder would be queued and sent, and an
31
+ * exclusion can't be taken back once it has.
32
+ *
33
+ * `reason` names the problem and never quotes the file, which holds the
34
+ * API key: it reaches daemon.log, status.json and a notification.
35
+ */
36
+ export class ExclusionsUnreadable extends Error {
37
+ /** What is wrong with the file, e.g. "~/.engram/config.json isn't valid JSON". */
38
+ reason;
39
+ kind = "config";
40
+ constructor(reason) {
41
+ super(`can't tell which folders are excluded from capture: ${reason}`);
42
+ this.name = "ExclusionsUnreadable";
43
+ this.reason = reason;
44
+ }
45
+ }
46
+ /** True for an error the watcher holds a transcript for, rather than skip the line. */
47
+ export function isCaptureHold(err) {
48
+ return err instanceof QueueWriteError || err instanceof ExclusionsUnreadable;
49
+ }
50
+ /** Runs one daemon.db step of queuing, turning its failure into a QueueWriteError. */
51
+ export function queueing(step) {
52
+ try {
53
+ return step();
54
+ }
55
+ catch (err) {
56
+ throw isCaptureHold(err) ? err : new QueueWriteError(err);
57
+ }
58
+ }
59
+ //# sourceMappingURL=queue-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-error.js","sourceRoot":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680 — a daemon left running as root in the user's ~/.engram.
3
+ *
4
+ * Before engram#653, `sudo engram start` started the daemon as root, and
5
+ * `sudo engram install` loaded its launchd job into the system domain,
6
+ * where it runs as root. macOS keeps HOME under sudo, so that daemon
7
+ * captures into the user's ~/.engram and makes files there that their own
8
+ * daemon can't write. The user can't signal it: `engram stop` failed, and
9
+ * a CLI from before this change took its PID file for a dead daemon's and
10
+ * removed it, then started a second daemon beside it.
11
+ *
12
+ * Now its PID file is kept, and `engram status`, `start`, `stop` and
13
+ * `install` say how to stop it. While it runs, no other daemon is started:
14
+ * two would capture the same transcripts (see claimDaemonLock).
15
+ */
16
+ import { type SystemJob } from "./launchd.js";
17
+ import type { ForeignFiles } from "./ownership.js";
18
+ /** A daemon running as root for this user, and Engram's job in launchd's system domain (macOS). */
19
+ export interface RootDaemon {
20
+ pid: number;
21
+ job: SystemJob | null;
22
+ }
23
+ /**
24
+ * The daemon running as root for this user, when one runs: named in the
25
+ * PID file (`inFile`, when the caller has looked), or run by the job a
26
+ * sudo install loaded into launchd's system domain from the user's plist.
27
+ * `job`: that job, when the caller has looked. Never on Windows, which has
28
+ * no root, and where looking means asking PowerShell.
29
+ */
30
+ export declare function findRootDaemon(inFile?: {
31
+ pid: number;
32
+ root: boolean;
33
+ } | null, job?: SystemJob | null): RootDaemon | null;
34
+ /**
35
+ * How to stop it. Through launchd when its job runs it: KeepAlive starts
36
+ * a daemon again after a crash, and unloading the job stops it for good.
37
+ */
38
+ export declare function rootStopCommand(root: RootDaemon): string;
39
+ /** What to say of it: the problem, then what to run, in order. */
40
+ export declare function rootDaemonLines(root: RootDaemon): {
41
+ problem: string;
42
+ fixes: string[];
43
+ };
44
+ /**
45
+ * Engram's job in launchd's system domain, loaded and running no daemon of
46
+ * the user's: KeepAlive or a kickstart would start one as root. Gone at the
47
+ * next restart: the system domain loads only /Library/LaunchDaemons.
48
+ */
49
+ export declare function systemJobLeft(): string;
50
+ /**
51
+ * Workers running as root that neither the PID file nor launchd ties to
52
+ * this user, besides `known`: only said, never acted on. On macOS, where
53
+ * the daemon never runs as root, any. On Linux only when ~/.engram has
54
+ * files root owns, the mark of one in it: a daemon root runs for itself,
55
+ * in its own home, is no concern of the user's.
56
+ */
57
+ export declare function untiedRootWorkers(known: readonly (number | null)[], foreign: ForeignFiles | null): number[];
58
+ /** What to say of untied root workers: one line, with the command that stops them. */
59
+ export declare function untiedRootLine(pids: readonly number[]): string;
60
+ //# sourceMappingURL=root-daemon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-daemon.d.ts","sourceRoot":"","sources":["../../src/daemon/root-daemon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,mGAAmG;AACnG,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,MAAM,CAAC,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,EAC9C,GAAG,CAAC,EAAE,SAAS,GAAG,IAAI,GACrB,UAAU,GAAG,IAAI,CAUnB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAExD;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAOtF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,MAAM,EAAE,CAO3G;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAK9D"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * engram#680 — a daemon left running as root in the user's ~/.engram.
3
+ *
4
+ * Before engram#653, `sudo engram start` started the daemon as root, and
5
+ * `sudo engram install` loaded its launchd job into the system domain,
6
+ * where it runs as root. macOS keeps HOME under sudo, so that daemon
7
+ * captures into the user's ~/.engram and makes files there that their own
8
+ * daemon can't write. The user can't signal it: `engram stop` failed, and
9
+ * a CLI from before this change took its PID file for a dead daemon's and
10
+ * removed it, then started a second daemon beside it.
11
+ *
12
+ * Now its PID file is kept, and `engram status`, `start`, `stop` and
13
+ * `install` say how to stop it. While it runs, no other daemon is started:
14
+ * two would capture the same transcripts (see claimDaemonLock).
15
+ */
16
+ import { daemonInPidFile, rootDaemonPid, rootWorkerPids } from "./instance.js";
17
+ import { SYSTEM_JOB_UNLOAD, systemJob } from "./launchd.js";
18
+ /**
19
+ * The daemon running as root for this user, when one runs: named in the
20
+ * PID file (`inFile`, when the caller has looked), or run by the job a
21
+ * sudo install loaded into launchd's system domain from the user's plist.
22
+ * `job`: that job, when the caller has looked. Never on Windows, which has
23
+ * no root, and where looking means asking PowerShell.
24
+ */
25
+ export function findRootDaemon(inFile, job) {
26
+ if (process.platform === "win32")
27
+ return null;
28
+ try {
29
+ const loaded = job === undefined ? systemJob() : job;
30
+ const pid = rootDaemonPid(inFile === undefined ? daemonInPidFile() : inFile, loaded);
31
+ return pid === null ? null : { pid, job: loaded };
32
+ }
33
+ catch {
34
+ // Never what stops start, stop or status.
35
+ return null;
36
+ }
37
+ }
38
+ /**
39
+ * How to stop it. Through launchd when its job runs it: KeepAlive starts
40
+ * a daemon again after a crash, and unloading the job stops it for good.
41
+ */
42
+ export function rootStopCommand(root) {
43
+ return root.job?.pid === root.pid ? SYSTEM_JOB_UNLOAD : `sudo kill ${root.pid}`;
44
+ }
45
+ /** What to say of it: the problem, then what to run, in order. */
46
+ export function rootDaemonLines(root) {
47
+ const fixes = [`Stop it with: ${rootStopCommand(root)}`];
48
+ // Loaded, and running another daemon or none: it would run one again.
49
+ if (root.job !== null && root.job.pid !== root.pid) {
50
+ fixes.push(`Also unload the job 'sudo engram install' loaded into launchd's system domain: ${SYSTEM_JOB_UNLOAD}`);
51
+ }
52
+ return { problem: `A daemon started with sudo is still running as root (pid ${root.pid}).`, fixes };
53
+ }
54
+ /**
55
+ * Engram's job in launchd's system domain, loaded and running no daemon of
56
+ * the user's: KeepAlive or a kickstart would start one as root. Gone at the
57
+ * next restart: the system domain loads only /Library/LaunchDaemons.
58
+ */
59
+ export function systemJobLeft() {
60
+ return `The job 'sudo engram install' loaded into launchd's system domain is still there, and would run the daemon as root. Unload it with: ${SYSTEM_JOB_UNLOAD}`;
61
+ }
62
+ /**
63
+ * Workers running as root that neither the PID file nor launchd ties to
64
+ * this user, besides `known`: only said, never acted on. On macOS, where
65
+ * the daemon never runs as root, any. On Linux only when ~/.engram has
66
+ * files root owns, the mark of one in it: a daemon root runs for itself,
67
+ * in its own home, is no concern of the user's.
68
+ */
69
+ export function untiedRootWorkers(known, foreign) {
70
+ if (process.platform === "linux" && !foreign?.root)
71
+ return [];
72
+ try {
73
+ return rootWorkerPids().filter((pid) => !known.includes(pid));
74
+ }
75
+ catch {
76
+ return [];
77
+ }
78
+ }
79
+ /** What to say of untied root workers: one line, with the command that stops them. */
80
+ export function untiedRootLine(pids) {
81
+ const list = pids.join(" ");
82
+ return pids.length === 1
83
+ ? `A daemon is running as root (pid ${list}), most likely started with sudo. Stop it with: sudo kill ${list}`
84
+ : `Daemons are running as root (pids ${pids.join(", ")}), most likely started with sudo. Stop them with: sudo kill ${list}`;
85
+ }
86
+ //# sourceMappingURL=root-daemon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-daemon.js","sourceRoot":"","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AC,GAAG,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC;QACnD,KAAK,CAAC,IAAI,CAAC,kFAAkF,iBAAiB,EAAE,CAAC,CAAC;IACpH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,4DAA4D,IAAI,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC;AACtG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,uIAAuI,iBAAiB,EAAE,CAAC;AACpK,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAiC,EAAE,OAA4B;IAC/F,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,OAAO,EAAE,IAAI;QAAE,OAAO,EAAE,CAAC;IAC9D,IAAI,CAAC;QACH,OAAO,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,cAAc,CAAC,IAAuB;IACpD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC;QACtB,CAAC,CAAC,oCAAoC,IAAI,6DAA6D,IAAI,EAAE;QAC7G,CAAC,CAAC,qCAAqC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,+DAA+D,IAAI,EAAE,CAAC;AAChI,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Node from Scoop by the name that outlasts its version (engram#664):
3
+ * `<root>\apps\<app>\<version>\node.exe` through
4
+ * `<root>\apps\<app>\current\node.exe`, the junction `scoop update` moves to
5
+ * each new version of the app. Any other path is returned as it is.
6
+ *
7
+ * The Windows sign-in entry names Node by its real path, through any links
8
+ * (nodePathForEntry), and on Windows that resolves Scoop's junction too. So
9
+ * the entry named a version that `scoop cleanup` removes after the next
10
+ * update: from the next sign-in, Windows ran a program that was gone.
11
+ *
12
+ * Only a file at the top of a version, where Scoop's Node apps (nodejs,
13
+ * nodejs-lts) keep node.exe: a file deeper in can be one the app left there
14
+ * that the next version doesn't have. And only when `current` leads to this
15
+ * very file: a version that is installed but isn't the app's current one,
16
+ * or an app with no `current` (Scoop's no_junction setting), keeps its own
17
+ * path. `current` is Scoop's, as the version is, so it hands the program to
18
+ * no one who couldn't change it already.
19
+ *
20
+ * The CLI needs nothing of the kind: Scoop's Node apps keep npm's global
21
+ * packages in their persist folder, which every version shares. A new
22
+ * version can be a new major of Node, for which the worker rebuilds
23
+ * better-sqlite3 before loading it (preflight.ts); the sign-in entry and the
24
+ * supervisor use only Node's built-ins.
25
+ *
26
+ * nvm-windows's link isn't followed: `nvm use` moves it to whichever version
27
+ * the user works with, and each version has its own global packages, this
28
+ * CLI among them. Its entry keeps the version it was written with.
29
+ *
30
+ * Either separator: Windows takes both, and the tests run this on every OS.
31
+ */
32
+ export declare function throughScoopCurrent(path: string): string;
33
+ /**
34
+ * `entry` names the program `ours` names by a Scoop app's `current`
35
+ * (throughScoopCurrent), by a version of that same app instead: the version
36
+ * `current` leads to now, or one it led to before the last update. The next
37
+ * update and `scoop cleanup` remove either, and `current` outlasts them. A
38
+ * sign-in entry from before engram#664 names one, or one a CLI wrote that
39
+ * ran on a version that wasn't current; this CLI's entry, which names
40
+ * `ours`, replaces it.
41
+ *
42
+ * Never of `ours` itself, so a CLI never rewrites the entry it just wrote.
43
+ * And never when `ours` isn't by a `current`: a CLI run on a version that
44
+ * isn't current, or on a Node that isn't Scoop's, would trade an entry that
45
+ * works for one no more lasting, so the entry stays until it breaks and is
46
+ * repaired then.
47
+ *
48
+ * The paths alone, looked up nowhere. Windows paths, the same whatever
49
+ * their case or separators.
50
+ */
51
+ export declare function scoopVersionOf(entry: string, ours: string): boolean;
52
+ //# sourceMappingURL=scoop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoop.d.ts","sourceRoot":"","sources":["../../src/daemon/scoop.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASxD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAWnE"}