@j0hanz/filesystem-mcp 2.5.2 → 2.6.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 +26 -19
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +12 -3
- package/dist/cli.js.map +1 -1
- package/dist/core/concurrency.d.ts +7 -4
- package/dist/core/concurrency.d.ts.map +1 -1
- package/dist/core/concurrency.js +9 -4
- package/dist/core/concurrency.js.map +1 -1
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js.map +1 -1
- package/dist/core/cursor.d.ts.map +1 -1
- package/dist/core/cursor.js +11 -1
- package/dist/core/cursor.js.map +1 -1
- package/dist/core/diff.d.ts +15 -2
- package/dist/core/diff.d.ts.map +1 -1
- package/dist/core/diff.js +38 -7
- package/dist/core/diff.js.map +1 -1
- package/dist/core/errors.d.ts +4 -5
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +14 -14
- package/dist/core/errors.js.map +1 -1
- package/dist/core/file-uri.d.ts +23 -9
- package/dist/core/file-uri.d.ts.map +1 -1
- package/dist/core/file-uri.js +29 -14
- package/dist/core/file-uri.js.map +1 -1
- package/dist/core/fmt.d.ts +3 -1
- package/dist/core/fmt.d.ts.map +1 -1
- package/dist/core/fmt.js +3 -3
- package/dist/core/fmt.js.map +1 -1
- package/dist/core/fs.d.ts +2 -8
- package/dist/core/fs.d.ts.map +1 -1
- package/dist/core/fs.js +32 -20
- package/dist/core/fs.js.map +1 -1
- package/dist/core/glob.d.ts +1 -1
- package/dist/core/glob.d.ts.map +1 -1
- package/dist/core/glob.js +77 -80
- package/dist/core/glob.js.map +1 -1
- package/dist/core/mime.d.ts +1 -0
- package/dist/core/mime.d.ts.map +1 -1
- package/dist/core/mime.js +1 -1
- package/dist/core/mime.js.map +1 -1
- package/dist/core/observability.js +1 -1
- package/dist/core/observability.js.map +1 -1
- package/dist/core/path-completer.d.ts +2 -1
- package/dist/core/path-completer.d.ts.map +1 -1
- package/dist/core/path-completer.js +14 -13
- package/dist/core/path-completer.js.map +1 -1
- package/dist/core/path-discovery.d.ts.map +1 -1
- package/dist/core/path-discovery.js +29 -21
- package/dist/core/path-discovery.js.map +1 -1
- package/dist/core/path-utils.d.ts +8 -0
- package/dist/core/path-utils.d.ts.map +1 -1
- package/dist/core/path-utils.js +24 -17
- package/dist/core/path-utils.js.map +1 -1
- package/dist/core/path.d.ts +13 -1
- package/dist/core/path.d.ts.map +1 -1
- package/dist/core/path.js +27 -11
- package/dist/core/path.js.map +1 -1
- package/dist/core/read.d.ts +1 -0
- package/dist/core/read.d.ts.map +1 -1
- package/dist/core/read.js +23 -12
- package/dist/core/read.js.map +1 -1
- package/dist/core/schema.d.ts +10 -0
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +20 -6
- package/dist/core/schema.js.map +1 -1
- package/dist/core/search.d.ts +12 -4
- package/dist/core/search.d.ts.map +1 -1
- package/dist/core/search.js +42 -26
- package/dist/core/search.js.map +1 -1
- package/dist/core/sensitive.d.ts +7 -0
- package/dist/core/sensitive.d.ts.map +1 -1
- package/dist/core/sensitive.js +21 -2
- package/dist/core/sensitive.js.map +1 -1
- package/dist/core/watcher-registry.d.ts.map +1 -1
- package/dist/core/watcher-registry.js +24 -9
- package/dist/core/watcher-registry.js.map +1 -1
- package/dist/instructions.js +4 -4
- package/dist/instructions.js.map +1 -1
- package/dist/resources.d.ts.map +1 -1
- package/dist/resources.js +21 -3
- package/dist/resources.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +16 -3
- package/dist/server.js.map +1 -1
- package/dist/tools/batch.d.ts +2 -5
- package/dist/tools/batch.d.ts.map +1 -1
- package/dist/tools/batch.js +1 -2
- package/dist/tools/batch.js.map +1 -1
- package/dist/tools/create.d.ts.map +1 -1
- package/dist/tools/create.js +32 -19
- package/dist/tools/create.js.map +1 -1
- package/dist/tools/define.d.ts +1 -1
- package/dist/tools/define.d.ts.map +1 -1
- package/dist/tools/define.js.map +1 -1
- package/dist/tools/delete.d.ts.map +1 -1
- package/dist/tools/delete.js +2 -7
- package/dist/tools/delete.js.map +1 -1
- package/dist/tools/diff.d.ts.map +1 -1
- package/dist/tools/diff.js +8 -5
- package/dist/tools/diff.js.map +1 -1
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js +89 -46
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/find-files.d.ts.map +1 -1
- package/dist/tools/find-files.js +1 -2
- package/dist/tools/find-files.js.map +1 -1
- package/dist/tools/list-roots.d.ts.map +1 -1
- package/dist/tools/list-roots.js +1 -3
- package/dist/tools/list-roots.js.map +1 -1
- package/dist/tools/list.js +4 -4
- package/dist/tools/list.js.map +1 -1
- package/dist/tools/move.d.ts +2 -0
- package/dist/tools/move.d.ts.map +1 -1
- package/dist/tools/move.js +10 -4
- package/dist/tools/move.js.map +1 -1
- package/dist/tools/patch.d.ts.map +1 -1
- package/dist/tools/patch.js +11 -3
- package/dist/tools/patch.js.map +1 -1
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +7 -29
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/replace-text.d.ts.map +1 -1
- package/dist/tools/replace-text.js +20 -17
- package/dist/tools/replace-text.js.map +1 -1
- package/dist/tools/search-text.d.ts.map +1 -1
- package/dist/tools/search-text.js +3 -1
- package/dist/tools/search-text.js.map +1 -1
- package/dist/tools/stat.d.ts.map +1 -1
- package/dist/tools/stat.js +4 -9
- package/dist/tools/stat.js.map +1 -1
- package/dist/transport/http-policy.d.ts +3 -3
- package/dist/transport/http-policy.d.ts.map +1 -1
- package/dist/transport/http-policy.js +10 -9
- package/dist/transport/http-policy.js.map +1 -1
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +38 -14
- package/dist/transport/http.js.map +1 -1
- package/dist/transport/shared.d.ts +2 -2
- package/dist/transport/shared.d.ts.map +1 -1
- package/dist/transport/shared.js.map +1 -1
- package/dist/transport/stdio.d.ts +1 -1
- package/dist/transport/stdio.js +1 -1
- package/dist/transport/stdio.js.map +1 -1
- package/package.json +1 -1
package/dist/core/errors.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ProtocolErrorCode } from '@modelcontextprotocol/server';
|
|
2
1
|
export const ErrorCode = {
|
|
3
2
|
ACCESS_DENIED: 'ACCESS_DENIED',
|
|
4
3
|
NOT_FOUND: 'NOT_FOUND',
|
|
@@ -54,7 +53,7 @@ const DEFAULT_SUGGESTIONS = {
|
|
|
54
53
|
[ErrorCode.PERMISSION_DENIED]: 'Check OS file permissions.',
|
|
55
54
|
[ErrorCode.SYMLINK_NOT_ALLOWED]: 'Symlink escapes allowed directories.',
|
|
56
55
|
};
|
|
57
|
-
|
|
56
|
+
const ERRNO_MAP = {
|
|
58
57
|
ENOENT: ErrorCode.NOT_FOUND,
|
|
59
58
|
EACCES: ErrorCode.PERMISSION_DENIED,
|
|
60
59
|
EPERM: ErrorCode.PERMISSION_DENIED,
|
|
@@ -82,7 +81,7 @@ export const SKIPPABLE_FS_CODES = new Set([
|
|
|
82
81
|
ErrorCode.PERMISSION_DENIED,
|
|
83
82
|
ErrorCode.SYMLINK_NOT_ALLOWED,
|
|
84
83
|
]);
|
|
85
|
-
|
|
84
|
+
const SKIPPABLE_ERRNOS = new Set(['ENOENT', 'EACCES', 'ELOOP']);
|
|
86
85
|
/**
|
|
87
86
|
* Walk `error` and its `cause` chain once for the three facts error handling
|
|
88
87
|
* needs: an abort anywhere, a timeout anywhere, and the FIRST errno seen.
|
|
@@ -114,7 +113,7 @@ function scanCauseChain(error) {
|
|
|
114
113
|
return { aborted, timedOut, errno };
|
|
115
114
|
}
|
|
116
115
|
/** The scan's facts as a Problem: an abort wins, then a timeout, then errno. */
|
|
117
|
-
function classifyCauseChain(error) {
|
|
116
|
+
export function classifyCauseChain(error) {
|
|
118
117
|
const message = formatUnknownErrorMessage(error);
|
|
119
118
|
const { aborted, timedOut, errno } = scanCauseChain(error);
|
|
120
119
|
if (aborted)
|
|
@@ -131,22 +130,19 @@ function classifyCauseChain(error) {
|
|
|
131
130
|
export function isFsError(error) {
|
|
132
131
|
return error instanceof FsError;
|
|
133
132
|
}
|
|
134
|
-
/** FsError traces to a caller-supplied argument; anything else is server-side. */
|
|
135
|
-
export function fsErrorCode(error) {
|
|
136
|
-
return isFsError(error) ? ProtocolErrorCode.InvalidParams : ProtocolErrorCode.InternalError;
|
|
137
|
-
}
|
|
138
133
|
function classify(error) {
|
|
139
134
|
if (error === null || error === undefined) {
|
|
140
135
|
return build(ErrorCode.UNKNOWN, 'Unknown error');
|
|
141
136
|
}
|
|
142
137
|
if (isFsError(error))
|
|
143
138
|
return error.problem;
|
|
144
|
-
// No `ZodError` branch, deliberately. Tool arguments are validated by
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
// calls `.parse()`. A ZodError reaching here would fall
|
|
148
|
-
// UNKNOWN with Zod's raw JSON-dump `.message`, so if a
|
|
149
|
-
// is ever added, add the branch back with it rather than
|
|
139
|
+
// No `ZodError` branch, deliberately. Tool arguments are validated by the
|
|
140
|
+
// SDK from the zod schema `defineTool` hands it (tools/define.ts); the SDK
|
|
141
|
+
// formats issues itself and never throws a ZodError into a handler, and
|
|
142
|
+
// nothing in `src/` calls `.parse()`. A ZodError reaching here would fall
|
|
143
|
+
// through to UNKNOWN with Zod's raw JSON-dump `.message`, so if a
|
|
144
|
+
// `.parse()` is ever added, add the branch back with it rather than
|
|
145
|
+
// discovering this.
|
|
150
146
|
if (!(error instanceof Error)) {
|
|
151
147
|
return build(ErrorCode.UNKNOWN, typeof error === 'string' ? error : '[non-Error thrown]');
|
|
152
148
|
}
|
|
@@ -164,6 +160,10 @@ export function isNodeError(error) {
|
|
|
164
160
|
export function isNotFoundErrno(error) {
|
|
165
161
|
return isNodeError(error) && error.code === 'ENOENT';
|
|
166
162
|
}
|
|
163
|
+
/** True when `error` is a Node errno error whose code is in `SKIPPABLE_ERRNOS`. */
|
|
164
|
+
export function isSkippableErrno(error) {
|
|
165
|
+
return isNodeError(error) && error.code !== undefined && SKIPPABLE_ERRNOS.has(error.code);
|
|
166
|
+
}
|
|
167
167
|
/**
|
|
168
168
|
* Rethrow when `error` reads as cancelled. Answers the question directly rather
|
|
169
169
|
* than through `classify`, which allocated a Problem — and ran
|
package/dist/core/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,aAAa,EAAE,eAAe;IAC9B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,eAAe,EAAE,iBAAiB;IAClC,aAAa,EAAE,eAAe;IAC9B,iBAAiB,EAAE,mBAAmB;IACtC,mBAAmB,EAAE,qBAAqB;IAC1C,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;CACV,CAAC;AAgBX,SAAS,KAAK,CAAC,IAAe,EAAE,OAAe,EAAE,OAA8B,EAAE;IAC/E,OAAO;QACL,IAAI;QACJ,OAAO;QACP,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,G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I,KAAK,CAAC,UAAU,EAAE,CAAC;QACrB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,OAAO,OAAQ,SAAQ,KAAK;IACvB,OAAO,CAAU;IAE1B,YAAY,IAAe,EAAE,OAAe,EAAE,IAAa,EAAE,KAAe;QAC1E,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACrD,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG;YACb,IAAI;YACJ,OAAO;YACP,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvC,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACpD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import { ProtocolErrorCode } from '@modelcontextprotocol/server';\n\nexport const ErrorCode = {\n ACCESS_DENIED: 'ACCESS_DENIED',\n NOT_FOUND: 'NOT_FOUND',\n NOT_FILE: 'NOT_FILE',\n NOT_DIRECTORY: 'NOT_DIRECTORY',\n TOO_LARGE: 'TOO_LARGE',\n TIMEOUT: 'TIMEOUT',\n CANCELLED: 'CANCELLED',\n INVALID_PATTERN: 'INVALID_PATTERN',\n INVALID_INPUT: 'INVALID_INPUT',\n PERMISSION_DENIED: 'PERMISSION_DENIED',\n SYMLINK_NOT_ALLOWED: 'SYMLINK_NOT_ALLOWED',\n IO_ERROR: 'IO_ERROR',\n UNKNOWN: 'UNKNOWN',\n} as const;\n\nexport type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];\n\nexport interface Problem {\n readonly code: ErrorCode;\n readonly message: string;\n readonly path?: string;\n readonly suggestion?: string;\n}\n\ninterface ProblemFactoryOptions {\n path?: string;\n suggestion?: string;\n}\n\nfunction build(code: ErrorCode, message: string, opts: ProblemFactoryOptions = {}): Problem {\n return {\n code,\n message,\n ...(opts.path !== undefined ? { path: opts.path } : {}),\n ...(opts.suggestion !== undefined ? { suggestion: opts.suggestion } : {}),\n };\n}\n\nexport const Problem = {\n invalidInput: (msg: string, o?: ProblemFactoryOptions): Problem =>\n build(ErrorCode.INVALID_INPUT, msg, o),\n accessDenied: (msg: string, o?: ProblemFactoryOptions): Problem =>\n build(ErrorCode.ACCESS_DENIED, msg, o),\n cancelled: (msg: string, o?: ProblemFactoryOptions): Problem =>\n build(ErrorCode.CANCELLED, msg, o),\n fromUnknown(error: unknown, defaultCode: ErrorCode, path?: string): Problem {\n const problem = classify(error);\n const shouldOverride =\n problem.code === ErrorCode.UNKNOWN || problem.code === ErrorCode.IO_ERROR;\n const code = shouldOverride ? defaultCode : problem.code;\n const suggestion =\n (shouldOverride ? DEFAULT_SUGGESTIONS[code] : undefined) ??\n problem.suggestion ??\n DEFAULT_SUGGESTIONS[problem.code];\n const resolvedPath = path ?? problem.path;\n return build(code, problem.message, {\n ...(resolvedPath !== undefined ? { path: resolvedPath } : {}),\n ...(suggestion !== undefined ? { suggestion } : {}),\n });\n },\n toText(error: unknown, defaultCode: ErrorCode): string {\n return formatDetailedError(Problem.fromUnknown(error, defaultCode));\n },\n} as const;\n\nconst DEFAULT_SUGGESTIONS: Readonly<Partial<Record<ErrorCode, string>>> = {\n [ErrorCode.ACCESS_DENIED]: 'Run list_roots to list allowed directories.',\n [ErrorCode.NOT_FOUND]: 'Run list or find_files to verify the path.',\n [ErrorCode.NOT_FILE]: 'Target is a directory, not a file.',\n [ErrorCode.NOT_DIRECTORY]: 'Target is a file, not a directory.',\n [ErrorCode.TOO_LARGE]: 'Use head/tail or line ranges to read partially.',\n [ErrorCode.TIMEOUT]: 'Reduce scope, depth, or maxResults.',\n [ErrorCode.INVALID_PATTERN]: 'Check syntax and escape special characters.',\n [ErrorCode.PERMISSION_DENIED]: 'Check OS file permissions.',\n [ErrorCode.SYMLINK_NOT_ALLOWED]: 'Symlink escapes allowed directories.',\n};\n\nexport const ERRNO_MAP: Readonly<Record<string, ErrorCode>> = {\n ENOENT: ErrorCode.NOT_FOUND,\n EACCES: ErrorCode.PERMISSION_DENIED,\n EPERM: ErrorCode.PERMISSION_DENIED,\n ENOTDIR: ErrorCode.NOT_DIRECTORY,\n EISDIR: ErrorCode.NOT_FILE,\n ELOOP: ErrorCode.SYMLINK_NOT_ALLOWED,\n ENAMETOOLONG: ErrorCode.INVALID_INPUT,\n ETIMEDOUT: ErrorCode.TIMEOUT,\n EMFILE: ErrorCode.IO_ERROR,\n ENFILE: ErrorCode.IO_ERROR,\n EBUSY: ErrorCode.IO_ERROR,\n ENOTEMPTY: ErrorCode.NOT_DIRECTORY,\n EEXIST: ErrorCode.INVALID_INPUT,\n EINVAL: ErrorCode.INVALID_INPUT,\n};\n\nconst ERRNO_RE = /^E[A-Z]+$/;\n\n// NOT_FOUND is in here (not just ENOENT) because a dangling symlink whose\n// target sits inside an allowed root surfaces as an FsError NOT_FOUND. Skipping\n// the entry is the point of a listing; rethrowing would fail the whole listing.\nexport const SKIPPABLE_FS_CODES: ReadonlySet<ErrorCode> = new Set([\n ErrorCode.ACCESS_DENIED,\n ErrorCode.NOT_FOUND,\n // OS-level EACCES/EPERM on a symlink target during a listing is exactly as\n // skippable as the other three codes.\n ErrorCode.PERMISSION_DENIED,\n ErrorCode.SYMLINK_NOT_ALLOWED,\n]);\n\nexport const SKIPPABLE_ERRNOS: ReadonlySet<string> = new Set(['ENOENT', 'EACCES', 'ELOOP']);\n\n/**\n * Walk `error` and its `cause` chain once for the three facts error handling\n * needs: an abort anywhere, a timeout anywhere, and the FIRST errno seen.\n * `visited` guards a cyclic chain. A node that reads as an abort or a timeout\n * never also contributes its errno.\n */\nfunction scanCauseChain(error: unknown): {\n aborted: boolean;\n timedOut: boolean;\n errno: { code: string; path?: string } | undefined;\n} {\n const visited = new Set<unknown>();\n let aborted = false;\n let timedOut = false;\n let errno: { code: string; path?: string } | undefined;\n\n for (\n let current: unknown = error;\n current !== undefined && current !== null && !visited.has(current);\n current = (current as { cause?: unknown }).cause\n ) {\n visited.add(current);\n if (!(current instanceof Error)) continue;\n const raw = (current as { code?: unknown }).code;\n const code = typeof raw === 'string' ? raw : undefined;\n if (current.name === 'AbortError' || code === 'ABORT_ERR') {\n aborted = true;\n } else if (current.name === 'TimeoutError' || code === 'ETIMEDOUT') {\n timedOut = true;\n } else if (errno === undefined && code !== undefined && ERRNO_RE.test(code)) {\n const { path } = current as NodeJS.ErrnoException;\n errno = { code, ...(typeof path === 'string' ? { path } : {}) };\n }\n }\n\n return { aborted, timedOut, errno };\n}\n\n/** The scan's facts as a Problem: an abort wins, then a timeout, then errno. */\nfunction classifyCauseChain(error: unknown): Problem {\n const message = formatUnknownErrorMessage(error);\n const { aborted, timedOut, errno } = scanCauseChain(error);\n if (aborted) return Problem.cancelled(message);\n if (timedOut) return build(ErrorCode.TIMEOUT, message);\n if (errno !== undefined) {\n return build(ERRNO_MAP[errno.code] ?? ErrorCode.IO_ERROR, message, {\n ...(errno.path !== undefined ? { path: errno.path } : {}),\n });\n }\n return build(ErrorCode.UNKNOWN, message);\n}\n\nexport function isFsError(error: unknown): error is FsError {\n return error instanceof FsError;\n}\n\n/** FsError traces to a caller-supplied argument; anything else is server-side. */\nexport function fsErrorCode(error: unknown): ProtocolErrorCode {\n return isFsError(error) ? ProtocolErrorCode.InvalidParams : ProtocolErrorCode.InternalError;\n}\n\nfunction classify(error: unknown): Problem {\n if (error === null || error === undefined) {\n return build(ErrorCode.UNKNOWN, 'Unknown error');\n }\n if (isFsError(error)) return error.problem;\n // No `ZodError` branch, deliberately. Tool arguments are validated by\n // `safeParse` inside the SDK's validator seam (tools/define.ts), which never\n // throws — it hands back `z.prettifyError`'s string — and nothing in `src/`\n // calls `.parse()`. A ZodError reaching here would fall through to\n // UNKNOWN with Zod's raw JSON-dump `.message`, so if a `.parse()`\n // is ever added, add the branch back with it rather than discovering this.\n if (!(error instanceof Error)) {\n return build(ErrorCode.UNKNOWN, typeof error === 'string' ? error : '[non-Error thrown]');\n }\n return classifyCauseChain(error);\n}\n\nexport function isNodeError(error: unknown): error is NodeJS.ErrnoException {\n if (!(error instanceof Error)) return false;\n if (!('code' in error)) return false;\n const { code } = error as { code?: unknown };\n return typeof code === 'string';\n}\n\n/** True when `error` is a Node errno error with code `ENOENT` (path not found). */\nexport function isNotFoundErrno(error: unknown): error is NodeJS.ErrnoException {\n return isNodeError(error) && error.code === 'ENOENT';\n}\n\n/**\n * Rethrow when `error` reads as cancelled. Answers the question directly rather\n * than through `classify`, which allocated a Problem — and ran\n * `formatUnknownErrorMessage`, i.e. a `JSON.stringify` on a non-Error — for a\n * boolean. This sits in eight catch blocks, several inside per-entry scan loops.\n */\nexport function rethrowIfAborted(error: unknown): void {\n if (isFsError(error)) {\n if (error.code === ErrorCode.CANCELLED) throw error;\n return;\n }\n if (scanCauseChain(error).aborted) throw error;\n}\n\nexport function formatUnknownErrorMessage(error: unknown): string {\n if (typeof error === 'string') return error;\n if (error instanceof Error) return error.message;\n try {\n return JSON.stringify(error);\n } catch {\n return `[non-serializable: ${Object.prototype.toString.call(error)}]`;\n }\n}\n\nexport function normalizeUnknownError(error: unknown): Error {\n return error instanceof Error ? error : new Error(formatUnknownErrorMessage(error));\n}\n\nfunction formatDetailedError(\n error: Pick<Problem, 'code' | 'message' | 'path' | 'suggestion'>,\n): string {\n const lines: string[] = [`${error.code}: ${error.message}`];\n if (error.path && !error.message.includes(error.path)) {\n lines.push(error.path);\n }\n if (error.suggestion) {\n lines.push(error.suggestion);\n }\n return lines.join('\\n');\n}\n\nexport class FsError extends Error {\n readonly problem: Problem;\n\n constructor(code: ErrorCode, message: string, path?: string, cause?: unknown) {\n super(message, cause === undefined ? {} : { cause });\n const suggestion = DEFAULT_SUGGESTIONS[code];\n this.problem = {\n code,\n message,\n ...(path !== undefined ? { path } : {}),\n ...(suggestion !== undefined ? { suggestion } : {}),\n };\n this.name = 'FsError';\n }\n\n get code(): ErrorCode {\n return this.problem.code;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,aAAa,EAAE,eAAe;IAC9B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,eAAe,EAAE,iBAAiB;IAClC,aAAa,EAAE,eAAe;IAC9B,iBAAiB,EAAE,mBAAmB;IACtC,mBAAmB,EAAE,qBAAqB;IAC1C,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;CACV,CAAC;AAgBX,SAAS,KAAK,CAAC,IAAe,EAAE,OAAe,EAAE,OAA8B,EAAE;IAC/E,OAAO;QACL,IAAI;QACJ,OAAO;QACP,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,YAAY,EAAE,CAAC,GAA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U,EAAE,CAAC;QACrB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,OAAO,OAAQ,SAAQ,KAAK;IACvB,OAAO,CAAU;IAE1B,YAAY,IAAe,EAAE,OAAe,EAAE,IAAa,EAAE,KAAe;QAC1E,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACrD,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG;YACb,IAAI;YACJ,OAAO;YACP,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvC,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACpD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF","sourcesContent":["export const ErrorCode = {\n ACCESS_DENIED: 'ACCESS_DENIED',\n NOT_FOUND: 'NOT_FOUND',\n NOT_FILE: 'NOT_FILE',\n NOT_DIRECTORY: 'NOT_DIRECTORY',\n TOO_LARGE: 'TOO_LARGE',\n TIMEOUT: 'TIMEOUT',\n CANCELLED: 'CANCELLED',\n INVALID_PATTERN: 'INVALID_PATTERN',\n INVALID_INPUT: 'INVALID_INPUT',\n PERMISSION_DENIED: 'PERMISSION_DENIED',\n SYMLINK_NOT_ALLOWED: 'SYMLINK_NOT_ALLOWED',\n IO_ERROR: 'IO_ERROR',\n UNKNOWN: 'UNKNOWN',\n} as const;\n\nexport type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];\n\nexport interface Problem {\n readonly code: ErrorCode;\n readonly message: string;\n readonly path?: string;\n readonly suggestion?: string;\n}\n\ninterface ProblemFactoryOptions {\n path?: string;\n suggestion?: string;\n}\n\nfunction build(code: ErrorCode, message: string, opts: ProblemFactoryOptions = {}): Problem {\n return {\n code,\n message,\n ...(opts.path !== undefined ? { path: opts.path } : {}),\n ...(opts.suggestion !== undefined ? { suggestion: opts.suggestion } : {}),\n };\n}\n\nexport const Problem = {\n invalidInput: (msg: string, o?: ProblemFactoryOptions): Problem =>\n build(ErrorCode.INVALID_INPUT, msg, o),\n accessDenied: (msg: string, o?: ProblemFactoryOptions): Problem =>\n build(ErrorCode.ACCESS_DENIED, msg, o),\n cancelled: (msg: string, o?: ProblemFactoryOptions): Problem =>\n build(ErrorCode.CANCELLED, msg, o),\n fromUnknown(error: unknown, defaultCode: ErrorCode, path?: string): Problem {\n const problem = classify(error);\n const shouldOverride =\n problem.code === ErrorCode.UNKNOWN || problem.code === ErrorCode.IO_ERROR;\n const code = shouldOverride ? defaultCode : problem.code;\n const suggestion =\n (shouldOverride ? DEFAULT_SUGGESTIONS[code] : undefined) ??\n problem.suggestion ??\n DEFAULT_SUGGESTIONS[problem.code];\n const resolvedPath = path ?? problem.path;\n return build(code, problem.message, {\n ...(resolvedPath !== undefined ? { path: resolvedPath } : {}),\n ...(suggestion !== undefined ? { suggestion } : {}),\n });\n },\n toText(error: unknown, defaultCode: ErrorCode): string {\n return formatDetailedError(Problem.fromUnknown(error, defaultCode));\n },\n} as const;\n\nconst DEFAULT_SUGGESTIONS: Readonly<Partial<Record<ErrorCode, string>>> = {\n [ErrorCode.ACCESS_DENIED]: 'Run list_roots to list allowed directories.',\n [ErrorCode.NOT_FOUND]: 'Run list or find_files to verify the path.',\n [ErrorCode.NOT_FILE]: 'Target is a directory, not a file.',\n [ErrorCode.NOT_DIRECTORY]: 'Target is a file, not a directory.',\n [ErrorCode.TOO_LARGE]: 'Use head/tail or line ranges to read partially.',\n [ErrorCode.TIMEOUT]: 'Reduce scope, depth, or maxResults.',\n [ErrorCode.INVALID_PATTERN]: 'Check syntax and escape special characters.',\n [ErrorCode.PERMISSION_DENIED]: 'Check OS file permissions.',\n [ErrorCode.SYMLINK_NOT_ALLOWED]: 'Symlink escapes allowed directories.',\n};\n\nconst ERRNO_MAP: Readonly<Record<string, ErrorCode>> = {\n ENOENT: ErrorCode.NOT_FOUND,\n EACCES: ErrorCode.PERMISSION_DENIED,\n EPERM: ErrorCode.PERMISSION_DENIED,\n ENOTDIR: ErrorCode.NOT_DIRECTORY,\n EISDIR: ErrorCode.NOT_FILE,\n ELOOP: ErrorCode.SYMLINK_NOT_ALLOWED,\n ENAMETOOLONG: ErrorCode.INVALID_INPUT,\n ETIMEDOUT: ErrorCode.TIMEOUT,\n EMFILE: ErrorCode.IO_ERROR,\n ENFILE: ErrorCode.IO_ERROR,\n EBUSY: ErrorCode.IO_ERROR,\n ENOTEMPTY: ErrorCode.NOT_DIRECTORY,\n EEXIST: ErrorCode.INVALID_INPUT,\n EINVAL: ErrorCode.INVALID_INPUT,\n};\n\nconst ERRNO_RE = /^E[A-Z]+$/;\n\n// NOT_FOUND is in here (not just ENOENT) because a dangling symlink whose\n// target sits inside an allowed root surfaces as an FsError NOT_FOUND. Skipping\n// the entry is the point of a listing; rethrowing would fail the whole listing.\nexport const SKIPPABLE_FS_CODES: ReadonlySet<ErrorCode> = new Set([\n ErrorCode.ACCESS_DENIED,\n ErrorCode.NOT_FOUND,\n // OS-level EACCES/EPERM on a symlink target during a listing is exactly as\n // skippable as the other three codes.\n ErrorCode.PERMISSION_DENIED,\n ErrorCode.SYMLINK_NOT_ALLOWED,\n]);\n\nconst SKIPPABLE_ERRNOS: ReadonlySet<string> = new Set(['ENOENT', 'EACCES', 'ELOOP']);\n\n/**\n * Walk `error` and its `cause` chain once for the three facts error handling\n * needs: an abort anywhere, a timeout anywhere, and the FIRST errno seen.\n * `visited` guards a cyclic chain. A node that reads as an abort or a timeout\n * never also contributes its errno.\n */\nfunction scanCauseChain(error: unknown): {\n aborted: boolean;\n timedOut: boolean;\n errno: { code: string; path?: string } | undefined;\n} {\n const visited = new Set<unknown>();\n let aborted = false;\n let timedOut = false;\n let errno: { code: string; path?: string } | undefined;\n\n for (\n let current: unknown = error;\n current !== undefined && current !== null && !visited.has(current);\n current = (current as { cause?: unknown }).cause\n ) {\n visited.add(current);\n if (!(current instanceof Error)) continue;\n const raw = (current as { code?: unknown }).code;\n const code = typeof raw === 'string' ? raw : undefined;\n if (current.name === 'AbortError' || code === 'ABORT_ERR') {\n aborted = true;\n } else if (current.name === 'TimeoutError' || code === 'ETIMEDOUT') {\n timedOut = true;\n } else if (errno === undefined && code !== undefined && ERRNO_RE.test(code)) {\n const { path } = current as NodeJS.ErrnoException;\n errno = { code, ...(typeof path === 'string' ? { path } : {}) };\n }\n }\n\n return { aborted, timedOut, errno };\n}\n\n/** The scan's facts as a Problem: an abort wins, then a timeout, then errno. */\nexport function classifyCauseChain(error: unknown): Problem {\n const message = formatUnknownErrorMessage(error);\n const { aborted, timedOut, errno } = scanCauseChain(error);\n if (aborted) return Problem.cancelled(message);\n if (timedOut) return build(ErrorCode.TIMEOUT, message);\n if (errno !== undefined) {\n return build(ERRNO_MAP[errno.code] ?? ErrorCode.IO_ERROR, message, {\n ...(errno.path !== undefined ? { path: errno.path } : {}),\n });\n }\n return build(ErrorCode.UNKNOWN, message);\n}\n\nexport function isFsError(error: unknown): error is FsError {\n return error instanceof FsError;\n}\n\nfunction classify(error: unknown): Problem {\n if (error === null || error === undefined) {\n return build(ErrorCode.UNKNOWN, 'Unknown error');\n }\n if (isFsError(error)) return error.problem;\n // No `ZodError` branch, deliberately. Tool arguments are validated by the\n // SDK from the zod schema `defineTool` hands it (tools/define.ts); the SDK\n // formats issues itself and never throws a ZodError into a handler, and\n // nothing in `src/` calls `.parse()`. A ZodError reaching here would fall\n // through to UNKNOWN with Zod's raw JSON-dump `.message`, so if a\n // `.parse()` is ever added, add the branch back with it rather than\n // discovering this.\n if (!(error instanceof Error)) {\n return build(ErrorCode.UNKNOWN, typeof error === 'string' ? error : '[non-Error thrown]');\n }\n return classifyCauseChain(error);\n}\n\nexport function isNodeError(error: unknown): error is NodeJS.ErrnoException {\n if (!(error instanceof Error)) return false;\n if (!('code' in error)) return false;\n const { code } = error as { code?: unknown };\n return typeof code === 'string';\n}\n\n/** True when `error` is a Node errno error with code `ENOENT` (path not found). */\nexport function isNotFoundErrno(error: unknown): error is NodeJS.ErrnoException {\n return isNodeError(error) && error.code === 'ENOENT';\n}\n\n/** True when `error` is a Node errno error whose code is in `SKIPPABLE_ERRNOS`. */\nexport function isSkippableErrno(error: unknown): error is NodeJS.ErrnoException {\n return isNodeError(error) && error.code !== undefined && SKIPPABLE_ERRNOS.has(error.code);\n}\n\n/**\n * Rethrow when `error` reads as cancelled. Answers the question directly rather\n * than through `classify`, which allocated a Problem — and ran\n * `formatUnknownErrorMessage`, i.e. a `JSON.stringify` on a non-Error — for a\n * boolean. This sits in eight catch blocks, several inside per-entry scan loops.\n */\nexport function rethrowIfAborted(error: unknown): void {\n if (isFsError(error)) {\n if (error.code === ErrorCode.CANCELLED) throw error;\n return;\n }\n if (scanCauseChain(error).aborted) throw error;\n}\n\nexport function formatUnknownErrorMessage(error: unknown): string {\n if (typeof error === 'string') return error;\n if (error instanceof Error) return error.message;\n try {\n return JSON.stringify(error);\n } catch {\n return `[non-serializable: ${Object.prototype.toString.call(error)}]`;\n }\n}\n\nexport function normalizeUnknownError(error: unknown): Error {\n return error instanceof Error ? error : new Error(formatUnknownErrorMessage(error));\n}\n\nfunction formatDetailedError(\n error: Pick<Problem, 'code' | 'message' | 'path' | 'suggestion'>,\n): string {\n const lines: string[] = [`${error.code}: ${error.message}`];\n if (error.path && !error.message.includes(error.path)) {\n lines.push(error.path);\n }\n if (error.suggestion) {\n lines.push(error.suggestion);\n }\n return lines.join('\\n');\n}\n\nexport class FsError extends Error {\n readonly problem: Problem;\n\n constructor(code: ErrorCode, message: string, path?: string, cause?: unknown) {\n super(message, cause === undefined ? {} : { cause });\n const suggestion = DEFAULT_SUGGESTIONS[code];\n this.problem = {\n code,\n message,\n ...(path !== undefined ? { path } : {}),\n ...(suggestion !== undefined ? { suggestion } : {}),\n };\n this.name = 'FsError';\n }\n\n get code(): ErrorCode {\n return this.problem.code;\n }\n}\n"]}
|
package/dist/core/file-uri.d.ts
CHANGED
|
@@ -21,24 +21,38 @@ export declare function buildFileResourceUri(validPath: string): string;
|
|
|
21
21
|
* disagree hand the client two subscriptions for one file.
|
|
22
22
|
*/
|
|
23
23
|
export declare function buildFileResourceLinkFor(uri: string, name: string, mimeType: string, size: number): ContentBlock;
|
|
24
|
-
export declare function buildFileResourceLink(validPath: string, mimeType: string, size: number): ContentBlock;
|
|
25
24
|
export declare function extractPath(uri: string): string | undefined;
|
|
26
25
|
export interface WrittenFileMeta {
|
|
27
26
|
size: number;
|
|
28
27
|
lineCount: number;
|
|
29
28
|
mimeType: string;
|
|
30
29
|
kind: FileKind;
|
|
31
|
-
/**
|
|
32
|
-
* Undefined when the resulting file exceeds the text-size cap: the store
|
|
33
|
-
* serves the URI via readRaw, which would reject it with TOO_LARGE.
|
|
34
|
-
*/
|
|
30
|
+
/** Undefined unless {@link writtenFileLinks} allows it: see there for when. */
|
|
35
31
|
resourceUri: string | undefined;
|
|
36
|
-
/** Undefined
|
|
32
|
+
/** Undefined unless {@link writtenFileLinks} allows it: see there for when. */
|
|
37
33
|
resourceLink: ContentBlock | undefined;
|
|
38
34
|
}
|
|
39
35
|
/**
|
|
40
|
-
* The
|
|
41
|
-
*
|
|
36
|
+
* The URI and link a write tool may advertise for the file it wrote. None on a
|
|
37
|
+
* dry run — nothing was written, so the file on disk is still the one the
|
|
38
|
+
* caller already has. None when the size is unknown or over the text-size cap —
|
|
39
|
+
* the store serves the URI via readRaw, which would reject it with TOO_LARGE.
|
|
40
|
+
* No link without a store to link into.
|
|
42
41
|
*/
|
|
43
|
-
export declare function
|
|
42
|
+
export declare function writtenFileLinks(validPath: string, mimeType: string, size: number | undefined, options: {
|
|
43
|
+
resourceStore: ResourceStore | undefined;
|
|
44
|
+
dryRun?: boolean | undefined;
|
|
45
|
+
}): Pick<WrittenFileMeta, 'resourceUri' | 'resourceLink'>;
|
|
46
|
+
/**
|
|
47
|
+
* The block every write tool reports for the content it wrote (or, with
|
|
48
|
+
* `dryRun`, would have written): size, line count, MIME, and whatever
|
|
49
|
+
* {@link writtenFileLinks} allows it to advertise. Named fields, because
|
|
50
|
+
* `validPath` and `content` are both strings and a positional swap type-checks.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildWrittenFileMeta(options: {
|
|
53
|
+
validPath: string;
|
|
54
|
+
content: string;
|
|
55
|
+
resourceStore: ResourceStore | undefined;
|
|
56
|
+
dryRun?: boolean | undefined;
|
|
57
|
+
}): WrittenFileMeta;
|
|
44
58
|
//# sourceMappingURL=file-uri.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-uri.d.ts","sourceRoot":"","sources":["../../src/core/file-uri.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAMjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAOhD,eAAO,MAAM,4BAA4B,kCAAkC,CAAC;AAE5E;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMrE;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,G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,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE;IAAE,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,GAClF,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,cAAc,CAAC,CAUvD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IACzC,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B,GAAG,eAAe,CAWlB"}
|
package/dist/core/file-uri.js
CHANGED
|
@@ -46,7 +46,7 @@ export function buildFileResourceLinkFor(uri, name, mimeType, size) {
|
|
|
46
46
|
annotations: { audience: ['user', 'assistant'] },
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
function buildFileResourceLink(validPath, mimeType, size) {
|
|
50
50
|
return buildFileResourceLinkFor(buildFileResourceUri(validPath), basename(validPath), mimeType, size);
|
|
51
51
|
}
|
|
52
52
|
export function extractPath(uri) {
|
|
@@ -56,24 +56,39 @@ export function extractPath(uri) {
|
|
|
56
56
|
return decodeFileUriPath(url.pathname.slice(1));
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* The
|
|
60
|
-
*
|
|
59
|
+
* The URI and link a write tool may advertise for the file it wrote. None on a
|
|
60
|
+
* dry run — nothing was written, so the file on disk is still the one the
|
|
61
|
+
* caller already has. None when the size is unknown or over the text-size cap —
|
|
62
|
+
* the store serves the URI via readRaw, which would reject it with TOO_LARGE.
|
|
63
|
+
* No link without a store to link into.
|
|
61
64
|
*/
|
|
62
|
-
export function
|
|
65
|
+
export function writtenFileLinks(validPath, mimeType, size, options) {
|
|
66
|
+
if (options.dryRun || size === undefined || size > getMaxTextFileSize()) {
|
|
67
|
+
return { resourceUri: undefined, resourceLink: undefined };
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
resourceUri: buildFileResourceUri(validPath),
|
|
71
|
+
resourceLink: options.resourceStore
|
|
72
|
+
? buildFileResourceLink(validPath, mimeType, size)
|
|
73
|
+
: undefined,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The block every write tool reports for the content it wrote (or, with
|
|
78
|
+
* `dryRun`, would have written): size, line count, MIME, and whatever
|
|
79
|
+
* {@link writtenFileLinks} allows it to advertise. Named fields, because
|
|
80
|
+
* `validPath` and `content` are both strings and a positional swap type-checks.
|
|
81
|
+
*/
|
|
82
|
+
export function buildWrittenFileMeta(options) {
|
|
83
|
+
const { validPath, content } = options;
|
|
63
84
|
const size = Buffer.byteLength(content, 'utf-8');
|
|
64
|
-
const
|
|
65
|
-
// An edit or patch can push a readable file past the text-size cap; the
|
|
66
|
-
// store serves the URI via readRaw, which would reject it with TOO_LARGE.
|
|
67
|
-
const servable = size <= getMaxTextFileSize();
|
|
85
|
+
const { mimeType, kind } = detectMimeFromContent(validPath, content);
|
|
68
86
|
return {
|
|
69
87
|
size,
|
|
70
88
|
lineCount: countLines(content),
|
|
71
|
-
mimeType
|
|
72
|
-
kind
|
|
73
|
-
|
|
74
|
-
resourceLink: resourceStore && servable
|
|
75
|
-
? buildFileResourceLink(validPath, mimeInfo.mimeType, size)
|
|
76
|
-
: undefined,
|
|
89
|
+
mimeType,
|
|
90
|
+
kind,
|
|
91
|
+
...writtenFileLinks(validPath, mimeType, size, options),
|
|
77
92
|
};
|
|
78
93
|
}
|
|
79
94
|
//# sourceMappingURL=file-uri.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-uri.js","sourceRoot":"","sources":["../../src/core/file-uri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,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';\n\nimport { basename } from 'node:path';\n\nimport { detectMimeFromContent } from './mime.ts';\nimport { countLines } from './read.ts';\nimport type { FileKind } from './schema.ts';\nimport type { ResourceStore } from './store.ts';\nimport { getMaxTextFileSize } from './util.ts';\n\n// Single owner of the `filesystem-mcp://file/` URI scheme — the template string,\n// the path→URI encoder, the URI→path decoder, the link blocks built from them,\n// and the post-write metadata block every write tool reports alongside them.\n\nexport const FILESYSTEM_FILE_URI_TEMPLATE = 'filesystem-mcp://file/{+path}';\n\n/**\n * The `{+path}` template-variable form of a path — what `completion/complete`\n * must return, since a client expands a suggestion into the template verbatim.\n * Unescaped, a '#' or '?' in a filename truncates the URI into a fragment or\n * query (silently naming a different path) and a '%' makes the decode throw.\n * Separators are restored so the value still reads as a path.\n */\nexport function encodeFileUriPath(validPath: string): string {\n const posix = validPath.replace(/\\\\/g, '/');\n return encodeURIComponent(posix).replace(/%2F/gi, '/');\n}\n\n/** Inverse of {@link encodeFileUriPath}; `undefined` on invalid percent-encoding. */\nexport function decodeFileUriPath(encoded: string): string | undefined {\n try {\n return decodeURIComponent(encoded);\n } catch {\n return undefined;\n }\n}\n\nexport function buildFileResourceUri(validPath: string): string {\n return `filesystem-mcp://file/${encodeFileUriPath(validPath)}`;\n}\n\n/**\n * The link block for a URI already built by `buildFileResourceUri`. Callers that\n * hold the URI must use this rather than rebuilding from a path: a path that\n * differs only in case (the drive letter, on Windows) yields a *different* URI\n * string, and watchers key on that string — a link and a `resourceUri` that\n * disagree hand the client two subscriptions for one file.\n */\nexport function buildFileResourceLinkFor(\n uri: string,\n name: string,\n mimeType: string,\n size: number,\n): ContentBlock {\n return {\n type: 'resource_link',\n uri,\n name,\n mimeType,\n size,\n annotations: { audience: ['user', 'assistant'] },\n };\n}\n\nfunction buildFileResourceLink(validPath: string, mimeType: string, size: number): ContentBlock {\n return buildFileResourceLinkFor(\n buildFileResourceUri(validPath),\n basename(validPath),\n mimeType,\n size,\n );\n}\n\nexport function extractPath(uri: string): string | undefined {\n const url = URL.parse(uri);\n if (url?.protocol !== 'filesystem-mcp:' || url.host !== 'file') return undefined;\n return decodeFileUriPath(url.pathname.slice(1));\n}\n\nexport interface WrittenFileMeta {\n size: number;\n lineCount: number;\n mimeType: string;\n kind: FileKind;\n /** Undefined unless {@link writtenFileLinks} allows it: see there for when. */\n resourceUri: string | undefined;\n /** Undefined unless {@link writtenFileLinks} allows it: see there for when. */\n resourceLink: ContentBlock | undefined;\n}\n\n/**\n * The URI and link a write tool may advertise for the file it wrote. None on a\n * dry run — nothing was written, so the file on disk is still the one the\n * caller already has. None when the size is unknown or over the text-size cap —\n * the store serves the URI via readRaw, which would reject it with TOO_LARGE.\n * No link without a store to link into.\n */\nexport function writtenFileLinks(\n validPath: string,\n mimeType: string,\n size: number | undefined,\n options: { resourceStore: ResourceStore | undefined; dryRun?: boolean | undefined },\n): Pick<WrittenFileMeta, 'resourceUri' | 'resourceLink'> {\n if (options.dryRun || size === undefined || size > getMaxTextFileSize()) {\n return { resourceUri: undefined, resourceLink: undefined };\n }\n return {\n resourceUri: buildFileResourceUri(validPath),\n resourceLink: options.resourceStore\n ? buildFileResourceLink(validPath, mimeType, size)\n : undefined,\n };\n}\n\n/**\n * The block every write tool reports for the content it wrote (or, with\n * `dryRun`, would have written): size, line count, MIME, and whatever\n * {@link writtenFileLinks} allows it to advertise. Named fields, because\n * `validPath` and `content` are both strings and a positional swap type-checks.\n */\nexport function buildWrittenFileMeta(options: {\n validPath: string;\n content: string;\n resourceStore: ResourceStore | undefined;\n dryRun?: boolean | undefined;\n}): WrittenFileMeta {\n const { validPath, content } = options;\n const size = Buffer.byteLength(content, 'utf-8');\n const { mimeType, kind } = detectMimeFromContent(validPath, content);\n return {\n size,\n lineCount: countLines(content),\n mimeType,\n kind,\n ...writtenFileLinks(validPath, mimeType, size, options),\n };\n}\n"]}
|
package/dist/core/fmt.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare function pathLabel(path: string): string;
|
|
|
22
22
|
* in full.
|
|
23
23
|
*/
|
|
24
24
|
export declare function joinRoster(items: readonly string[], separator?: string): string;
|
|
25
|
-
export declare function truncateProgressPattern(pattern: string
|
|
25
|
+
export declare function truncateProgressPattern(pattern: string): string;
|
|
26
26
|
/**
|
|
27
27
|
* The `//` lines a paged search appends to its text block. Paging, the
|
|
28
28
|
* engine's stop state and the files it skipped live in the structured half,
|
|
@@ -41,6 +41,8 @@ export declare function pageTrailer(p: {
|
|
|
41
41
|
noun: string;
|
|
42
42
|
tool: string;
|
|
43
43
|
nextCursor?: string | undefined;
|
|
44
|
+
/** The call's own arguments; printed merged with the cursor so the hint is sendable as-is. */
|
|
45
|
+
nextArgs?: Record<string, unknown> | undefined;
|
|
44
46
|
stoppedReason?: string | undefined;
|
|
45
47
|
skippedTooLarge?: number | undefined;
|
|
46
48
|
skippedInaccessible?: number | undefined;
|
package/dist/core/fmt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fmt.d.ts","sourceRoot":"","sources":["../../src/core/fmt.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,KAAK,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAkCtC,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,GAAG,MAAM,CAGnE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAiB,GAAG,MAAM,CAE5F;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EA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AAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC/C,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C,GAAG,MAAM,CAsBT;AAED,iDAAiD;AACjD,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAG9D"}
|
package/dist/core/fmt.js
CHANGED
|
@@ -58,8 +58,8 @@ export function joinRoster(items, separator = ' · ') {
|
|
|
58
58
|
const shown = items.slice(0, MAX_ROSTER_ITEMS).join(separator);
|
|
59
59
|
return `${shown}${separator}+${String(items.length - MAX_ROSTER_ITEMS)} more`;
|
|
60
60
|
}
|
|
61
|
-
export function truncateProgressPattern(pattern
|
|
62
|
-
return pattern.length <=
|
|
61
|
+
export function truncateProgressPattern(pattern) {
|
|
62
|
+
return pattern.length <= 40 ? pattern : `${pattern.slice(0, 40)}…`;
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* `stoppedReason` names the engine's own cap, and `maxResults` is also the name
|
|
@@ -88,7 +88,7 @@ export function pageTrailer(p) {
|
|
|
88
88
|
if (p.offset > 0 || p.total > p.shown) {
|
|
89
89
|
const next = p.nextCursor === undefined
|
|
90
90
|
? ''
|
|
91
|
-
: ` Next page: ${p.tool} ${JSON.stringify({ cursor: p.nextCursor })}`;
|
|
91
|
+
: ` Next page: ${p.tool} ${JSON.stringify({ ...p.nextArgs, cursor: p.nextCursor })}`;
|
|
92
92
|
lines.push(`// showing ${String(p.offset + 1)}-${String(p.offset + p.shown)} of ${String(p.total)} ${p.noun}.${next}`);
|
|
93
93
|
}
|
|
94
94
|
if (p.stoppedReason !== undef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AC,CAAC,EAAE;KACrF,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClB,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,cAAc,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3D,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,gBAAgB,CAAC,aAAqB;IACpD,MAAM,GAAG,GAAG,gBAAgB,CAAC,aAAa,CAAC,IAAI,YAAY,aAAa,GAAG,CAAC;IAC5E,OAAO,0BAA0B,GAAG,8EAA8E,CAAC;AACrH,CAAC","sourcesContent":["import { basename } from 'node:path';\n\nimport { MAX_SEARCH_RESULTS } from './util.ts';\n\nexport interface ProgressCtx {\n label: string;\n subject?: string;\n scope?: string;\n current?: number;\n total?: number;\n detail?: string;\n error?: string;\n}\n\ntype Phase = 'tick' | 'done' | 'fail';\n\nfunction buildBody(ctx: ProgressCtx, phase: Phase): string {\n const items: string[] = [];\n if (ctx.subject) {\n items.push(ctx.subject);\n }\n\n switch (phase) {\n case 'tick':\n if (ctx.current !== undefined && ctx.total !== undefined) {\n items.push(`${ctx.current}/${ctx.total}`);\n } else if (ctx.current !== undefined) {\n items.push(String(ctx.current));\n }\n break;\n case 'done':\n if (ctx.scope) {\n items.push(ctx.scope);\n }\n if (ctx.detail) {\n items.push(ctx.detail);\n }\n break;\n case 'fail':\n if (ctx.error) {\n items.push(ctx.error);\n }\n break;\n }\n\n return items.join(' · ');\n}\n\nexport function plainMessage(phase: Phase, ctx: ProgressCtx): string {\n const body = buildBody(ctx, phase);\n return body ? `${ctx.label}: ${body}` : `${ctx.label}:`;\n}\n\nexport function formatCount(count: number, singular: string, plural = `${singular}s`): string {\n return `${String(count)} ${count === 1 ? singular : plural}`;\n}\n\n/**\n * Short label for a path in summary text. `basename` returns '' for a root\n * (`C:\\`, `/`) and for a trailing-slash path, which rendered as a bare\n * separator in the per-path summaries, so fall back to the full path.\n */\nexport function pathLabel(path: string): string {\n return basename(path) || path;\n}\n\n/** Names past this point are noise in a summary line; structuredContent holds them all. */\nconst MAX_ROSTER_ITEMS = 20;\n\n/**\n * Join a per-path summary roster, capped. A 1000-path delete would otherwise\n * name every entry in the text block that `structuredContent` already carries\n * in full.\n */\nexport function joinRoster(items: readonly string[], separator = ' · '): string {\n if (items.length <= MAX_ROSTER_ITEMS) return items.join(separator);\n const shown = items.slice(0, MAX_ROSTER_ITEMS).join(separator);\n return `${shown}${separator}+${String(items.length - MAX_ROSTER_ITEMS)} more`;\n}\n\nexport function truncateProgressPattern(pattern: string): string {\n return pattern.length <= 40 ? pattern : `${pattern.slice(0, 40)}…`;\n}\n\n/**\n * `stoppedReason` names the engine's own cap, and `maxResults` is also the name\n * of the caller's page-size argument — spelling the cap out keeps a caller who\n * passed `maxResults: 5` from reading their own argument back.\n */\nconst STOP_REASON_TEXT: Record<string, string> = {\n maxResults: `hit the server's ${String(MAX_SEARCH_RESULTS)}-result scan cap, not your maxResults`,\n timeout: 'hit the time limit, or the request was cancelled',\n};\n\n/**\n * The `//` lines a paged search appends to its text block. Paging, the\n * engine's stop state and the files it skipped live in the structured half,\n * which `defineTool` ships under `_meta` for a tool that authors its own text —\n * and no client renders that. These lines are the only place a caller learns\n * that more remains, that the scan was cut, or that files went unexamined (a\n * lone match in an oversized file otherwise reads as \"No matches\"). They are\n * independent: a scan can stop early with too few results to page, so a\n * truncation with no cursor must still say so. Prefixed `//` so none can be\n * mistaken for a result row.\n */\nexport function pageTrailer(p: {\n offset: number;\n shown: number;\n total: number;\n noun: string;\n tool: string;\n nextCursor?: string | undefined;\n /** The call's own arguments; printed merged with the cursor so the hint is sendable as-is. */\n nextArgs?: Record<string, unknown> | undefined;\n stoppedReason?: string | undefined;\n skippedTooLarge?: number | undefined;\n skippedInaccessible?: number | undefined;\n}): string {\n const lines: string[] = [];\n // Position is owed on every page of a split set, including the last one —\n // which has no cursor and would otherwise read as the whole answer.\n if (p.offset > 0 || p.total > p.shown) {\n const next =\n p.nextCursor === undefined\n ? ''\n : ` Next page: ${p.tool} ${JSON.stringify({ ...p.nextArgs, cursor: p.nextCursor })}`;\n lines.push(\n `// showing ${String(p.offset + 1)}-${String(p.offset + p.shown)} of ${String(p.total)} ${p.noun}.${next}`,\n );\n }\n if (p.stoppedReason !== undefined) lines.push(stoppedEarlyLine(p.stoppedReason));\n const skipped = [\n p.skippedTooLarge ? `${formatCount(p.skippedTooLarge, 'file')} over the text size limit` : '',\n p.skippedInaccessible ? formatCount(p.skippedInaccessible, 'inaccessible file') : '',\n ].filter(Boolean);\n if (skipped.length > 0) {\n lines.push(`// skipped ${skipped.join(', ')}; results may be incomplete.`);\n }\n return lines.length > 0 ? `\\n\\n${lines.join('\\n')}` : '';\n}\n\n/** The `//` line saying a scan was cut short. */\nexport function stoppedEarlyLine(stoppedReason: string): string {\n const why = STOP_REASON_TEXT[stoppedReason] ?? `stopped (${stoppedReason})`;\n return `// scan stopped early: ${why}. That total is a floor, not the count. Narrow path or pattern for the rest.`;\n}\n"]}
|
package/dist/core/fs.d.ts
CHANGED
|
@@ -6,8 +6,6 @@ import type { PathGuard } from './path.ts';
|
|
|
6
6
|
import type { ReadFileResult, ReadSpec } from './read.ts';
|
|
7
7
|
export type { FileType };
|
|
8
8
|
export type { Stats };
|
|
9
|
-
export type { FileHandle };
|
|
10
|
-
export declare function isHidden(name: string): boolean;
|
|
11
9
|
/**
|
|
12
10
|
* Line count for a file on disk, counting newline bytes in fixed 64 KiB
|
|
13
11
|
* chunks so an arbitrarily large file (one append's result metadata) costs
|
|
@@ -17,7 +15,7 @@ export declare function isHidden(name: string): boolean;
|
|
|
17
15
|
* Matches read.ts's countLines semantics: a trailing newline does not open
|
|
18
16
|
* a new line, an unterminated final line counts, an empty file is 0.
|
|
19
17
|
*/
|
|
20
|
-
export declare function countFileLines(filePath: string
|
|
18
|
+
export declare function countFileLines(filePath: string): Promise<number>;
|
|
21
19
|
export declare class GuardedFileSystem {
|
|
22
20
|
readonly pathGuard: PathGuard;
|
|
23
21
|
constructor(pathGuard: PathGuard);
|
|
@@ -40,7 +38,6 @@ export declare class GuardedFileSystem {
|
|
|
40
38
|
mkdir(filePath: string, options?: Parameters<typeof fsMkdir>[1]): Promise<void>;
|
|
41
39
|
rename(oldPath: string, newPath: string): Promise<void>;
|
|
42
40
|
writeFile(filePath: string, content: string, options?: {
|
|
43
|
-
encoding?: BufferEncoding;
|
|
44
41
|
signal?: AbortSignal | undefined;
|
|
45
42
|
}): Promise<{
|
|
46
43
|
validPath: string;
|
|
@@ -52,7 +49,6 @@ export declare class GuardedFileSystem {
|
|
|
52
49
|
* there — inode and mode survive by construction.
|
|
53
50
|
*/
|
|
54
51
|
appendFile(filePath: string, content: string, options?: {
|
|
55
|
-
encoding?: BufferEncoding;
|
|
56
52
|
signal?: AbortSignal | undefined;
|
|
57
53
|
}): Promise<{
|
|
58
54
|
validPath: string;
|
|
@@ -62,9 +58,7 @@ export declare class GuardedFileSystem {
|
|
|
62
58
|
* file — an append's result must describe the resulting file (which may be
|
|
63
59
|
* a multi-GB log), not the chunk that was appended.
|
|
64
60
|
*/
|
|
65
|
-
readLeadingSample(filePath: string, size: number
|
|
66
|
-
signal?: AbortSignal | undefined;
|
|
67
|
-
}): Promise<Buffer>;
|
|
61
|
+
readLeadingSample(filePath: string, size: number): Promise<Buffer>;
|
|
68
62
|
rm(filePath: string, options?: Parameters<typeof fsRm>[1]): Promise<void>;
|
|
69
63
|
rmdir(filePath: string, options?: Parameters<typeof fsRmdir>[1]): Promise<void>;
|
|
70
64
|
cp(source: string, destination: string, options?: Parameters<typeof fsCp>[2]): Promise<void>;
|
package/dist/core/fs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/core/fs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAEL,EAAE,IAAI,IAAI,EAEV,KAAK,IAAI,OAAO,EAIhB,QAAQ,IAAI,UAAU,EAEtB,EAAE,IAAI,IAAI,EACV,KAAK,IAAI,OAAO,EAIjB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/core/fs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAEL,EAAE,IAAI,IAAI,EAEV,KAAK,IAAI,OAAO,EAIhB,QAAQ,IAAI,UAAU,EAEtB,EAAE,IAAI,IAAI,EACV,KAAK,IAAI,OAAO,EAIjB,MAAM,kBAAkB,CAAC;AAc1B,OAAO,KAAK,EAAE,SAAS,IAAI,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAI1D,YAAY,EAAE,QAAQ,EAAE,CAAC;AACzB,YAAY,EAAE,KAAK,EAAE,CAAC;AA+FtB;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBtE;AAED,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;IAI1B,IAAI,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QAAE,MAAM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