@zswarm/core 0.1.6 → 0.1.8

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.
@@ -1,14 +1,87 @@
1
+ import { type Server, type Socket } from "node:net";
2
+ import { type NetworkInterfacesFn, type ServeBindDeps, type TailscaleStatusRunner } from "./serve-bind.js";
1
3
  import type { OpsResult } from "./types.js";
2
4
  export declare const DEFAULT_SERVE_LISTEN = "127.0.0.1:9419";
3
5
  export declare const SERVE_TASK_NAME = "zswarm-serve";
4
6
  /** One JSONL request; a client that never sends newline cannot grow forever. */
5
7
  export declare const SERVE_MAX_REQUEST_BYTES: number;
8
+ /**
9
+ * Zellij `execFile` capture budget (`maxBuffer`). `dump --max 0` can return
10
+ * that much pane text; serve JSONL is UTF-8 and may expand (newlines → `\n`).
11
+ */
12
+ export declare const SERVE_CAPTURE_BUDGET_BYTES: number;
13
+ /**
14
+ * Ordinary JSONL reply cap, UTF-8 bytes of the complete frame including the
15
+ * terminating newline. Sized for an 8MiB capture with newline escaping (2×)
16
+ * plus envelope slack. Not a silent truncate: over-cap fails with
17
+ * `serve_protocol`. Override with `ZSWARM_SERVE_MAX_REPLY_BYTES`.
18
+ */
19
+ export declare const SERVE_MAX_REPLY_BYTES: number;
20
+ /** Hello is a small control reply; keep it independent of dump-sized ops. */
21
+ export declare const SERVE_MAX_HELLO_BYTES: number;
6
22
  /** Drop a socket that never finishes a JSONL line. */
7
23
  export declare const SERVE_IDLE_TIMEOUT_MS = 30000;
8
24
  /** Concurrent TCP clients, including in-flight wait ops. */
9
25
  export declare const SERVE_MAX_CONNECTIONS = 32;
10
26
  /** Wait/await allow 15 minutes; this is that plus slack. */
11
27
  export declare const SERVE_CALL_TIMEOUT_CAP_MS: number;
28
+ /** TCP connect is bounded even when the op wait budget is long. */
29
+ export declare const SERVE_CONNECT_TIMEOUT_MS = 15000;
30
+ /** Hello probe wait is bounded within the overall deadline. */
31
+ export declare const SERVE_HELLO_TIMEOUT_MS = 15000;
32
+ /** Wire protocol number returned by hello. */
33
+ export declare const SERVE_PROTOCOL = 1;
34
+ export declare const SERVE_CONTROL_FIELD = "serveControl";
35
+ export declare const SERVE_HELLO_CONTROL = "hello";
36
+ export declare const SERVE_CAPABILITY_HELLO = "hello";
37
+ /** Per-launch identity for Windows install verification. Additive hello field. */
38
+ export declare const SERVE_LAUNCH_ID_ENV = "ZSWARM_SERVE_LAUNCH_ID";
39
+ /** Package version baked into the Windows logon-task command so upgrades restart. */
40
+ export declare const SERVE_CORE_VERSION: string;
41
+ export type ServePhase = "connect" | "hello" | "request";
42
+ /** Conservative: `uncertain` means a request was written and no complete reply arrived. */
43
+ export type ServeDelivery = "not_sent" | "uncertain" | "replied";
44
+ export type ServeErrorDetails = {
45
+ phase: ServePhase;
46
+ endpoint: string;
47
+ delivery: ServeDelivery;
48
+ remedy: string;
49
+ };
50
+ export type ServeCapability = typeof SERVE_CAPABILITY_HELLO;
51
+ export type ServeHelloData = {
52
+ protocol: number;
53
+ serverId: string;
54
+ hostname: string;
55
+ platform: string;
56
+ version: string;
57
+ capabilities: string[];
58
+ /** Present when the process was started with `ZSWARM_SERVE_LAUNCH_ID`. */
59
+ launchId?: string;
60
+ };
61
+ export type ProbeServeOptions = {
62
+ token?: string;
63
+ timeoutMs?: number;
64
+ signal?: AbortSignal;
65
+ };
66
+ export type CallServeOptions = {
67
+ timeoutMs?: number;
68
+ token?: string;
69
+ signal?: AbortSignal;
70
+ maxReplyBytes?: number;
71
+ connectTimeoutMs?: number;
72
+ };
73
+ export declare const SERVE_REMEDY: {
74
+ readonly connect: "Check that zswarm serve is running and the tunnel still forwards to this endpoint. Serve does not fall back to SSH.";
75
+ readonly unauthorized: "Set the same ZSWARM_SERVE_TOKEN on the server and this caller.";
76
+ readonly helloUnsupported: "This endpoint does not speak serve hello (protocol 1). Upgrade zswarm serve. Ordinary commands still work without probing hello first.";
77
+ readonly incompatible: "This serve protocol is not supported by this client. Upgrade zswarm on both sides.";
78
+ readonly protocol: "The endpoint returned a malformed or unexpected serve reply. Do not echo or retry blindly.";
79
+ readonly timeoutConnect: "The TCP connection did not complete in time. Check the tunnel and that zswarm serve is listening.";
80
+ readonly timeoutHello: "Connected but serve hello did not finish. Check the tunnel; do not treat this as a completed command.";
81
+ readonly timeoutRequest: "The request was sent but no reply arrived. Treat the remote outcome as uncertain; do not retry automatically.";
82
+ readonly incomplete: "The connection closed before a complete reply. If a request was already sent, treat the remote outcome as uncertain; do not retry automatically.";
83
+ readonly cancelled: "The caller cancelled this serve call. If a request was already sent, treat the remote outcome as uncertain; do not retry automatically.";
84
+ };
12
85
  export declare function isLoopbackHost(host: string): boolean;
