@hadoku/host-wire 0.1.200 → 0.1.202
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/files.d.ts +21 -0
- package/dist/files.js +51 -0
- package/dist/wire.d.ts +1 -0
- package/dist/wire.js +1 -0
- package/package.json +2 -2
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File and process helpers that both sides of the wire use: the coordinator packs and hashes
|
|
3
|
+
* artifacts, the agent checks and unpacks them, and both keep small state files on disk. Node
|
|
4
|
+
* builtins only, like `wire.ts`: the agent bundles this for node 22.
|
|
5
|
+
*/
|
|
6
|
+
/** How much of a failed command's stderr its error keeps: the end, where the reason is. */
|
|
7
|
+
export declare const STDERR_TAIL = 2000;
|
|
8
|
+
/** sha256 hex of a file, streamed: a JDK tarball is too big to hold in a claw's slice. */
|
|
9
|
+
export declare function hashFile(file: string): Promise<string>;
|
|
10
|
+
/** A command, off the event loop, its stdout ignored; rejects with the last `STDERR_TAIL` characters of its stderr. */
|
|
11
|
+
export declare function run(cmd: string, args: string[], opts?: {
|
|
12
|
+
cwd?: string;
|
|
13
|
+
env?: NodeJS.ProcessEnv;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Write `file` whole or not at all: into a temporary file beside it named for this process,
|
|
17
|
+
* flushed to disk, then renamed over it. `writeFileSync` in place truncates first, so a full disk
|
|
18
|
+
* left a match's `jvm.json` empty and the match un-re-attachable; here a failed write leaves the
|
|
19
|
+
* old file as it was, removes the temporary one, and throws.
|
|
20
|
+
*/
|
|
21
|
+
export declare function writeFileAtomicSync(file: string, text: string): void;
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File and process helpers that both sides of the wire use: the coordinator packs and hashes
|
|
3
|
+
* artifacts, the agent checks and unpacks them, and both keep small state files on disk. Node
|
|
4
|
+
* builtins only, like `wire.ts`: the agent bundles this for node 22.
|
|
5
|
+
*/
|
|
6
|
+
import { spawn } from 'node:child_process';
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import { closeSync, createReadStream, fsyncSync, openSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
9
|
+
/** How much of a failed command's stderr its error keeps: the end, where the reason is. */
|
|
10
|
+
export const STDERR_TAIL = 2000;
|
|
11
|
+
/** sha256 hex of a file, streamed: a JDK tarball is too big to hold in a claw's slice. */
|
|
12
|
+
export async function hashFile(file) {
|
|
13
|
+
const hash = createHash('sha256');
|
|
14
|
+
for await (const chunk of createReadStream(file))
|
|
15
|
+
hash.update(chunk);
|
|
16
|
+
return hash.digest('hex');
|
|
17
|
+
}
|
|
18
|
+
/** A command, off the event loop, its stdout ignored; rejects with the last `STDERR_TAIL` characters of its stderr. */
|
|
19
|
+
export function run(cmd, args, opts = {}) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const child = spawn(cmd, args, { ...opts, stdio: ['ignore', 'ignore', 'pipe'] });
|
|
22
|
+
let stderr = '';
|
|
23
|
+
child.stderr.on('data', (c) => (stderr = (stderr + c.toString()).slice(-STDERR_TAIL)));
|
|
24
|
+
child.on('error', (err) => reject(new Error(`${cmd}: ${err.message}`)));
|
|
25
|
+
child.on('close', (code) => (code === 0 ? resolve() : reject(new Error(`${cmd} ${args[0] ?? ''}: ${stderr.trim() || `exit ${String(code)}`}`))));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Write `file` whole or not at all: into a temporary file beside it named for this process,
|
|
30
|
+
* flushed to disk, then renamed over it. `writeFileSync` in place truncates first, so a full disk
|
|
31
|
+
* left a match's `jvm.json` empty and the match un-re-attachable; here a failed write leaves the
|
|
32
|
+
* old file as it was, removes the temporary one, and throws.
|
|
33
|
+
*/
|
|
34
|
+
export function writeFileAtomicSync(file, text) {
|
|
35
|
+
const tmp = `${file}.tmp-${process.pid}`;
|
|
36
|
+
try {
|
|
37
|
+
const fd = openSync(tmp, 'w');
|
|
38
|
+
try {
|
|
39
|
+
writeFileSync(fd, text);
|
|
40
|
+
fsyncSync(fd);
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
closeSync(fd);
|
|
44
|
+
}
|
|
45
|
+
renameSync(tmp, file);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
rmSync(tmp, { force: true });
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
}
|
package/dist/wire.d.ts
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
* A newer session replaces the older one: one coordinator at a time.
|
|
34
34
|
*/
|
|
35
35
|
import { type KeyObject } from 'node:crypto';
|
|
36
|
+
export * from './files.js';
|
|
36
37
|
/** The agent's port on a claw (fleet-manager's `CARDTABLE_AGENT_PORT`). */
|
|
37
38
|
export declare const AGENT_PORT = 7621;
|
|
38
39
|
/** A request's timestamp must be within this of the agent's clock. */
|
package/dist/wire.js
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
* A newer session replaces the older one: one coordinator at a time.
|
|
34
34
|
*/
|
|
35
35
|
import { createHash, createPrivateKey, createPublicKey, sign, verify } from 'node:crypto';
|
|
36
|
+
export * from "./files.js";
|
|
36
37
|
/** The agent's port on a claw (fleet-manager's `CARDTABLE_AGENT_PORT`). */
|
|
37
38
|
export const AGENT_PORT = 7621;
|
|
38
39
|
/** A request's timestamp must be within this of the agent's clock. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/host-wire",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.202",
|
|
4
|
+
"gitHead": "4ba2350938ced47e5519c9acf331d81ff6f6235c",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The signed wire between a match host and the agent on a hosting claw: request signing, the relay's frames, the messages each side sends, artifact hashes and slice sizing. Knows no game. MIT; imports only node builtins, because the agent bundles it for node 22.",
|