@zswarm/core 0.3.0 → 0.3.1

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.
@@ -337,11 +337,26 @@ export function buildCrewClientScript(action, params) {
337
337
  PS_CLIENT_PREAMBLE,
338
338
  `$marker = '${marker}'`,
339
339
  psClientPidLine(marker),
340
+ "$all = @(Get-CimInstance Win32_Process)",
340
341
  "$closed = @()",
341
342
  "foreach ($clientPid in $clientPids) {",
342
- " # The window is the launcher's console, so the tree has to go with it:",
343
- " # /T reaches the attached `zellij` client that shares that console.",
344
- " & taskkill.exe /PID $clientPid /T /F 2>$null | Out-Null",
343
+ " # The window is the launcher's console, so its tree goes with it: the",
344
+ " # attached `zellij` client shares that console. The Zellij server is in the",
345
+ " # tree too (the client that created the session spawned it) and must stay,",
346
+ " # or the session dies with its window: skip it and everything under it.",
347
+ " # A child is never older than its parent, so a reused parent PID never",
348
+ " # links an unrelated process.",
349
+ " $tree = New-Object System.Collections.Generic.List[object]",
350
+ " $queue = New-Object System.Collections.Generic.Queue[object]",
351
+ " $queue.Enqueue(($all | Where-Object { $_.ProcessId -eq $clientPid } | Select-Object -First 1))",
352
+ " while ($queue.Count -gt 0) {",
353
+ " $proc = $queue.Dequeue()",
354
+ " if (-not $proc) { continue }",
355
+ " if ($proc.Name -eq 'zellij.exe' -and $proc.CommandLine -match '(^|\\s)--server(\\s|=)') { continue }",
356
+ " $tree.Add($proc)",
357
+ " foreach ($child in @($all | Where-Object { $_.ParentProcessId -eq $proc.ProcessId -and $_.CreationDate -ge $proc.CreationDate })) { $queue.Enqueue($child) }",
358
+ " }",
359
+ " for ($i = $tree.Count - 1; $i -ge 0; $i--) { Stop-Process -Id $tree[$i].ProcessId -Force -ErrorAction SilentlyContinue }",
345
360
  " $closed += $clientPid",
346
361
  "}",
347
362
  "Write-ZswarmJson @{ closed = @($closed); count = $closed.Count }",
package/dist/host/crew.js CHANGED
@@ -212,6 +212,14 @@ export async function crewStart(session, deps = {}) {
212
212
  // `zellij --layout ... attach --create`, which `crew client` starts. That
213
213
  // window is what `crew start` reopens when it is gone.
214
214
  const client = windowsClient(deps, env);
215
+ // A live session that already has its layout is the crew: keep it and only
216
+ // make sure its window is there. Rebuilding would restart every pane.
217
+ if ((await sessions(env)).includes(session)
218
+ && checkLayout(await panes(session, env), files.first, names).state === "ok") {
219
+ const opened = await client.ensure(session);
220
+ log(`session ${session} already up; client window ${opened.opened ? "opened" : "already open"}`);
221
+ return 0;
222
+ }
215
223
  for (let attempt = 1; attempt <= 3; attempt++) {
216
224
  zellij(["delete-session", session], env); // clears only a dead session of this name
217
225
  await client.close(session); // a window left over from the previous attempt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zswarm/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "description": "zSwarm Zellij client and shared ops dispatch",
6
6
  "exports": {