@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.
Files changed (208) hide show
  1. package/LICENSE +112 -0
  2. package/README.md +1 -1
  3. package/dist/commands/auth.d.ts.map +1 -1
  4. package/dist/commands/auth.js +38 -11
  5. package/dist/commands/auth.js.map +1 -1
  6. package/dist/commands/conversations.d.ts.map +1 -1
  7. package/dist/commands/conversations.js +8 -2
  8. package/dist/commands/conversations.js.map +1 -1
  9. package/dist/commands/exclude.d.ts.map +1 -1
  10. package/dist/commands/exclude.js +73 -21
  11. package/dist/commands/exclude.js.map +1 -1
  12. package/dist/commands/import.d.ts +30 -3
  13. package/dist/commands/import.d.ts.map +1 -1
  14. package/dist/commands/import.js +374 -45
  15. package/dist/commands/import.js.map +1 -1
  16. package/dist/commands/login.d.ts.map +1 -1
  17. package/dist/commands/login.js +144 -29
  18. package/dist/commands/login.js.map +1 -1
  19. package/dist/commands/search.js +2 -2
  20. package/dist/commands/search.js.map +1 -1
  21. package/dist/commands/status.d.ts +16 -0
  22. package/dist/commands/status.d.ts.map +1 -0
  23. package/dist/commands/status.js +51 -0
  24. package/dist/commands/status.js.map +1 -0
  25. package/dist/commands/store.d.ts.map +1 -1
  26. package/dist/commands/store.js +19 -3
  27. package/dist/commands/store.js.map +1 -1
  28. package/dist/commands/upgrade.d.ts +24 -0
  29. package/dist/commands/upgrade.d.ts.map +1 -1
  30. package/dist/commands/upgrade.js +64 -15
  31. package/dist/commands/upgrade.js.map +1 -1
  32. package/dist/commands/usage.d.ts +44 -0
  33. package/dist/commands/usage.d.ts.map +1 -1
  34. package/dist/commands/usage.js +79 -19
  35. package/dist/commands/usage.js.map +1 -1
  36. package/dist/commands/vault.d.ts +11 -2
  37. package/dist/commands/vault.d.ts.map +1 -1
  38. package/dist/commands/vault.js +372 -53
  39. package/dist/commands/vault.js.map +1 -1
  40. package/dist/config-file.d.ts +74 -0
  41. package/dist/config-file.d.ts.map +1 -0
  42. package/dist/config-file.js +152 -0
  43. package/dist/config-file.js.map +1 -0
  44. package/dist/config-guard.d.ts +96 -0
  45. package/dist/config-guard.d.ts.map +1 -0
  46. package/dist/config-guard.js +184 -0
  47. package/dist/config-guard.js.map +1 -0
  48. package/dist/config.d.ts +48 -4
  49. package/dist/config.d.ts.map +1 -1
  50. package/dist/config.js +101 -12
  51. package/dist/config.js.map +1 -1
  52. package/dist/daemon/as-root.d.ts +46 -0
  53. package/dist/daemon/as-root.d.ts.map +1 -0
  54. package/dist/daemon/as-root.js +64 -0
  55. package/dist/daemon/as-root.js.map +1 -0
  56. package/dist/daemon/backoff.d.ts +26 -0
  57. package/dist/daemon/backoff.d.ts.map +1 -0
  58. package/dist/daemon/backoff.js +37 -0
  59. package/dist/daemon/backoff.js.map +1 -0
  60. package/dist/daemon/codex-parser.d.ts +38 -4
  61. package/dist/daemon/codex-parser.d.ts.map +1 -1
  62. package/dist/daemon/codex-parser.js +111 -23
  63. package/dist/daemon/codex-parser.js.map +1 -1
  64. package/dist/daemon/command-path.d.ts +13 -0
  65. package/dist/daemon/command-path.d.ts.map +1 -0
  66. package/dist/daemon/command-path.js +35 -0
  67. package/dist/daemon/command-path.js.map +1 -0
  68. package/dist/daemon/commands.d.ts +153 -3
  69. package/dist/daemon/commands.d.ts.map +1 -1
  70. package/dist/daemon/commands.js +2775 -235
  71. package/dist/daemon/commands.js.map +1 -1
  72. package/dist/daemon/db.d.ts +255 -27
  73. package/dist/daemon/db.d.ts.map +1 -1
  74. package/dist/daemon/db.js +749 -53
  75. package/dist/daemon/db.js.map +1 -1
  76. package/dist/daemon/exclusions.d.ts +23 -3
  77. package/dist/daemon/exclusions.d.ts.map +1 -1
  78. package/dist/daemon/exclusions.js +91 -21
  79. package/dist/daemon/exclusions.js.map +1 -1
  80. package/dist/daemon/homebrew.d.ts +26 -0
  81. package/dist/daemon/homebrew.d.ts.map +1 -0
  82. package/dist/daemon/homebrew.js +43 -0
  83. package/dist/daemon/homebrew.js.map +1 -0
  84. package/dist/daemon/instance.d.ts +427 -0
  85. package/dist/daemon/instance.d.ts.map +1 -0
  86. package/dist/daemon/instance.js +1201 -0
  87. package/dist/daemon/instance.js.map +1 -0
  88. package/dist/daemon/key-source.d.ts +41 -0
  89. package/dist/daemon/key-source.d.ts.map +1 -0
  90. package/dist/daemon/key-source.js +89 -0
  91. package/dist/daemon/key-source.js.map +1 -0
  92. package/dist/daemon/launch.d.ts +56 -0
  93. package/dist/daemon/launch.d.ts.map +1 -0
  94. package/dist/daemon/launch.js +153 -0
  95. package/dist/daemon/launch.js.map +1 -0
  96. package/dist/daemon/launchd.d.ts +215 -0
  97. package/dist/daemon/launchd.d.ts.map +1 -0
  98. package/dist/daemon/launchd.js +527 -0
  99. package/dist/daemon/launchd.js.map +1 -0
  100. package/dist/daemon/login-start.d.ts +2 -0
  101. package/dist/daemon/login-start.d.ts.map +1 -0
  102. package/dist/daemon/login-start.js +25 -0
  103. package/dist/daemon/login-start.js.map +1 -0
  104. package/dist/daemon/ownership.d.ts +123 -0
  105. package/dist/daemon/ownership.d.ts.map +1 -0
  106. package/dist/daemon/ownership.js +245 -0
  107. package/dist/daemon/ownership.js.map +1 -0
  108. package/dist/daemon/package-runner.d.ts +28 -0
  109. package/dist/daemon/package-runner.d.ts.map +1 -0
  110. package/dist/daemon/package-runner.js +113 -0
  111. package/dist/daemon/package-runner.js.map +1 -0
  112. package/dist/daemon/parser.d.ts +50 -5
  113. package/dist/daemon/parser.d.ts.map +1 -1
  114. package/dist/daemon/parser.js +224 -47
  115. package/dist/daemon/parser.js.map +1 -1
  116. package/dist/daemon/powershell.d.ts +25 -0
  117. package/dist/daemon/powershell.d.ts.map +1 -0
  118. package/dist/daemon/powershell.js +30 -0
  119. package/dist/daemon/powershell.js.map +1 -0
  120. package/dist/daemon/preflight.d.ts +0 -17
  121. package/dist/daemon/preflight.d.ts.map +1 -1
  122. package/dist/daemon/preflight.js +32 -6
  123. package/dist/daemon/preflight.js.map +1 -1
  124. package/dist/daemon/prune.d.ts +101 -0
  125. package/dist/daemon/prune.d.ts.map +1 -0
  126. package/dist/daemon/prune.js +287 -0
  127. package/dist/daemon/prune.js.map +1 -0
  128. package/dist/daemon/queue-error.d.ts +47 -0
  129. package/dist/daemon/queue-error.d.ts.map +1 -0
  130. package/dist/daemon/queue-error.js +59 -0
  131. package/dist/daemon/queue-error.js.map +1 -0
  132. package/dist/daemon/root-daemon.d.ts +60 -0
  133. package/dist/daemon/root-daemon.d.ts.map +1 -0
  134. package/dist/daemon/root-daemon.js +86 -0
  135. package/dist/daemon/root-daemon.js.map +1 -0
  136. package/dist/daemon/scoop.d.ts +52 -0
  137. package/dist/daemon/scoop.d.ts.map +1 -0
  138. package/dist/daemon/scoop.js +84 -0
  139. package/dist/daemon/scoop.js.map +1 -0
  140. package/dist/daemon/scrubber.d.ts +456 -0
  141. package/dist/daemon/scrubber.d.ts.map +1 -0
  142. package/dist/daemon/scrubber.js +994 -0
  143. package/dist/daemon/scrubber.js.map +1 -0
  144. package/dist/daemon/status.d.ts +306 -11
  145. package/dist/daemon/status.d.ts.map +1 -1
  146. package/dist/daemon/status.js +568 -43
  147. package/dist/daemon/status.js.map +1 -1
  148. package/dist/daemon/supervise.d.ts +78 -0
  149. package/dist/daemon/supervise.d.ts.map +1 -0
  150. package/dist/daemon/supervise.js +121 -0
  151. package/dist/daemon/supervise.js.map +1 -0
  152. package/dist/daemon/supervisor.d.ts +18 -0
  153. package/dist/daemon/supervisor.d.ts.map +1 -0
  154. package/dist/daemon/supervisor.js +56 -0
  155. package/dist/daemon/supervisor.js.map +1 -0
  156. package/dist/daemon/syncer.d.ts +382 -21
  157. package/dist/daemon/syncer.d.ts.map +1 -1
  158. package/dist/daemon/syncer.js +1448 -178
  159. package/dist/daemon/syncer.js.map +1 -1
  160. package/dist/daemon/systemd.d.ts +109 -0
  161. package/dist/daemon/systemd.d.ts.map +1 -0
  162. package/dist/daemon/systemd.js +363 -0
  163. package/dist/daemon/systemd.js.map +1 -0
  164. package/dist/daemon/types.d.ts +58 -6
  165. package/dist/daemon/types.d.ts.map +1 -1
  166. package/dist/daemon/vault-changed.d.ts +29 -0
  167. package/dist/daemon/vault-changed.d.ts.map +1 -0
  168. package/dist/daemon/vault-changed.js +47 -0
  169. package/dist/daemon/vault-changed.js.map +1 -0
  170. package/dist/daemon/vault-key-missing.d.ts +70 -0
  171. package/dist/daemon/vault-key-missing.d.ts.map +1 -0
  172. package/dist/daemon/vault-key-missing.js +125 -0
  173. package/dist/daemon/vault-key-missing.js.map +1 -0
  174. package/dist/daemon/watcher.d.ts +87 -4
  175. package/dist/daemon/watcher.d.ts.map +1 -1
  176. package/dist/daemon/watcher.js +286 -36
  177. package/dist/daemon/watcher.js.map +1 -1
  178. package/dist/daemon/worker-main.js +363 -51
  179. package/dist/daemon/worker-main.js.map +1 -1
  180. package/dist/daemon/worker.js +19 -1
  181. package/dist/daemon/worker.js.map +1 -1
  182. package/dist/import-resume.d.ts +163 -0
  183. package/dist/import-resume.d.ts.map +1 -0
  184. package/dist/import-resume.js +267 -0
  185. package/dist/import-resume.js.map +1 -0
  186. package/dist/index.js +242 -33
  187. package/dist/index.js.map +1 -1
  188. package/dist/message-bounds.d.ts +52 -0
  189. package/dist/message-bounds.d.ts.map +1 -0
  190. package/dist/message-bounds.js +157 -0
  191. package/dist/message-bounds.js.map +1 -0
  192. package/dist/output.d.ts +14 -0
  193. package/dist/output.d.ts.map +1 -1
  194. package/dist/output.js +33 -5
  195. package/dist/output.js.map +1 -1
  196. package/dist/private-files.d.ts +126 -0
  197. package/dist/private-files.d.ts.map +1 -0
  198. package/dist/private-files.js +372 -0
  199. package/dist/private-files.js.map +1 -0
  200. package/dist/server-url.d.ts +31 -0
  201. package/dist/server-url.d.ts.map +1 -0
  202. package/dist/server-url.js +47 -0
  203. package/dist/server-url.js.map +1 -0
  204. package/dist/vault-key.d.ts +122 -0
  205. package/dist/vault-key.d.ts.map +1 -0
  206. package/dist/vault-key.js +273 -0
  207. package/dist/vault-key.js.map +1 -0
  208. package/package.json +11 -12
