@pyrokine/mcp-ssh 2.3.2 → 2.4.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.
- package/README.md +141 -27
- package/README_zh.md +76 -27
- package/dist/command-risk.d.ts +7 -0
- package/dist/command-risk.js +106 -0
- package/dist/directory-verification.d.ts +43 -0
- package/dist/directory-verification.js +485 -0
- package/dist/file-ops.d.ts +77 -14
- package/dist/file-ops.js +839 -205
- package/dist/forward-manager.d.ts +22 -3
- package/dist/forward-manager.js +501 -85
- package/dist/index.js +2 -1
- package/dist/operation-manager.d.ts +64 -0
- package/dist/operation-manager.js +545 -0
- package/dist/pty-manager.d.ts +1 -0
- package/dist/pty-manager.js +11 -7
- package/dist/session-manager.d.ts +47 -11
- package/dist/session-manager.js +564 -114
- package/dist/tools/connection.js +58 -17
- package/dist/tools/exec.js +7 -66
- package/dist/tools/file.d.ts +1 -0
- package/dist/tools/file.js +575 -119
- package/dist/tools/forward.js +18 -8
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/operation.d.ts +2 -0
- package/dist/tools/operation.js +134 -0
- package/dist/tools/utils.d.ts +2 -2
- package/dist/transfer-outcome.d.ts +12 -0
- package/dist/transfer-outcome.js +72 -0
- package/dist/types.d.ts +95 -6
- package/package.json +10 -8
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - 会话持久化
|
|
9
9
|
*/
|
|
10
10
|
import { Client, SFTPWrapper } from 'ssh2';
|
|
11
|
-
import { ExecOptions, ExecResult, PortForwardInfo, PtyOptions, PtySessionInfo, SSHConnectionConfig,
|
|
11
|
+
import { ExecOptions, ExecResult, ExternalTransferCapability, ForwardCloseOptions, ForwardCloseResult, OperationCancelResult, OperationInfo, OperationReadResult, OperationStartOptions, PortForwardInfo, PtyOptions, PtySessionInfo, SSHConnectionConfig, SSHSessionBrief, SSHSessionDetail } from './types.js';
|
|
12
12
|
interface SSHSession {
|
|
13
13
|
client: Client;
|
|
14
14
|
config: SSHConnectionConfig;
|
|
@@ -20,12 +20,26 @@ interface SSHSession {
|
|
|
20
20
|
/** 当前正在等待的重连定时器,disconnect 时需要清除以防 zombie 重连 */
|
|
21
21
|
reconnectTimer?: NodeJS.Timeout;
|
|
22
22
|
}
|
|
23
|
+
interface SessionConnectionInfo {
|
|
24
|
+
alias: string;
|
|
25
|
+
identity: string;
|
|
26
|
+
loginUser: string;
|
|
27
|
+
runAs?: string;
|
|
28
|
+
host: string;
|
|
29
|
+
port: number;
|
|
30
|
+
defaultEnvKeys: string[];
|
|
31
|
+
envKeys: string[];
|
|
32
|
+
hasJumpHost: boolean;
|
|
33
|
+
}
|
|
23
34
|
export declare class SessionManager {
|
|
24
35
|
private sessions;
|
|
25
36
|
/** per-alias connect 进行中的 Promise,防止并发 connect 同一 alias 时重复建连 */
|
|
26
37
|
private connectInFlight;
|
|
38
|
+
private pendingConnections;
|
|
39
|
+
private connectionGenerations;
|
|
27
40
|
private readonly ptyManager;
|
|
28
41
|
private readonly forwardManager;
|
|
42
|
+
private readonly operationManager;
|
|
29
43
|
private readonly persistPath;
|
|
30
44
|
private defaultKeepaliveInterval;
|
|
31
45
|
private defaultKeepaliveCountMax;
|
|
@@ -52,14 +66,23 @@ export declare class SessionManager {
|
|
|
52
66
|
* 获取会话
|
|
53
67
|
*/
|
|
54
68
|
getSession(alias: string): SSHSession;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
listSessions(): SSHSessionBrief[];
|
|
70
|
+
listSessionDetails(): SSHSessionDetail[];
|
|
71
|
+
getSessionConnectionInfo(alias: string): SessionConnectionInfo;
|
|
72
|
+
getExternalTransferCapability(alias: string): ExternalTransferCapability;
|
|
59
73
|
/**
|
|
60
74
|
* 执行命令
|
|
61
75
|
*/
|
|
62
76
|
exec(alias: string, command: string, options?: ExecOptions): Promise<ExecResult>;
|
|
77
|
+
operationStart(alias: string, command: string, options?: OperationStartOptions): Promise<OperationInfo>;
|
|
78
|
+
operationStatus(operationId: string): OperationInfo;
|
|
79
|
+
operationRead(operationId: string, options?: {
|
|
80
|
+
stdoutOffset?: number;
|
|
81
|
+
stderrOffset?: number;
|
|
82
|
+
maxBytes?: number;
|
|
83
|
+
}): OperationReadResult;
|
|
84
|
+
operationCancel(operationId: string): Promise<OperationCancelResult>;
|
|
85
|
+
operationList(alias?: string): OperationInfo[];
|
|
63
86
|
/**
|
|
64
87
|
* 以其他用户身份执行命令
|
|
65
88
|
*
|
|
@@ -105,17 +128,25 @@ export declare class SessionManager {
|
|
|
105
128
|
forwardId: string;
|
|
106
129
|
localPort: number;
|
|
107
130
|
}>;
|
|
108
|
-
forwardRemote(alias: string, remotePort: number, localHost: string, localPort: number, remoteHost?: string): Promise<
|
|
109
|
-
|
|
131
|
+
forwardRemote(alias: string, remotePort: number, localHost: string, localPort: number, remoteHost?: string): Promise<{
|
|
132
|
+
forwardId: string;
|
|
133
|
+
remotePort: number;
|
|
134
|
+
}>;
|
|
135
|
+
forwardClose(forwardId: string, options?: ForwardCloseOptions): Promise<ForwardCloseResult>;
|
|
110
136
|
forwardList(): PortForwardInfo[];
|
|
137
|
+
private isSshAgentAvailable;
|
|
138
|
+
private isOpenSshKeyPathUsable;
|
|
111
139
|
private sessionIdentity;
|
|
112
140
|
private configIdentity;
|
|
141
|
+
private connectionFingerprint;
|
|
113
142
|
private resultMetadata;
|
|
114
143
|
private appendOutputTail;
|
|
115
144
|
private recommendedReadCommand;
|
|
116
145
|
private emptyOutputFailureMetadata;
|
|
117
146
|
private outputMetadata;
|
|
118
147
|
private normalizeMaxOutputSize;
|
|
148
|
+
private openOperationStream;
|
|
149
|
+
private cancelRemoteOperation;
|
|
119
150
|
private execDirect;
|
|
120
151
|
private connectInternal;
|
|
121
152
|
/**
|
|
@@ -131,19 +162,24 @@ export declare class SessionManager {
|
|
|
131
162
|
* 通过跳板机转发连接
|
|
132
163
|
*/
|
|
133
164
|
private forwardConnection;
|
|
165
|
+
private getConnectionGeneration;
|
|
166
|
+
private isCurrentPendingConnection;
|
|
167
|
+
private cancelPendingConnection;
|
|
168
|
+
private invalidateAliasResources;
|
|
134
169
|
/**
|
|
135
170
|
* 检查连接是否存活
|
|
136
171
|
*/
|
|
137
172
|
private isAlive;
|
|
173
|
+
private isCurrentSession;
|
|
174
|
+
private closeClientChannel;
|
|
175
|
+
private destroySftp;
|
|
138
176
|
/**
|
|
139
177
|
* 调度自动重连(支持多次重试)
|
|
140
178
|
*/
|
|
141
179
|
private scheduleReconnect;
|
|
142
180
|
private createCommandTimeoutError;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
*/
|
|
146
|
-
private diagnoseConnectionError;
|
|
181
|
+
private createConnectionError;
|
|
182
|
+
private classifyConnectionError;
|
|
147
183
|
/**
|
|
148
184
|
* 转义 shell 参数(使用单引号方式,防止命令注入)
|
|
149
185
|
* 委托给 tools/utils.ts 的共享实现
|