@zswarm/cli 0.1.5 → 0.1.7
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 +2 -0
- package/dist/cli.js +12 -0
- package/dist/input.d.ts +2 -0
- package/dist/input.js +30 -0
- package/dist/output.d.ts +3 -0
- package/dist/output.js +14 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,6 +30,8 @@ zswarm keys --to terminal_2 --key "Ctrl c" --key Esc
|
|
|
30
30
|
Prints JSON. No arguments prints usage, generated from the same schema as the
|
|
31
31
|
MCP tool.
|
|
32
32
|
|
|
33
|
+
Spawn lifecycle, body files, guarded keys, status tabs and routing context: [crew operations](../../docs/crew-operations.md).
|
|
34
|
+
|
|
33
35
|
Ops, env, and the event bus: the [zswarm README](../../README.md).
|
|
34
36
|
|
|
35
37
|
## License
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { ZellijError, cliUsage, dispatchZswarm, parseCliArgv, serveChildEnv, startServe, } from "@zswarm/core";
|
|
3
|
+
import { readBodyFile } from "./input.js";
|
|
4
|
+
import { routingNotice } from "./output.js";
|
|
3
5
|
const argv = process.argv.slice(2);
|
|
4
6
|
if (argv.length === 0 || argv[0] === "-h" || argv[0] === "--help") {
|
|
5
7
|
process.stderr.write(cliUsage());
|
|
@@ -14,6 +16,15 @@ catch (err) {
|
|
|
14
16
|
process.stderr.write(`${message}\n${cliUsage()}`);
|
|
15
17
|
process.exit(2);
|
|
16
18
|
}
|
|
19
|
+
try {
|
|
20
|
+
args = await readBodyFile(args);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
const code = err instanceof ZellijError ? err.code : "body_file_read";
|
|
24
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
25
|
+
process.stdout.write(JSON.stringify({ ok: false, error: { code, message } }) + "\n");
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
17
28
|
// TCP server holds the event loop; process.exit would tear it down.
|
|
18
29
|
if (args.op === "serve" && args.install !== true && args.clear !== true) {
|
|
19
30
|
const listen = typeof args.listen === "string" ? args.listen : undefined;
|
|
@@ -29,6 +40,7 @@ if (args.op === "serve" && args.install !== true && args.clear !== true) {
|
|
|
29
40
|
}
|
|
30
41
|
else {
|
|
31
42
|
const result = await dispatchZswarm(args);
|
|
43
|
+
process.stderr.write(routingNotice(result, process.stderr.isTTY === true));
|
|
32
44
|
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
33
45
|
process.exit(result.ok ? 0 : 1);
|
|
34
46
|
}
|
package/dist/input.d.ts
ADDED
package/dist/input.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { ZellijError } from "@zswarm/core";
|
|
3
|
+
/** Local CLI preprocessing. File paths never cross SSH or the serve protocol. */
|
|
4
|
+
export async function readBodyFile(args, stdin = process.stdin) {
|
|
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;
|
|
12
|
+
try {
|
|
13
|
+
if (path === "-") {
|
|
14
|
+
const chunks = [];
|
|
15
|
+
for await (const chunk of stdin) {
|
|
16
|
+
chunks.push(typeof chunk === "string" ? Buffer.from(chunk, "utf8") : Buffer.from(chunk));
|
|
17
|
+
}
|
|
18
|
+
body = Buffer.concat(chunks).toString("utf8");
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
body = await readFile(path, "utf8");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
throw new ZellijError("body_file_read", `cannot read body from ${JSON.stringify(path)}: ${err instanceof Error ? err.message : String(err)}`);
|
|
26
|
+
}
|
|
27
|
+
const out = { ...args, body };
|
|
28
|
+
delete out.bodyFile;
|
|
29
|
+
return out;
|
|
30
|
+
}
|
package/dist/output.d.ts
ADDED
package/dist/output.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Human diagnostics stay on stderr; stdout is always one JSON response. */
|
|
2
|
+
export function routingNotice(result, interactive) {
|
|
3
|
+
const route = result.context;
|
|
4
|
+
if (!interactive || !route)
|
|
5
|
+
return "";
|
|
6
|
+
// Prevent terminal control characters or newlines in host/session labels.
|
|
7
|
+
const label = (s) => JSON.stringify(s);
|
|
8
|
+
const data = result.ok && result.data && typeof result.data === "object" ? result.data : null;
|
|
9
|
+
const polling = data?.polling;
|
|
10
|
+
return `zswarm: ${route.transport} ${label(route.host)}` +
|
|
11
|
+
(route.session ? ` session=${label(route.session)}` : "") +
|
|
12
|
+
` (via ${route.origin.transport}; session ${route.origin.session})\n` +
|
|
13
|
+
(polling?.recommendation ? `zswarm: ${label(polling.recommendation)}\n` : "");
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zswarm/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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.1.
|
|
10
|
+
"@zswarm/core": "0.1.7"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/node": "22.14.1",
|