@@ -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":"","sources":["../../src/daemon/root-daemon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE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C;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"}
@@ -0,0 +1,84 @@
1
+ import { realpathSync } from "node:fs";
2
+ /**
3
+ * Node from Scoop by the name that outlasts its version (engram#664):
4
+ * `<root>\apps\<app>\<version>\node.exe` through
5
+ * `<root>\apps\<app>\current\node.exe`, the junction `scoop update` moves to
6
+ * each new version of the app. Any other path is returned as it is.
7
+ *
8
+ * The Windows sign-in entry names Node by its real path, through any links
9
+ * (nodePathForEntry), and on Windows that resolves Scoop's junction too. So
10
+ * the entry named a version that `scoop cleanup` removes after the next
11
+ * update: from the next sign-in, Windows ran a program that was gone.
12
+ *
13
+ * Only a file at the top of a version, where Scoop's Node apps (nodejs,
14
+ * nodejs-lts) keep node.exe: a file deeper in can be one the app left there
15
+ * that the next version doesn't have. And only when `current` leads to this
16
+ * very file: a version that is installed but isn't the app's current one,
17
+ * or an app with no `current` (Scoop's no_junction setting), keeps its own
18
+ * path. `current` is Scoop's, as the version is, so it hands the program to
19
+ * no one who couldn't change it already.
20
+ *
21
+ * The CLI needs nothing of the kind: Scoop's Node apps keep npm's global
22
+ * packages in their persist folder, which every version shares. A new
23
+ * version can be a new major of Node, for which the worker rebuilds
24
+ * better-sqlite3 before loading it (preflight.ts); the sign-in entry and the
25
+ * supervisor use only Node's built-ins.
26
+ *
27
+ * nvm-windows's link isn't followed: `nvm use` moves it to whichever version
28
+ * the user works with, and each version has its own global packages, this
29
+ * CLI among them. Its entry keeps the version it was written with.
30
+ *
31
+ * Either separator: Windows takes both, and the tests run this on every OS.
32
+ */
33
+ export function throughScoopCurrent(path) {
34
+ const v = inVersion(path);
35
+ if (v === null || isCurrent(v.version))
36
+ return path;
37
+ const current = `${v.app}${v.sep}current${v.sep}${v.file}`;
38
+ try {
39
+ return realpathSync.native(current) === path ? current : path;
40
+ }
41
+ catch {
42
+ return path; // no current, or nothing there
43
+ }
44
+ }
45
+ /**
46
+ * `entry` names the program `ours` names by a Scoop app's `current`
47
+ * (throughScoopCurrent), by a version of that same app instead: the version
48
+ * `current` leads to now, or one it led to before the last update. The next
49
+ * update and `scoop cleanup` remove either, and `current` outlasts them. A
50
+ * sign-in entry from before engram#664 names one, or one a CLI wrote that
51
+ * ran on a version that wasn't current; this CLI's entry, which names
52
+ * `ours`, replaces it.
53
+ *
54
+ * Never of `ours` itself, so a CLI never rewrites the entry it just wrote.
55
+ * And never when `ours` isn't by a `current`: a CLI run on a version that
56
+ * isn't current, or on a Node that isn't Scoop's, would trade an entry that
57
+ * works for one no more lasting, so the entry stays until it breaks and is
58
+ * repaired then.
59
+ *
60
+ * The paths alone, looked up nowhere. Windows paths, the same whatever
61
+ * their case or separators.
62
+ */
63
+ export function scoopVersionOf(entry, ours) {
64
+ const o = inVersion(ours);
65
+ const e = inVersion(entry);
66
+ return (o !== null &&
67
+ e !== null &&
68
+ isCurrent(o.version) &&
69
+ !isCurrent(e.version) &&
70
+ samePath(o.app, e.app) &&
71
+ samePath(o.file, e.file));
72
+ }
73
+ /** A file at the top of a version of a Scoop app: <root>\apps\<app>\<version>\<file>. */
74
+ function inVersion(path) {
75
+ const m = /^(.*[\\/]apps[\\/][^\\/]+)([\\/])([^\\/]+)[\\/]([^\\/]+)$/i.exec(path);
76
+ return m === null ? null : { app: m[1], sep: m[2], version: m[3], file: m[4] };
77
+ }
78
+ function isCurrent(version) {
79
+ return version.toLowerCase() === "current";
80
+ }
81
+ function samePath(a, b) {
82
+ return a.replace(/\//g, "\\").toLowerCase() === b.replace(/\//g, "\\").toLowerCase();
83
+ }
84
+ //# sourceMappingURL=scoop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoop.js","sourceRoot":"","sources":["../../src/daemon/sc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