@pyrokine/mcp-ssh 2.4.3 → 3.1.0
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 +257 -49
- package/README_zh.md +251 -68
- package/dist/command-risk.d.ts +2 -1
- package/dist/command-risk.js +238 -87
- package/dist/directory-verification.d.ts +7 -3
- package/dist/directory-verification.js +302 -208
- package/dist/file-mode.d.ts +6 -0
- package/dist/file-mode.js +71 -0
- package/dist/file-ops.d.ts +38 -7
- package/dist/file-ops.js +822 -293
- package/dist/forward-manager.d.ts +2 -0
- package/dist/forward-manager.js +19 -10
- package/dist/openssh.d.ts +51 -0
- package/dist/openssh.js +528 -0
- package/dist/operation-manager.d.ts +4 -4
- package/dist/operation-manager.js +28 -3
- package/dist/pty-manager.d.ts +5 -13
- package/dist/pty-manager.js +47 -15
- package/dist/remote-platform.d.ts +13 -0
- package/dist/remote-platform.js +132 -0
- package/dist/security.js +12 -2
- package/dist/session-manager.d.ts +31 -15
- package/dist/session-manager.js +483 -120
- package/dist/ssh-config.d.ts +3 -0
- package/dist/ssh-config.js +48 -20
- package/dist/tools/connection.js +132 -3
- package/dist/tools/exec.d.ts +1 -0
- package/dist/tools/exec.js +108 -31
- package/dist/tools/file.js +406 -129
- package/dist/tools/operation.js +1 -1
- package/dist/tools/pty.js +5 -3
- package/dist/tools/utils.js +2 -2
- package/dist/types.d.ts +63 -2
- package/dist/utf8.d.ts +1 -0
- package/dist/utf8.js +10 -0
- package/dist/windows-acl.d.ts +4 -0
- package/dist/windows-acl.js +109 -0
- package/package.json +4 -3
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const S_IFMT = 0o170000;
|
|
2
|
+
const S_IFDIR = 0o040000;
|
|
3
|
+
const S_IFREG = 0o100000;
|
|
4
|
+
const S_IFLNK = 0o120000;
|
|
5
|
+
export const FILE_CREATE_MODE_MASK = 0o777;
|
|
6
|
+
export const FILE_MODE_MASK = 0o7777;
|
|
7
|
+
export function extractFileMode(mode) {
|
|
8
|
+
return mode & FILE_MODE_MASK;
|
|
9
|
+
}
|
|
10
|
+
export function formatFileMode(mode) {
|
|
11
|
+
return extractFileMode(mode).toString(8).padStart(4, '0');
|
|
12
|
+
}
|
|
13
|
+
function executeCharacter(mode, executeBit, specialBit, special) {
|
|
14
|
+
if (mode & specialBit) {
|
|
15
|
+
return mode & executeBit ? special : special.toUpperCase();
|
|
16
|
+
}
|
|
17
|
+
return mode & executeBit ? 'x' : '-';
|
|
18
|
+
}
|
|
19
|
+
export function formatFilePermissions(mode) {
|
|
20
|
+
const fileType = mode & S_IFMT;
|
|
21
|
+
const type = fileType === S_IFDIR ? 'd' : fileType === S_IFLNK ? 'l' : fileType === S_IFREG ? '-' : '?';
|
|
22
|
+
const permissions = [
|
|
23
|
+
mode & 0o400 ? 'r' : '-',
|
|
24
|
+
mode & 0o200 ? 'w' : '-',
|
|
25
|
+
executeCharacter(mode, 0o100, 0o4000, 's'),
|
|
26
|
+
mode & 0o040 ? 'r' : '-',
|
|
27
|
+
mode & 0o020 ? 'w' : '-',
|
|
28
|
+
executeCharacter(mode, 0o010, 0o2000, 's'),
|
|
29
|
+
mode & 0o004 ? 'r' : '-',
|
|
30
|
+
mode & 0o002 ? 'w' : '-',
|
|
31
|
+
executeCharacter(mode, 0o001, 0o1000, 't'),
|
|
32
|
+
];
|
|
33
|
+
return type + permissions.join('');
|
|
34
|
+
}
|
|
35
|
+
export function parseExpectedFileMode(value) {
|
|
36
|
+
const trimmed = value.trim();
|
|
37
|
+
if (/^[0-7]{3,4}$/.test(trimmed)) {
|
|
38
|
+
return Number.parseInt(trimmed, 8) & FILE_MODE_MASK;
|
|
39
|
+
}
|
|
40
|
+
const match = /^(?:[-dl?])?([r-][w-][xSs-][r-][w-][xSs-][r-][w-][xTt-])$/.exec(trimmed);
|
|
41
|
+
if (!match) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const bits = match[1];
|
|
45
|
+
let mode = 0;
|
|
46
|
+
if (bits[0] === 'r')
|
|
47
|
+
mode |= 0o400;
|
|
48
|
+
if (bits[1] === 'w')
|
|
49
|
+
mode |= 0o200;
|
|
50
|
+
if (bits[2] === 'x' || bits[2] === 's')
|
|
51
|
+
mode |= 0o100;
|
|
52
|
+
if (bits[2] === 's' || bits[2] === 'S')
|
|
53
|
+
mode |= 0o4000;
|
|
54
|
+
if (bits[3] === 'r')
|
|
55
|
+
mode |= 0o040;
|
|
56
|
+
if (bits[4] === 'w')
|
|
57
|
+
mode |= 0o020;
|
|
58
|
+
if (bits[5] === 'x' || bits[5] === 's')
|
|
59
|
+
mode |= 0o010;
|
|
60
|
+
if (bits[5] === 's' || bits[5] === 'S')
|
|
61
|
+
mode |= 0o2000;
|
|
62
|
+
if (bits[6] === 'r')
|
|
63
|
+
mode |= 0o004;
|
|
64
|
+
if (bits[7] === 'w')
|
|
65
|
+
mode |= 0o002;
|
|
66
|
+
if (bits[8] === 'x' || bits[8] === 't')
|
|
67
|
+
mode |= 0o001;
|
|
68
|
+
if (bits[8] === 't' || bits[8] === 'T')
|
|
69
|
+
mode |= 0o1000;
|
|
70
|
+
return mode;
|
|
71
|
+
}
|
package/dist/file-ops.d.ts
CHANGED
|
@@ -16,6 +16,17 @@ type RsyncProbeResult = {
|
|
|
16
16
|
};
|
|
17
17
|
/** 由 SessionManager.disconnect 调用,防止 alias 重连后读到旧主机的判断 */
|
|
18
18
|
export declare function clearRsyncCache(alias?: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* 校验本地路径是否在 SSH_MCP_FILE_OPS_ALLOW_DIRS 白名单内
|
|
21
|
+
*
|
|
22
|
+
* 默认未设置环境变量时不限制(保留灵活性)
|
|
23
|
+
* 设置后,所有 upload/download/sync 的本地路径必须在白名单目录之一内,否则抛出错误
|
|
24
|
+
*
|
|
25
|
+
* 格式:path.delimiter 分隔的绝对路径列表(POSIX `:`,Windows `;`),如 `/tmp:/home/user/work`
|
|
26
|
+
* 安全性:路径会通过 fs.realpathSync 解析 symlink,防止 symlink 逃出白名单
|
|
27
|
+
*/
|
|
28
|
+
export declare function convertRsyncPath(value: string, profile: 'posix' | 'native-win32' | 'msys2' | 'cygwin'): string;
|
|
29
|
+
export declare function quoteRsyncSshArg(value: string | number, profile?: 'posix' | 'native-win32' | 'msys2' | 'cygwin'): string;
|
|
19
30
|
export declare function validateLocalPathPolicy(localPath: string): void;
|
|
20
31
|
type ValidatedLocalUploadSource = {
|
|
21
32
|
expandedPath: string;
|
|
@@ -35,6 +46,7 @@ export declare function probeLocalPath(localPath: string, followSymlinks?: boole
|
|
|
35
46
|
};
|
|
36
47
|
size?: undefined;
|
|
37
48
|
mode?: undefined;
|
|
49
|
+
modeValue?: undefined;
|
|
38
50
|
mtimeMs?: undefined;
|
|
39
51
|
isSymlink?: undefined;
|
|
40
52
|
isDirectory?: undefined;
|
|
@@ -46,6 +58,7 @@ export declare function probeLocalPath(localPath: string, followSymlinks?: boole
|
|
|
46
58
|
resolvedPath: string;
|
|
47
59
|
size: number;
|
|
48
60
|
mode: string;
|
|
61
|
+
modeValue: number;
|
|
49
62
|
mtimeMs: number;
|
|
50
63
|
isSymlink: boolean;
|
|
51
64
|
isDirectory: boolean;
|
|
@@ -55,12 +68,19 @@ export declare function probeLocalPath(localPath: string, followSymlinks?: boole
|
|
|
55
68
|
matched?: boolean;
|
|
56
69
|
};
|
|
57
70
|
};
|
|
58
|
-
export declare function hashRemoteFileDigest(alias: string, remotePath: string, algorithm: 'md5' | 'sha256'
|
|
71
|
+
export declare function hashRemoteFileDigest(alias: string, remotePath: string, algorithm: 'md5' | 'sha256', timeout?: number, limits?: {
|
|
72
|
+
maxBytes: number;
|
|
73
|
+
expectedSize: number;
|
|
74
|
+
}): Promise<string>;
|
|
75
|
+
export declare function atomicReplaceCapability(alias: string, timeout?: number): Promise<{
|
|
76
|
+
atomicReplaceSupported: boolean;
|
|
77
|
+
reason?: string;
|
|
78
|
+
}>;
|
|
59
79
|
export declare class RemoteRenameNotStartedError extends Error {
|
|
60
80
|
constructor(message: string);
|
|
61
81
|
}
|
|
62
82
|
export declare function renameRemoteFile(alias: string, sourcePath: string, targetPath: string, replaceExisting?: boolean, timeout?: number): Promise<void>;
|
|
63
|
-
export declare function removeRemoteFile(alias: string, remotePath: string): Promise<void>;
|
|
83
|
+
export declare function removeRemoteFile(alias: string, remotePath: string, timeout?: number): Promise<void>;
|
|
64
84
|
export declare class UploadFileError extends Error {
|
|
65
85
|
readonly remoteCreated: boolean;
|
|
66
86
|
readonly details?: Record<string, unknown>;
|
|
@@ -85,7 +105,10 @@ export declare function downloadFile(alias: string, remotePath: string, localPat
|
|
|
85
105
|
export declare const DEFAULT_READ_FILE_MAX_BYTES: number;
|
|
86
106
|
export declare const HARD_READ_FILE_MAX_BYTES: number;
|
|
87
107
|
type ReadFileSampleKind = 'full' | 'head' | 'tail' | 'range' | 'line_range';
|
|
108
|
+
export type ReadEncoding = 'auto' | 'utf8' | 'utf16le' | 'utf16be' | 'gbk';
|
|
88
109
|
type ReadFileOptions = {
|
|
110
|
+
encoding?: ReadEncoding;
|
|
111
|
+
binary?: boolean;
|
|
89
112
|
maxBytes?: number;
|
|
90
113
|
offset?: number;
|
|
91
114
|
tail?: boolean;
|
|
@@ -94,6 +117,8 @@ type ReadFileOptions = {
|
|
|
94
117
|
};
|
|
95
118
|
type ReadFileResult = {
|
|
96
119
|
content: string;
|
|
120
|
+
encoding?: ReadEncoding | 'base64';
|
|
121
|
+
content_base64?: string;
|
|
97
122
|
size: number;
|
|
98
123
|
total_size: number;
|
|
99
124
|
read_offset: number;
|
|
@@ -110,11 +135,12 @@ type ReadFileResult = {
|
|
|
110
135
|
byte_limit_reached?: boolean;
|
|
111
136
|
final_line_terminated?: boolean;
|
|
112
137
|
};
|
|
113
|
-
export declare function buildLineRangeAwkProgram(start: number, end: number): string;
|
|
114
138
|
/**
|
|
115
139
|
* 读取远程文件内容
|
|
116
140
|
*/
|
|
117
141
|
export declare function readFile(alias: string, remotePath: string, options?: number | ReadFileOptions): Promise<ReadFileResult>;
|
|
142
|
+
export declare function createEmptyRemoteFile(alias: string, remotePath: string, timeout?: number): Promise<void>;
|
|
143
|
+
export declare function prepareWindowsRemotePrivateFile(alias: string, remotePath: string, timeout?: number, shellPath?: string): Promise<void>;
|
|
118
144
|
/**
|
|
119
145
|
* 写入远程文件
|
|
120
146
|
*/
|
|
@@ -125,19 +151,19 @@ export declare function writeFile(alias: string, remotePath: string, content: st
|
|
|
125
151
|
/**
|
|
126
152
|
* 列出目录内容
|
|
127
153
|
*/
|
|
128
|
-
export declare function listDir(alias: string, remotePath: string, showHidden?: boolean, sharedSftp?: SFTPWrapper, timeout?: number): Promise<FileInfo[]>;
|
|
154
|
+
export declare function listDir(alias: string, remotePath: string, showHidden?: boolean, sharedSftp?: SFTPWrapper, timeout?: number, style?: 'posix' | 'win32' | 'sftp-posix'): Promise<FileInfo[]>;
|
|
129
155
|
/**
|
|
130
156
|
* 获取文件信息
|
|
131
157
|
*/
|
|
132
|
-
export declare function getFileInfo(alias: string, remotePath: string, timeout?: number): Promise<FileInfo>;
|
|
158
|
+
export declare function getFileInfo(alias: string, remotePath: string, timeout?: number, style?: 'posix' | 'win32' | 'sftp-posix'): Promise<FileInfo>;
|
|
133
159
|
/**
|
|
134
160
|
* 创建目录
|
|
135
161
|
*/
|
|
136
|
-
export declare function mkdir(alias: string, remotePath: string, recursive?: boolean, sharedSftp?: SFTPWrapper, timeout?: number): Promise<boolean>;
|
|
162
|
+
export declare function mkdir(alias: string, remotePath: string, recursive?: boolean, sharedSftp?: SFTPWrapper, timeout?: number, style?: 'posix' | 'win32' | 'sftp-posix'): Promise<boolean>;
|
|
137
163
|
/**
|
|
138
164
|
* 检查远程是否安装 rsync
|
|
139
165
|
*/
|
|
140
|
-
export declare function checkRsync(alias: string, timeout?: number): Promise<RsyncProbeResult>;
|
|
166
|
+
export declare function checkRsync(alias: string, timeout?: number, executable?: string, shell?: 'posix' | 'cmd' | 'powershell'): Promise<RsyncProbeResult>;
|
|
141
167
|
type SyncOptions = {
|
|
142
168
|
delete?: boolean;
|
|
143
169
|
dryRun?: boolean;
|
|
@@ -149,6 +175,7 @@ type SyncOptions = {
|
|
|
149
175
|
operationTimeout?: number;
|
|
150
176
|
sourceIsDirectory?: boolean;
|
|
151
177
|
signal?: AbortSignal;
|
|
178
|
+
remotePathStyle?: 'posix' | 'win32' | 'sftp-posix';
|
|
152
179
|
};
|
|
153
180
|
/**
|
|
154
181
|
* 智能文件同步(根据连接能力选择 rsync 或 SFTP)
|
|
@@ -207,4 +234,8 @@ type SyncResult = {
|
|
|
207
234
|
commandSummary?: Record<string, unknown>;
|
|
208
235
|
output?: string;
|
|
209
236
|
};
|
|
237
|
+
export declare function hashLocalFile(filePath: string, algorithm?: 'md5' | 'sha256', timeout?: number, limits?: {
|
|
238
|
+
maxBytes: number;
|
|
239
|
+
expectedSize: number;
|
|
240
|
+
}): Promise<string>;
|
|
210
241
|
export {};
|