13
86
  export declare function formatListenLabel(host: string, port: number): string;
14
87
  export declare function parseListenAddress(raw: string | undefined): {
@@ -21,38 +94,33 @@ export declare function serveCallTimeout(args: Record<string, unknown>): number;
21
94
  /** Env for a serve worker: talk to the local Zellij, never loop back into serve/ssh. */
22
95
  export declare function serveChildEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
23
96
  export type ServeDispatch = (args: Record<string, unknown>) => Promise<OpsResult>;
24
- export type StartServeOptions = {
97
+ export type StartServeOptions = ServeBindDeps & {
25
98
  token?: string;
26
99
  maxRequestBytes?: number;
27
100
  idleTimeoutMs?: number;
28
101
  maxConnections?: number;
102
+ /** Additive hello field; omitted on ordinary foreground `serve --listen`. */
103
+ launchId?: string;
104
+ /**
105
+ * Test seam for the TCP listener. Production uses `node:net` createServer.
106
+ * Bind failures must surface without falling back to another address.
107
+ */
108
+ createServer?: (connectionListener?: (socket: Socket) => void) => Pick<Server, "listen" | "close" | "on" | "address">;
29
109
  };
30
110
  export declare function startServe(listen: string | undefined, dispatch: ServeDispatch, options?: StartServeOptions): Promise<{
31
111
  label: string;
32
112
  close: () => Promise<void>;
33
113
  }>;
114
+ export type { NetworkInterfacesFn, TailscaleStatusRunner };
115
+ /** Direct host:port / tcp:// only. ssh:// URIs are resolved by serve-tunnel. */
34
116
  export declare function parseServeTarget(raw: string): {
35
117
  host: string;
36
118
  port: number;
37
119
  };
38
- export declare function callServe(target: string, args: Record<string, unknown>, timeoutMs?: number, token?: string): Promise<OpsResult>;
120
+ /** CLI/MCP inherit `process.env`; a positive integer overrides the default reply cap. */
121
+ export declare function serveMaxReplyBytes(env?: NodeJS.ProcessEnv): number;
122
+ export declare function callServe(target: string, args: Record<string, unknown>, timeoutMsOrOptions?: number | CallServeOptions, token?: string, signal?: AbortSignal): Promise<OpsResult>;
123
+ /** Authenticated hello probe. Never reports a legacy or incompatible endpoint as healthy. */
124
+ export declare function probeServe(target: string, options?: ProbeServeOptions): Promise<OpsResult>;
39
125
  export declare function redactServeSecret(command: string, token: string): string;
40
- export declare function serveLogonCommand(execPath: string, scriptPath: string, listen: string, token?: string): string;
41
- export declare function installServeLogon(input: {
42
- listen?: string;
43
- execPath?: string;
44
- scriptPath?: string;
45
- platform?: NodeJS.Platform;
46
- token?: string;
47
- env?: NodeJS.ProcessEnv;
48
- }): Promise<{
49
- task: string;
50
- listen: string;
51
- command: string;
52
- }>;
53
- export declare function uninstallServeLogon(input?: {
54
- platform?: NodeJS.Platform;
55
- }): Promise<{
56
- task: string;
57
- cleared: true;
58
- }>;
126
+ export declare function serveLogonCommand(execPath: string, scriptPath: string, listen: string, token?: string, extraEnv?: Record<string, string>): string;