@j0hanz/filesystem-mcp 2.1.4 → 2.1.5
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/dist/cli.d.ts +2 -14
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -9
- package/dist/cli.js.map +1 -1
- package/dist/core/cursor.d.ts +2 -14
- package/dist/core/cursor.d.ts.map +1 -1
- package/dist/core/cursor.js +25 -39
- package/dist/core/cursor.js.map +1 -1
- package/dist/core/errors.d.ts +2 -11
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +6 -26
- package/dist/core/errors.js.map +1 -1
- package/dist/core/fmt.js +5 -5
- package/dist/core/fmt.js.map +1 -1
- package/dist/core/fs.d.ts +3 -11
- package/dist/core/fs.d.ts.map +1 -1
- package/dist/core/fs.js +3 -21
- package/dist/core/fs.js.map +1 -1
- package/dist/core/glob.d.ts +0 -1
- package/dist/core/glob.d.ts.map +1 -1
- package/dist/core/glob.js +1 -2
- package/dist/core/glob.js.map +1 -1
- package/dist/core/input-required.d.ts +0 -6
- package/dist/core/input-required.d.ts.map +1 -1
- package/dist/core/input-required.js +0 -8
- package/dist/core/input-required.js.map +1 -1
- package/dist/core/path-completer.d.ts.map +1 -1
- package/dist/core/path-completer.js +2 -1
- package/dist/core/path-completer.js.map +1 -1
- package/dist/core/path-discovery.js +2 -2
- package/dist/core/path-discovery.js.map +1 -1
- package/dist/core/path.d.ts +7 -18
- package/dist/core/path.d.ts.map +1 -1
- package/dist/core/path.js +14 -39
- package/dist/core/path.js.map +1 -1
- package/dist/core/primitives.d.ts +0 -1
- package/dist/core/primitives.d.ts.map +1 -1
- package/dist/core/primitives.js +0 -3
- package/dist/core/primitives.js.map +1 -1
- package/dist/core/read.d.ts +0 -1
- package/dist/core/read.d.ts.map +1 -1
- package/dist/core/read.js +7 -15
- package/dist/core/read.js.map +1 -1
- package/dist/core/schema.d.ts +0 -16
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +10 -35
- package/dist/core/schema.js.map +1 -1
- package/dist/core/search.d.ts +6 -2
- package/dist/core/search.d.ts.map +1 -1
- package/dist/core/search.js +103 -99
- package/dist/core/search.js.map +1 -1
- package/dist/core/store.d.ts +1 -2
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/store.js +1 -4
- package/dist/core/store.js.map +1 -1
- package/dist/core/watcher-registry.d.ts +1 -8
- package/dist/core/watcher-registry.d.ts.map +1 -1
- package/dist/core/watcher-registry.js +3 -12
- package/dist/core/watcher-registry.js.map +1 -1
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +32 -43
- package/dist/prompts.js.map +1 -1
- package/dist/resources.d.ts +1 -1
- package/dist/resources.d.ts.map +1 -1
- package/dist/resources.js +3 -9
- package/dist/resources.js.map +1 -1
- package/dist/server.d.ts +0 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -5
- package/dist/server.js.map +1 -1
- package/dist/tools/batch.d.ts +11 -2
- 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/define.d.ts.map +1 -1
- package/dist/tools/define.js +5 -2
- package/dist/tools/define.js.map +1 -1
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js +18 -30
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/list.js +1 -1
- package/dist/tools/list.js.map +1 -1
- package/dist/tools/move.d.ts.map +1 -1
- package/dist/tools/move.js +7 -3
- package/dist/tools/move.js.map +1 -1
- package/dist/tools/progress.d.ts +0 -1
- package/dist/tools/progress.d.ts.map +1 -1
- package/dist/tools/progress.js +2 -8
- package/dist/tools/progress.js.map +1 -1
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +1 -4
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/replace-in-files.d.ts.map +1 -1
- package/dist/tools/replace-in-files.js +5 -9
- package/dist/tools/replace-in-files.js.map +1 -1
- package/dist/tools/search-content.d.ts.map +1 -1
- package/dist/tools/search-content.js +17 -28
- package/dist/tools/search-content.js.map +1 -1
- package/dist/tools/stat.d.ts.map +1 -1
- package/dist/tools/stat.js +1 -3
- package/dist/tools/stat.js.map +1 -1
- package/dist/transport/http-policy.d.ts +6 -0
- package/dist/transport/http-policy.d.ts.map +1 -1
- package/dist/transport/http-policy.js +1 -1
- package/dist/transport/http-policy.js.map +1 -1
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +4 -11
- package/dist/transport/http.js.map +1 -1
- package/dist/transport/stdio.js +1 -1
- package/dist/transport/stdio.js.map +1 -1
- package/dist/transport.d.ts +1 -3
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +5 -2
- package/dist/transport.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.d.ts
CHANGED
|
@@ -12,17 +12,7 @@ export declare function parseArgs(): Promise<{
|
|
|
12
12
|
httpHost: string | undefined;
|
|
13
13
|
apiKey: string | undefined;
|
|
14
14
|
}>;
|
|
15
|
-
export
|
|
16
|
-
transport: string;
|
|
17
|
-
readOnly: boolean;
|
|
18
|
-
allowedRoots: string[];
|
|
19
|
-
tools: string[];
|
|
20
|
-
apiKey: string | null;
|
|
21
|
-
limits: {
|
|
22
|
-
maxFileSizeBytes: number;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export interface PrintConfigOptions {
|
|
15
|
+
export declare function runPrintConfig(options: {
|
|
26
16
|
allowedDirs: string[];
|
|
27
17
|
allowCwd: boolean;
|
|
28
18
|
readOnly: boolean;
|
|
@@ -31,7 +21,5 @@ export interface PrintConfigOptions {
|
|
|
31
21
|
port?: number;
|
|
32
22
|
httpHost?: string;
|
|
33
23
|
apiKey?: string;
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
export declare function runPrintConfig(options: PrintConfigOptions): Promise<EffectiveConfig>;
|
|
24
|
+
}): Promise<void>;
|
|
37
25
|
//# sourceMappingURL=cli.d.ts.map
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAsBA,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAK9C;AA8GD,wBAAsB,SAAS,IAAI,OAAO,CAAC;IACzC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,CAAC,CAgFD;AAMD,wBAAsB,cAAc,CAAC,OAAO,EAAE;IAC5C,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqChB"}
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { stat } from 'node:fs/promises';
|
|
2
2
|
import { parseArgs as utilParseArgs } from 'node:util';
|
|
3
3
|
import { printHelpAndExit, printVersionAndExit } from './cli-help.js';
|
|
4
|
-
import { processInParallel } from './core/concurrency.js';
|
|
5
4
|
import { cli } from './core/config.js';
|
|
6
5
|
import { formatUnknownErrorMessage } from './core/errors.js';
|
|
7
6
|
import { cliFmt, padEndVisible } from './core/fmt.js';
|
|
@@ -10,7 +9,6 @@ import { PathGuard } from './core/path.js';
|
|
|
10
9
|
import { IS_WINDOWS, parseTrueEnvFlag } from './core/primitives.js';
|
|
11
10
|
import { getMaxTextFileSize } from './core/util.js';
|
|
12
11
|
import { registeredTools } from './tools/index.js';
|
|
13
|
-
const CLI_VALIDATE_CONCURRENCY = 8;
|
|
14
12
|
// ════════════════════════════════════════════════════════════
|
|
15
13
|
// Path & Config Utilities — pure functions and error types
|
|
16
14
|
// ════════════════════════════════════════════════════════════
|
|
@@ -60,12 +58,11 @@ async function validateDirectoryPath(inputPath, allowMissing = false) {
|
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
60
|
async function normalizeAndValidateDirs(paths, allowMissing = false) {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
const normalized = [];
|
|
62
|
+
for (const p of paths) {
|
|
63
|
+
normalized.push(await validateDirectoryPath(p, allowMissing));
|
|
66
64
|
}
|
|
67
|
-
|
|
68
|
-
throw first.error;
|
|
65
|
+
return deduplicateAllowedDirectories(normalized);
|
|
69
66
|
}
|
|
70
67
|
function normalizeCliExitMessage(error) {
|
|
71
68
|
const rawMessage = formatUnknownErrorMessage(error);
|
|
@@ -193,8 +190,11 @@ export async function parseArgs() {
|
|
|
193
190
|
throw new CliExitError(normalizeCliExitMessage(error), 1);
|
|
194
191
|
}
|
|
195
192
|
}
|
|
193
|
+
// ════════════════════════════════════════════════════════════
|
|
194
|
+
// Effective config reporting — prints the resolved server config
|
|
195
|
+
// ════════════════════════════════════════════════════════════
|
|
196
196
|
export async function runPrintConfig(options) {
|
|
197
|
-
const write =
|
|
197
|
+
const write = (s) => process.stdout.write(s);
|
|
198
198
|
const pathGuard = new PathGuard({
|
|
199
199
|
allowCwd: options.allowCwd,
|
|
200
200
|
cliAllowedDirs: options.allowedDirs,
|
|
@@ -226,6 +226,5 @@ export async function runPrintConfig(options) {
|
|
|
226
226
|
write(`${key('tools:')}${cliFmt.dim(config.tools.join(', '))}\n`);
|
|
227
227
|
write(`${key('maxFileSize:')}${cliFmt.yellow(String(config.limits.maxFileSizeBytes))}\n`);
|
|
228
228
|
}
|
|
229
|
-
return config;
|
|
230
229
|
}
|
|
231
230
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAEnC,+DAA+D;AAC/D,2DAA2D;AAC3D,+DAA+D;AAE/D,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,QAAQ,CAAS;IAE1B,YAA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,CAAC,CAAC,IAAI,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { Stats } from 'node:fs';\nimport { stat } from 'node:fs/promises';\nimport { parseArgs as utilParseArgs } from 'node:util';\n\nimport { printHelpAndExit, printVersionAndExit } from './cli-help.js';\nimport { processInParallel } from './core/concurrency.js';\nimport { cli } from './core/config.js';\nimport { formatUnknownErrorMessage } from './core/errors.js';\nimport { cliFmt, padEndVisible } from './core/fmt.js';\nimport {\n getReservedDeviceNameForPath,\n isWindowsDriveRelativePath,\n normalizePath,\n} from './core/path-utils.js';\nimport { PathGuard } from './core/path.js';\nimport { IS_WINDOWS, parseTrueEnvFlag } from './core/primitives.js';\nimport { getMaxTextFileSize } from './core/util.js';\nimport { registeredTools } from './tools/index.js';\n\nconst CLI_VALIDATE_CONCURRENCY = 8;\n\n// ════════════════════════════════════════════════════════════\n// Path & Config Utilities — pure functions and error types\n// ════════════════════════════════════════════════════════════\n\nexport class CliExitError extends Error {\n readonly exitCode: number;\n\n constructor(message: string, exitCode: number) {\n super(message);\n this.name = 'CliExitError';\n this.exitCode = exitCode;\n }\n}\n\nfunction validateCliPath(inputPath: string): void {\n if (inputPath.includes('\\0')) {\n throw new CliExitError('Path contains null bytes.', 1);\n }\n\n if (isWindowsDriveRelativePath(inputPath)) {\n throw new CliExitError(\n 'Windows drive-relative paths are not allowed. Use C:\\\\path or C:/path instead of C:path.',\n 1,\n );\n }\n\n const reserved = getReservedDeviceNameForPath(inputPath);\n if (reserved) {\n throw new CliExitError(`Windows reserved device name not allowed: ${reserved}.`, 1);\n }\n}\n\nfunction assertDirectory(stats: Stats, inputPath: string): void {\n if (stats.isDirectory()) return;\n throw new Error(`${inputPath} is not a directory`);\n}\n\nasync function validateDirectoryPath(inputPath: string, allowMissing = false): Promise<string> {\n const normalized = normalizePath(inputPath);\n\n try {\n const stats = await stat(normalized);\n assertDirectory(stats, inputPath);\n return normalized;\n } catch (error) {\n if (allowMissing) {\n if (error instanceof Error && error.message.includes('is not a directory')) {\n throw error;\n }\n return normalized;\n }\n // Node's own message already names the syscall and the errno.\n throw new Error(`Cannot access directory ${inputPath}: ${formatUnknownErrorMessage(error)}`, {\n cause: error,\n });\n }\n}\n\nasync function normalizeAndValidateDirs(\n paths: readonly string[],\n allowMissing = false,\n): Promise<string[]> {\n const { results, errors } = await processInParallel(\n [...paths],\n (p) => validateDirectoryPath(p, allowMissing),\n CLI_VALIDATE_CONCURRENCY,\n );\n if (errors.length === 0) {\n return deduplicateAllowedDirectories(results.map((r) => r.value));\n }\n const first = errors.reduce((prev, curr) => (curr.index < prev.index ? curr : prev));\n throw first.error;\n}\n\nfunction normalizeCliExitMessage(error: unknown): string {\n const rawMessage = formatUnknownErrorMessage(error);\n return rawMessage.startsWith('Error:') ? rawMessage : `Error: ${rawMessage}`;\n}\n\nfunction deduplicateAllowedDirectories(dirs: readonly string[]): string[] {\n const seen = new Set<string>();\n const deduplicated: string[] = [];\n\n for (const dir of dirs) {\n const key = IS_WINDOWS ? dir.toLowerCase() : dir;\n if (seen.has(key)) continue;\n seen.add(key);\n deduplicated.push(dir);\n }\n\n return deduplicated;\n}\n\nfunction parsePortOption(raw: unknown): number | undefined {\n // '' reads as unset: FS_PORT set-but-empty (compose templating) means stdio.\n if (raw === undefined || raw === '') return undefined;\n const n = Number(raw);\n if (!Number.isInteger(n) || n < 1 || n > 65535) {\n throw new CliExitError(`Error: --port / FS_PORT must be an integer between 1 and 65535`, 1);\n }\n return n;\n}\n\nconst CLI_PARSER_CONFIG = {\n options: {\n 'allow-cwd': { type: 'boolean', default: false },\n 'read-only': { type: 'boolean', default: false },\n safe: { type: 'boolean', default: false },\n 'print-config': { type: 'boolean', default: false },\n json: { type: 'boolean', default: false },\n port: { type: 'string' },\n help: { type: 'boolean', short: 'h' },\n version: { type: 'boolean', short: 'v' },\n 'log-level': { type: 'string' },\n 'http-host': { type: 'string' },\n 'api-key': { type: 'string' },\n 'allow-sensitive': { type: 'boolean', default: false },\n 'root-boundary': { type: 'string' },\n 'max-file-size': { type: 'string' },\n 'walk-cwd': { type: 'boolean', default: false },\n deny: { type: 'string', multiple: true },\n 'allow-missing-roots': { type: 'boolean', default: false },\n },\n strict: true,\n allowPositionals: true,\n} as const;\n\nexport async function parseArgs(): Promise<{\n allowedDirs: string[];\n allowCwd: boolean;\n port: number | undefined;\n readOnly: boolean;\n printConfig: boolean;\n json: boolean;\n httpHost: string | undefined;\n apiKey: string | undefined;\n}> {\n try {\n const parsed = utilParseArgs(CLI_PARSER_CONFIG);\n\n if (parsed.values.help) {\n printHelpAndExit();\n }\n\n if (parsed.values.version) {\n printVersionAndExit();\n }\n\n for (const positional of parsed.positionals) {\n validateCliPath(positional);\n }\n\n const vals = parsed.values as Record<string, unknown>;\n // `--http-host` and `--api-key` are returned to the caller and handed to\n // the server as config. Every other flag lands in the CLI-override store\n // (core/config.ts) — the one owner of the flag-beats-env rule — which deep\n // core readers (path, sensitive, observability, util) consult before\n // falling back to the operator's environment. Nothing writes process.env.\n const httpHost =\n typeof vals['http-host'] === 'string' ? vals['http-host'] : process.env['FS_HTTP_HOST'];\n const apiKey =\n typeof vals['api-key'] === 'string' ? vals['api-key'] : process.env['FS_API_KEY'];\n\n if (typeof vals['log-level'] === 'string') cli.logLevel = vals['log-level'];\n if (typeof vals['max-file-size'] === 'string') cli.maxFileSize = vals['max-file-size'];\n if (typeof vals['root-boundary'] === 'string') cli.rootBoundary = vals['root-boundary'];\n if (vals['allow-sensitive'] === true) cli.allowSensitive = true;\n if (vals['walk-cwd'] === true) cli.allowCwdWalk = true;\n if (vals['allow-missing-roots'] === true) cli.allowMissingRoots = true;\n if (Array.isArray(vals['deny'])) {\n const denyPatterns = vals['deny']\n .filter((entry): entry is string => typeof entry === 'string')\n .map((entry) => entry.trim())\n .filter(Boolean);\n if (denyPatterns.length > 0) cli.denyPatterns = [...new Set(denyPatterns)];\n }\n\n const allowCwd =\n (vals['allow-cwd'] as boolean) ||\n (vals['walk-cwd'] as boolean) ||\n parseTrueEnvFlag(process.env['FS_ALLOW_CWD_WALK'], 'FS_ALLOW_CWD_WALK');\n const readOnly = (vals['read-only'] as boolean) || (vals['safe'] as boolean);\n const printConfig = vals['print-config'] as boolean;\n const json = vals['json'] as boolean;\n const port = parsePortOption(parsed.values.port ?? process.env['FS_PORT']);\n const allowMissingRoots =\n (vals['allow-missing-roots'] as boolean) ||\n parseTrueEnvFlag(process.env['FS_ALLOW_MISSING_ROOTS'], 'FS_ALLOW_MISSING_ROOTS');\n\n let allowedDirs: string[] = [];\n try {\n allowedDirs =\n parsed.positionals.length > 0\n ? await normalizeAndValidateDirs(parsed.positionals, allowMissingRoots)\n : [];\n } catch (error: unknown) {\n throw new CliExitError(normalizeCliExitMessage(error), 1);\n }\n\n return {\n allowedDirs,\n allowCwd,\n port,\n readOnly,\n printConfig,\n json,\n httpHost,\n apiKey,\n };\n } catch (error: unknown) {\n if (error instanceof CliExitError) {\n throw error;\n }\n\n throw new CliExitError(normalizeCliExitMessage(error), 1);\n }\n}\n\n// ════════════════════════════════════════════════════════════\n// Effective config reporting — prints the resolved server config\n// ════════════════════════════════════════════════════════════\n\nexport interface EffectiveConfig {\n transport: string;\n readOnly: boolean;\n allowedRoots: string[];\n tools: string[];\n apiKey: string | null;\n limits: { maxFileSizeBytes: number };\n}\n\nexport interface PrintConfigOptions {\n allowedDirs: string[];\n allowCwd: boolean;\n readOnly: boolean;\n json: boolean;\n /** Resolved `--port`. Present means the launch this reports on is an HTTP bind. */\n port?: number;\n httpHost?: string;\n apiKey?: string;\n stdout?: (chunk: string) => void;\n}\n\nexport async function runPrintConfig(options: PrintConfigOptions): Promise<EffectiveConfig> {\n const write = options.stdout ?? ((s: string) => process.stdout.write(s));\n\n const pathGuard = new PathGuard({\n allowCwd: options.allowCwd,\n cliAllowedDirs: options.allowedDirs,\n });\n await pathGuard.recomputeAllowedDirectories();\n const allowedRoots = pathGuard.getAllowedDirectories();\n\n const tools = registeredTools(options.readOnly).map((t) => t.name);\n\n // Derived, never assumed: `--print-config --port 3000` reports the HTTP bind\n // that `--port` would actually have started, not the stdio default.\n const config: EffectiveConfig = {\n transport:\n options.port !== undefined\n ? `http://${options.httpHost ?? '127.0.0.1'}:${String(options.port)}`\n : 'stdio',\n readOnly: options.readOnly,\n allowedRoots,\n tools,\n apiKey: options.apiKey ? '***' : null,\n limits: { maxFileSizeBytes: getMaxTextFileSize() },\n };\n\n if (options.json) {\n write(JSON.stringify(config, null, 2));\n } else {\n const key = (k: string) => padEndVisible(cliFmt.cyan(k), 14);\n write(`${key('transport:')}${config.transport}\\n`);\n write(`${key('readOnly:')}${cliFmt.bool(config.readOnly)}\\n`);\n write(`${key('apiKey:')}${cliFmt.dim(config.apiKey ?? 'none')}\\n`);\n write(`${key('allowedRoots:')}${config.allowedRoots.join(', ') || cliFmt.dim('(none)')}\\n`);\n write(`${key('tools:')}${cliFmt.dim(config.tools.join(', '))}\\n`);\n write(`${key('maxFileSize:')}${cliFmt.yellow(String(config.limits.maxFileSizeBytes))}\\n`);\n }\n\n return config;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE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ParseArgs } from 'node:util';\n\nimport { printHelpAndExit, printVersionAndExit } from './cli-help.js';\nimport { cli } from './core/config.js';\nimport { formatUnknownErrorMessage } from './core/errors.js';\nimport { cliFmt, padEndVisible } from './core/fmt.js';\nimport {\n getReservedDeviceNameForPath,\n isWindowsDriveRelativePath,\n normalizePath,\n} from './core/path-utils.js';\nimport { PathGuard } from './core/path.js';\nimport { IS_WINDOWS, parseTrueEnvFlag } from './core/primitives.js';\nimport { getMaxTextFileSize } from './core/util.js';\nimport { registeredTools } from './tools/index.js';\n\n// ════════════════════════════════════════════════════════════\n// Path & Config Utilities — pure functions and error types\n// ════════════════════════════════════════════════════════════\n\nexport class CliExitError extends Error {\n readonly exitCode: number;\n\n constructor(message: string, exitCode: number) {\n super(message);\n this.name = 'CliExitError';\n this.exitCode = exitCode;\n }\n}\n\nfunction validateCliPath(inputPath: string): void {\n if (inputPath.includes('\\0')) {\n throw new CliExitError('Path contains null bytes.', 1);\n }\n\n if (isWindowsDriveRelativePath(inputPath)) {\n throw new CliExitError(\n 'Windows drive-relative paths are not allowed. Use C:\\\\path or C:/path instead of C:path.',\n 1,\n );\n }\n\n const reserved = getReservedDeviceNameForPath(inputPath);\n if (reserved) {\n throw new CliExitError(`Windows reserved device name not allowed: ${reserved}.`, 1);\n }\n}\n\nfunction assertDirectory(stats: Stats, inputPath: string): void {\n if (stats.isDirectory()) return;\n throw new Error(`${inputPath} is not a directory`);\n}\n\nasync function validateDirectoryPath(inputPath: string, allowMissing = false): Promise<string> {\n const normalized = normalizePath(inputPath);\n\n try {\n const stats = await stat(normalized);\n assertDirectory(stats, inputPath);\n return normalized;\n } catch (error) {\n if (allowMissing) {\n if (error instanceof Error && error.message.includes('is not a directory')) {\n throw error;\n }\n return normalized;\n }\n // Node's own message already names the syscall and the errno.\n throw new Error(`Cannot access directory ${inputPath}: ${formatUnknownErrorMessage(error)}`, {\n cause: error,\n });\n }\n}\n\nasync function normalizeAndValidateDirs(\n paths: readonly string[],\n allowMissing = false,\n): Promise<string[]> {\n const normalized: string[] = [];\n for (const p of paths) {\n normalized.push(await validateDirectoryPath(p, allowMissing));\n }\n return deduplicateAllowedDirectories(normalized);\n}\n\nfunction normalizeCliExitMessage(error: unknown): string {\n const rawMessage = formatUnknownErrorMessage(error);\n return rawMessage.startsWith('Error:') ? rawMessage : `Error: ${rawMessage}`;\n}\n\nfunction deduplicateAllowedDirectories(dirs: readonly string[]): string[] {\n const seen = new Set<string>();\n const deduplicated: string[] = [];\n\n for (const dir of dirs) {\n const key = IS_WINDOWS ? dir.toLowerCase() : dir;\n if (seen.has(key)) continue;\n seen.add(key);\n deduplicated.push(dir);\n }\n\n return deduplicated;\n}\n\nfunction parsePortOption(raw: unknown): number | undefined {\n // '' reads as unset: FS_PORT set-but-empty (compose templating) means stdio.\n if (raw === undefined || raw === '') return undefined;\n const n = Number(raw);\n if (!Number.isInteger(n) || n < 1 || n > 65535) {\n throw new CliExitError(`Error: --port / FS_PORT must be an integer between 1 and 65535`, 1);\n }\n return n;\n}\n\nconst CLI_PARSER_CONFIG = {\n options: {\n 'allow-cwd': { type: 'boolean', default: false },\n 'read-only': { type: 'boolean', default: false },\n safe: { type: 'boolean', default: false },\n 'print-config': { type: 'boolean', default: false },\n json: { type: 'boolean', default: false },\n port: { type: 'string' },\n help: { type: 'boolean', short: 'h' },\n version: { type: 'boolean', short: 'v' },\n 'log-level': { type: 'string' },\n 'http-host': { type: 'string' },\n 'api-key': { type: 'string' },\n 'allow-sensitive': { type: 'boolean', default: false },\n 'root-boundary': { type: 'string' },\n 'max-file-size': { type: 'string' },\n 'walk-cwd': { type: 'boolean', default: false },\n deny: { type: 'string', multiple: true },\n 'allow-missing-roots': { type: 'boolean', default: false },\n },\n strict: true,\n allowPositionals: true,\n} as const;\n\nexport async function parseArgs(): Promise<{\n allowedDirs: string[];\n allowCwd: boolean;\n port: number | undefined;\n readOnly: boolean;\n printConfig: boolean;\n json: boolean;\n httpHost: string | undefined;\n apiKey: string | undefined;\n}> {\n try {\n const parsed = utilParseArgs(CLI_PARSER_CONFIG);\n\n if (parsed.values.help) {\n printHelpAndExit();\n }\n\n if (parsed.values.version) {\n printVersionAndExit();\n }\n\n for (const positional of parsed.positionals) {\n validateCliPath(positional);\n }\n\n const vals = parsed.values as Record<string, unknown>;\n // `--http-host` and `--api-key` are returned to the caller and handed to\n // the server as config. Every other flag lands in the CLI-override store\n // (core/config.ts) — the one owner of the flag-beats-env rule — which deep\n // core readers (path, sensitive, observability, util) consult before\n // falling back to the operator's environment. Nothing writes process.env.\n const httpHost =\n typeof vals['http-host'] === 'string' ? vals['http-host'] : process.env['FS_HTTP_HOST'];\n const apiKey =\n typeof vals['api-key'] === 'string' ? vals['api-key'] : process.env['FS_API_KEY'];\n\n if (typeof vals['log-level'] === 'string') cli.logLevel = vals['log-level'];\n if (typeof vals['max-file-size'] === 'string') cli.maxFileSize = vals['max-file-size'];\n if (typeof vals['root-boundary'] === 'string') cli.rootBoundary = vals['root-boundary'];\n if (vals['allow-sensitive'] === true) cli.allowSensitive = true;\n if (vals['walk-cwd'] === true) cli.allowCwdWalk = true;\n if (vals['allow-missing-roots'] === true) cli.allowMissingRoots = true;\n if (Array.isArray(vals['deny'])) {\n const denyPatterns = vals['deny']\n .filter((entry): entry is string => typeof entry === 'string')\n .map((entry) => entry.trim())\n .filter(Boolean);\n if (denyPatterns.length > 0) cli.denyPatterns = [...new Set(denyPatterns)];\n }\n\n const allowCwd =\n (vals['allow-cwd'] as boolean) ||\n (vals['walk-cwd'] as boolean) ||\n parseTrueEnvFlag(process.env['FS_ALLOW_CWD_WALK'], 'FS_ALLOW_CWD_WALK');\n const readOnly = (vals['read-only'] as boolean) || (vals['safe'] as boolean);\n const printConfig = vals['print-config'] as boolean;\n const json = vals['json'] as boolean;\n const port = parsePortOption(parsed.values.port ?? process.env['FS_PORT']);\n const allowMissingRoots =\n (vals['allow-missing-roots'] as boolean) ||\n parseTrueEnvFlag(process.env['FS_ALLOW_MISSING_ROOTS'], 'FS_ALLOW_MISSING_ROOTS');\n\n let allowedDirs: string[] = [];\n try {\n allowedDirs =\n parsed.positionals.length > 0\n ? await normalizeAndValidateDirs(parsed.positionals, allowMissingRoots)\n : [];\n } catch (error: unknown) {\n throw new CliExitError(normalizeCliExitMessage(error), 1);\n }\n\n return {\n allowedDirs,\n allowCwd,\n port,\n readOnly,\n printConfig,\n json,\n httpHost,\n apiKey,\n };\n } catch (error: unknown) {\n if (error instanceof CliExitError) {\n throw error;\n }\n\n throw new CliExitError(normalizeCliExitMessage(error), 1);\n }\n}\n\n// ════════════════════════════════════════════════════════════\n// Effective config reporting — prints the resolved server config\n// ════════════════════════════════════════════════════════════\n\nexport async function runPrintConfig(options: {\n allowedDirs: string[];\n allowCwd: boolean;\n readOnly: boolean;\n json: boolean;\n /** Resolved `--port`. Present means the launch this reports on is an HTTP bind. */\n port?: number;\n httpHost?: string;\n apiKey?: string;\n}): Promise<void> {\n const write = (s: string) => process.stdout.write(s);\n\n const pathGuard = new PathGuard({\n allowCwd: options.allowCwd,\n cliAllowedDirs: options.allowedDirs,\n });\n await pathGuard.recomputeAllowedDirectories();\n const allowedRoots = pathGuard.getAllowedDirectories();\n\n const tools = registeredTools(options.readOnly).map((t) => t.name);\n\n // Derived, never assumed: `--print-config --port 3000` reports the HTTP bind\n // that `--port` would actually have started, not the stdio default.\n const config = {\n transport:\n options.port !== undefined\n ? `http://${options.httpHost ?? '127.0.0.1'}:${String(options.port)}`\n : 'stdio',\n readOnly: options.readOnly,\n allowedRoots,\n tools,\n apiKey: options.apiKey ? '***' : null,\n limits: { maxFileSizeBytes: getMaxTextFileSize() },\n };\n\n if (options.json) {\n write(JSON.stringify(config, null, 2));\n } else {\n const key = (k: string) => padEndVisible(cliFmt.cyan(k), 14);\n write(`${key('transport:')}${config.transport}\\n`);\n write(`${key('readOnly:')}${cliFmt.bool(config.readOnly)}\\n`);\n write(`${key('apiKey:')}${cliFmt.dim(config.apiKey ?? 'none')}\\n`);\n write(`${key('allowedRoots:')}${config.allowedRoots.join(', ') || cliFmt.dim('(none)')}\\n`);\n write(`${key('tools:')}${cliFmt.dim(config.tools.join(', '))}\\n`);\n write(`${key('maxFileSize:')}${cliFmt.yellow(String(config.limits.maxFileSizeBytes))}\\n`);\n }\n}\n"]}
|
package/dist/core/cursor.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import type { PageSnapshotStore } from './page-store.js';
|
|
2
|
-
export declare function createFirstPage<T, M>(params: {
|
|
3
|
-
store: PageSnapshotStore;
|
|
4
|
-
queryKey: string;
|
|
5
|
-
items: readonly T[];
|
|
6
|
-
metadata: M;
|
|
7
|
-
pageSize: number;
|
|
8
|
-
}): Page<T, M>;
|
|
9
2
|
/**
|
|
10
3
|
* The full result set a paged tool produced, before slicing. `truncated` is the
|
|
11
4
|
* engine's own stop state — the hard result cap or a timeout cut the set — and
|
|
@@ -16,7 +9,7 @@ export interface ProducedPage<T, M> {
|
|
|
16
9
|
readonly metadata: M;
|
|
17
10
|
readonly truncated: boolean;
|
|
18
11
|
}
|
|
19
|
-
|
|
12
|
+
interface Page<T, M> {
|
|
20
13
|
readonly page: readonly T[];
|
|
21
14
|
readonly metadata: M;
|
|
22
15
|
readonly nextCursor: string | undefined;
|
|
@@ -51,10 +44,5 @@ export declare function paginate<T, M, R>(params: {
|
|
|
51
44
|
produce: () => Promise<ProducedPage<T, M>>;
|
|
52
45
|
externalize?: ((items: readonly T[], metadata: M) => R) | undefined;
|
|
53
46
|
}): Promise<PaginatedPage<T, M, R>>;
|
|
54
|
-
export
|
|
55
|
-
store: PageSnapshotStore;
|
|
56
|
-
queryKey: string;
|
|
57
|
-
cursor: string;
|
|
58
|
-
pageSize: number;
|
|
59
|
-
}): Page<T, M>;
|
|
47
|
+
export {};
|
|
60
48
|
//# sourceMappingURL=cursor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../src/core/cursor.ts"],"names":[],"mappings":"AAC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,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,SAAS,CAAC;CACrE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CA6BlC"}
|
package/dist/core/cursor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ErrorCode,
|
|
1
|
+
import { ErrorCode, FsError } from './errors.js';
|
|
2
2
|
import { invalidCursor } from './page-store.js';
|
|
3
3
|
function encodePageCursor(cursor) {
|
|
4
4
|
return Buffer.from(JSON.stringify(cursor)).toString('base64url');
|
|
@@ -17,25 +17,6 @@ function pageResult(snapshotId, offset, pageSize, snapshot) {
|
|
|
17
17
|
: undefined,
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
export function createFirstPage(params) {
|
|
21
|
-
if (params.items.length <= params.pageSize) {
|
|
22
|
-
return {
|
|
23
|
-
page: params.items,
|
|
24
|
-
metadata: params.metadata,
|
|
25
|
-
nextCursor: undefined,
|
|
26
|
-
offset: 0,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
const snapshotId = params.store.create({
|
|
30
|
-
queryKey: params.queryKey,
|
|
31
|
-
items: params.items,
|
|
32
|
-
metadata: params.metadata,
|
|
33
|
-
});
|
|
34
|
-
return pageResult(snapshotId, 0, params.pageSize, {
|
|
35
|
-
items: params.items,
|
|
36
|
-
metadata: params.metadata,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
20
|
/**
|
|
40
21
|
* The one replay-or-produce branch every paged tool runs. A cursor replays a
|
|
41
22
|
* stored snapshot; without one, `produce` runs the query and its result is
|
|
@@ -50,31 +31,36 @@ export function createFirstPage(params) {
|
|
|
50
31
|
*/
|
|
51
32
|
export async function paginate(params) {
|
|
52
33
|
if (params.cursor !== undefined) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
cursor: params.cursor,
|
|
57
|
-
pageSize: params.pageSize,
|
|
58
|
-
});
|
|
34
|
+
const decoded = decodePageCursor(params.cursor);
|
|
35
|
+
const snapshot = params.store.read(decoded.snapshotId, params.queryKey);
|
|
36
|
+
return pageResult(decoded.snapshotId, decoded.offset, params.pageSize, snapshot);
|
|
59
37
|
}
|
|
60
38
|
const produced = await params.produce();
|
|
61
39
|
const incomplete = produced.items.length > params.pageSize || produced.truncated;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
40
|
+
let first;
|
|
41
|
+
if (produced.items.length <= params.pageSize) {
|
|
42
|
+
first = {
|
|
43
|
+
page: produced.items,
|
|
44
|
+
metadata: produced.metadata,
|
|
45
|
+
nextCursor: undefined,
|
|
46
|
+
offset: 0,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const snapshotId = params.store.create({
|
|
51
|
+
queryKey: params.queryKey,
|
|
52
|
+
items: produced.items,
|
|
53
|
+
metadata: produced.metadata,
|
|
54
|
+
});
|
|
55
|
+
first = pageResult(snapshotId, 0, params.pageSize, {
|
|
56
|
+
items: produced.items,
|
|
57
|
+
metadata: produced.metadata,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
69
60
|
if (!incomplete || params.externalize === undefined)
|
|
70
61
|
return first;
|
|
71
62
|
return { ...first, resource: params.externalize(produced.items, produced.metadata) };
|
|
72
63
|
}
|
|
73
|
-
export function readNextPage(params) {
|
|
74
|
-
const decoded = decodePageCursor(params.cursor);
|
|
75
|
-
const snapshot = params.store.read(decoded.snapshotId, params.queryKey);
|
|
76
|
-
return pageResult(decoded.snapshotId, decoded.offset, params.pageSize, snapshot);
|
|
77
|
-
}
|
|
78
64
|
function decodePageCursor(cursor) {
|
|
79
65
|
try {
|
|
80
66
|
const text = Buffer.from(cursor, 'base64url').toString('utf-8');
|
|
@@ -91,7 +77,7 @@ function decodePageCursor(cursor) {
|
|
|
91
77
|
catch (error) {
|
|
92
78
|
if (error instanceof FsError)
|
|
93
79
|
throw error;
|
|
94
|
-
throw new FsError(ErrorCode.INVALID_INPUT, invalidCursor().message, undefined,
|
|
80
|
+
throw new FsError(ErrorCode.INVALID_INPUT, invalidCursor().message, undefined, error instanceof Error ? error : undefined);
|
|
95
81
|
}
|
|
96
82
|
}
|
|
97
83
|
//# sourceMappingURL=cursor.js.map
|
package/dist/core/cursor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursor.js","sourceRoot":"","sources":["../../src/core/cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"cursor.js","sourceRoot":"","sources":["../../src/core/cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAOhD,SAAS,gBAAgB,CAAC,MAAkB;IAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,UAAU,CACjB,UAAkB,EAClB,MAAc,EACd,QAAgB,EAChB,QAA4B;IAE5B,IAAI,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM;QAAE,MAAM,aAAa,EAAE,CAAC;IAC3D,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;IAC7D,MAAM,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACxC,OAAO;QACL,IAAI;QACJ,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,MAAM;QACN,UAAU,EACR,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM;YAChC,CAAC,CAAC,gBAAgB,CAAC,EAAE,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C,CAAC,CAAC,SAAS,CAC3C,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { ErrorCode, FsError } from './errors.js';\nimport type { PageSnapshot, PageSnapshotStore } from './page-store.js';\nimport { invalidCursor } from './page-store.js';\n\ninterface PageCursor {\n readonly snapshotId: string;\n readonly offset: number;\n}\n\nfunction encodePageCursor(cursor: PageCursor): string {\n return Buffer.from(JSON.stringify(cursor)).toString('base64url');\n}\n\nfunction pageResult<T, M>(\n snapshotId: string,\n offset: number,\n pageSize: number,\n snapshot: PageSnapshot<T, M>,\n): Page<T, M> {\n if (offset >= snapshot.items.length) throw invalidCursor();\n const page = snapshot.items.slice(offset, offset + pageSize);\n const nextOffset = offset + page.length;\n return {\n page,\n metadata: snapshot.metadata,\n offset,\n nextCursor:\n nextOffset < snapshot.items.length\n ? encodePageCursor({ snapshotId, offset: nextOffset })\n : undefined,\n };\n}\n\n/**\n * The full result set a paged tool produced, before slicing. `truncated` is the\n * engine's own stop state — the hard result cap or a timeout cut the set — and\n * says nothing about page size.\n */\nexport interface ProducedPage<T, M> {\n readonly items: readonly T[];\n readonly metadata: M;\n readonly truncated: boolean;\n}\n\ninterface Page<T, M> {\n readonly page: readonly T[];\n readonly metadata: M;\n readonly nextCursor: string | undefined;\n /**\n * Index of this page's first item in the full set. A tool that reports\n * progress in its text needs it: without it every page can only say how many\n * rows it holds, which is the same number on page 1 and page 9.\n */\n readonly offset: number;\n}\n\nexport interface PaginatedPage<T, M, R> extends Page<T, M> {\n /** The externalized full set. First page only, and only when incomplete. */\n readonly resource?: R;\n}\n\n/**\n * The one replay-or-produce branch every paged tool runs. A cursor replays a\n * stored snapshot; without one, `produce` runs the query and its result is\n * snapshotted for later pages.\n *\n * The response is incomplete when the set spans more than one page or the\n * engine truncated it. Then — and only on the first page — `externalize`\n * stores the full set and its handle rides back as `resource`. Replayed pages\n * never carry it: the stored entry expires on the resource store's own TTL and\n * LRU, not this snapshot's, so replaying its URI would hand back a dead\n * pointer. Nor do they mint a new one; the set was already stored whole.\n */\nexport async function paginate<T, M, R>(params: {\n store: PageSnapshotStore;\n queryKey: string;\n cursor: string | undefined;\n pageSize: number;\n produce: () => Promise<ProducedPage<T, M>>;\n externalize?: ((items: readonly T[], metadata: M) => R) | undefined;\n}): Promise<PaginatedPage<T, M, R>> {\n if (params.cursor !== undefined) {\n const decoded = decodePageCursor(params.cursor);\n const snapshot = params.store.read<T, M>(decoded.snapshotId, params.queryKey);\n return pageResult(decoded.snapshotId, decoded.offset, params.pageSize, snapshot);\n }\n const produced = await params.produce();\n const incomplete = produced.items.length > params.pageSize || produced.truncated;\n let first: Page<T, M>;\n if (produced.items.length <= params.pageSize) {\n first = {\n page: produced.items,\n metadata: produced.metadata,\n nextCursor: undefined,\n offset: 0,\n };\n } else {\n const snapshotId = params.store.create({\n queryKey: params.queryKey,\n items: produced.items,\n metadata: produced.metadata,\n });\n first = pageResult(snapshotId, 0, params.pageSize, {\n items: produced.items,\n metadata: produced.metadata,\n });\n }\n if (!incomplete || params.externalize === undefined) return first;\n return { ...first, resource: params.externalize(produced.items, produced.metadata) };\n}\n\nfunction decodePageCursor(cursor: string): PageCursor {\n try {\n const text = Buffer.from(cursor, 'base64url').toString('utf-8');\n const parsed = JSON.parse(text) as { snapshotId?: unknown; offset?: unknown };\n if (\n typeof parsed.snapshotId === 'string' &&\n parsed.snapshotId.length > 0 &&\n typeof parsed.offset === 'number' &&\n Number.isInteger(parsed.offset) &&\n parsed.offset >= 0\n ) {\n return { snapshotId: parsed.snapshotId, offset: parsed.offset };\n }\n throw new Error('Invalid page cursor');\n } catch (error) {\n if (error instanceof FsError) throw error;\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n invalidCursor().message,\n undefined,\n error instanceof Error ? error : undefined,\n );\n }\n}\n"]}
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -28,7 +28,6 @@ export interface Problem {
|
|
|
28
28
|
readonly path?: string;
|
|
29
29
|
readonly issues?: readonly ProblemIssue[];
|
|
30
30
|
readonly suggestion?: string;
|
|
31
|
-
readonly details?: ProblemDetails;
|
|
32
31
|
}
|
|
33
32
|
interface ProblemIssue {
|
|
34
33
|
readonly path: readonly (string | number)[];
|
|
@@ -38,16 +37,9 @@ interface ProblemIssue {
|
|
|
38
37
|
readonly received?: string;
|
|
39
38
|
readonly params?: Readonly<Record<string, unknown>>;
|
|
40
39
|
}
|
|
41
|
-
interface ProblemDetails {
|
|
42
|
-
readonly errno?: string;
|
|
43
|
-
readonly syscall?: string;
|
|
44
|
-
readonly tool?: string;
|
|
45
|
-
readonly extra?: Readonly<Record<string, unknown>>;
|
|
46
|
-
}
|
|
47
40
|
interface ProblemFactoryOptions {
|
|
48
41
|
path?: string;
|
|
49
42
|
suggestion?: string;
|
|
50
|
-
details?: ProblemDetails;
|
|
51
43
|
issues?: readonly ProblemIssue[];
|
|
52
44
|
}
|
|
53
45
|
export declare const Problem: {
|
|
@@ -76,7 +68,7 @@ export declare function fsErrorCode(error: unknown): ProtocolErrorCode;
|
|
|
76
68
|
* survives cross-realm / multi-SDK-copy conditions where the prototype chain
|
|
77
69
|
* breaks. Mirrors the isFsError pattern.
|
|
78
70
|
*/
|
|
79
|
-
export declare function hasErrorShape(error: unknown, name: string
|
|
71
|
+
export declare function hasErrorShape(error: unknown, name: string): error is Error & {
|
|
80
72
|
code: string | number;
|
|
81
73
|
};
|
|
82
74
|
export declare function isNodeError(error: unknown): error is NodeJS.ErrnoException;
|
|
@@ -87,10 +79,9 @@ export declare function formatUnknownErrorMessage(error: unknown): string;
|
|
|
87
79
|
export declare function normalizeUnknownError(error: unknown): Error;
|
|
88
80
|
export declare class FsError extends Error {
|
|
89
81
|
readonly problem: Problem;
|
|
90
|
-
constructor(code: ErrorCode, message: string, path?: string,
|
|
82
|
+
constructor(code: ErrorCode, message: string, path?: string, cause?: unknown);
|
|
91
83
|
get code(): ErrorCode;
|
|
92
84
|
get path(): string | undefined;
|
|
93
|
-
get details(): Record<string, unknown> | undefined;
|
|
94
85
|
}
|
|
95
86
|
export {};
|
|
96
87
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAIjE,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;CAeZ,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAEnE,UAAU,YAAY;IACpB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAIjE,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;CAeZ,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAEnE,UAAU,YAAY;IACpB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,C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AM,EAAE,KAAK,CAAC,EAAE,OAAO;IAa5E,IAAI,IAAI,IAAI,SAAS,CAEpB;IAED,IAAI,IAAI,IAAI,MAAM,GAAG,SAAS,CAE7B;CACF"}
|
package/dist/core/errors.js
CHANGED
|
@@ -22,7 +22,6 @@ function build(code, message, opts = {}) {
|
|
|
22
22
|
message,
|
|
23
23
|
...(opts.path !== undefined ? { path: opts.path } : {}),
|
|
24
24
|
...(opts.suggestion !== undefined ? { suggestion: opts.suggestion } : {}),
|
|
25
|
-
...(opts.details !== undefined ? { details: opts.details } : {}),
|
|
26
25
|
...(opts.issues !== undefined ? { issues: opts.issues } : {}),
|
|
27
26
|
};
|
|
28
27
|
}
|
|
@@ -187,13 +186,8 @@ function buildProblemFromSignal(signal, error) {
|
|
|
187
186
|
return Problem.timeout(message);
|
|
188
187
|
case 'errno': {
|
|
189
188
|
const code = ERRNO_MAP[signal.errno] ?? ErrorCode.IO_ERROR;
|
|
190
|
-
const details = {
|
|
191
|
-
errno: signal.errno,
|
|
192
|
-
...(signal.syscall !== undefined ? { syscall: signal.syscall } : {}),
|
|
193
|
-
};
|
|
194
189
|
return build(code, message, {
|
|
195
190
|
...(signal.path !== undefined ? { path: signal.path } : {}),
|
|
196
|
-
details,
|
|
197
191
|
});
|
|
198
192
|
}
|
|
199
193
|
case 'unknown':
|
|
@@ -254,13 +248,11 @@ export function fsErrorCode(error) {
|
|
|
254
248
|
* survives cross-realm / multi-SDK-copy conditions where the prototype chain
|
|
255
249
|
* breaks. Mirrors the isFsError pattern.
|
|
256
250
|
*/
|
|
257
|
-
export function hasErrorShape(error, name
|
|
251
|
+
export function hasErrorShape(error, name) {
|
|
258
252
|
if (!(error instanceof Error) || error.name !== name)
|
|
259
253
|
return false;
|
|
260
254
|
const c = error.code;
|
|
261
|
-
|
|
262
|
-
return false;
|
|
263
|
-
return code === undefined || c === code;
|
|
255
|
+
return typeof c === 'string' || typeof c === 'number';
|
|
264
256
|
}
|
|
265
257
|
function classify(error) {
|
|
266
258
|
if (error === null || error === undefined) {
|
|
@@ -276,11 +268,8 @@ function classify(error) {
|
|
|
276
268
|
const signal = walkCauseChain(error);
|
|
277
269
|
return buildProblemFromSignal(signal, error);
|
|
278
270
|
}
|
|
279
|
-
function isNativeError(error) {
|
|
280
|
-
return error instanceof Error;
|
|
281
|
-
}
|
|
282
271
|
export function isNodeError(error) {
|
|
283
|
-
if (!
|
|
272
|
+
if (!(error instanceof Error))
|
|
284
273
|
return false;
|
|
285
274
|
if (!('code' in error))
|
|
286
275
|
return false;
|
|
@@ -301,7 +290,7 @@ export function rethrowIfAborted(error) {
|
|
|
301
290
|
export function formatUnknownErrorMessage(error) {
|
|
302
291
|
if (typeof error === 'string')
|
|
303
292
|
return error;
|
|
304
|
-
if (
|
|
293
|
+
if (error instanceof Error)
|
|
305
294
|
return error.message;
|
|
306
295
|
try {
|
|
307
296
|
return JSON.stringify(error);
|
|
@@ -311,7 +300,7 @@ export function formatUnknownErrorMessage(error) {
|
|
|
311
300
|
}
|
|
312
301
|
}
|
|
313
302
|
export function normalizeUnknownError(error) {
|
|
314
|
-
return
|
|
303
|
+
return error instanceof Error ? error : new Error(formatUnknownErrorMessage(error));
|
|
315
304
|
}
|
|
316
305
|
function formatDetailedError(error) {
|
|
317
306
|
const lines = [`${error.code}: ${error.message}`];
|
|
@@ -325,14 +314,13 @@ function formatDetailedError(error) {
|
|
|
325
314
|
}
|
|
326
315
|
export class FsError extends Error {
|
|
327
316
|
problem;
|
|
328
|
-
constructor(code, message, path,
|
|
317
|
+
constructor(code, message, path, cause) {
|
|
329
318
|
super(message, cause === undefined ? {} : { cause });
|
|
330
319
|
const suggestion = DEFAULT_SUGGESTIONS[code];
|
|
331
320
|
this.problem = {
|
|
332
321
|
code,
|
|
333
322
|
message,
|
|
334
323
|
...(path !== undefined ? { path } : {}),
|
|
335
|
-
...(details !== undefined ? { details: { extra: details } } : {}),
|
|
336
324
|
...(suggestion !== undefined ? { suggestion } : {}),
|
|
337
325
|
};
|
|
338
326
|
this.name = 'FsError';
|
|
@@ -344,13 +332,5 @@ export class FsError extends Error {
|
|
|
344
332
|
get path() {
|
|
345
333
|
return this.problem.path;
|
|
346
334
|
}
|
|
347
|
-
get details() {
|
|
348
|
-
if (!this.problem.details)
|
|
349
|
-
return undefined;
|
|
350
|
-
const { extra, ...rest } = this.problem.details;
|
|
351
|
-
if (!extra)
|
|
352
|
-
return Object.keys(rest).length > 0 ? rest : undefined;
|
|
353
|
-
return { ...rest, ...extra };
|
|
354
|
-
}
|
|
355
335
|
}
|
|
356
336
|
//# sourceMappingURL=errors.js.map
|