@verax-ai/body 0.4.0 → 0.4.2
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/dist/approval-signature.d.ts +47 -0
- package/dist/approval-signature.js +281 -0
- package/dist/cli.js +12 -3
- package/dist/desktop.d.ts +43 -1
- package/dist/desktop.js +335 -34
- package/dist/halt.d.ts +35 -0
- package/dist/halt.js +81 -3
- package/dist/install.d.ts +54 -3
- package/dist/install.js +471 -29
- package/dist/operator-credentials.d.ts +1 -0
- package/dist/operator-credentials.js +4 -2
- package/dist/ps-module-imports.d.ts +17 -0
- package/dist/ps-module-imports.js +34 -0
- package/dist/server.js +110 -4
- package/dist/verify-cli.d.ts +2 -2
- package/dist/verify-cli.js +67 -5
- package/dist/webauthn-verify.d.ts +40 -0
- package/dist/webauthn-verify.js +159 -0
- package/dist/wiring.js +3 -0
- package/package.json +3 -3
package/dist/halt.js
CHANGED
|
@@ -1,12 +1,90 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { userInfo } from "node:os";
|
|
2
3
|
import { join } from "node:path";
|
|
4
|
+
const SWITCH = "halted";
|
|
5
|
+
const HISTORY = "halt-history.jsonl";
|
|
6
|
+
function cliUser() {
|
|
7
|
+
try {
|
|
8
|
+
return userInfo().username || "unknown";
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return "unknown";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function appendHistory(stateDir, event) {
|
|
15
|
+
appendFileSync(join(stateDir, HISTORY), `${JSON.stringify(event)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
16
|
+
}
|
|
17
|
+
function lastHalt(stateDir) {
|
|
18
|
+
let raw;
|
|
19
|
+
try {
|
|
20
|
+
raw = readFileSync(join(stateDir, HISTORY), "utf8");
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const lines = raw.split("\n").filter((line) => line.trim() !== "");
|
|
26
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
27
|
+
try {
|
|
28
|
+
const row = JSON.parse(lines[i] ?? "");
|
|
29
|
+
if (row.action === "halt" && typeof row.atMs === "number" && typeof row.by === "string") {
|
|
30
|
+
return { action: "halt", atMs: row.atMs, by: row.by, via: row.via === "http" ? "http" : "cli" };
|
|
31
|
+
}
|
|
32
|
+
if (row.action === "resume")
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// A torn last line says nothing about who halted.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
export function readHalt(stateDir) {
|
|
42
|
+
if (!existsSync(join(stateDir, SWITCH)))
|
|
43
|
+
return { halted: false };
|
|
44
|
+
const since = lastHalt(stateDir);
|
|
45
|
+
return since ? { halted: true, since } : { halted: true };
|
|
46
|
+
}
|
|
47
|
+
/** Halting twice is one halt: the first line keeps saying who stopped it. */
|
|
48
|
+
export function haltBody(stateDir, by, via, now = Date.now()) {
|
|
49
|
+
mkdirSync(stateDir, { recursive: true, mode: 0o700 });
|
|
50
|
+
if (!existsSync(join(stateDir, SWITCH))) {
|
|
51
|
+
writeFileSync(join(stateDir, SWITCH), "", { encoding: "utf8", mode: 0o600 });
|
|
52
|
+
appendHistory(stateDir, { action: "halt", atMs: now, by, via });
|
|
53
|
+
}
|
|
54
|
+
return readHalt(stateDir);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resuming a body that is not halted changes nothing and writes nothing.
|
|
58
|
+
* The line goes to the history before the switch is removed: if it cannot be
|
|
59
|
+
* written, the append throws and the body stays halted, rather than running
|
|
60
|
+
* again with no record of who let it.
|
|
61
|
+
*/
|
|
62
|
+
export function resumeBody(stateDir, by, via, now = Date.now()) {
|
|
63
|
+
if (existsSync(join(stateDir, SWITCH))) {
|
|
64
|
+
appendHistory(stateDir, { action: "resume", atMs: now, by, via });
|
|
65
|
+
rmSync(join(stateDir, SWITCH), { force: true });
|
|
66
|
+
}
|
|
67
|
+
return readHalt(stateDir);
|
|
68
|
+
}
|
|
3
69
|
export function runHalt(stateDir, writeErr = (s) => process.stderr.write(s)) {
|
|
4
70
|
if (!stateDir) {
|
|
5
71
|
writeErr("verax halt <stateDir>\n");
|
|
6
72
|
return 78;
|
|
7
73
|
}
|
|
8
|
-
|
|
9
|
-
writeFileSync(join(stateDir, "halted"), "", { encoding: "utf8", mode: 0o600 });
|
|
74
|
+
haltBody(stateDir, cliUser(), "cli");
|
|
10
75
|
writeErr("halted\n");
|
|
11
76
|
return 0;
|
|
12
77
|
}
|
|
78
|
+
export function runResume(stateDir, writeErr = (s) => process.stderr.write(s)) {
|
|
79
|
+
if (!stateDir) {
|
|
80
|
+
writeErr("verax resume <stateDir>\n");
|
|
81
|
+
return 78;
|
|
82
|
+
}
|
|
83
|
+
if (!existsSync(join(stateDir, SWITCH))) {
|
|
84
|
+
writeErr("not halted\n");
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
resumeBody(stateDir, cliUser(), "cli");
|
|
88
|
+
writeErr("resumed\n");
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
package/dist/install.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare function readWindowsMachineRoots(exec?: ToolExec): WindowsMachine
|
|
|
39
39
|
* Absolute path for a system tool. Windows uses System32 under SystemRoot.
|
|
40
40
|
* Linux walks fixed directories and never consults PATH.
|
|
41
41
|
* macOS uses the fixed table (dscl, launchctl, chown, chmod, id, stat, plutil, lsof).
|
|
42
|
+
* `ls` is the POSIX ACL reader at `/bin/ls`, not an install-plan tool, so it is not in that table.
|
|
42
43
|
* A missing Linux binary falls back to the first candidate so a plan can name
|
|
43
44
|
* the path; spawning still refuses when that file is absent.
|
|
44
45
|
*/
|
|
@@ -54,7 +55,9 @@ export declare const PS_ERROR_MARK = "verax-ps-error:";
|
|
|
54
55
|
* AppData directory and must not receive install files.
|
|
55
56
|
* On Windows, PSModulePath is only the System32 Windows PowerShell 5.1 module
|
|
56
57
|
* directory. Without it, PowerShell 5.1 puts Documents\WindowsPowerShell\Modules
|
|
57
|
-
* first, and -NoProfile does not change that list.
|
|
58
|
+
* first, and -NoProfile does not change that list. PowerShell 5.1 still inserts
|
|
59
|
+
* Program Files\WindowsPowerShell\Modules in front of the pinned value (measured
|
|
60
|
+
* on 5.1.26100); the install trust-checks that directory as an object.
|
|
58
61
|
*/
|
|
59
62
|
export declare function systemToolEnv(platform?: NodeJS.Platform, tempDir?: string): NodeJS.ProcessEnv;
|
|
60
63
|
export declare function toolArgv(tool: string, args: readonly string[], platform?: NodeJS.Platform): string[];
|
|
@@ -315,6 +318,8 @@ export type InstallHooks = {
|
|
|
315
318
|
elevated?: () => boolean;
|
|
316
319
|
exec?: ToolExec;
|
|
317
320
|
stateExists?: (dir: string) => boolean;
|
|
321
|
+
/** Whether a `node_modules` directory on a module search path exists. Defaults to `existsSync`. */
|
|
322
|
+
moduleDirExists?: (dir: string) => boolean;
|
|
318
323
|
layout?: {
|
|
319
324
|
execPath: string;
|
|
320
325
|
bodyVersion: string;
|
|
@@ -389,6 +394,9 @@ export declare function windowsSddlBatchStdin(paths: readonly string[]): string;
|
|
|
389
394
|
* object: `{ "<path>": "<sddl>" | { "error": "<msg>" } }`.
|
|
390
395
|
* PowerShell 5.1 unwraps a one-element JSON array, so the script re-wraps with
|
|
391
396
|
* `| ForEach-Object { $_ }`.
|
|
397
|
+
* JSON cmdlets are loaded with psModuleImports before first use. #119, measured
|
|
398
|
+
* on windows-full 5a75875: autoload of ConvertFrom-Json took 23 to 30 s on a
|
|
399
|
+
* GitHub Windows runner, and 0.27 s once the module was loaded from System32 first.
|
|
392
400
|
*/
|
|
393
401
|
export declare function windowsSddlBatchArgv(paths: readonly string[]): string[];
|
|
394
402
|
export type SddlHit = {
|
|
@@ -448,6 +456,17 @@ export declare function trustTargets(file: string, platform: InstallPlatform): {
|
|
|
448
456
|
path: string;
|
|
449
457
|
ancestor: boolean;
|
|
450
458
|
}[];
|
|
459
|
+
/**
|
|
460
|
+
* The `node_modules` directories Node searches for a bare specifier that code
|
|
461
|
+
* under `start` imports: `<dir>/node_modules` for `start` and every parent, up
|
|
462
|
+
* to the root, skipping a directory that is itself named `node_modules`.
|
|
463
|
+
* Stock Windows lets any authenticated user create a folder under `C:\`, so
|
|
464
|
+
* `C:\node_modules` can be planted beside an elevated or service Node. Each
|
|
465
|
+
* one that exists is judged as an object (add-file counts). A missing one is
|
|
466
|
+
* not listed: the loader skips it, and refusing every machine for a folder
|
|
467
|
+
* that is not there would refuse them all.
|
|
468
|
+
*/
|
|
469
|
+
export declare function moduleSearchDirs(start: string, platform: InstallPlatform, exists?: (dir: string) => boolean): string[];
|
|
451
470
|
/**
|
|
452
471
|
* Another user can rename or replace this entry.
|
|
453
472
|
* An ancestor with the sticky bit is kept: only its owner can rename a child (mode 1777, the way `/tmp` works).
|
|
@@ -459,12 +478,32 @@ export declare function posixOthersCanReplace(st: {
|
|
|
459
478
|
mode: number;
|
|
460
479
|
symlink?: boolean;
|
|
461
480
|
}, ancestor: boolean): boolean;
|
|
462
|
-
/**
|
|
481
|
+
/**
|
|
482
|
+
* Text for a POSIX ACL refusal, or null when the extended ACL adds no writer.
|
|
483
|
+
* `"unreadable"` is fail-closed: Linux showed `+` and `getfacl` did not return the entries.
|
|
484
|
+
* The phrase is what the operator sees: install acl or remove the ACL.
|
|
485
|
+
*/
|
|
486
|
+
export declare function posixAclWriterDetail(found: readonly string[] | "unreadable" | undefined): string | null;
|
|
487
|
+
/**
|
|
488
|
+
* Extended ACL writers for every path, from one `ls` (and on Linux one `getfacl` for the `+` paths).
|
|
489
|
+
* macOS: `allow` entries with a write right, except the file owner, `user:root`, and `group:admin`.
|
|
490
|
+
* `deny` is ignored. `inherited` still counts.
|
|
491
|
+
* Linux: a named `user:` or `group:` with `w` that the `mask` also allows.
|
|
492
|
+
* `getfacl` missing while `ls` shows `+` is `"unreadable"` (fail closed).
|
|
493
|
+
* A non-zero `ls` is `"unreadable"` too: the `+` could not be seen.
|
|
494
|
+
* Exit 0 with no `+` is an empty list.
|
|
495
|
+
*/
|
|
496
|
+
export declare function posixAclWriters(paths: readonly string[], platform: NodeJS.Platform, exec: ToolExec): Map<string, string[] | "unreadable">;
|
|
497
|
+
/**
|
|
498
|
+
* POSIX half of the elevated code check. `read` supplies uid and mode so a test does not lstat the machine.
|
|
499
|
+
* `acls` is the one `posixAclWriters` map for this trust list. When mode says the entry is safe, a writer
|
|
500
|
+
* or `"unreadable"` is still a refusal. Omit `acls` only when the caller is injecting modes and not ACLs.
|
|
501
|
+
*/
|
|
463
502
|
export declare function posixCodeDirectoryDetail(dir: string, platform: InstallPlatform, read: (file: string) => {
|
|
464
503
|
uid: number;
|
|
465
504
|
mode: number;
|
|
466
505
|
symlink?: boolean;
|
|
467
|
-
} | null): string | false;
|
|
506
|
+
} | null, acls?: ReadonlyMap<string, string[] | "unreadable">): string | false;
|
|
468
507
|
/**
|
|
469
508
|
* Directory grant only. `(OI)(CI)` on a directory propagates to children.
|
|
470
509
|
* Never combine this with `/T`: `/inheritance:r /T` strips every child, and `(OI)(CI)`
|
|
@@ -496,6 +535,18 @@ export declare function normalizeLogonHolders(csv: string, nameToSid: Readonly<R
|
|
|
496
535
|
export declare function logonHolderMismatchLines(previous: readonly string[], expected: readonly string[], after: readonly string[]): string[];
|
|
497
536
|
/** Terminating errors exit 1. Native calls still need an explicit `$LASTEXITCODE` check. */
|
|
498
537
|
export declare function powerShellScript(body: string): string;
|
|
538
|
+
export type WindowsPowerShellScript = {
|
|
539
|
+
id: string;
|
|
540
|
+
script: string;
|
|
541
|
+
};
|
|
542
|
+
/**
|
|
543
|
+
* Every PowerShell -Command install.ts runs, with sample paths.
|
|
544
|
+
* Call sites: readWindowsMachineRoots, windowsSddlArgv, windowsSddlBatchArgv,
|
|
545
|
+
* powershellStdin (account create, account update, scheduled task), ownerModeLine,
|
|
546
|
+
* the service SID lookup in execute, directoryOwnerSid, the ProfileImagePath lookup,
|
|
547
|
+
* and windowsServiceSid. desktop.ts local account SIDs are a separate command.
|
|
548
|
+
*/
|
|
549
|
+
export declare function windowsPowerShellScripts(): WindowsPowerShellScript[];
|
|
499
550
|
export declare function successText(platform: InstallPlatform, info: {
|
|
500
551
|
codeDir: string;
|
|
501
552
|
stateDir: string;
|