@getengram/cli 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +38 -11
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/conversations.d.ts.map +1 -1
- package/dist/commands/conversations.js +8 -2
- package/dist/commands/conversations.js.map +1 -1
- package/dist/commands/exclude.d.ts.map +1 -1
- package/dist/commands/exclude.js +73 -21
- package/dist/commands/exclude.js.map +1 -1
- package/dist/commands/import.d.ts +30 -3
- package/dist/commands/import.d.ts.map +1 -1
- package/dist/commands/import.js +374 -45
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +144 -29
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/search.js +2 -2
- package/dist/commands/search.js.map +1 -1
- package/dist/commands/status.d.ts +16 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +51 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/store.d.ts.map +1 -1
- package/dist/commands/store.js +19 -3
- package/dist/commands/store.js.map +1 -1
- package/dist/commands/upgrade.d.ts +24 -0
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +64 -15
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/usage.d.ts +44 -0
- package/dist/commands/usage.d.ts.map +1 -1
- package/dist/commands/usage.js +79 -19
- package/dist/commands/usage.js.map +1 -1
- package/dist/commands/vault.d.ts +11 -2
- package/dist/commands/vault.d.ts.map +1 -1
- package/dist/commands/vault.js +372 -53
- package/dist/commands/vault.js.map +1 -1
- package/dist/config-file.d.ts +74 -0
- package/dist/config-file.d.ts.map +1 -0
- package/dist/config-file.js +152 -0
- package/dist/config-file.js.map +1 -0
- package/dist/config-guard.d.ts +96 -0
- package/dist/config-guard.d.ts.map +1 -0
- package/dist/config-guard.js +184 -0
- package/dist/config-guard.js.map +1 -0
- package/dist/config.d.ts +48 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +101 -12
- package/dist/config.js.map +1 -1
- package/dist/daemon/as-root.d.ts +46 -0
- package/dist/daemon/as-root.d.ts.map +1 -0
- package/dist/daemon/as-root.js +64 -0
- package/dist/daemon/as-root.js.map +1 -0
- package/dist/daemon/backoff.d.ts +26 -0
- package/dist/daemon/backoff.d.ts.map +1 -0
- package/dist/daemon/backoff.js +37 -0
- package/dist/daemon/backoff.js.map +1 -0
- package/dist/daemon/codex-parser.d.ts +38 -4
- package/dist/daemon/codex-parser.d.ts.map +1 -1
- package/dist/daemon/codex-parser.js +111 -23
- package/dist/daemon/codex-parser.js.map +1 -1
- package/dist/daemon/command-path.d.ts +13 -0
- package/dist/daemon/command-path.d.ts.map +1 -0
- package/dist/daemon/command-path.js +35 -0
- package/dist/daemon/command-path.js.map +1 -0
- package/dist/daemon/commands.d.ts +146 -5
- package/dist/daemon/commands.d.ts.map +1 -1
- package/dist/daemon/commands.js +2766 -316
- package/dist/daemon/commands.js.map +1 -1
- package/dist/daemon/db.d.ts +255 -27
- package/dist/daemon/db.d.ts.map +1 -1
- package/dist/daemon/db.js +749 -53
- package/dist/daemon/db.js.map +1 -1
- package/dist/daemon/exclusions.d.ts +23 -3
- package/dist/daemon/exclusions.d.ts.map +1 -1
- package/dist/daemon/exclusions.js +91 -21
- package/dist/daemon/exclusions.js.map +1 -1
- package/dist/daemon/homebrew.d.ts +26 -0
- package/dist/daemon/homebrew.d.ts.map +1 -0
- package/dist/daemon/homebrew.js +43 -0
- package/dist/daemon/homebrew.js.map +1 -0
- package/dist/daemon/instance.d.ts +427 -0
- package/dist/daemon/instance.d.ts.map +1 -0
- package/dist/daemon/instance.js +1201 -0
- package/dist/daemon/instance.js.map +1 -0
- package/dist/daemon/key-source.d.ts +41 -0
- package/dist/daemon/key-source.d.ts.map +1 -0
- package/dist/daemon/key-source.js +89 -0
- package/dist/daemon/key-source.js.map +1 -0
- package/dist/daemon/launch.d.ts +56 -0
- package/dist/daemon/launch.d.ts.map +1 -0
- package/dist/daemon/launch.js +153 -0
- package/dist/daemon/launch.js.map +1 -0
- package/dist/daemon/launchd.d.ts +215 -0
- package/dist/daemon/launchd.d.ts.map +1 -0
- package/dist/daemon/launchd.js +527 -0
- package/dist/daemon/launchd.js.map +1 -0
- package/dist/daemon/login-start.d.ts +2 -0
- package/dist/daemon/login-start.d.ts.map +1 -0
- package/dist/daemon/login-start.js +25 -0
- package/dist/daemon/login-start.js.map +1 -0
- package/dist/daemon/ownership.d.ts +123 -0
- package/dist/daemon/ownership.d.ts.map +1 -0
- package/dist/daemon/ownership.js +245 -0
- package/dist/daemon/ownership.js.map +1 -0
- package/dist/daemon/package-runner.d.ts +28 -0
- package/dist/daemon/package-runner.d.ts.map +1 -0
- package/dist/daemon/package-runner.js +113 -0
- package/dist/daemon/package-runner.js.map +1 -0
- package/dist/daemon/parser.d.ts +45 -7
- package/dist/daemon/parser.d.ts.map +1 -1
- package/dist/daemon/parser.js +153 -53
- package/dist/daemon/parser.js.map +1 -1
- package/dist/daemon/powershell.d.ts +25 -0
- package/dist/daemon/powershell.d.ts.map +1 -0
- package/dist/daemon/powershell.js +30 -0
- package/dist/daemon/powershell.js.map +1 -0
- package/dist/daemon/preflight.d.ts.map +1 -1
- package/dist/daemon/preflight.js +5 -1
- package/dist/daemon/preflight.js.map +1 -1
- package/dist/daemon/prune.d.ts +101 -0
- package/dist/daemon/prune.d.ts.map +1 -0
- package/dist/daemon/prune.js +287 -0
- package/dist/daemon/prune.js.map +1 -0
- package/dist/daemon/queue-error.d.ts +47 -0
- package/dist/daemon/queue-error.d.ts.map +1 -0
- package/dist/daemon/queue-error.js +59 -0
- package/dist/daemon/queue-error.js.map +1 -0
- package/dist/daemon/root-daemon.d.ts +60 -0
- package/dist/daemon/root-daemon.d.ts.map +1 -0
- package/dist/daemon/root-daemon.js +86 -0
- package/dist/daemon/root-daemon.js.map +1 -0
- package/dist/daemon/scoop.d.ts +52 -0
- package/dist/daemon/scoop.d.ts.map +1 -0
- package/dist/daemon/scoop.js +84 -0
- package/dist/daemon/scoop.js.map +1 -0
- package/dist/daemon/scrubber.d.ts +396 -14
- package/dist/daemon/scrubber.d.ts.map +1 -1
- package/dist/daemon/scrubber.js +915 -52
- package/dist/daemon/scrubber.js.map +1 -1
- package/dist/daemon/status.d.ts +306 -11
- package/dist/daemon/status.d.ts.map +1 -1
- package/dist/daemon/status.js +568 -43
- package/dist/daemon/status.js.map +1 -1
- package/dist/daemon/supervise.d.ts +78 -0
- package/dist/daemon/supervise.d.ts.map +1 -0
- package/dist/daemon/supervise.js +121 -0
- package/dist/daemon/supervise.js.map +1 -0
- package/dist/daemon/supervisor.d.ts +18 -0
- package/dist/daemon/supervisor.d.ts.map +1 -0
- package/dist/daemon/supervisor.js +56 -0
- package/dist/daemon/supervisor.js.map +1 -0
- package/dist/daemon/syncer.d.ts +380 -21
- package/dist/daemon/syncer.d.ts.map +1 -1
- package/dist/daemon/syncer.js +1432 -182
- package/dist/daemon/syncer.js.map +1 -1
- package/dist/daemon/systemd.d.ts +109 -0
- package/dist/daemon/systemd.d.ts.map +1 -0
- package/dist/daemon/systemd.js +363 -0
- package/dist/daemon/systemd.js.map +1 -0
- package/dist/daemon/types.d.ts +58 -6
- package/dist/daemon/types.d.ts.map +1 -1
- package/dist/daemon/vault-changed.d.ts +29 -0
- package/dist/daemon/vault-changed.d.ts.map +1 -0
- package/dist/daemon/vault-changed.js +47 -0
- package/dist/daemon/vault-changed.js.map +1 -0
- package/dist/daemon/vault-key-missing.d.ts +70 -0
- package/dist/daemon/vault-key-missing.d.ts.map +1 -0
- package/dist/daemon/vault-key-missing.js +125 -0
- package/dist/daemon/vault-key-missing.js.map +1 -0
- package/dist/daemon/watcher.d.ts +87 -4
- package/dist/daemon/watcher.d.ts.map +1 -1
- package/dist/daemon/watcher.js +286 -36
- package/dist/daemon/watcher.js.map +1 -1
- package/dist/daemon/worker-main.js +352 -64
- package/dist/daemon/worker-main.js.map +1 -1
- package/dist/daemon/worker.js +19 -1
- package/dist/daemon/worker.js.map +1 -1
- package/dist/import-resume.d.ts +163 -0
- package/dist/import-resume.d.ts.map +1 -0
- package/dist/import-resume.js +267 -0
- package/dist/import-resume.js.map +1 -0
- package/dist/index.js +242 -33
- package/dist/index.js.map +1 -1
- package/dist/message-bounds.d.ts +52 -0
- package/dist/message-bounds.d.ts.map +1 -0
- package/dist/message-bounds.js +157 -0
- package/dist/message-bounds.js.map +1 -0
- package/dist/output.d.ts +14 -0
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +33 -5
- package/dist/output.js.map +1 -1
- package/dist/private-files.d.ts +126 -0
- package/dist/private-files.d.ts.map +1 -0
- package/dist/private-files.js +372 -0
- package/dist/private-files.js.map +1 -0
- package/dist/server-url.d.ts +31 -0
- package/dist/server-url.d.ts.map +1 -0
- package/dist/server-url.js +47 -0
- package/dist/server-url.js.map +1 -0
- package/dist/vault-key.d.ts +122 -0
- package/dist/vault-key.d.ts.map +1 -0
- package/dist/vault-key.js +273 -0
- package/dist/vault-key.js.map +1 -0
- package/package.json +2 -2
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAc,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAE,SA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;QACrD,CAAC;QACD,IAAI,EAAE,CAAC,GAAG,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QAChC,IAAI,CAAC,EAAE,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC;YAAE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACvC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CACX,8BAA8B;YAC5B,0BAA0B;YAC1B,KAAK,aAAa,CAAC,YAAY,CAAC,IAAI;YACpC,UAAU;YACV,8CAA8C,CACjD,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* engram#653 — capture is the user's own: the daemon runs as the user, and
|
|
3
|
+
* start at login is set up in the user's session. Run as root for the user
|
|
4
|
+
* (`sudo engram …`), it would be set up for root instead:
|
|
5
|
+
*
|
|
6
|
+
* - macOS: root has no login session (`launchctl bootstrap gui/0` fails),
|
|
7
|
+
* and `launchctl load` run as root can load the job into the system
|
|
8
|
+
* domain, where the daemon runs as root.
|
|
9
|
+
* - Linux: `systemctl --user` reaches root's user manager, not the user's.
|
|
10
|
+
* - Everywhere: a daemon running as root in the user's ~/.engram makes files
|
|
11
|
+
* there, its database among them, that the user's own daemon can't write.
|
|
12
|
+
*/
|
|
13
|
+
export interface RootCheck {
|
|
14
|
+
platform?: NodeJS.Platform;
|
|
15
|
+
/** The effective uid: undefined on Windows. */
|
|
16
|
+
euid?: number;
|
|
17
|
+
env?: NodeJS.ProcessEnv;
|
|
18
|
+
home?: string;
|
|
19
|
+
/** Who owns `path`: null when it can't be looked at. */
|
|
20
|
+
ownerOf?: (path: string) => number | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether this is root running Engram for someone else: on macOS, any root;
|
|
24
|
+
* elsewhere, root through sudo (SUDO_UID, which run0 sets too), pkexec
|
|
25
|
+
* (PKEXEC_UID) or doas (DOAS_USER), or root with a home directory another
|
|
26
|
+
* user owns. Root that is the user, on a server people sign in to as root
|
|
27
|
+
* or in a container, still gets capture. Never on Windows: there is no
|
|
28
|
+
* root there, and the usual elevated prompt runs as the user's own account.
|
|
29
|
+
*/
|
|
30
|
+
export declare function rootForAnotherUser({ platform, euid, env, home, ownerOf, }?: RootCheck): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* What a command run as root for someone else says (engram#682): only
|
|
33
|
+
* `engram help` and `engram version` run. On macOS, sudo keeps HOME, so
|
|
34
|
+
* a command run with sudo wrote the user's ~/.engram as root, leaving
|
|
35
|
+
* files there they can't read or change: config.json from login, signup,
|
|
36
|
+
* auth, exclude, stop and uninstall, the vault key from `vault keygen
|
|
37
|
+
* --save` and `vault save-key`, and the notice from `vault set` and
|
|
38
|
+
* `vault delete` that the vault changed.
|
|
39
|
+
* On Linux it set Engram up for root instead. `cmd`: the command's words,
|
|
40
|
+
* as the CLI parsed them, without its arguments.
|
|
41
|
+
*/
|
|
42
|
+
export declare function asRootRefusal(cmd: string): {
|
|
43
|
+
problem: string;
|
|
44
|
+
fix: string;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=as-root.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"as-root.d.ts","sourceRoot":"","sources":["../../src/daemon/as-root.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CAC3C;AAeD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,QAA2B,EAC3B,IAA0B,EAC1B,GAAiB,EACjB,IAAgB,EAChB,OAAe,GAChB,GAAE,SAAc,GAAG,OAAO,CAO1B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAgB3E"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { engramCommand } from "./package-runner.js";
|
|
4
|
+
function owner(path) {
|
|
5
|
+
try {
|
|
6
|
+
return statSync(path).uid;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** A uid, from sudo or pkexec, of someone other than root. */
|
|
13
|
+
function otherUid(value) {
|
|
14
|
+
return value !== undefined && /^\d+$/.test(value) && Number(value) !== 0;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Whether this is root running Engram for someone else: on macOS, any root;
|
|
18
|
+
* elsewhere, root through sudo (SUDO_UID, which run0 sets too), pkexec
|
|
19
|
+
* (PKEXEC_UID) or doas (DOAS_USER), or root with a home directory another
|
|
20
|
+
* user owns. Root that is the user, on a server people sign in to as root
|
|
21
|
+
* or in a container, still gets capture. Never on Windows: there is no
|
|
22
|
+
* root there, and the usual elevated prompt runs as the user's own account.
|
|
23
|
+
*/
|
|
24
|
+
export function rootForAnotherUser({ platform = process.platform, euid = process.geteuid?.(), env = process.env, home = homedir(), ownerOf = owner, } = {}) {
|
|
25
|
+
if (platform === "win32" || euid !== 0)
|
|
26
|
+
return false;
|
|
27
|
+
if (platform === "darwin")
|
|
28
|
+
return true;
|
|
29
|
+
if (otherUid(env.SUDO_UID) || otherUid(env.PKEXEC_UID))
|
|
30
|
+
return true;
|
|
31
|
+
if (env.DOAS_USER && env.DOAS_USER !== "root")
|
|
32
|
+
return true;
|
|
33
|
+
const uid = ownerOf(home);
|
|
34
|
+
return uid !== null && uid !== 0;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What a command run as root for someone else says (engram#682): only
|
|
38
|
+
* `engram help` and `engram version` run. On macOS, sudo keeps HOME, so
|
|
39
|
+
* a command run with sudo wrote the user's ~/.engram as root, leaving
|
|
40
|
+
* files there they can't read or change: config.json from login, signup,
|
|
41
|
+
* auth, exclude, stop and uninstall, the vault key from `vault keygen
|
|
42
|
+
* --save` and `vault save-key`, and the notice from `vault set` and
|
|
43
|
+
* `vault delete` that the vault changed.
|
|
44
|
+
* On Linux it set Engram up for root instead. `cmd`: the command's words,
|
|
45
|
+
* as the CLI parsed them, without its arguments.
|
|
46
|
+
*/
|
|
47
|
+
export function asRootRefusal(cmd) {
|
|
48
|
+
const fix = ` Run '${engramCommand(cmd)}' as yourself, without sudo.`;
|
|
49
|
+
switch (cmd.replace(/^daemon /, "")) {
|
|
50
|
+
case "install":
|
|
51
|
+
return { problem: "Start at login is per user, and this is running as root.", fix };
|
|
52
|
+
case "start":
|
|
53
|
+
return { problem: "Engram's daemon runs as you, and this is running as root.", fix };
|
|
54
|
+
case "stop":
|
|
55
|
+
// One started with sudo is root's: it says what stops that (engram#680).
|
|
56
|
+
return {
|
|
57
|
+
problem: "Engram runs as you, and this is running as root.",
|
|
58
|
+
fix: `${fix} For a daemon started with sudo, it says what stops it.`,
|
|
59
|
+
};
|
|
60
|
+
default:
|
|
61
|
+
return { problem: "Engram runs as you, and this is running as root.", fix };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=as-root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"as-root.js","sourceRoot":"","sources":["../../src/daemon/as-root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAwBpD,SAAS,KAAK,CAAC,IAAY;IACzB,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,8DAA8D;AAC9D,SAAS,QAAQ,CAAC,KAAyB;IACzC,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,EACjC,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAC3B,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,EAAE,EAC1B,GAAG,GAAG,OAAO,CAAC,GAAG,EACjB,IAAI,GAAG,OAAO,EAAE,EAChB,OAAO,GAAG,KAAK,MACF,EAAE;IACf,IAAI,QAAQ,KAAK,OAAO,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACrD,IAAI,QAAQ,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACvC,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IACpE,IAAI,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,SAAS,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAC3D,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,GAAG,GAAG,UAAU,aAAa,CAAC,GAAG,CAAC,8BAA8B,CAAC;IACvE,QAAQ,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC;QACpC,KAAK,SAAS;YACZ,OAAO,EAAE,OAAO,EAAE,0DAA0D,EAAE,GAAG,EAAE,CAAC;QACtF,KAAK,OAAO;YACV,OAAO,EAAE,OAAO,EAAE,2DAA2D,EAAE,GAAG,EAAE,CAAC;QACvF,KAAK,MAAM;YACT,yEAAyE;YACzE,OAAO;gBACL,OAAO,EAAE,kDAAkD;gBAC3D,GAAG,EAAE,GAAG,GAAG,yDAAyD;aACrE,CAAC;QACJ;YACE,OAAO,EAAE,OAAO,EAAE,kDAAkD,EAAE,GAAG,EAAE,CAAC;IAChF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long the daemon waits before trying again after a request failed in
|
|
3
|
+
* a way that passes on its own (engram#596): an error on the server's
|
|
4
|
+
* side, a timeout, the server out of reach, a rate limit, a maintenance
|
|
5
|
+
* pause. Each of these was retried at the next flush, every 2 s, for as
|
|
6
|
+
* long as it lasted, by every daemon running.
|
|
7
|
+
*
|
|
8
|
+
* The wait doubles with each failure in a row, from RETRY_BASE_MS up to
|
|
9
|
+
* RETRY_CAP_MS, and is drawn at random between half and all of that
|
|
10
|
+
* ("equal jitter"). Daemons that failed together, in an outage or a
|
|
11
|
+
* maintenance pause, come back spread out rather than all at once, and
|
|
12
|
+
* until the cap a wait is never shorter than the one before it.
|
|
13
|
+
*/
|
|
14
|
+
/** The longest first wait. */
|
|
15
|
+
export declare const RETRY_BASE_MS = 5000;
|
|
16
|
+
/** The longest wait. A few minutes: what the daemon queued meanwhile goes
|
|
17
|
+
* out soon after the server is back. */
|
|
18
|
+
export declare const RETRY_CAP_MS: number;
|
|
19
|
+
/**
|
|
20
|
+
* The wait after `failures` failures in a row (1 for the first), in ms.
|
|
21
|
+
* `random` is for tests.
|
|
22
|
+
*/
|
|
23
|
+
export declare function retryDelay(failures: number, random?: () => number): number;
|
|
24
|
+
/** A wait in words, for the log and `engram status`: "4s", "2m 30s". */
|
|
25
|
+
export declare function formatWait(ms: number): string;
|
|
26
|
+
//# sourceMappingURL=backoff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../src/daemon/backoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,8BAA8B;AAC9B,eAAO,MAAM,aAAa,OAAQ,CAAC;AACnC;yCACyC;AACzC,eAAO,MAAM,YAAY,QAAa,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,MAAoB,GAAG,MAAM,CAIvF;AAED,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAM7C"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long the daemon waits before trying again after a request failed in
|
|
3
|
+
* a way that passes on its own (engram#596): an error on the server's
|
|
4
|
+
* side, a timeout, the server out of reach, a rate limit, a maintenance
|
|
5
|
+
* pause. Each of these was retried at the next flush, every 2 s, for as
|
|
6
|
+
* long as it lasted, by every daemon running.
|
|
7
|
+
*
|
|
8
|
+
* The wait doubles with each failure in a row, from RETRY_BASE_MS up to
|
|
9
|
+
* RETRY_CAP_MS, and is drawn at random between half and all of that
|
|
10
|
+
* ("equal jitter"). Daemons that failed together, in an outage or a
|
|
11
|
+
* maintenance pause, come back spread out rather than all at once, and
|
|
12
|
+
* until the cap a wait is never shorter than the one before it.
|
|
13
|
+
*/
|
|
14
|
+
/** The longest first wait. */
|
|
15
|
+
export const RETRY_BASE_MS = 5_000;
|
|
16
|
+
/** The longest wait. A few minutes: what the daemon queued meanwhile goes
|
|
17
|
+
* out soon after the server is back. */
|
|
18
|
+
export const RETRY_CAP_MS = 5 * 60_000;
|
|
19
|
+
/**
|
|
20
|
+
* The wait after `failures` failures in a row (1 for the first), in ms.
|
|
21
|
+
* `random` is for tests.
|
|
22
|
+
*/
|
|
23
|
+
export function retryDelay(failures, random = Math.random) {
|
|
24
|
+
const doublings = Math.min(Math.max(failures - 1, 0), 30);
|
|
25
|
+
const ceiling = Math.min(RETRY_CAP_MS, RETRY_BASE_MS * 2 ** doublings);
|
|
26
|
+
return Math.round(ceiling / 2 + random() * (ceiling / 2));
|
|
27
|
+
}
|
|
28
|
+
/** A wait in words, for the log and `engram status`: "4s", "2m 30s". */
|
|
29
|
+
export function formatWait(ms) {
|
|
30
|
+
const seconds = Math.max(1, Math.ceil(ms / 1000));
|
|
31
|
+
if (seconds < 60)
|
|
32
|
+
return `${seconds}s`;
|
|
33
|
+
const minutes = Math.floor(seconds / 60);
|
|
34
|
+
const rest = seconds % 60;
|
|
35
|
+
return rest === 0 ? `${minutes}m` : `${minutes}m ${rest}s`;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=backoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backoff.js","sourceRoot":"","sources":["../../src/daemon/backoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,8BAA8B;AAC9B,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AACnC;yCACyC;AACzC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAG,MAAM,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,QAAgB,EAAE,SAAuB,IAAI,CAAC,MAAM;IAC7E,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,aAAa,GAAG,CAAC,IAAI,SAAS,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,UAAU,CAAC,EAAU;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAClD,IAAI,OAAO,GAAG,EAAE;QAAE,OAAO,GAAG,OAAO,GAAG,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,OAAO,GAAG,EAAE,CAAC;IAC1B,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,IAAI,GAAG,CAAC;AAC7D,CAAC"}
|
|
@@ -2,14 +2,48 @@ import type { LineParser, OnMessages } from "./types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Parses Codex CLI rollout JSONL into Engram messages.
|
|
4
4
|
* Emits per completed user/assistant message (one line = one message).
|
|
5
|
+
*
|
|
6
|
+
* The session and cwd come from the file's own `session_meta` and
|
|
7
|
+
* `turn_context` lines, kept per file (engram#579). They used to be
|
|
8
|
+
* parser-wide, so once a second rollout had started, lines from either file
|
|
9
|
+
* were filed under whichever session last wrote `session_meta`, with
|
|
10
|
+
* whichever cwd was seen last — misfiled, dropped with an opted-out
|
|
11
|
+
* session, or captured past a path exclusion.
|
|
12
|
+
*
|
|
13
|
+
* The id is `session_id ?? id`, not the rollout filename: a subagent's or a
|
|
14
|
+
* fork's rollout names its own id in the filename but carries its parent's
|
|
15
|
+
* `session_id`, and its messages have always gone to the parent's
|
|
16
|
+
* conversation.
|
|
17
|
+
*
|
|
18
|
+
* A subagent's rollout copies its parent's history in before its own turns.
|
|
19
|
+
* Those messages are the parent's, captured from the parent's own rollout,
|
|
20
|
+
* so appending them again would repeat them in the conversation. When the
|
|
21
|
+
* rollout numbers its records (paginated), the subagent's own session_meta
|
|
22
|
+
* says where its own records begin, and the messages before that are
|
|
23
|
+
* skipped (engram#583). A legacy rollout has no numbers and no boundary, so
|
|
24
|
+
* its copy is still captured: skipping by a guess could drop the
|
|
25
|
+
* subagent's own turns (engram#671).
|
|
5
26
|
*/
|
|
6
27
|
export declare class CodexParser implements LineParser {
|
|
28
|
+
/**
|
|
29
|
+
* `session_meta` opens the file (a subagent's has two); the latest
|
|
30
|
+
* `turn_context` sits just before the resume point.
|
|
31
|
+
*/
|
|
32
|
+
readonly resumeContext: {
|
|
33
|
+
headBytes: number;
|
|
34
|
+
tailBytes: number;
|
|
35
|
+
};
|
|
7
36
|
private onMessages;
|
|
8
|
-
private
|
|
9
|
-
private cwd;
|
|
37
|
+
private files;
|
|
10
38
|
constructor(onMessages: OnMessages);
|
|
11
|
-
processLine(line: string, filePath: string): void;
|
|
12
|
-
|
|
39
|
+
processLine(line: string, filePath: string, _offset: number): void;
|
|
40
|
+
restoreLine(line: string, filePath: string): void;
|
|
41
|
+
bufferedFrom(_filePath: string): number | null;
|
|
42
|
+
flush(_filePath?: string): void;
|
|
43
|
+
discard(_filePath: string): void;
|
|
44
|
+
private stateOf;
|
|
45
|
+
/** Applies a session_meta / turn_context line; true when it was one. */
|
|
46
|
+
private track;
|
|
13
47
|
/** rollout-2026-07-23T04-46-50-<uuid>.jsonl → <uuid> */
|
|
14
48
|
private sessionIdFromPath;
|
|
15
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-parser.d.ts","sourceRoot":"","sources":["../../src/daemon/codex-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAA8B,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"codex-parser.d.ts","sourceRoot":"","sources":["../../src/daemon/codex-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAA8B,MAAM,YAAY,CAAC;AAyCrF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,WAAY,YAAW,UAAU;IAC5C;;;OAGG;IACH,QAAQ,CAAC,aAAa;;;MAAqD;IAE3E,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,KAAK,CAAmC;gBAEpC,UAAU,EAAE,UAAU;IAIlC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAmClE,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAOjD,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAI9C,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAI/B,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAMhC,OAAO,CAAC,OAAO;IASf,wEAAwE;IACxE,OAAO,CAAC,KAAK;IAyBb,wDAAwD;IACxD,OAAO,CAAC,iBAAiB;CAI1B"}
|
|
@@ -3,63 +3,151 @@ const CONTEXT_PREFIX = /^<(environment_context|recommended_plugins|user_instruct
|
|
|
3
3
|
/**
|
|
4
4
|
* Parses Codex CLI rollout JSONL into Engram messages.
|
|
5
5
|
* Emits per completed user/assistant message (one line = one message).
|
|
6
|
+
*
|
|
7
|
+
* The session and cwd come from the file's own `session_meta` and
|
|
8
|
+
* `turn_context` lines, kept per file (engram#579). They used to be
|
|
9
|
+
* parser-wide, so once a second rollout had started, lines from either file
|
|
10
|
+
* were filed under whichever session last wrote `session_meta`, with
|
|
11
|
+
* whichever cwd was seen last — misfiled, dropped with an opted-out
|
|
12
|
+
* session, or captured past a path exclusion.
|
|
13
|
+
*
|
|
14
|
+
* The id is `session_id ?? id`, not the rollout filename: a subagent's or a
|
|
15
|
+
* fork's rollout names its own id in the filename but carries its parent's
|
|
16
|
+
* `session_id`, and its messages have always gone to the parent's
|
|
17
|
+
* conversation.
|
|
18
|
+
*
|
|
19
|
+
* A subagent's rollout copies its parent's history in before its own turns.
|
|
20
|
+
* Those messages are the parent's, captured from the parent's own rollout,
|
|
21
|
+
* so appending them again would repeat them in the conversation. When the
|
|
22
|
+
* rollout numbers its records (paginated), the subagent's own session_meta
|
|
23
|
+
* says where its own records begin, and the messages before that are
|
|
24
|
+
* skipped (engram#583). A legacy rollout has no numbers and no boundary, so
|
|
25
|
+
* its copy is still captured: skipping by a guess could drop the
|
|
26
|
+
* subagent's own turns (engram#671).
|
|
6
27
|
*/
|
|
7
28
|
export class CodexParser {
|
|
29
|
+
/**
|
|
30
|
+
* `session_meta` opens the file (a subagent's has two); the latest
|
|
31
|
+
* `turn_context` sits just before the resume point.
|
|
32
|
+
*/
|
|
33
|
+
resumeContext = { headBytes: 1024 * 1024, tailBytes: 256 * 1024 };
|
|
8
34
|
onMessages;
|
|
9
|
-
|
|
10
|
-
cwd;
|
|
35
|
+
files = new Map();
|
|
11
36
|
constructor(onMessages) {
|
|
12
37
|
this.onMessages = onMessages;
|
|
13
38
|
}
|
|
14
|
-
processLine(line, filePath) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
data = JSON.parse(line);
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
39
|
+
processLine(line, filePath, _offset) {
|
|
40
|
+
const data = parse(line);
|
|
41
|
+
if (!data)
|
|
20
42
|
return;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (data.type === "session_meta") {
|
|
24
|
-
this.sessionId = p.session_id ?? p.id ?? this.sessionId;
|
|
43
|
+
const state = this.stateOf(filePath);
|
|
44
|
+
if (this.track(data, state))
|
|
25
45
|
return;
|
|
26
|
-
}
|
|
27
|
-
if (data.type === "turn_context" && p.cwd) {
|
|
28
|
-
this.cwd = p.cwd;
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
46
|
+
const p = data.payload ?? {};
|
|
31
47
|
if (data.type !== "response_item" || p.type !== "message")
|
|
32
48
|
return;
|
|
33
49
|
const role = p.role;
|
|
34
50
|
if (role !== "user" && role !== "assistant")
|
|
35
51
|
return; // skip developer/system/tool
|
|
52
|
+
if (inherited(data, state))
|
|
53
|
+
return;
|
|
36
54
|
const text = (p.content ?? [])
|
|
37
55
|
.map((c) => c.text ?? c.input_text ?? "")
|
|
38
56
|
.join("")
|
|
39
57
|
.trim();
|
|
40
58
|
if (!text || CONTEXT_PREFIX.test(text))
|
|
41
59
|
return;
|
|
42
|
-
//
|
|
43
|
-
// (
|
|
44
|
-
|
|
60
|
+
// The rollout filename's uuid is the last resort: a resumed read gets
|
|
61
|
+
// the file's session_meta replayed first (restoreLine), so this is only
|
|
62
|
+
// reached when that line could not be read at all.
|
|
63
|
+
const sessionId = state.sessionId ?? this.sessionIdFromPath(filePath);
|
|
45
64
|
if (!sessionId)
|
|
46
65
|
return;
|
|
47
66
|
const meta = {
|
|
48
67
|
sessionId,
|
|
49
|
-
cwd:
|
|
50
|
-
projectDir:
|
|
68
|
+
cwd: state.cwd,
|
|
69
|
+
projectDir: state.cwd ?? "",
|
|
51
70
|
host: "codex",
|
|
52
71
|
};
|
|
53
72
|
const message = { role, content: text };
|
|
54
73
|
this.onMessages(sessionId, meta, [message]);
|
|
55
74
|
}
|
|
56
|
-
|
|
75
|
+
restoreLine(line, filePath) {
|
|
76
|
+
// Cheap pre-check: only these two record types carry state.
|
|
77
|
+
if (!line.includes("session_meta") && !line.includes("turn_context"))
|
|
78
|
+
return;
|
|
79
|
+
const data = parse(line);
|
|
80
|
+
if (data)
|
|
81
|
+
this.track(data, this.stateOf(filePath));
|
|
82
|
+
}
|
|
83
|
+
bufferedFrom(_filePath) {
|
|
84
|
+
return null; // No buffering — each line emits immediately.
|
|
85
|
+
}
|
|
86
|
+
flush(_filePath) {
|
|
57
87
|
// No buffering — each line emits immediately.
|
|
58
88
|
}
|
|
89
|
+
discard(_filePath) {
|
|
90
|
+
// Nothing buffered. The session id, cwd and boundary kept per file
|
|
91
|
+
// aren't buffered content: they are already true of the lines read
|
|
92
|
+
// again.
|
|
93
|
+
}
|
|
94
|
+
stateOf(filePath) {
|
|
95
|
+
let state = this.files.get(filePath);
|
|
96
|
+
if (!state) {
|
|
97
|
+
state = { sessionId: null, cwd: undefined, ownFrom: null };
|
|
98
|
+
this.files.set(filePath, state);
|
|
99
|
+
}
|
|
100
|
+
return state;
|
|
101
|
+
}
|
|
102
|
+
/** Applies a session_meta / turn_context line; true when it was one. */
|
|
103
|
+
track(data, state) {
|
|
104
|
+
const p = data.payload ?? {};
|
|
105
|
+
if (data.type === "session_meta") {
|
|
106
|
+
state.sessionId = p.session_id ?? p.id ?? state.sessionId;
|
|
107
|
+
// The session's starting directory. Messages can come before the
|
|
108
|
+
// first turn_context, and without it they had no cwd at all — so a
|
|
109
|
+
// path exclusion could not apply to them. A subagent's second
|
|
110
|
+
// session_meta is its parent's, so the first one wins.
|
|
111
|
+
if (p.cwd && state.cwd === undefined)
|
|
112
|
+
state.cwd = p.cwd;
|
|
113
|
+
// The boundary is this file's own session_meta's: its first record,
|
|
114
|
+
// numbered 0. A subagent's parent's session_meta comes next. When the
|
|
115
|
+
// parent is a subagent too, that one has a boundary of its own, which
|
|
116
|
+
// isn't this file's. Going by the number rather than by which
|
|
117
|
+
// session_meta came first, a resumed read that couldn't replay the
|
|
118
|
+
// file's first line never takes the parent's (engram#583).
|
|
119
|
+
if (data.ordinal === 0)
|
|
120
|
+
state.ownFrom = startOrdinal(p.subagent_history_start_ordinal);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
if (data.type === "turn_context") {
|
|
124
|
+
if (p.cwd)
|
|
125
|
+
state.cwd = p.cwd;
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
59
130
|
/** rollout-2026-07-23T04-46-50-<uuid>.jsonl → <uuid> */
|
|
60
131
|
sessionIdFromPath(filePath) {
|
|
61
132
|
const m = filePath.match(/rollout-[\dT-]+-([0-9a-f-]{36})\.jsonl$/i);
|
|
62
133
|
return m ? m[1] : null;
|
|
63
134
|
}
|
|
64
135
|
}
|
|
136
|
+
/** A record numbered before this subagent's own: its parent's history. */
|
|
137
|
+
function inherited(data, state) {
|
|
138
|
+
return state.ownFrom !== null && typeof data.ordinal === "number" && data.ordinal < state.ownFrom;
|
|
139
|
+
}
|
|
140
|
+
/** A boundary to skip to, or null: one at 0 has nothing before it. */
|
|
141
|
+
function startOrdinal(value) {
|
|
142
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : null;
|
|
143
|
+
}
|
|
144
|
+
function parse(line) {
|
|
145
|
+
try {
|
|
146
|
+
const data = JSON.parse(line);
|
|
147
|
+
return data && typeof data === "object" ? data : null;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
65
153
|
//# sourceMappingURL=codex-parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-parser.js","sourceRoot":"","sources":["../../src/daemon/codex-parser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codex-parser.js","sourceRoot":"","sources":["../../src/daemon/codex-parser.ts"],"names":[],"mappings":"AA0BA,uEAAuE;AACvE,MAAM,cAAc,GAAG,+DAA+D,CAAC;AAcvF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAC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,CAAC,IAAI,CAAC;IACzB,CAAC;CACF;AAED,0EAA0E;AAC1E,SAAS,SAAS,CAAC,IAAiB,EAAE,KAAmB;IACvD,OAAO,KAAK,CAAC,OAAO,KAAK,IAAI,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;AACpG,CAAC;AAED,sEAAsE;AACtE,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9F,CAAC;AAED,SAAS,KAAK,CAAC,IAAY;IACzB,IAAI,CAAC;QACH,MAAM,IAAI,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvC,OAAO,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAE,IAAoB,CAAC,CAAC,CAAC,IAAI,CAAC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A program on PATH, from an absolute directory only: never one that PATH's
|
|
3
|
+
* relative entries would find in the working directory. Null when there is
|
|
4
|
+
* none.
|
|
5
|
+
*/
|
|
6
|
+
export declare function commandPath(name: string): string | null;
|
|
7
|
+
/**
|
|
8
|
+
* What went wrong with a command, in a line, to print: the first line it
|
|
9
|
+
* said on stderr, else the first line of the error. Never more than one
|
|
10
|
+
* line, and never a long one.
|
|
11
|
+
*/
|
|
12
|
+
export declare function commandFailure(err: unknown): string;
|
|
13
|
+
//# sourceMappingURL=command-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-path.d.ts","sourceRoot":"","sources":["../../src/daemon/command-path.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYvD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAKnD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
2
|
+
import { delimiter, isAbsolute, join } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* A program on PATH, from an absolute directory only: never one that PATH's
|
|
5
|
+
* relative entries would find in the working directory. Null when there is
|
|
6
|
+
* none.
|
|
7
|
+
*/
|
|
8
|
+
export function commandPath(name) {
|
|
9
|
+
for (const dir of (process.env.PATH ?? "").split(delimiter)) {
|
|
10
|
+
if (!isAbsolute(dir))
|
|
11
|
+
continue;
|
|
12
|
+
const file = join(dir, name);
|
|
13
|
+
try {
|
|
14
|
+
accessSync(file, constants.X_OK);
|
|
15
|
+
if (statSync(file).isFile())
|
|
16
|
+
return file;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// not here
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* What went wrong with a command, in a line, to print: the first line it
|
|
26
|
+
* said on stderr, else the first line of the error. Never more than one
|
|
27
|
+
* line, and never a long one.
|
|
28
|
+
*/
|
|
29
|
+
export function commandFailure(err) {
|
|
30
|
+
const stderr = err.stderr;
|
|
31
|
+
const said = typeof stderr === "string" ? stderr.split("\n").find((l) => l.trim() !== "") : undefined;
|
|
32
|
+
const line = (said ?? (err instanceof Error ? err.message : String(err)).split("\n")[0]).trim();
|
|
33
|
+
return line.length > 200 ? `${line.slice(0, 199)}…` : line;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=command-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-path.js","sourceRoot":"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