@zswarm/cli 0.1.9 → 0.2.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.
Files changed (2) hide show
  1. package/dist/cli.js +29 -2
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -1,8 +1,28 @@
1
1
  #!/usr/bin/env node
2
- import { ZellijError, cliUsage, createServeTunnelManager, dispatchZswarm, parseCliArgv, serveChildEnv, startServe, } from "@zswarm/core";
2
+ import { HOST_COMMANDS, ZellijError, cliUsage, createServeTunnelManager, dispatchZswarm, parseCliArgv, runHostCommand, SERVE_AWAIT_SESSION_ENV, SERVE_CORE_VERSION, serveTokenFromEnv, serveChildEnv, startServe, } from "@zswarm/core";
3
3
  import { readBodyFile } from "./input.js";
4
4
  import { routingNotice } from "./output.js";
5
+ /** Wait until `session` is a live Zellij session (a crew service creates it). */
6
+ async function awaitLiveSession(session, ms) {
7
+ const deadline = Date.now() + ms;
8
+ for (;;) {
9
+ const res = await dispatchZswarm({ op: "sessions" }).catch(() => undefined);
10
+ const sessions = res?.ok ? (res.data.sessions ?? []) : [];
11
+ if (sessions.some((s) => s.name === session))
12
+ return;
13
+ if (Date.now() >= deadline)
14
+ throw new Error(`session ${session} did not come up within ${ms} ms`);
15
+ await new Promise((r) => setTimeout(r, 1_000));
16
+ }
17
+ }
5
18
  const argv = process.argv.slice(2);
19
+ if (argv[0] === "--version" || argv[0] === "-V") {
20
+ process.stdout.write(`${SERVE_CORE_VERSION}\n`);
21
+ process.exit(0);
22
+ }
23
+ if (argv.length > 0 && HOST_COMMANDS.includes(argv[0])) {
24
+ process.exit(await runHostCommand(argv));
25
+ }
6
26
  if (argv.length === 0 || argv[0] === "-h" || argv[0] === "--help") {
7
27
  process.stderr.write(cliUsage());
8
28
  process.exit(argv.length === 0 ? 2 : 0);
@@ -29,8 +49,15 @@ catch (err) {
29
49
  if (args.op === "serve" && args.install !== true && args.clear !== true) {
30
50
  const listen = typeof args.listen === "string" ? args.listen : undefined;
31
51
  try {
52
+ // A service-run serve (serve --install on Linux/macOS) reads its token
53
+ // from a mode-600 file and waits for its session before listening.
54
+ const token = serveTokenFromEnv(process.env);
55
+ const awaitMs = Number(process.env[SERVE_AWAIT_SESSION_ENV] ?? 0);
56
+ if (awaitMs > 0 && typeof args.session === "string") {
57
+ await awaitLiveSession(args.session, awaitMs);
58
+ }
32
59
  const { label } = await startServe(listen, (request) => dispatchZswarm(request, undefined, { env: serveChildEnv(process.env) }), {
33
- token: process.env.ZSWARM_SERVE_TOKEN,
60
+ token,
34
61
  launchId: process.env.ZSWARM_SERVE_LAUNCH_ID,
35
62
  env: process.env,
36
63
  });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@zswarm/cli",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
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.9"
10
+ "@zswarm/core": "0.2.0"
11
11
  },
12
12
  "devDependencies": {
13
13
  "@types/node": "22.14.1",