@zswarm/cli 0.2.6 → 0.2.8
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/cli.js +2 -2
- package/dist/input.d.ts +7 -0
- package/dist/input.js +35 -14
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { HOST_COMMANDS, OP_NAMES, ZellijError, cliUsage, commandUsage, wantsHelp, createServeTunnelManager, dispatchZswarm, extractOp, parseCliArgv, runHostCommand, SERVE_AWAIT_SESSION_ENV, SERVE_CORE_VERSION, serveTokenFromEnv, serveChildEnv, startServe, } from "@zswarm/core";
|
|
3
|
-
import { readBodyFile } from "./input.js";
|
|
3
|
+
import { readBodyFile, readHandoffFile } from "./input.js";
|
|
4
4
|
import { routingNotice } from "./output.js";
|
|
5
5
|
/** Wait until `session` is a live Zellij session (a crew service creates it). */
|
|
6
6
|
async function awaitLiveSession(session, ms) {
|
|
@@ -50,7 +50,7 @@ catch (err) {
|
|
|
50
50
|
process.exit(2);
|
|
51
51
|
}
|
|
52
52
|
try {
|
|
53
|
-
args = await readBodyFile(args);
|
|
53
|
+
args = await readHandoffFile(await readBodyFile(args));
|
|
54
54
|
}
|
|
55
55
|
catch (err) {
|
|
56
56
|
const code = err instanceof ZellijError ? err.code : "body_file_read";
|
package/dist/input.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
/** Local CLI preprocessing. File paths never cross SSH or the serve protocol. */
|
|
2
2
|
export declare function readBodyFile(args: Record<string, unknown>, stdin?: AsyncIterable<Uint8Array | string>): Promise<Record<string, unknown>>;
|
|
3
|
+
/**
|
|
4
|
+
* Resolve `--handoff-file` on the caller. The path is remembered for the
|
|
5
|
+
* post-relaunch pointer and for `--handoff-self`, which asks the running agent
|
|
6
|
+
* to write the file, so its content is only read here when the caller supplied
|
|
7
|
+
* it (not in self mode). `-` reads stdin once, like `--body-file`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readHandoffFile(args: Record<string, unknown>, stdin?: AsyncIterable<Uint8Array | string>): Promise<Record<string, unknown>>;
|
package/dist/input.js
CHANGED
|
@@ -1,30 +1,51 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { ZellijError } from "@zswarm/core";
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
if (args.bodyFile === undefined)
|
|
6
|
-
return args;
|
|
7
|
-
if (args.op !== "send" || args.body !== undefined || args.text !== undefined) {
|
|
8
|
-
throw new ZellijError("usage", "--body-file requires send and cannot be combined with another body source");
|
|
9
|
-
}
|
|
10
|
-
const path = String(args.bodyFile);
|
|
11
|
-
let body;
|
|
3
|
+
/** Read `-` (stdin) or a UTF-8 file, with a caller-shaped error. */
|
|
4
|
+
async function readInput(path, stdin, code, label) {
|
|
12
5
|
try {
|
|
13
6
|
if (path === "-") {
|
|
14
7
|
const chunks = [];
|
|
15
8
|
for await (const chunk of stdin) {
|
|
16
9
|
chunks.push(typeof chunk === "string" ? Buffer.from(chunk, "utf8") : Buffer.from(chunk));
|
|
17
10
|
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
body = await readFile(path, "utf8");
|
|
11
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
22
12
|
}
|
|
13
|
+
return await readFile(path, "utf8");
|
|
23
14
|
}
|
|
24
15
|
catch (err) {
|
|
25
|
-
throw new ZellijError(
|
|
16
|
+
throw new ZellijError(code, `cannot read ${label} from ${JSON.stringify(path)}: ${err instanceof Error ? err.message : String(err)}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Local CLI preprocessing. File paths never cross SSH or the serve protocol. */
|
|
20
|
+
export async function readBodyFile(args, stdin = process.stdin) {
|
|
21
|
+
if (args.bodyFile === undefined)
|
|
22
|
+
return args;
|
|
23
|
+
if (args.op !== "send" || args.body !== undefined || args.text !== undefined) {
|
|
24
|
+
throw new ZellijError("usage", "--body-file requires send and cannot be combined with another body source");
|
|
26
25
|
}
|
|
26
|
+
const path = String(args.bodyFile);
|
|
27
|
+
const body = await readInput(path, stdin, "body_file_read", "body");
|
|
27
28
|
const out = { ...args, body };
|
|
28
29
|
delete out.bodyFile;
|
|
29
30
|
return out;
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolve `--handoff-file` on the caller. The path is remembered for the
|
|
34
|
+
* post-relaunch pointer and for `--handoff-self`, which asks the running agent
|
|
35
|
+
* to write the file, so its content is only read here when the caller supplied
|
|
36
|
+
* it (not in self mode). `-` reads stdin once, like `--body-file`.
|
|
37
|
+
*/
|
|
38
|
+
export async function readHandoffFile(args, stdin = process.stdin) {
|
|
39
|
+
if (args.handoffFile === undefined)
|
|
40
|
+
return args;
|
|
41
|
+
if (args.op !== "restart") {
|
|
42
|
+
throw new ZellijError("usage", "--handoff-file requires restart");
|
|
43
|
+
}
|
|
44
|
+
const path = String(args.handoffFile);
|
|
45
|
+
const out = { ...args, handoffPath: path };
|
|
46
|
+
delete out.handoffFile;
|
|
47
|
+
if (args.handoffSelf === true || args.handoffSelf === "true")
|
|
48
|
+
return out;
|
|
49
|
+
out.handoff = await readInput(path, stdin, "handoff_file_read", "handoff");
|
|
50
|
+
return out;
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zswarm/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "zSwarm CLI — list, send, dump Zellij panes",
|
|
6
6
|
"bin": {
|
|
7
7
|
"zswarm": "./dist/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@zswarm/core": "0.2.
|
|
10
|
+
"@zswarm/core": "0.2.8"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/node": "22.14.1",
|