@zswarm/core 0.1.7 → 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.
@@ -0,0 +1,109 @@
1
+ import { type ChildProcess } from "node:child_process";
2
+ import { type ProbeServeOptions, type ServeHelloData } from "./serve.js";
3
+ import type { OpsResult } from "./types.js";
4
+ export declare const DEFAULT_SSH_SERVE_PORT: number;
5
+ /** Ordinary OpenSSH default when neither the URI nor ssh_config supplies Port. */
6
+ export declare const DEFAULT_SSH_PORT = 22;
7
+ export declare const SSH_SERVE_REMOTE_HOST = "127.0.0.1";
8
+ export declare const SSH_TUNNEL_KEEPALIVE_INTERVAL_S = 15;
9
+ export declare const SSH_TUNNEL_KEEPALIVE_COUNT = 3;
10
+ export declare const SSH_TUNNEL_PORT_RETRIES = 8;
11
+ export type ParsedSshServeTarget = {
12
+ user: string | undefined;
13
+ host: string;
14
+ /** Explicit URI authority port. `undefined` leaves Port to ssh_config / ssh. */
15
+ sshPort: number | undefined;
16
+ servePort: number;
17
+ destination: string;
18
+ };
19
+ export type SshTunnelArgv = {
20
+ bin: string;
21
+ args: string[];
22
+ };
23
+ export type SshTunnelSpawn = (bin: string, args: string[], options: {
24
+ env?: NodeJS.ProcessEnv;
25
+ stdio: ["ignore", "ignore", "pipe"];
26
+ windowsHide: true;
27
+ detached: false;
28
+ }) => ChildProcess;
29
+ export type AcquireServeTunnelOptions = {
30
+ env?: NodeJS.ProcessEnv;
31
+ token?: string;
32
+ timeoutMs: number;
33
+ signal?: AbortSignal;
34
+ };
35
+ export type ServeTunnelHandle = {
36
+ localTarget: string;
37
+ identity: string;
38
+ hello: ServeHelloData;
39
+ release: () => Promise<void>;
40
+ invalidate: () => Promise<void>;
41
+ };
42
+ export type ServeTunnelAcquireSuccess = {
43
+ ok: true;
44
+ handle: ServeTunnelHandle;
45
+ localTarget: string;
46
+ hello: ServeHelloData;
47
+ };
48
+ export type ServeTunnelManager = {
49
+ acquire: (raw: string, options: AcquireServeTunnelOptions) => Promise<ServeTunnelAcquireSuccess | OpsResult>;
50
+ /**
51
+ * Terminal disposal: cancels pending acquires, reaps every owned child
52
+ * (including in-flight startups), and rejects later acquires.
53
+ */
54
+ closeAll: () => Promise<void>;
55
+ ownedCount: () => number;
56
+ };
57
+ export type ServeTunnelManagerOptions = {
58
+ /** MCP keeps idle owned tunnels; CLI tears them down when the last op releases. */
59
+ persistIdle?: boolean;
60
+ spawnSsh?: SshTunnelSpawn;
61
+ allocatePort?: () => Promise<number>;
62
+ probe?: (target: string, options?: ProbeServeOptions) => Promise<OpsResult>;
63
+ now?: () => number;
64
+ sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
65
+ };
66
+ export declare function isSshServeTarget(raw: string): boolean;
67
+ /**
68
+ * Safe label for logs/errors. Successful parses use the canonical URI.
69
+ * Failed parses omit userinfo, query, path, and fragment so secrets cannot
70
+ * echo through diagnostics.
71
+ */
72
+ export declare function describeServeTarget(raw: string): string;
73
+ /** @deprecated Use describeServeTarget; kept for callers that redacted userinfo only. */
74
+ export declare function redactSshUserinfo(raw: string): string;
75
+ export declare function formatSshServeTarget(target: ParsedSshServeTarget): string;
76
+ /**
77
+ * ssh:// is not host:port. Authority port is the SSH port when present; omitting
78
+ * it leaves Port to OpenSSH (alias ssh_config, then ssh's own default).
79
+ * `servePort` is the already-running loopback serve on the remote (default 9419).
80
+ */
81
+ export declare function parseSshServeTarget(raw: string): ParsedSshServeTarget;
82
+ /**
83
+ * Reject ControlMaster/daemonize/fork/extra forwards/remote commands that would
84
+ * outlive or escape the tracked foreground child. Combined clusters (`-fn`) and
85
+ * whitespace `-o Keyword Value` forms are parsed, not only `-o Keyword=value`.
86
+ */
87
+ export declare function assertSafeSshTunnelOpts(opts: string[]): void;
88
+ /**
89
+ * Required `-o` keywords come first so OpenSSH's first-obtained-value rule
90
+ * cannot be overridden by later user `-o` or ssh_config. `-S none` is last so
91
+ * a last-assignment ControlPath flag still loses. Explicit URI `-p` is emitted
92
+ * only when the URI supplied a port; omitted port leaves alias Port intact.
93
+ */
94
+ export declare function buildSshTunnelArgv(target: ParsedSshServeTarget, localPort: number, env?: NodeJS.ProcessEnv): SshTunnelArgv;
95
+ /** Isolated identity for an owned tunnel. Never includes the serve token or raw secrets. */
96
+ export declare function serveTunnelCacheKey(target: ParsedSshServeTarget, env?: NodeJS.ProcessEnv): string;
97
+ export declare function allocateLoopbackPort(): Promise<number>;
98
+ export declare function stripControllerRouting(args: Record<string, unknown>): Record<string, unknown>;
99
+ export declare function createServeTunnelManager(options?: ServeTunnelManagerOptions): ServeTunnelManager;
100
+ export declare function forwardServe(input: {
101
+ target: string;
102
+ args: Record<string, unknown>;
103
+ timeoutMs: number;
104
+ token?: string;
105
+ signal?: AbortSignal;
106
+ env?: NodeJS.ProcessEnv;
107
+ manager?: ServeTunnelManager;
108
+ now?: () => number;
109
+ }): Promise<OpsResult>;