@zswarm/core 0.1.2 → 0.1.4

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.
@@ -7,7 +7,7 @@
7
7
  */
8
8
  /** `…/zellij/contract_version_N/…` or Unix `…/zellij-<uid>/contract_version_N/…`. */
9
9
  const ZELLIJ_DIR = /[\\/](zellij(?:-\d+)?)[\\/]contract_version_[^\\/]+[\\/]/i;
10
- const SERVER_FLAG = /(?:^|\s)--server(?:\s+|=)(\S+)/;
10
+ const SERVER_FLAG = /(?:^|\s)--server(?:\s+|=)(?:"([^"]+)"|'([^']+)'|(\S+))/;
11
11
  /** Drive letter plus rest, or a UNC / posix path. */
12
12
  export function looksLikeWindowsPath(path) {
13
13
  return /^[A-Za-z]:[\\/]/.test(path) || path.includes("\\");
@@ -50,8 +50,9 @@ export function parseZellijServerPaths(commandLines) {
50
50
  const found = [];
51
51
  for (const line of commandLines.split(/\r?\n/)) {
52
52
  const match = SERVER_FLAG.exec(line);
53
- if (match?.[1])
54
- found.push(stripQuotes(match[1]));
53
+ const captured = match?.[1] || match?.[2] || match?.[3];
54
+ if (captured)
55
+ found.push(stripQuotes(captured));
55
56
  }
56
57
  return found;
57
58
  }
@@ -104,9 +105,12 @@ export function inferRemoteShell(input) {
104
105
  export function cmdQuote(arg) {
105
106
  if (arg === "")
106
107
  return '""';
107
- if (/^[A-Za-z0-9_@%+=:,.\\/-]+$/.test(arg))
108
- return arg;
109
- return `"${arg.replace(/"/g, '""')}"`;
108
+ // cmd.exe expands %VAR% even inside quotes; double percents to keep literals.
109
+ const escaped = arg.replace(/%/g, "%%");
110
+ if (/^[A-Za-z0-9_@+=:,.\\/-]+$/.test(escaped.replace(/%%/g, ""))) {
111
+ return escaped;
112
+ }
113
+ return `"${escaped.replace(/"/g, '""')}"`;
110
114
  }
111
115
  function defaultSocketDir(tmp, shell) {
112
116
  if (shell !== "cmd")
@@ -161,11 +165,13 @@ export function windowsInteractiveRemote(innerCmd, timeoutMs) {
161
165
  "$out = Join-Path $dir \"zswarm-$id.out\"",
162
166
  "$err = Join-Path $dir \"zswarm-$id.err\"",
163
167
  "$code = Join-Path $dir \"zswarm-$id.code\"",
164
- "@(",
168
+ "$lines = @(",
165
169
  " '@echo off'",
170
+ " 'chcp 65001 >nul'",
166
171
  " \"$inner > `\"$out`\" 2> `\"$err`\"\"",
167
172
  " \"echo %ERRORLEVEL% > `\"$code`\"\"",
168
- ") | Set-Content -Path $bat -Encoding ASCII",
173
+ ")",
174
+ "[IO.File]::WriteAllLines($bat, $lines, [Text.UTF8Encoding]::new($false))",
169
175
  "try {",
170
176
  " $create = & schtasks.exe /Create /TN $task /TR $bat /SC ONCE /ST 00:00 /IT /F /RL LIMITED 2>&1",
171
177
  " if ($LASTEXITCODE -ne 0) {",
@@ -8,6 +8,8 @@ export type ZellijSessionResolve = {
8
8
  */
9
9
  export declare function resolveSelfPaneId(env?: NodeJS.ProcessEnv): string | null;
10
10
  export declare function parseSessionList(stdout: string): string[];
11
+ /** Zellij exits 1 and prints this when the machine simply has no sessions. */
12
+ export declare function isZellijNoSessionsOutput(stdout: string, stderr: string): boolean;
11
13
  /** Session from an explicit argument or the environment, before asking Zellij. */
12
14
  export declare function sessionFromEnv(env: NodeJS.ProcessEnv, explicit?: string | null): ZellijSessionResolve | null;
13
15
  /** Pick a session when the environment gave no answer. */
@@ -19,6 +19,10 @@ export function parseSessionList(stdout) {
19
19
  .map((l) => l.trim())
20
20
  .filter(Boolean);
21
21
  }
22
+ /** Zellij exits 1 and prints this when the machine simply has no sessions. */
23
+ export function isZellijNoSessionsOutput(stdout, stderr) {
24
+ return /no active zellij sessions found/i.test(`${stderr}\n${stdout}`);
25
+ }
22
26
  /** Session from an explicit argument or the environment, before asking Zellij. */
23
27
  export function sessionFromEnv(env, explicit) {
24
28
  const arg = explicit?.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zswarm/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "description": "zSwarm Zellij client and shared ops dispatch",
6
6
  "exports": {
@@ -25,7 +25,7 @@
25
25
  "access": "public"
26
26
  },
27
27
  "dependencies": {
28
- "@zswarm/wasm": "0.1.0"
28
+ "@zswarm/wasm": "0.1.1"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "tsc -p tsconfig.json",