@j0hanz/filesystem-mcp 1.19.0 → 2.0.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 +333 -838
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +169 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/cli.d.ts +28 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +168 -123
- package/dist/cli.js.map +1 -0
- package/dist/core/concurrency.d.ts +70 -0
- package/dist/core/concurrency.d.ts.map +1 -0
- package/dist/core/concurrency.js +173 -0
- package/dist/core/concurrency.js.map +1 -0
- package/dist/core/config.d.ts +19 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +11 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/cursor.d.ts +23 -0
- package/dist/core/cursor.d.ts.map +1 -0
- package/dist/core/cursor.js +62 -0
- package/dist/core/cursor.js.map +1 -0
- package/dist/core/errors.d.ts +96 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +356 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/file-uri.d.ts +24 -0
- package/dist/core/file-uri.d.ts.map +1 -0
- package/dist/core/file-uri.js +52 -0
- package/dist/core/file-uri.js.map +1 -0
- package/dist/core/fmt.d.ts +38 -0
- package/dist/core/fmt.d.ts.map +1 -0
- package/dist/core/fmt.js +109 -0
- package/dist/core/fmt.js.map +1 -0
- package/dist/core/fs.d.ts +108 -0
- package/dist/core/fs.d.ts.map +1 -0
- package/dist/core/fs.js +243 -0
- package/dist/core/fs.js.map +1 -0
- package/dist/core/glob.d.ts +41 -0
- package/dist/core/glob.d.ts.map +1 -0
- package/dist/core/glob.js +399 -0
- package/dist/core/glob.js.map +1 -0
- package/dist/core/input-required.d.ts +147 -0
- package/dist/core/input-required.d.ts.map +1 -0
- package/dist/core/input-required.js +261 -0
- package/dist/core/input-required.js.map +1 -0
- package/dist/core/mime.d.ts +15 -0
- package/dist/core/mime.d.ts.map +1 -0
- package/dist/core/mime.js +188 -0
- package/dist/core/mime.js.map +1 -0
- package/dist/core/observability.d.ts +10 -0
- package/dist/core/observability.d.ts.map +1 -0
- package/dist/core/observability.js +76 -0
- package/dist/core/observability.js.map +1 -0
- package/dist/core/page-store.d.ts +41 -0
- package/dist/core/page-store.d.ts.map +1 -0
- package/dist/core/page-store.js +74 -0
- package/dist/core/page-store.js.map +1 -0
- package/dist/core/path-completer.d.ts +10 -0
- package/dist/core/path-completer.d.ts.map +1 -0
- package/dist/core/path-completer.js +227 -0
- package/dist/core/path-completer.js.map +1 -0
- package/dist/core/path-discovery.d.ts +8 -0
- package/dist/core/path-discovery.d.ts.map +1 -0
- package/dist/core/path-discovery.js +105 -0
- package/dist/core/path-discovery.js.map +1 -0
- package/dist/core/path-utils.d.ts +9 -0
- package/dist/core/path-utils.d.ts.map +1 -0
- package/dist/core/path-utils.js +121 -0
- package/dist/core/path-utils.js.map +1 -0
- package/dist/core/path.d.ts +148 -0
- package/dist/core/path.d.ts.map +1 -0
- package/dist/core/path.js +674 -0
- package/dist/core/path.js.map +1 -0
- package/dist/core/primitives.d.ts +23 -0
- package/dist/core/primitives.d.ts.map +1 -0
- package/dist/core/primitives.js +54 -0
- package/dist/core/primitives.js.map +1 -0
- package/dist/core/read.d.ts +74 -0
- package/dist/core/read.d.ts.map +1 -0
- package/dist/core/read.js +562 -0
- package/dist/core/read.js.map +1 -0
- package/dist/core/schema.d.ts +139 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +345 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/search.d.ts +100 -0
- package/dist/core/search.d.ts.map +1 -0
- package/dist/core/search.js +248 -0
- package/dist/core/search.js.map +1 -0
- package/dist/core/sensitive.d.ts +6 -0
- package/dist/core/sensitive.d.ts.map +1 -0
- package/dist/core/sensitive.js +142 -0
- package/dist/core/sensitive.js.map +1 -0
- package/dist/core/store.d.ts +57 -0
- package/dist/core/store.d.ts.map +1 -0
- package/dist/core/store.js +162 -0
- package/dist/core/store.js.map +1 -0
- package/dist/core/util.d.ts +26 -0
- package/dist/core/util.d.ts.map +1 -0
- package/dist/core/util.js +66 -0
- package/dist/core/util.js.map +1 -0
- package/dist/core/watcher-registry.d.ts +68 -0
- package/dist/core/watcher-registry.d.ts.map +1 -0
- package/dist/core/watcher-registry.js +312 -0
- package/dist/core/watcher-registry.js.map +1 -0
- package/dist/http-policy.d.ts +121 -0
- package/dist/http-policy.d.ts.map +1 -0
- package/dist/http-policy.js +340 -0
- package/dist/http-policy.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -41
- package/dist/index.js.map +1 -0
- package/dist/instructions.d.ts +12 -0
- package/dist/instructions.d.ts.map +1 -0
- package/dist/instructions.js +71 -0
- package/dist/instructions.js.map +1 -0
- package/dist/prompts.d.ts +8 -6
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +74 -168
- package/dist/prompts.js.map +1 -0
- package/dist/resources.d.ts +73 -9
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +392 -163
- package/dist/resources.js.map +1 -0
- package/dist/server.d.ts +62 -1
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +139 -1
- package/dist/server.js.map +1 -0
- package/dist/tools/batch.d.ts +89 -0
- package/dist/tools/batch.d.ts.map +1 -0
- package/dist/tools/batch.js +157 -0
- package/dist/tools/batch.js.map +1 -0
- package/dist/tools/create.d.ts +2 -0
- package/dist/tools/create.d.ts.map +1 -0
- package/dist/tools/create.js +142 -0
- package/dist/tools/create.js.map +1 -0
- package/dist/tools/define.d.ts +110 -0
- package/dist/tools/define.d.ts.map +1 -0
- package/dist/tools/define.js +394 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/delete-file.d.ts +2 -4
- package/dist/tools/delete-file.d.ts.map +1 -0
- package/dist/tools/delete-file.js +330 -87
- package/dist/tools/delete-file.js.map +1 -0
- package/dist/tools/diff.d.ts +2 -0
- package/dist/tools/diff.d.ts.map +1 -0
- package/dist/tools/diff.js +94 -0
- package/dist/tools/diff.js.map +1 -0
- package/dist/tools/edit.d.ts +2 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +442 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/index.d.ts +26 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +52 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/list.d.ts +2 -0
- package/dist/tools/list.d.ts.map +1 -0
- package/dist/tools/list.js +291 -0
- package/dist/tools/list.js.map +1 -0
- package/dist/tools/move.d.ts +2 -0
- package/dist/tools/move.d.ts.map +1 -0
- package/dist/tools/move.js +321 -0
- package/dist/tools/move.js.map +1 -0
- package/dist/tools/patch.d.ts +2 -0
- package/dist/tools/patch.d.ts.map +1 -0
- package/dist/tools/patch.js +155 -0
- package/dist/tools/patch.js.map +1 -0
- package/dist/tools/progress.d.ts +52 -0
- package/dist/tools/progress.d.ts.map +1 -0
- package/dist/tools/progress.js +172 -0
- package/dist/tools/progress.js.map +1 -0
- package/dist/tools/read.d.ts +2 -4
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +398 -152
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/replace-in-files.d.ts +2 -4
- package/dist/tools/replace-in-files.d.ts.map +1 -0
- package/dist/tools/replace-in-files.js +435 -264
- package/dist/tools/replace-in-files.js.map +1 -0
- package/dist/tools/roots.d.ts +2 -4
- package/dist/tools/roots.d.ts.map +1 -0
- package/dist/tools/roots.js +29 -52
- package/dist/tools/roots.js.map +1 -0
- package/dist/tools/search-content.d.ts +2 -4
- package/dist/tools/search-content.d.ts.map +1 -0
- package/dist/tools/search-content.js +262 -228
- package/dist/tools/search-content.js.map +1 -0
- package/dist/tools/search-files.d.ts +2 -4
- package/dist/tools/search-files.d.ts.map +1 -0
- package/dist/tools/search-files.js +162 -161
- package/dist/tools/search-files.js.map +1 -0
- package/dist/tools/stat.d.ts +2 -4
- package/dist/tools/stat.d.ts.map +1 -0
- package/dist/tools/stat.js +202 -62
- package/dist/tools/stat.js.map +1 -0
- package/dist/transport/http.d.ts +5 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +276 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/shared.d.ts +45 -0
- package/dist/transport/shared.d.ts.map +1 -0
- package/dist/transport/shared.js +65 -0
- package/dist/transport/shared.js.map +1 -0
- package/dist/transport/stdio.d.ts +32 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/transport/stdio.js +279 -0
- package/dist/transport/stdio.js.map +1 -0
- package/dist/transport.d.ts +5 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +4 -0
- package/dist/transport.js.map +1 -0
- package/package.json +37 -46
- package/dist/assets/logo.svg +0 -35
- package/dist/completions.d.ts +0 -2
- package/dist/completions.js +0 -572
- package/dist/config.d.ts +0 -119
- package/dist/config.js +0 -31
- package/dist/lib/abort.d.ts +0 -7
- package/dist/lib/abort.js +0 -81
- package/dist/lib/constants.d.ts +0 -42
- package/dist/lib/constants.js +0 -313
- package/dist/lib/errors.d.ts +0 -28
- package/dist/lib/errors.js +0 -301
- package/dist/lib/file-operations/core.d.ts +0 -53
- package/dist/lib/file-operations/core.js +0 -144
- package/dist/lib/file-operations/metadata.d.ts +0 -77
- package/dist/lib/file-operations/metadata.js +0 -878
- package/dist/lib/file-operations/search.d.ts +0 -46
- package/dist/lib/file-operations/search.js +0 -1194
- package/dist/lib/file-operations/traversal.d.ts +0 -40
- package/dist/lib/file-operations/traversal.js +0 -310
- package/dist/lib/fs-helpers.d.ts +0 -46
- package/dist/lib/fs-helpers.js +0 -606
- package/dist/lib/globs.d.ts +0 -2
- package/dist/lib/globs.js +0 -19
- package/dist/lib/logger.d.ts +0 -27
- package/dist/lib/logger.js +0 -91
- package/dist/lib/observability.d.ts +0 -33
- package/dist/lib/observability.js +0 -373
- package/dist/lib/paths.d.ts +0 -35
- package/dist/lib/paths.js +0 -634
- package/dist/lib/resource-store.d.ts +0 -28
- package/dist/lib/resource-store.js +0 -195
- package/dist/lib/utils.d.ts +0 -7
- package/dist/lib/utils.js +0 -37
- package/dist/lib/zod-codecs.d.ts +0 -2
- package/dist/lib/zod-codecs.js +0 -18
- package/dist/pkg-info.d.ts +0 -7
- package/dist/pkg-info.js +0 -9
- package/dist/resources/generated-instructions.d.ts +0 -1
- package/dist/resources/generated-instructions.js +0 -105
- package/dist/resources/tool-catalog.d.ts +0 -2
- package/dist/resources/tool-catalog.js +0 -78
- package/dist/resources/tool-info.d.ts +0 -9
- package/dist/resources/tool-info.js +0 -206
- package/dist/resources/workflows.d.ts +0 -1
- package/dist/resources/workflows.js +0 -72
- package/dist/schemas.d.ts +0 -505
- package/dist/schemas.js +0 -676
- package/dist/server/bootstrap.d.ts +0 -6
- package/dist/server/bootstrap.js +0 -563
- package/dist/server/event-store.d.ts +0 -18
- package/dist/server/event-store.js +0 -71
- package/dist/server/roots-manager.d.ts +0 -28
- package/dist/server/roots-manager.js +0 -227
- package/dist/server/task-store.d.ts +0 -10
- package/dist/server/task-store.js +0 -91
- package/dist/tools/apply-patch.d.ts +0 -4
- package/dist/tools/apply-patch.js +0 -235
- package/dist/tools/calculate-hash.d.ts +0 -4
- package/dist/tools/calculate-hash.js +0 -187
- package/dist/tools/contract.d.ts +0 -50
- package/dist/tools/contract.js +0 -1
- package/dist/tools/create-directory.d.ts +0 -4
- package/dist/tools/create-directory.js +0 -68
- package/dist/tools/diff-files.d.ts +0 -4
- package/dist/tools/diff-files.js +0 -136
- package/dist/tools/edit-file.d.ts +0 -4
- package/dist/tools/edit-file.js +0 -256
- package/dist/tools/icons.d.ts +0 -15
- package/dist/tools/icons.js +0 -24
- package/dist/tools/list-directory.d.ts +0 -4
- package/dist/tools/list-directory.js +0 -218
- package/dist/tools/move-file.d.ts +0 -4
- package/dist/tools/move-file.js +0 -178
- package/dist/tools/read-multiple.d.ts +0 -4
- package/dist/tools/read-multiple.js +0 -207
- package/dist/tools/shared.d.ts +0 -172
- package/dist/tools/shared.js +0 -599
- package/dist/tools/stat-many.d.ts +0 -4
- package/dist/tools/stat-many.js +0 -104
- package/dist/tools/task-support.d.ts +0 -29
- package/dist/tools/task-support.js +0 -472
- package/dist/tools/tree.d.ts +0 -4
- package/dist/tools/tree.js +0 -102
- package/dist/tools/write-file.d.ts +0 -4
- package/dist/tools/write-file.js +0 -60
- package/dist/tools.d.ts +0 -5
- package/dist/tools.js +0 -54
package/dist/lib/errors.js
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import { constants as osConstants } from 'node:os';
|
|
2
|
-
import { getSystemErrorMap, getSystemErrorName, inspect } from 'node:util';
|
|
3
|
-
import { ErrorCode, joinLines } from '../config.js';
|
|
4
|
-
import { getTraceContext } from './observability.js';
|
|
5
|
-
export { ErrorCode };
|
|
6
|
-
function isNativeError(error) {
|
|
7
|
-
const candidate = Error;
|
|
8
|
-
if (typeof candidate.isError === 'function') {
|
|
9
|
-
return candidate.isError(error);
|
|
10
|
-
}
|
|
11
|
-
return error instanceof Error;
|
|
12
|
-
}
|
|
13
|
-
export function isNodeError(error) {
|
|
14
|
-
if (!isNativeError(error))
|
|
15
|
-
return false;
|
|
16
|
-
if (!('code' in error))
|
|
17
|
-
return false;
|
|
18
|
-
const { code } = error;
|
|
19
|
-
return typeof code === 'string';
|
|
20
|
-
}
|
|
21
|
-
function getNodeErrno(error) {
|
|
22
|
-
if (!isNativeError(error))
|
|
23
|
-
return undefined;
|
|
24
|
-
if (!('errno' in error))
|
|
25
|
-
return undefined;
|
|
26
|
-
const { errno } = error;
|
|
27
|
-
if (typeof errno !== 'number' || !Number.isInteger(errno))
|
|
28
|
-
return undefined;
|
|
29
|
-
return errno;
|
|
30
|
-
}
|
|
31
|
-
function messageIncludesAny(message, patterns) {
|
|
32
|
-
return patterns.some((pattern) => message.includes(pattern));
|
|
33
|
-
}
|
|
34
|
-
const ERRNO_CODE_BY_VALUE = new Map();
|
|
35
|
-
const SYSTEM_ERROR_MAP = getSystemErrorMap();
|
|
36
|
-
for (const [name, value] of Object.entries(osConstants.errno)) {
|
|
37
|
-
if (typeof value !== 'number')
|
|
38
|
-
continue;
|
|
39
|
-
if (!ERRNO_CODE_BY_VALUE.has(value)) {
|
|
40
|
-
ERRNO_CODE_BY_VALUE.set(value, name);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const ERROR_CODE_RE = /^[A-Z][A-Z0-9_]+$/u;
|
|
44
|
-
function getSystemErrorNameFromMap(errno) {
|
|
45
|
-
const direct = SYSTEM_ERROR_MAP.get(errno);
|
|
46
|
-
if (direct)
|
|
47
|
-
return direct[0];
|
|
48
|
-
const normalized = SYSTEM_ERROR_MAP.get(-Math.abs(errno));
|
|
49
|
-
if (normalized)
|
|
50
|
-
return normalized[0];
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
function getNodeErrorCodeFromErrno(errno) {
|
|
54
|
-
const direct = ERRNO_CODE_BY_VALUE.get(errno);
|
|
55
|
-
if (direct)
|
|
56
|
-
return direct;
|
|
57
|
-
const normalized = ERRNO_CODE_BY_VALUE.get(Math.abs(errno));
|
|
58
|
-
if (normalized)
|
|
59
|
-
return normalized;
|
|
60
|
-
const fromMap = getSystemErrorNameFromMap(errno);
|
|
61
|
-
if (fromMap && ERROR_CODE_RE.test(fromMap))
|
|
62
|
-
return fromMap;
|
|
63
|
-
try {
|
|
64
|
-
const fromSystem = getSystemErrorName(errno <= 0 ? errno : -errno);
|
|
65
|
-
return ERROR_CODE_RE.test(fromSystem) ? fromSystem : undefined;
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function getNodeErrorCodeLabel(error) {
|
|
72
|
-
if (isNodeError(error))
|
|
73
|
-
return error.code;
|
|
74
|
-
const errno = getNodeErrno(error);
|
|
75
|
-
if (errno === undefined)
|
|
76
|
-
return undefined;
|
|
77
|
-
return getNodeErrorCodeFromErrno(errno);
|
|
78
|
-
}
|
|
79
|
-
export function formatUnknownErrorMessage(error) {
|
|
80
|
-
if (typeof error === 'string')
|
|
81
|
-
return error;
|
|
82
|
-
if (isNativeError(error))
|
|
83
|
-
return error.message;
|
|
84
|
-
try {
|
|
85
|
-
return inspect(error, {
|
|
86
|
-
depth: 3,
|
|
87
|
-
colors: false,
|
|
88
|
-
compact: 3,
|
|
89
|
-
breakLength: 80,
|
|
90
|
-
maxArrayLength: 50,
|
|
91
|
-
maxStringLength: 2000,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
return String(error);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
export function normalizeUnknownError(error) {
|
|
99
|
-
return error instanceof Error
|
|
100
|
-
? error
|
|
101
|
-
: new Error(formatUnknownErrorMessage(error));
|
|
102
|
-
}
|
|
103
|
-
const NODE_ERROR_CODE_MAP = {
|
|
104
|
-
ENOENT: ErrorCode.NOT_FOUND,
|
|
105
|
-
EACCES: ErrorCode.PERMISSION_DENIED,
|
|
106
|
-
EPERM: ErrorCode.PERMISSION_DENIED,
|
|
107
|
-
ENOTDIR: ErrorCode.NOT_DIRECTORY,
|
|
108
|
-
EISDIR: ErrorCode.NOT_FILE,
|
|
109
|
-
ELOOP: ErrorCode.SYMLINK_NOT_ALLOWED,
|
|
110
|
-
ENAMETOOLONG: ErrorCode.INVALID_INPUT,
|
|
111
|
-
ETIMEDOUT: ErrorCode.TIMEOUT,
|
|
112
|
-
EMFILE: ErrorCode.TIMEOUT,
|
|
113
|
-
ENFILE: ErrorCode.TIMEOUT,
|
|
114
|
-
EBUSY: ErrorCode.PERMISSION_DENIED,
|
|
115
|
-
ENOTEMPTY: ErrorCode.NOT_DIRECTORY,
|
|
116
|
-
EEXIST: ErrorCode.INVALID_INPUT,
|
|
117
|
-
EINVAL: ErrorCode.INVALID_INPUT,
|
|
118
|
-
};
|
|
119
|
-
function isKnownNodeErrorCode(code) {
|
|
120
|
-
return code in NODE_ERROR_CODE_MAP;
|
|
121
|
-
}
|
|
122
|
-
function getNodeErrorCode(code) {
|
|
123
|
-
return isKnownNodeErrorCode(code) ? NODE_ERROR_CODE_MAP[code] : undefined;
|
|
124
|
-
}
|
|
125
|
-
function walkErrorChain(error, visitor) {
|
|
126
|
-
let current = error;
|
|
127
|
-
const visited = new Set();
|
|
128
|
-
while (current !== undefined && current !== null && !visited.has(current)) {
|
|
129
|
-
const visitedResult = visitor(current);
|
|
130
|
-
if (visitedResult !== undefined)
|
|
131
|
-
return visitedResult;
|
|
132
|
-
if (!isNativeError(current))
|
|
133
|
-
break;
|
|
134
|
-
visited.add(current);
|
|
135
|
-
const next = current.cause;
|
|
136
|
-
current = next;
|
|
137
|
-
}
|
|
138
|
-
return undefined;
|
|
139
|
-
}
|
|
140
|
-
function isAbortErrorSingle(error) {
|
|
141
|
-
if (!isNativeError(error))
|
|
142
|
-
return false;
|
|
143
|
-
if (error.name === 'AbortError')
|
|
144
|
-
return true;
|
|
145
|
-
const code = getNodeErrorCodeLabel(error);
|
|
146
|
-
return code === 'ABORT_ERR';
|
|
147
|
-
}
|
|
148
|
-
export function isAbortError(error) {
|
|
149
|
-
return (walkErrorChain(error, (candidate) => isAbortErrorSingle(candidate) ? true : undefined) === true);
|
|
150
|
-
}
|
|
151
|
-
function isTimeoutErrorSingle(error) {
|
|
152
|
-
if (!isNativeError(error))
|
|
153
|
-
return false;
|
|
154
|
-
if (error.name === 'TimeoutError')
|
|
155
|
-
return true;
|
|
156
|
-
const code = getNodeErrorCodeLabel(error);
|
|
157
|
-
if (code === 'ETIMEDOUT')
|
|
158
|
-
return true;
|
|
159
|
-
const message = error.message.toLowerCase();
|
|
160
|
-
return message.includes('timed out') || message.includes('timeout');
|
|
161
|
-
}
|
|
162
|
-
export function isTimeoutLikeError(error) {
|
|
163
|
-
return (walkErrorChain(error, (candidate) => isTimeoutErrorSingle(candidate) ? true : undefined) === true);
|
|
164
|
-
}
|
|
165
|
-
export class McpError extends Error {
|
|
166
|
-
code;
|
|
167
|
-
path;
|
|
168
|
-
details;
|
|
169
|
-
constructor(code, message, path, details, cause) {
|
|
170
|
-
super(message, { cause });
|
|
171
|
-
this.code = code;
|
|
172
|
-
this.path = path;
|
|
173
|
-
this.name = 'McpError';
|
|
174
|
-
Object.setPrototypeOf(this, McpError.prototype);
|
|
175
|
-
const trace = getTraceContext();
|
|
176
|
-
if (trace?.traceparent || details) {
|
|
177
|
-
this.details = { ...trace, ...details };
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
static notFound(message, path, details, cause) {
|
|
181
|
-
return new McpError(ErrorCode.NOT_FOUND, message, path, details, cause);
|
|
182
|
-
}
|
|
183
|
-
static invalidInput(message, path, details, cause) {
|
|
184
|
-
return new McpError(ErrorCode.INVALID_INPUT, message, path, details, cause);
|
|
185
|
-
}
|
|
186
|
-
static accessDenied(message, path, details, cause) {
|
|
187
|
-
return new McpError(ErrorCode.ACCESS_DENIED, message, path, details, cause);
|
|
188
|
-
}
|
|
189
|
-
static timeout(message, path, details, cause) {
|
|
190
|
-
return new McpError(ErrorCode.TIMEOUT, message, path, details, cause);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
const ERROR_SUGGESTIONS = {
|
|
194
|
-
[ErrorCode.ACCESS_DENIED]: 'Run roots to list allowed directories.',
|
|
195
|
-
[ErrorCode.NOT_FOUND]: 'Run ls or find to verify the path.',
|
|
196
|
-
[ErrorCode.NOT_FILE]: 'Target is a directory, not a file.',
|
|
197
|
-
[ErrorCode.NOT_DIRECTORY]: 'Target is a file, not a directory.',
|
|
198
|
-
[ErrorCode.TOO_LARGE]: 'Use head/tail or line ranges to read partially.',
|
|
199
|
-
[ErrorCode.TIMEOUT]: 'Reduce scope, depth, or maxResults.',
|
|
200
|
-
[ErrorCode.CANCELLED]: undefined,
|
|
201
|
-
[ErrorCode.INVALID_PATTERN]: 'Check syntax and escape special characters.',
|
|
202
|
-
[ErrorCode.INVALID_INPUT]: undefined,
|
|
203
|
-
[ErrorCode.PERMISSION_DENIED]: 'Check OS file permissions.',
|
|
204
|
-
[ErrorCode.SYMLINK_NOT_ALLOWED]: 'Symlink escapes allowed directories.',
|
|
205
|
-
[ErrorCode.UNKNOWN]: undefined,
|
|
206
|
-
};
|
|
207
|
-
const NOT_FOUND_PATTERNS = [
|
|
208
|
-
'no such file or directory',
|
|
209
|
-
'does not exist',
|
|
210
|
-
];
|
|
211
|
-
const PERMISSION_DENIED_PATTERNS = [
|
|
212
|
-
'permission denied',
|
|
213
|
-
'not permitted',
|
|
214
|
-
];
|
|
215
|
-
function getDirectErrorCode(error) {
|
|
216
|
-
if (error instanceof McpError) {
|
|
217
|
-
return error.code;
|
|
218
|
-
}
|
|
219
|
-
const code = getNodeErrorCodeLabel(error);
|
|
220
|
-
return code ? getNodeErrorCode(code) : undefined;
|
|
221
|
-
}
|
|
222
|
-
function classifyMessageError(error) {
|
|
223
|
-
const message = isNativeError(error) ? error.message : String(error);
|
|
224
|
-
const lower = message.toLowerCase();
|
|
225
|
-
if (messageIncludesAny(lower, NOT_FOUND_PATTERNS)) {
|
|
226
|
-
return ErrorCode.NOT_FOUND;
|
|
227
|
-
}
|
|
228
|
-
if (messageIncludesAny(lower, PERMISSION_DENIED_PATTERNS)) {
|
|
229
|
-
return ErrorCode.PERMISSION_DENIED;
|
|
230
|
-
}
|
|
231
|
-
if (lower.includes('not a directory')) {
|
|
232
|
-
return ErrorCode.NOT_DIRECTORY;
|
|
233
|
-
}
|
|
234
|
-
if (lower.includes('is a directory')) {
|
|
235
|
-
return ErrorCode.NOT_FILE;
|
|
236
|
-
}
|
|
237
|
-
return undefined;
|
|
238
|
-
}
|
|
239
|
-
export function classifyError(error) {
|
|
240
|
-
let timeoutCode;
|
|
241
|
-
let fallbackCode;
|
|
242
|
-
const terminalCode = walkErrorChain(error, (candidate) => {
|
|
243
|
-
if (isAbortErrorSingle(candidate)) {
|
|
244
|
-
return ErrorCode.CANCELLED;
|
|
245
|
-
}
|
|
246
|
-
if (timeoutCode === undefined && isTimeoutErrorSingle(candidate)) {
|
|
247
|
-
timeoutCode = ErrorCode.TIMEOUT;
|
|
248
|
-
}
|
|
249
|
-
fallbackCode ??=
|
|
250
|
-
getDirectErrorCode(candidate) ?? classifyMessageError(candidate);
|
|
251
|
-
return undefined;
|
|
252
|
-
});
|
|
253
|
-
return terminalCode ?? timeoutCode ?? fallbackCode ?? ErrorCode.UNKNOWN;
|
|
254
|
-
}
|
|
255
|
-
export function createDetailedError(error, path, additionalDetails) {
|
|
256
|
-
const message = formatUnknownErrorMessage(error);
|
|
257
|
-
const code = classifyError(error);
|
|
258
|
-
const suggestion = ERROR_SUGGESTIONS[code];
|
|
259
|
-
const resolvedPath = resolveErrorPath(error, path);
|
|
260
|
-
const details = mergeErrorDetails(error, additionalDetails);
|
|
261
|
-
const result = {
|
|
262
|
-
code,
|
|
263
|
-
message,
|
|
264
|
-
...(suggestion ? { suggestion } : {}),
|
|
265
|
-
};
|
|
266
|
-
if (resolvedPath)
|
|
267
|
-
result.path = resolvedPath;
|
|
268
|
-
if (details)
|
|
269
|
-
result.details = details;
|
|
270
|
-
return result;
|
|
271
|
-
}
|
|
272
|
-
function resolveErrorPath(error, path) {
|
|
273
|
-
if (path)
|
|
274
|
-
return path;
|
|
275
|
-
if (error instanceof McpError)
|
|
276
|
-
return error.path;
|
|
277
|
-
return undefined;
|
|
278
|
-
}
|
|
279
|
-
function mergeErrorDetails(error, additionalDetails) {
|
|
280
|
-
const mcpDetails = error instanceof McpError ? error.details : undefined;
|
|
281
|
-
const mergedDetails = {
|
|
282
|
-
...mcpDetails,
|
|
283
|
-
...additionalDetails,
|
|
284
|
-
};
|
|
285
|
-
if (Object.keys(mergedDetails).length === 0)
|
|
286
|
-
return undefined;
|
|
287
|
-
return mergedDetails;
|
|
288
|
-
}
|
|
289
|
-
export function formatDetailedError(error) {
|
|
290
|
-
const lines = [`${error.code}: ${error.message}`];
|
|
291
|
-
if (error.path && !error.message.includes(error.path)) {
|
|
292
|
-
lines.push(error.path);
|
|
293
|
-
}
|
|
294
|
-
if (error.suggestion) {
|
|
295
|
-
lines.push(error.suggestion);
|
|
296
|
-
}
|
|
297
|
-
return joinLines(lines);
|
|
298
|
-
}
|
|
299
|
-
export function getSuggestion(code) {
|
|
300
|
-
return ERROR_SUGGESTIONS[code];
|
|
301
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { type Ignore } from 'ignore';
|
|
2
|
-
export declare function needsStatsForSort(sortBy: string): boolean;
|
|
3
|
-
export declare function withOptionalStoppedReason<T extends object, R extends string>(summary: T, stoppedReason: R | undefined): T & {
|
|
4
|
-
stoppedReason?: R;
|
|
5
|
-
};
|
|
6
|
-
export interface DirentLike {
|
|
7
|
-
isDirectory(): boolean;
|
|
8
|
-
isFile(): boolean;
|
|
9
|
-
isSymbolicLink(): boolean;
|
|
10
|
-
}
|
|
11
|
-
export type EntryType = 'file' | 'directory' | 'symlink' | 'other';
|
|
12
|
-
interface IndexedValue<T> {
|
|
13
|
-
index: number;
|
|
14
|
-
value: T;
|
|
15
|
-
}
|
|
16
|
-
interface IndexedError {
|
|
17
|
-
index: number;
|
|
18
|
-
error: Error;
|
|
19
|
-
}
|
|
20
|
-
export declare function resolveEntryType(dirent: DirentLike): EntryType;
|
|
21
|
-
export declare function resolveStopReason<R extends string>(options: {
|
|
22
|
-
signal: AbortSignal;
|
|
23
|
-
current: number;
|
|
24
|
-
max: number;
|
|
25
|
-
abortedReason: R;
|
|
26
|
-
maxReason: R;
|
|
27
|
-
}): R | undefined;
|
|
28
|
-
export declare function compareStringValues(left?: string, right?: string): number;
|
|
29
|
-
export declare function compareOptionalNumberDesc(left: number | undefined, right: number | undefined, tieBreak: () => number): number;
|
|
30
|
-
export declare function stableSortByDerivedString<T>(items: T[], derive: (item: T) => string, tieBreak: (left: T, right: T) => number): void;
|
|
31
|
-
export declare function applyIndexedValues<T>(output: T[], results: readonly IndexedValue<T>[]): void;
|
|
32
|
-
export declare function applyIndexedErrors<T>(options: {
|
|
33
|
-
output: T[];
|
|
34
|
-
errors: readonly IndexedError[];
|
|
35
|
-
resolveIndex: (failureIndex: number) => number | undefined;
|
|
36
|
-
buildValue: (resolvedIndex: number, error: Error) => T;
|
|
37
|
-
}): void;
|
|
38
|
-
export interface EntryAccessDependencies {
|
|
39
|
-
normalizePath: (inputPath: string) => string;
|
|
40
|
-
isPathWithinDirectories: (normalizedPath: string, rootDirectories: readonly string[]) => boolean;
|
|
41
|
-
isSensitivePath: (requestedPath: string, resolvedPath: string) => boolean;
|
|
42
|
-
validateSymlinkPath: (inputPath: string, signal: AbortSignal) => Promise<{
|
|
43
|
-
requestedPath: string;
|
|
44
|
-
resolvedPath: string;
|
|
45
|
-
}>;
|
|
46
|
-
}
|
|
47
|
-
export declare function isEntryAccessibleByType(entryPath: string, entryType: EntryType, rootDirectories: readonly string[], signal: AbortSignal, deps: EntryAccessDependencies): Promise<boolean>;
|
|
48
|
-
export declare function loadRootGitignore(root: string, signal?: AbortSignal): Promise<Ignore | null>;
|
|
49
|
-
export declare function isIgnoredByGitignore(matcher: Ignore, root: string, absolutePath: string, options?: {
|
|
50
|
-
isDirectory?: boolean;
|
|
51
|
-
relativePath?: string;
|
|
52
|
-
}): boolean;
|
|
53
|
-
export {};
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { join, relative } from 'node:path';
|
|
3
|
-
import ignore, {} from 'ignore';
|
|
4
|
-
import { isNodeError } from '../errors.js';
|
|
5
|
-
import { toPosixPath } from '../paths.js';
|
|
6
|
-
export function needsStatsForSort(sortBy) {
|
|
7
|
-
return sortBy === 'size' || sortBy === 'modified';
|
|
8
|
-
}
|
|
9
|
-
const collator = new Intl.Collator(undefined, { numeric: true });
|
|
10
|
-
export function withOptionalStoppedReason(summary, stoppedReason) {
|
|
11
|
-
if (stoppedReason === undefined) {
|
|
12
|
-
return summary;
|
|
13
|
-
}
|
|
14
|
-
return { ...summary, stoppedReason };
|
|
15
|
-
}
|
|
16
|
-
export function resolveEntryType(dirent) {
|
|
17
|
-
if (dirent.isSymbolicLink())
|
|
18
|
-
return 'symlink';
|
|
19
|
-
if (dirent.isDirectory())
|
|
20
|
-
return 'directory';
|
|
21
|
-
if (dirent.isFile())
|
|
22
|
-
return 'file';
|
|
23
|
-
return 'other';
|
|
24
|
-
}
|
|
25
|
-
export function resolveStopReason(options) {
|
|
26
|
-
if (options.signal.aborted)
|
|
27
|
-
return options.abortedReason;
|
|
28
|
-
if (options.current >= options.max)
|
|
29
|
-
return options.maxReason;
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
export function compareStringValues(left, right) {
|
|
33
|
-
return collator.compare(left ?? '', right ?? '');
|
|
34
|
-
}
|
|
35
|
-
export function compareOptionalNumberDesc(left, right, tieBreak) {
|
|
36
|
-
const diff = (right ?? 0) - (left ?? 0);
|
|
37
|
-
if (diff !== 0)
|
|
38
|
-
return diff;
|
|
39
|
-
return tieBreak();
|
|
40
|
-
}
|
|
41
|
-
export function stableSortByDerivedString(items, derive, tieBreak) {
|
|
42
|
-
const decorated = [];
|
|
43
|
-
const len = items.length;
|
|
44
|
-
for (let index = 0; index < len; index++) {
|
|
45
|
-
const item = items[index];
|
|
46
|
-
if (item === undefined)
|
|
47
|
-
continue;
|
|
48
|
-
decorated.push({
|
|
49
|
-
item,
|
|
50
|
-
derived: derive(item),
|
|
51
|
-
index,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
decorated.sort((left, right) => {
|
|
55
|
-
const derivedCompare = compareStringValues(left.derived, right.derived);
|
|
56
|
-
if (derivedCompare !== 0)
|
|
57
|
-
return derivedCompare;
|
|
58
|
-
const tiedCompare = tieBreak(left.item, right.item);
|
|
59
|
-
if (tiedCompare !== 0)
|
|
60
|
-
return tiedCompare;
|
|
61
|
-
return left.index - right.index;
|
|
62
|
-
});
|
|
63
|
-
const decoratedLen = decorated.length;
|
|
64
|
-
for (let index = 0; index < decoratedLen; index++) {
|
|
65
|
-
const entry = decorated[index];
|
|
66
|
-
if (!entry)
|
|
67
|
-
continue;
|
|
68
|
-
items[index] = entry.item;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
export function applyIndexedValues(output, results) {
|
|
72
|
-
for (const result of results) {
|
|
73
|
-
if (result.index < 0 || result.index >= output.length)
|
|
74
|
-
continue;
|
|
75
|
-
output[result.index] = result.value;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
export function applyIndexedErrors(options) {
|
|
79
|
-
const { output, errors, resolveIndex, buildValue } = options;
|
|
80
|
-
for (const failure of errors) {
|
|
81
|
-
const resolvedIndex = resolveIndex(failure.index);
|
|
82
|
-
if (resolvedIndex === undefined)
|
|
83
|
-
continue;
|
|
84
|
-
if (resolvedIndex < 0 || resolvedIndex >= output.length)
|
|
85
|
-
continue;
|
|
86
|
-
output[resolvedIndex] = buildValue(resolvedIndex, failure.error);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export async function isEntryAccessibleByType(entryPath, entryType, rootDirectories, signal, deps) {
|
|
90
|
-
if (entryType !== 'symlink') {
|
|
91
|
-
const normalizedPath = deps.normalizePath(entryPath);
|
|
92
|
-
if (!deps.isPathWithinDirectories(normalizedPath, rootDirectories)) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
return !deps.isSensitivePath(entryPath, normalizedPath);
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
const validated = await deps.validateSymlinkPath(entryPath, signal);
|
|
99
|
-
return !deps.isSensitivePath(validated.requestedPath, validated.resolvedPath);
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function parseGitignoreLines(contents) {
|
|
106
|
-
const lines = [];
|
|
107
|
-
const parts = contents.split(/\r?\n/u);
|
|
108
|
-
for (const part of parts) {
|
|
109
|
-
const trimmed = part.trim();
|
|
110
|
-
if (trimmed.length > 0) {
|
|
111
|
-
lines.push(trimmed);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return lines;
|
|
115
|
-
}
|
|
116
|
-
export async function loadRootGitignore(root, signal) {
|
|
117
|
-
const gitignorePath = join(root, '.gitignore');
|
|
118
|
-
try {
|
|
119
|
-
const contents = await readFile(gitignorePath, {
|
|
120
|
-
encoding: 'utf-8',
|
|
121
|
-
signal,
|
|
122
|
-
});
|
|
123
|
-
const matcher = ignore();
|
|
124
|
-
matcher.add(parseGitignoreLines(contents));
|
|
125
|
-
return matcher;
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
if (isNodeError(error) && error.code === 'ENOENT') {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
throw error;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
export function isIgnoredByGitignore(matcher, root, absolutePath, options = {}) {
|
|
135
|
-
let { relativePath } = options;
|
|
136
|
-
relativePath ??= relative(root, absolutePath);
|
|
137
|
-
if (relativePath.length === 0)
|
|
138
|
-
return false;
|
|
139
|
-
const normalized = toPosixPath(relativePath);
|
|
140
|
-
if (options.isDirectory) {
|
|
141
|
-
return matcher.ignores(normalized.endsWith('/') ? normalized : `${normalized}/`);
|
|
142
|
-
}
|
|
143
|
-
return matcher.ignores(normalized);
|
|
144
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { FileInfo, GetMultipleFileInfoResult, ListDirectoryResult } from '../../config.js';
|
|
2
|
-
import { type EntryType } from './core.js';
|
|
3
|
-
interface FileInfoOptions {
|
|
4
|
-
includeMimeType?: boolean | undefined;
|
|
5
|
-
signal?: AbortSignal | undefined;
|
|
6
|
-
onProgress?: () => void;
|
|
7
|
-
}
|
|
8
|
-
export declare function getFileInfo(filePath: string, options?: FileInfoOptions): Promise<FileInfo>;
|
|
9
|
-
type GetMultipleFileInfoOptions = FileInfoOptions;
|
|
10
|
-
export declare function getMultipleFileInfo(paths: readonly string[], options?: GetMultipleFileInfoOptions): Promise<GetMultipleFileInfoResult>;
|
|
11
|
-
interface ListDirectoryOptions {
|
|
12
|
-
includeHidden?: boolean;
|
|
13
|
-
excludePatterns?: readonly string[];
|
|
14
|
-
maxDepth?: number;
|
|
15
|
-
maxEntries?: number;
|
|
16
|
-
sortBy?: 'name' | 'size' | 'modified' | 'type';
|
|
17
|
-
includeSymlinkTargets?: boolean;
|
|
18
|
-
pattern?: string;
|
|
19
|
-
timeoutMs?: number;
|
|
20
|
-
signal?: AbortSignal;
|
|
21
|
-
}
|
|
22
|
-
export declare function listDirectory(dirPath: string, options?: ListDirectoryOptions): Promise<ListDirectoryResult>;
|
|
23
|
-
interface TreeEntry {
|
|
24
|
-
name: string;
|
|
25
|
-
type: EntryType;
|
|
26
|
-
relativePath: string;
|
|
27
|
-
size?: number;
|
|
28
|
-
children?: TreeEntry[];
|
|
29
|
-
}
|
|
30
|
-
interface TreeOptions {
|
|
31
|
-
maxDepth?: number;
|
|
32
|
-
maxEntries?: number;
|
|
33
|
-
includeHidden?: boolean;
|
|
34
|
-
includeIgnored?: boolean;
|
|
35
|
-
includeSizes?: boolean;
|
|
36
|
-
timeoutMs?: number;
|
|
37
|
-
signal?: AbortSignal;
|
|
38
|
-
onProgress?: (progress: {
|
|
39
|
-
total?: number;
|
|
40
|
-
current: number;
|
|
41
|
-
}) => void;
|
|
42
|
-
}
|
|
43
|
-
interface TreeResult {
|
|
44
|
-
root: string;
|
|
45
|
-
tree: TreeEntry;
|
|
46
|
-
truncated: boolean;
|
|
47
|
-
totalEntries: number;
|
|
48
|
-
}
|
|
49
|
-
export declare function formatTreeAscii(tree: TreeEntry): string;
|
|
50
|
-
export declare function treeDirectory(dirPath: string, options?: TreeOptions): Promise<TreeResult>;
|
|
51
|
-
interface ReadMultipleResult {
|
|
52
|
-
path: string;
|
|
53
|
-
content?: string;
|
|
54
|
-
truncated?: boolean;
|
|
55
|
-
totalLines?: number;
|
|
56
|
-
readMode?: 'full' | 'head' | 'tail' | 'range';
|
|
57
|
-
head?: number;
|
|
58
|
-
tail?: number;
|
|
59
|
-
startLine?: number;
|
|
60
|
-
endLine?: number;
|
|
61
|
-
linesRead?: number;
|
|
62
|
-
hasMoreLines?: boolean;
|
|
63
|
-
error?: Error;
|
|
64
|
-
}
|
|
65
|
-
interface ReadMultipleOptions {
|
|
66
|
-
encoding?: BufferEncoding;
|
|
67
|
-
maxSize?: number;
|
|
68
|
-
maxTotalSize?: number;
|
|
69
|
-
head?: number;
|
|
70
|
-
tail?: number;
|
|
71
|
-
startLine?: number;
|
|
72
|
-
endLine?: number;
|
|
73
|
-
signal?: AbortSignal;
|
|
74
|
-
onReadComplete?: () => void;
|
|
75
|
-
}
|
|
76
|
-
export declare function readMultipleFiles(filePaths: readonly string[], options?: ReadMultipleOptions): Promise<ReadMultipleResult[]>;
|
|
77
|
-
export {};
|