@zswarm/core 0.2.4 → 0.2.6
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/host/cli.js +9 -2
- package/dist/host/crew-windows.d.ts +155 -0
- package/dist/host/crew-windows.js +556 -0
- package/dist/host/crew.d.ts +32 -2
- package/dist/host/crew.js +212 -23
- package/dist/host/services.d.ts +7 -4
- package/dist/host/services.js +18 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/schema.d.ts +27 -0
- package/dist/schema.js +112 -2
- package/package.json +1 -1
package/dist/host/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { ZellijError } from "../errors.js";
|
|
3
3
|
import { createStateStore } from "../state.js";
|
|
4
|
-
import { crewCheck, crewDown, crewStart, crewStatus, crewUp } from "./crew.js";
|
|
4
|
+
import { crewCheck, crewClient, crewDown, crewStart, crewStatus, crewUp } from "./crew.js";
|
|
5
5
|
import { hostDoctor, hostInstall, hostInstallArgs, hostScriptPath } from "./host.js";
|
|
6
6
|
import { listLeases } from "./lease.js";
|
|
7
7
|
import { cancelAllTo, cancelRelay, listRelays, pruneRelays, runRelayDir, startRelay, waitForRelay } from "./relay.js";
|
|
@@ -75,6 +75,10 @@ async function crew(argv) {
|
|
|
75
75
|
return crewStart(session);
|
|
76
76
|
case "check":
|
|
77
77
|
return crewCheck(session);
|
|
78
|
+
case "client":
|
|
79
|
+
// What the minimized console window on Windows runs: attach (and create)
|
|
80
|
+
// the session so its panes render and take input.
|
|
81
|
+
return crewClient(session);
|
|
78
82
|
default:
|
|
79
83
|
process.stderr.write(`${COMMANDS.crew.usage}\n`);
|
|
80
84
|
return 2;
|
|
@@ -227,10 +231,13 @@ const COMMANDS = {
|
|
|
227
231
|
crew: {
|
|
228
232
|
usage: [
|
|
229
233
|
"zswarm crew up <session> --layout L.kdl [--config C.kdl] [--env-file F] [--first-pane NAME] [--run-as USER]",
|
|
230
|
-
" keep the session running from its layout (service + 2-min watchdog
|
|
234
|
+
" keep the session running from its layout (service + 2-min watchdog;",
|
|
235
|
+
" on Windows: Scheduled Tasks under \\zswarm\\ + an attached client window)",
|
|
231
236
|
"zswarm crew status <session> [--run-as USER] services, session, panes",
|
|
232
237
|
"zswarm crew down <session> [--run-as USER] remove the services and kill the session",
|
|
233
238
|
"zswarm crew start|check <session> what the service and the watchdog run",
|
|
239
|
+
"zswarm crew client <session> what the minimized console window runs (Windows)",
|
|
240
|
+
"--run-as installs for another account and is Linux/macOS only; a Windows crew runs as the signed-in user",
|
|
234
241
|
].join("\n"),
|
|
235
242
|
run: crew,
|
|
236
243
|
},
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows half of `zswarm crew`.
|
|
3
|
+
*
|
|
4
|
+
* A background Zellij session started with `zellij attach --create-background`
|
|
5
|
+
* on Windows renders empty pane grids and drops pasted input, because nothing
|
|
6
|
+
* is attached in a real console. The fix is two Scheduled Tasks under
|
|
7
|
+
* `\zswarm\` plus a minimized attached-client console window:
|
|
8
|
+
*
|
|
9
|
+
* zswarm-crew-<session> starts the session (interactive, highest)
|
|
10
|
+
* zswarm-crew-<session>-watch `crew check` every two minutes, so the crew
|
|
11
|
+
* restarts only when the session or its first
|
|
12
|
+
* layout pane is gone, and the client window is
|
|
13
|
+
* reopened when it is gone but the session lives
|
|
14
|
+
*
|
|
15
|
+
* This module is pure PowerShell text (unit-tested by text) plus thin async
|
|
16
|
+
* wrappers. It deliberately mirrors `buildServeTaskScript` in
|
|
17
|
+
* `ops/serve-install.ts`: same preamble helpers, same base64 UTF-8 round-trip
|
|
18
|
+
* for the cmd.exe action body, same `-EncodedCommand` invocation. It must not
|
|
19
|
+
* import `./crew.js`; that module imports this one.
|
|
20
|
+
*/
|
|
21
|
+
/** Scheduled-task folder every crew task lives in. */
|
|
22
|
+
export declare const CREW_TASK_FOLDER = "\\zswarm\\";
|
|
23
|
+
/** Watchdog cadence, matching the Linux/macOS `crew-<s>-watch` timer. */
|
|
24
|
+
export declare const CREW_WATCH_MINUTES = 2;
|
|
25
|
+
export type PowerShellResult = {
|
|
26
|
+
code: number;
|
|
27
|
+
stdout: string;
|
|
28
|
+
stderr: string;
|
|
29
|
+
};
|
|
30
|
+
export type PowerShellExec = (script: string, options: {
|
|
31
|
+
timeoutMs: number;
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}) => Promise<PowerShellResult>;
|
|
34
|
+
export type CrewTaskNames = {
|
|
35
|
+
folder: string;
|
|
36
|
+
start: string;
|
|
37
|
+
watch: string;
|
|
38
|
+
};
|
|
39
|
+
export type CrewTaskState = {
|
|
40
|
+
/** Which of the two crew tasks this is. */
|
|
41
|
+
name: "start" | "watch";
|
|
42
|
+
/** Task name only, e.g. `zswarm-crew-crew`. */
|
|
43
|
+
task: string;
|
|
44
|
+
/** `\zswarm\zswarm-crew-crew`. */
|
|
45
|
+
path: string;
|
|
46
|
+
/** `Ready` | `Running` | `Disabled` | `missing` ... */
|
|
47
|
+
state: string;
|
|
48
|
+
/** Registered at all: Ready/Running/Disabled count; `missing` does not. */
|
|
49
|
+
active: boolean;
|
|
50
|
+
lastResult: number | null;
|
|
51
|
+
lastRun: string | null;
|
|
52
|
+
};
|
|
53
|
+
export type CrewClientWindow = {
|
|
54
|
+
present: boolean;
|
|
55
|
+
pid: number | null;
|
|
56
|
+
count: number;
|
|
57
|
+
};
|
|
58
|
+
/** `zswarm-crew-<session>`: task names, and the client window's title marker. */
|
|
59
|
+
export declare function crewTaskNames(session: string): CrewTaskNames;
|
|
60
|
+
/** The token that proves a console window is this crew's client: its title and
|
|
61
|
+
* the string in its launcher's command line. */
|
|
62
|
+
export declare function crewClientMarker(session: string): string;
|
|
63
|
+
/** The cmd.exe action body for a task: `set "K=V"&& ...` then the CLI argv. */
|
|
64
|
+
export declare function crewTaskCommand(input: {
|
|
65
|
+
launch: {
|
|
66
|
+
execPath: string;
|
|
67
|
+
scriptPath: string;
|
|
68
|
+
};
|
|
69
|
+
mode: "start" | "check";
|
|
70
|
+
session: string;
|
|
71
|
+
env: NodeJS.ProcessEnv;
|
|
72
|
+
}): string;
|
|
73
|
+
/** Pure PowerShell text, unit-tested by text. */
|
|
74
|
+
export declare function buildCrewTaskScript(action: "register" | "inspect" | "start" | "unregister", params: {
|
|
75
|
+
session: string;
|
|
76
|
+
startCommand?: string;
|
|
77
|
+
watchCommand?: string;
|
|
78
|
+
intervalMinutes?: number;
|
|
79
|
+
}): string;
|
|
80
|
+
/**
|
|
81
|
+
* The command line the client window runs. The marker is both the window title
|
|
82
|
+
* and the token `ensure`/`close` look for in a process command line; the crew
|
|
83
|
+
* CLI does the actual `zellij attach --create`, so the window can read the crew
|
|
84
|
+
* dir (and its env file) itself instead of taking secrets on a command line.
|
|
85
|
+
*/
|
|
86
|
+
export declare function crewClientCommand(input: {
|
|
87
|
+
session: string;
|
|
88
|
+
launch: {
|
|
89
|
+
execPath: string;
|
|
90
|
+
scriptPath: string;
|
|
91
|
+
};
|
|
92
|
+
}): string;
|
|
93
|
+
/** The minimized attached-client window that makes a Windows Zellij session render. */
|
|
94
|
+
export declare function buildCrewClientScript(action: "ensure" | "close", params: {
|
|
95
|
+
session: string;
|
|
96
|
+
clientCommand?: string;
|
|
97
|
+
}): string;
|
|
98
|
+
/** Last line that parses as a JSON object, else the first; null when none does. */
|
|
99
|
+
export declare function parseCrewJson(stdout: string): Record<string, unknown> | null;
|
|
100
|
+
/** Powershell runner used in production; injected in tests. Never throws. */
|
|
101
|
+
export declare const defaultPowerShellExec: PowerShellExec;
|
|
102
|
+
export declare function inspectCrewTasks(input: {
|
|
103
|
+
session: string;
|
|
104
|
+
runPowerShell: PowerShellExec;
|
|
105
|
+
timeoutMs?: number;
|
|
106
|
+
signal?: AbortSignal;
|
|
107
|
+
}): Promise<{
|
|
108
|
+
tasks: CrewTaskState[];
|
|
109
|
+
client: CrewClientWindow;
|
|
110
|
+
}>;
|
|
111
|
+
export declare function installCrewTasks(input: {
|
|
112
|
+
session: string;
|
|
113
|
+
startCommand: string;
|
|
114
|
+
watchCommand: string;
|
|
115
|
+
intervalMinutes?: number;
|
|
116
|
+
runPowerShell: PowerShellExec;
|
|
117
|
+
timeoutMs?: number;
|
|
118
|
+
signal?: AbortSignal;
|
|
119
|
+
}): Promise<{
|
|
120
|
+
lines: string[];
|
|
121
|
+
notes: string[];
|
|
122
|
+
tasks: CrewTaskState[];
|
|
123
|
+
client: CrewClientWindow;
|
|
124
|
+
}>;
|
|
125
|
+
export declare function removeCrewTasks(input: {
|
|
126
|
+
session: string;
|
|
127
|
+
runPowerShell: PowerShellExec;
|
|
128
|
+
timeoutMs?: number;
|
|
129
|
+
signal?: AbortSignal;
|
|
130
|
+
}): Promise<{
|
|
131
|
+
lines: string[];
|
|
132
|
+
tasks: CrewTaskState[];
|
|
133
|
+
}>;
|
|
134
|
+
export declare function ensureCrewClient(input: {
|
|
135
|
+
session: string;
|
|
136
|
+
clientCommand: string;
|
|
137
|
+
runPowerShell: PowerShellExec;
|
|
138
|
+
timeoutMs?: number;
|
|
139
|
+
signal?: AbortSignal;
|
|
140
|
+
}): Promise<{
|
|
141
|
+
opened: boolean;
|
|
142
|
+
pid: number | null;
|
|
143
|
+
title: string;
|
|
144
|
+
present: boolean;
|
|
145
|
+
count: number;
|
|
146
|
+
}>;
|
|
147
|
+
export declare function closeCrewClient(input: {
|
|
148
|
+
session: string;
|
|
149
|
+
runPowerShell: PowerShellExec;
|
|
150
|
+
timeoutMs?: number;
|
|
151
|
+
signal?: AbortSignal;
|
|
152
|
+
}): Promise<{
|
|
153
|
+
closed: number[];
|
|
154
|
+
count: number;
|
|
155
|
+
}>;
|