@j0hanz/filesystem-mcp 2.0.0 → 2.1.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.
Files changed (77) hide show
  1. package/README.md +27 -86
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.js +6 -31
  4. package/dist/cli.js.map +1 -1
  5. package/dist/core/config.d.ts +7 -0
  6. package/dist/core/config.d.ts.map +1 -1
  7. package/dist/core/config.js +7 -0
  8. package/dist/core/config.js.map +1 -1
  9. package/dist/core/fmt.d.ts +1 -2
  10. package/dist/core/fmt.d.ts.map +1 -1
  11. package/dist/core/fmt.js +0 -21
  12. package/dist/core/fmt.js.map +1 -1
  13. package/dist/core/input-required.d.ts +0 -9
  14. package/dist/core/input-required.d.ts.map +1 -1
  15. package/dist/core/input-required.js +4 -26
  16. package/dist/core/input-required.js.map +1 -1
  17. package/dist/core/primitives.d.ts +0 -1
  18. package/dist/core/primitives.d.ts.map +1 -1
  19. package/dist/core/primitives.js +0 -3
  20. package/dist/core/primitives.js.map +1 -1
  21. package/dist/core/schema.d.ts +0 -1
  22. package/dist/core/schema.d.ts.map +1 -1
  23. package/dist/core/schema.js +5 -2
  24. package/dist/core/schema.js.map +1 -1
  25. package/dist/core/util.d.ts +0 -2
  26. package/dist/core/util.d.ts.map +1 -1
  27. package/dist/core/util.js +1 -2
  28. package/dist/core/util.js.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/instructions.d.ts +0 -1
  32. package/dist/instructions.d.ts.map +1 -1
  33. package/dist/instructions.js +2 -3
  34. package/dist/instructions.js.map +1 -1
  35. package/dist/prompts.d.ts.map +1 -1
  36. package/dist/prompts.js +5 -11
  37. package/dist/prompts.js.map +1 -1
  38. package/dist/tools/create.d.ts.map +1 -1
  39. package/dist/tools/create.js +6 -24
  40. package/dist/tools/create.js.map +1 -1
  41. package/dist/tools/define.d.ts +0 -8
  42. package/dist/tools/define.d.ts.map +1 -1
  43. package/dist/tools/define.js +28 -19
  44. package/dist/tools/define.js.map +1 -1
  45. package/dist/tools/delete-file.d.ts.map +1 -1
  46. package/dist/tools/delete-file.js +0 -3
  47. package/dist/tools/delete-file.js.map +1 -1
  48. package/dist/tools/edit.d.ts.map +1 -1
  49. package/dist/tools/edit.js +0 -2
  50. package/dist/tools/edit.js.map +1 -1
  51. package/dist/tools/list.d.ts.map +1 -1
  52. package/dist/tools/list.js +11 -1
  53. package/dist/tools/list.js.map +1 -1
  54. package/dist/tools/progress.d.ts +2 -7
  55. package/dist/tools/progress.d.ts.map +1 -1
  56. package/dist/tools/progress.js +10 -26
  57. package/dist/tools/progress.js.map +1 -1
  58. package/dist/tools/read.d.ts.map +1 -1
  59. package/dist/tools/read.js +32 -5
  60. package/dist/tools/read.js.map +1 -1
  61. package/dist/tools/replace-in-files.d.ts.map +1 -1
  62. package/dist/tools/replace-in-files.js +0 -3
  63. package/dist/tools/replace-in-files.js.map +1 -1
  64. package/dist/tools/roots.d.ts.map +1 -1
  65. package/dist/tools/roots.js +21 -5
  66. package/dist/tools/roots.js.map +1 -1
  67. package/dist/tools/stat.d.ts.map +1 -1
  68. package/dist/tools/stat.js +4 -17
  69. package/dist/tools/stat.js.map +1 -1
  70. package/dist/transport/http.d.ts.map +1 -1
  71. package/dist/transport/http.js +1 -11
  72. package/dist/transport/http.js.map +1 -1
  73. package/dist/transport/shared.d.ts +0 -5
  74. package/dist/transport/shared.d.ts.map +1 -1
  75. package/dist/transport/shared.js +4 -0
  76. package/dist/transport/shared.js.map +1 -1
  77. package/package.json +2 -3
package/README.md CHANGED
@@ -380,92 +380,33 @@ All boolean variables accept `true` or `1` to enable and `false`, `0`, or
380
380
  unset to disable; any other value logs a warning and reads as disabled.
381
381
  Flags take precedence when both are set.
382
382
 
383
- | Variable | Purpose |
384
- | :---------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
385
- | `FS_ALLOWED_DIRS` | Colon-separated (POSIX) or semicolon-separated (Windows) list of directories to allow. |
386
- | `FS_ROOT_BOUNDARY` | Path prefix all allowed roots must fall under (mirrors `--root-boundary`). |
387
- | `FS_ALLOW_CWD_WALK` | Walk up from CWD to find a project root (mirrors `--walk-cwd`). |
388
- | `FS_ALLOW_MISSING_ROOTS` | Start even if configured directories do not exist (mirrors `--allow-missing-roots`). |
389
- | `FS_ALLOW_SENSITIVE` | Allow access to sensitive system paths (mirrors `--allow-sensitive`). |
390
- | `FS_DENYLIST` | Comma-separated list of paths or patterns to block (mirrors `--deny`). |
391
- | `FS_MAX_FILE_SIZE` | Maximum file size for reads in bytes (mirrors `--max-file-size`). |
392
- | `FS_LOG_LEVEL` | RFC 5424 log level: `debug`, `info`, `notice`, `warn`/`warning`, `error`, `critical`, `alert`, or `emergency` (mirrors `--log-level`). |
393
- | `FS_PORT` | Start the Streamable HTTP transport on this port; unset = stdio (mirrors `--port`). |
394
- | `FS_HTTP_HOST` | HTTP server bind address (mirrors `--http-host`). |
395
- | `FS_API_KEY` | API key required on HTTP requests (mirrors `--api-key`). |
396
- | `FS_TRUST_PROXY` | Express `trust proxy` setting: hop count or expression. Unset = do not trust `X-Forwarded-*`. |
397
- | `FS_ALLOWED_HOSTS` | Comma-separated Host header values to accept (HTTP transport). |
398
- | `FS_ALLOWED_ORIGINS` | Comma-separated origin hostnames for CORS. |
399
- | `FS_ALLOW_UNRESTRICTED_HOSTS` | Bind a wildcard host with no Host validation (accepts the risk). |
400
- | `FS_PUBLIC_URL` | Resource identifier URL for RFC 9728 discovery. |
401
- | `FS_RATE_LIMIT_RPM` | Per-client-IP requests/minute (default 120 with API-key authentication, 6,000 for keyless loopback; range 1–100000). |
402
- | `FS_MAX_REQUEST_BYTES` | Max HTTP request body bytes (default 4194304, 1024–268435456). |
403
- | `FS_KEEPALIVE_TIMEOUT_MS` | HTTP keep-alive timeout in ms; set above any fronting proxy's idle timeout (default 5000, 1000–600000). |
404
- | `FS_MAX_WATCHERS` | Max concurrent file watchers (default 256, 1–4096). |
405
- | `FS_MAX_INLINE_MATCHES` | Max inline content matches per search (default 50, 1–10000). |
406
- | `FS_MAX_READ_MANY_BYTES` | Max total bytes across a batched `read` (default 524288, 10240–104857600). |
407
- | `FS_SEARCH_TIMEOUT_MS` | Search timeout in ms (default 5000, 100–60000). |
408
- | `NO_COLOR` | Any value disables ANSI color output. |
409
- | `FS_REQUEST_STATE_KEY` | HMAC key sealing `input_required` requestState across retry rounds. Optional for stdio and single-instance HTTP (random per boot if unset); mandatory and shared across every fleet instance (UTF-8, >=32 bytes). |
410
-
411
- #### Multi-instance HTTP deployments
412
-
413
- Each instance delivers `subscriptions/listen` change events
414
- (`resources/updated`, `tools/list_changed`, etc.) on an in-process bus by
415
- default. Behind a load balancer with more than one instance, a listener on
416
- instance A will not see an event published on instance B. Explicit fleet mode
417
- therefore refuses to boot without a shared event bus.
418
-
419
- To fan events out across instances, implement the SDK's `ServerEventBus`
420
- interface (two methods: `publish`/`subscribe`) over whatever pub/sub you
421
- already run, then pass it to filesystem-mcp's programmatic HTTP entry:
422
-
423
- ```ts
424
- import type { ServerEvent, ServerEventBus } from '@modelcontextprotocol/server';
425
-
426
- import { startHttpServer } from '@j0hanz/filesystem-mcp/transport';
427
- import Redis from 'ioredis';
428
-
429
- // any pub/sub client works the same way
430
-
431
- class RedisServerEventBus implements ServerEventBus {
432
- private readonly listeners = new Set<(event: ServerEvent) => void>();
433
- private readonly pub = new Redis(process.env['REDIS_URL']);
434
- private readonly sub = new Redis(process.env['REDIS_URL']);
435
-
436
- constructor() {
437
- void this.sub.subscribe('fs-mcp-events');
438
- this.sub.on('message', (_channel, message) => {
439
- const event = JSON.parse(message) as ServerEvent;
440
- for (const listener of this.listeners) listener(event);
441
- });
442
- }
443
-
444
- publish(event: ServerEvent): void {
445
- void this.pub.publish('fs-mcp-events', JSON.stringify(event));
446
- }
447
-
448
- subscribe(listener: (event: ServerEvent) => void): () => void {
449
- this.listeners.add(listener);
450
- return () => this.listeners.delete(listener);
451
- }
452
- }
453
-
454
- const eventBus = new RedisServerEventBus();
455
- const apiKey = process.env['FS_API_KEY'];
456
- if (!apiKey) throw new Error('FS_API_KEY is required for a multi-instance HTTP deployment');
457
-
458
- await startHttpServer(
459
- 3000,
460
- { cliAllowedDirs: ['/workspace'] },
461
- { apiKey, eventBus, deploymentMode: 'fleet' },
462
- );
463
- ```
464
-
465
- This project ships no bus adapter and no pub/sub dependency. A single
466
- in-process instance (the common case) needs nothing extra and is the CLI's
467
- default. Load-balanced deployments must use the programmatic API with
468
- `deploymentMode: 'fleet'`.
383
+ | Variable | Purpose |
384
+ | :---------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
385
+ | `FS_ALLOWED_DIRS` | Colon-separated (POSIX) or semicolon-separated (Windows) list of directories to allow. |
386
+ | `FS_ROOT_BOUNDARY` | Path prefix all allowed roots must fall under (mirrors `--root-boundary`). |
387
+ | `FS_ALLOW_CWD_WALK` | Walk up from CWD to find a project root (mirrors `--walk-cwd`). |
388
+ | `FS_ALLOW_MISSING_ROOTS` | Start even if configured directories do not exist (mirrors `--allow-missing-roots`). |
389
+ | `FS_ALLOW_SENSITIVE` | Allow access to sensitive system paths (mirrors `--allow-sensitive`). |
390
+ | `FS_DENYLIST` | Comma-separated list of paths or patterns to block (mirrors `--deny`). |
391
+ | `FS_MAX_FILE_SIZE` | Maximum file size for reads in bytes (mirrors `--max-file-size`). |
392
+ | `FS_LOG_LEVEL` | RFC 5424 log level: `debug`, `info`, `notice`, `warn`/`warning`, `error`, `critical`, `alert`, or `emergency` (mirrors `--log-level`). |
393
+ | `FS_PORT` | Start the Streamable HTTP transport on this port; unset = stdio (mirrors `--port`). |
394
+ | `FS_HTTP_HOST` | HTTP server bind address (mirrors `--http-host`). |
395
+ | `FS_API_KEY` | API key required on HTTP requests (mirrors `--api-key`). |
396
+ | `FS_TRUST_PROXY` | Express `trust proxy` setting: hop count or expression. Unset = do not trust `X-Forwarded-*`. |
397
+ | `FS_ALLOWED_HOSTS` | Comma-separated Host header values to accept (HTTP transport). |
398
+ | `FS_ALLOWED_ORIGINS` | Comma-separated origin hostnames for CORS. |
399
+ | `FS_ALLOW_UNRESTRICTED_HOSTS` | Bind a wildcard host with no Host validation (accepts the risk). |
400
+ | `FS_PUBLIC_URL` | Resource identifier URL for RFC 9728 discovery. |
401
+ | `FS_RATE_LIMIT_RPM` | Per-client-IP requests/minute (default 120 with API-key authentication, 6,000 for keyless loopback; range 1–100000). |
402
+ | `FS_MAX_REQUEST_BYTES` | Max HTTP request body bytes (default 4194304, 1024–268435456). |
403
+ | `FS_KEEPALIVE_TIMEOUT_MS` | HTTP keep-alive timeout in ms; set above any fronting proxy's idle timeout (default 5000, 1000–600000). |
404
+ | `FS_MAX_WATCHERS` | Max concurrent file watchers (default 256, 1–4096). |
405
+ | `FS_MAX_INLINE_MATCHES` | Max inline content matches per search (default 50, 1–10000). |
406
+ | `FS_MAX_READ_MANY_BYTES` | Max total bytes across a batched `read` (default 524288, 10240–104857600). |
407
+ | `FS_SEARCH_TIMEOUT_MS` | Search timeout in ms (default 5000, 100–60000). |
408
+ | `NO_COLOR` | Any value disables ANSI color output. |
409
+ | `FS_REQUEST_STATE_KEY` | HMAC key sealing `input_required` requestState across retry rounds. Optional (random per boot if unset); set it, at >=32 bytes UTF-8, to keep in-flight rounds alive across a restart. |
469
410
 
470
411
  ### Examples
471
412
 
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAyBA,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAK9C;AAkJD,wBAAsB,SAAS,IAAI,OAAO,CAAC;IACzC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,G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B,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,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAA;KAAE,CAAC;CACtC;AAED,MAAM,WAAW,kBAAkB;IACjC,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;IAChB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED,wBAAsB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CAuC1F"}
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { stat } from 'node:fs/promises';
2
- import { getSystemErrorMessage, getSystemErrorName, parseArgs as utilParseArgs } from 'node:util';
2
+ import { parseArgs as utilParseArgs } from 'node:util';
3
3
  import { printHelpAndExit, printVersionAndExit } from './cli-help.js';
4
4
  import { processInParallel } from './core/concurrency.js';
5
5
  import { cli } from './core/config.js';
@@ -7,7 +7,7 @@ import { formatUnknownErrorMessage } from './core/errors.js';
7
7
  import { cliFmt, padEndVisible } from './core/fmt.js';
8
8
  import { getReservedDeviceNameForPath, isWindowsDriveRelativePath, normalizePath, } from './core/path-utils.js';
9
9
  import { PathGuard } from './core/path.js';
10
- import { IS_WINDOWS, isRecord, parseTrueEnvFlag } from './core/primitives.js';
10
+ import { IS_WINDOWS, parseTrueEnvFlag } from './core/primitives.js';
11
11
  import { getMaxTextFileSize } from './core/util.js';
12
12
  import { registeredTools } from './tools/index.js';
13
13
  const CLI_VALIDATE_CONCURRENCY = 8;
@@ -34,34 +34,6 @@ function validateCliPath(inputPath) {
34
34
  throw new CliExitError(`Windows reserved device name not allowed: ${reserved}.`, 1);
35
35
  }
36
36
  }
37
- function getSystemErrorDetails(error) {
38
- if (!isRecord(error))
39
- return { code: undefined, errno: undefined };
40
- const code = typeof error['code'] === 'string' ? error['code'] : undefined;
41
- const errno = typeof error['errno'] === 'number' ? error['errno'] : undefined;
42
- return { code, errno };
43
- }
44
- function normalizeDirectoryError(error, inputPath) {
45
- const { code, errno } = getSystemErrorDetails(error);
46
- if (error instanceof Error && code === undefined && errno === undefined) {
47
- return error;
48
- }
49
- if (typeof errno === 'number') {
50
- try {
51
- const name = getSystemErrorName(errno);
52
- const message = getSystemErrorMessage(errno);
53
- return new Error(`Cannot access directory ${inputPath} (${name}: ${message})`);
54
- }
55
- catch {
56
- // Fall through, but preserve raw errno value
57
- }
58
- return new Error(`Cannot access directory ${inputPath} (errno ${errno})`);
59
- }
60
- if (code) {
61
- return new Error(`Cannot access directory ${inputPath} (${code})`);
62
- }
63
- return new Error(`Cannot access directory ${inputPath}`);
64
- }
65
37
  function assertDirectory(stats, inputPath) {
66
38
  if (stats.isDirectory())
67
39
  return;
@@ -81,7 +53,10 @@ async function validateDirectoryPath(inputPath, allowMissing = false) {
81
53
  }
82
54
  return normalized;
83
55
  }
84
- throw normalizeDirectoryError(error, inputPath);
56
+ // Node's own message already names the syscall and the errno.
57
+ throw new Error(`Cannot access directory ${inputPath}: ${formatUnknownErrorMessage(error)}`, {
58
+ cause: error,
59
+ });
85
60
  }
86
61
  }
87
62
  async function normalizeAndValidateDirs(paths, allowMissing = false) {
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,qBAAqB,EAAE,kBAAkB,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,WAAW,CAAC;AAElG,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,QAAQ,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,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,YAAY,OAAe,EAAE,QAAgB;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAA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/promises';\nimport { getSystemErrorMessage, getSystemErrorName, 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, isRecord, 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 getSystemErrorDetails(error: unknown): {\n code: string | undefined;\n errno: number | undefined;\n} {\n if (!isRecord(error)) return { code: undefined, errno: undefined };\n const code = typeof error['code'] === 'string' ? error['code'] : undefined;\n const errno = typeof error['errno'] === 'number' ? error['errno'] : undefined;\n return { code, errno };\n}\n\nfunction normalizeDirectoryError(error: unknown, inputPath: string): Error {\n const { code, errno } = getSystemErrorDetails(error);\n if (error instanceof Error && code === undefined && errno === undefined) {\n return error;\n }\n\n if (typeof errno === 'number') {\n try {\n const name = getSystemErrorName(errno);\n const message = getSystemErrorMessage(errno);\n return new Error(`Cannot access directory ${inputPath} (${name}: ${message})`);\n } catch {\n // Fall through, but preserve raw errno value\n }\n return new Error(`Cannot access directory ${inputPath} (errno ${errno})`);\n }\n\n if (code) {\n return new Error(`Cannot access directory ${inputPath} (${code})`);\n }\n\n return new Error(`Cannot access directory ${inputPath}`);\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 throw normalizeDirectoryError(error, inputPath);\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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G,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;QACnD,KAAK,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC9D,KAAK,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;QACnE,KAAK,CAAC,GAAG,GAAG,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5F,KAAK,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAClE,KAAK,CAAC,GAAG,GAAG,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,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,3 +1,10 @@
1
+ /**
2
+ * How an operator gives this server a root. Lives here rather than beside its
3
+ * readers because both ends of the repo need it — `index.ts` prints it at
4
+ * startup, `list_roots` returns it when it has nothing to list — and this
5
+ * module is the one place either can import without a cycle.
6
+ */
7
+ export declare const NO_POSITIONAL_ROOTS_GUIDANCE = "No positional directories specified. Configure roots with directory arguments, FS_ALLOWED_DIRS, or --allow-cwd. Modern clients with elicitation can also call a tool with a concrete path and approve the requested grant.";
1
8
  export interface CliOverrides {
2
9
  /** `--log-level` */
3
10
  logLevel?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,YAAY;IAC3B,oBAAoB;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+EAA+E;IAC/E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wBAAwB;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0BAA0B;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mBAAmB;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,8BAA8B;IAC9B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,4DAA4D;IAC5D,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC;AAED,iFAAiF;AACjF,eAAO,MAAM,GAAG,EAAE,YAAiB,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,+NACqL,CAAC;AAE/N,MAAM,WAAW,YAAY;IAC3B,oBAAoB;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+EAA+E;IAC/E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wBAAwB;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0BAA0B;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mBAAmB;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,8BAA8B;IAC9B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,4DAA4D;IAC5D,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC;AAED,iFAAiF;AACjF,eAAO,MAAM,GAAG,EAAE,YAAiB,CAAC"}
@@ -6,6 +6,13 @@
6
6
  // assigns onto `cli` once at startup and each reader consults it first, falling
7
7
  // back to the operator's environment. This module deliberately has zero imports
8
8
  // so any core module can read it without a cycle.
9
+ /**
10
+ * How an operator gives this server a root. Lives here rather than beside its
11
+ * readers because both ends of the repo need it — `index.ts` prints it at
12
+ * startup, `list_roots` returns it when it has nothing to list — and this
13
+ * module is the one place either can import without a cycle.
14
+ */
15
+ export const NO_POSITIONAL_ROOTS_GUIDANCE = 'No positional directories specified. Configure roots with directory arguments, FS_ALLOWED_DIRS, or --allow-cwd. Modern clients with elicitation can also call a tool with a concrete path and approve the requested grant.';
9
16
  /** Written once by cli.ts; an absent key means "not set on the command line". */
10
17
  export const cli = {};
11
18
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,kDAAkD;AAmBlD,iFAAiF;AACjF,MAAM,CAAC,MAAM,GAAG,GAAiB,EAAE,CAAC","sourcesContent":["// Resolved CLI-flag overrides — the one owner of the flag-beats-env rule.\n//\n// `parseArgs` (cli.ts) used to write flag values back into `process.env` so\n// deep core readers (path, sensitive, observability, util) would pick them up.\n// That made the environment a hidden mutable config bus. Instead, cli.ts\n// assigns onto `cli` once at startup and each reader consults it first, falling\n// back to the operator's environment. This module deliberately has zero imports\n// so any core module can read it without a cycle.\n\nexport interface CliOverrides {\n /** `--log-level` */\n logLevel?: string;\n /** `--max-file-size` (raw string; validated by the reader like the env var) */\n maxFileSize?: string;\n /** `--root-boundary` */\n rootBoundary?: string;\n /** `--allow-sensitive` */\n allowSensitive?: boolean;\n /** `--walk-cwd` */\n allowCwdWalk?: boolean;\n /** `--allow-missing-roots` */\n allowMissingRoots?: boolean;\n /** `--deny` entries (merged with DENYLIST by the reader) */\n denyPatterns?: readonly string[];\n}\n\n/** Written once by cli.ts; an absent key means \"not set on the command line\". */\nexport const cli: CliOverrides = {};\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,kDAAkD;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GACvC,4NAA4N,CAAC;AAmB/N,iFAAiF;AACjF,MAAM,CAAC,MAAM,GAAG,GAAiB,EAAE,CAAC","sourcesContent":["// Resolved CLI-flag overrides — the one owner of the flag-beats-env rule.\n//\n// `parseArgs` (cli.ts) used to write flag values back into `process.env` so\n// deep core readers (path, sensitive, observability, util) would pick them up.\n// That made the environment a hidden mutable config bus. Instead, cli.ts\n// assigns onto `cli` once at startup and each reader consults it first, falling\n// back to the operator's environment. This module deliberately has zero imports\n// so any core module can read it without a cycle.\n\n/**\n * How an operator gives this server a root. Lives here rather than beside its\n * readers because both ends of the repo need it — `index.ts` prints it at\n * startup, `list_roots` returns it when it has nothing to list — and this\n * module is the one place either can import without a cycle.\n */\nexport const NO_POSITIONAL_ROOTS_GUIDANCE =\n 'No positional directories specified. Configure roots with directory arguments, FS_ALLOWED_DIRS, or --allow-cwd. Modern clients with elicitation can also call a tool with a concrete path and approve the requested grant.';\n\nexport interface CliOverrides {\n /** `--log-level` */\n logLevel?: string;\n /** `--max-file-size` (raw string; validated by the reader like the env var) */\n maxFileSize?: string;\n /** `--root-boundary` */\n rootBoundary?: string;\n /** `--allow-sensitive` */\n allowSensitive?: boolean;\n /** `--walk-cwd` */\n allowCwdWalk?: boolean;\n /** `--allow-missing-roots` */\n allowMissingRoots?: boolean;\n /** `--deny` entries (merged with DENYLIST by the reader) */\n denyPatterns?: readonly string[];\n}\n\n/** Written once by cli.ts; an absent key means \"not set on the command line\". */\nexport const cli: CliOverrides = {};\n"]}
@@ -7,9 +7,8 @@ export interface ProgressCtx {
7
7
  detail?: string;
8
8
  error?: string;
9
9
  }
10
- export type Phase = 'start' | 'tick' | 'done' | 'fail';
10
+ export type Phase = 'tick' | 'done' | 'fail';
11
11
  export declare function plainMessage(phase: Phase, ctx: ProgressCtx): string;
12
- export declare function formatBytes(bytes: number): string;
13
12
  export declare function formatCount(count: number, singular: string, plural?: string): string;
14
13
  /**
15
14
  * Short label for a path in summary text. `basename` returns '' for a root
@@ -1 +1 @@
1
- {"version":3,"file":"fmt.d.ts","sourceRoot":"","sources":["../../src/core/fmt.ts"],"names":[],"mappings":"AAKA,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,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAuCvD,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAA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AK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAiB,GAAG,MAAM,CAE5F;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAKD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,SAAQ,GAAG,MAAM,CAI9E;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAK,GAAG,MAAM,CAE/E;AAUD,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG9D;AASD,eAAO,MAAM,MAAM;cACP,MAAM;aACP,MAAM;cACL,MAAM;gBACJ,MAAM;cACR,MAAM;qBACC,MAAM;iBACV,MAAM;cACT,OAAO;CAClB,CAAC"}
package/dist/core/fmt.js CHANGED
@@ -1,17 +1,11 @@
1
1
  import { basename } from 'node:path';
2
2
  import { stripVTControlCharacters, styleText } from 'node:util';
3
- import { GIB, KIB, MIB } from './util.js';
4
3
  function buildBody(ctx, phase) {
5
4
  const items = [];
6
5
  if (ctx.subject) {
7
6
  items.push(ctx.subject);
8
7
  }
9
8
  switch (phase) {
10
- case 'start':
11
- if (ctx.scope) {
12
- items.push(ctx.scope);
13
- }
14
- break;
15
9
  case 'tick':
16
10
  if (ctx.current !== undefined && ctx.total !== undefined) {
17
11
  items.push(`${ctx.current}/${ctx.total}`);
@@ -40,21 +34,6 @@ export function plainMessage(phase, ctx) {
40
34
  const body = buildBody(ctx, phase);
41
35
  return body ? `${ctx.label}: ${body}` : `${ctx.label}:`;
42
36
  }
43
- export function formatBytes(bytes) {
44
- if (!Number.isFinite(bytes) || bytes < 0) {
45
- return '0 B';
46
- }
47
- if (bytes < KIB) {
48
- return `${bytes} B`;
49
- }
50
- if (bytes < MIB) {
51
- return `${(bytes / KIB).toFixed(1)} KB`;
52
- }
53
- if (bytes < GIB) {
54
- return `${(bytes / MIB).toFixed(1)} MB`;
55
- }
56
- return `${(bytes / GIB).toFixed(1)} GB`;
57
- }
58
37
  export function formatCount(count, singular, plural = `${singular}s`) {
59
38
  return `${String(count)} ${count === 1 ? singular : plural}`;
60
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fmt.js","sourceRoot":"","sources":["../../src/core/fmt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAc1C,SAAS,SAAS,CAAC,GAAgB,EAAE,KAAY;IAC/C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,OAAO;YACV,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;gBACd,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;YACD,MAAM;QACR,KAAK,MAAM;YACT,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBACzD,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;YAC5C,CAAC;iBAAM,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;gBACrC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;YAClC,CAAC;YACD,MAAM;QACR,KAAK,MAAM;YACT,IAAI,GAAG,CAAC,KAAK,E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,CAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CACzE,CAAC","sourcesContent":["import { basename } from 'node:path';\nimport { stripVTControlCharacters, styleText } from 'node:util';\n\nimport { GIB, KIB, MIB } from './util.js';\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\nexport type Phase = 'start' | '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 'start':\n if (ctx.scope) {\n items.push(ctx.scope);\n }\n break;\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 formatBytes(bytes: number): string {\n if (!Number.isFinite(bytes) || bytes < 0) {\n return '0 B';\n }\n if (bytes < KIB) {\n return `${bytes} B`;\n }\n if (bytes < MIB) {\n return `${(bytes / KIB).toFixed(1)} KB`;\n }\n if (bytes < GIB) {\n return `${(bytes / MIB).toFixed(1)} MB`;\n }\n return `${(bytes / GIB).toFixed(1)} GB`;\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, maxLength = 40): string {\n return pattern.length <= maxLength ? pattern : `${pattern.slice(0, maxLength)}…`;\n}\n\n// ---------------------------------------------------------------------------\n// CLI color helpers\n// ---------------------------------------------------------------------------\n\nfunction isColorEnabled(stream: { isTTY?: boolean } = process.stdout): boolean {\n return stream.isTTY === true && !process.env['NO_COLOR'];\n}\n\nexport function padEndVisible(s: string, width: number): string {\n const visible = stripVTControlCharacters(s).length;\n return visible >= width ? s : s + ' '.repeat(width - visible);\n}\n\ntype Style = Parameters<typeof styleText>[0];\n\n/** Same palette as above, but only when the target stream wants color. */\nfunction tint(format: Style, text: string, stream?: { isTTY?: boolean }): string {\n return isColorEnabled(stream) ? styleText(format, text) : text;\n}\n\nexport const cliFmt = {\n bold: (t: string) => tint('bold', t),\n dim: (t: string) => tint('dim', t),\n cyan: (t: string) => tint('cyan', t),\n yellow: (t: string) => tint('yellow', t),\n flag: (t: string) => tint('green', t),\n placeholder: (t: string) => tint('yellow', t),\n section: (t: string) => tint(['cyan', 'bold'], t),\n bool: (v: boolean) => (v ? tint('green', 'true') : tint('red', 'false')),\n};\n"]}
1
+ {"version":3,"file":"fmt.js","sourceRoot":"","sources":["../../src/core/fmt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAA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E,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACjD,IAAI,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CACzE,CAAC","sourcesContent":["import { basename } from 'node:path';\nimport { stripVTControlCharacters, styleText } from 'node:util';\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\nexport type 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, maxLength = 40): string {\n return pattern.length <= maxLength ? pattern : `${pattern.slice(0, maxLength)}…`;\n}\n\n// ---------------------------------------------------------------------------\n// CLI color helpers\n// ---------------------------------------------------------------------------\n\nfunction isColorEnabled(stream: { isTTY?: boolean } = process.stdout): boolean {\n return stream.isTTY === true && !process.env['NO_COLOR'];\n}\n\nexport function padEndVisible(s: string, width: number): string {\n const visible = stripVTControlCharacters(s).length;\n return visible >= width ? s : s + ' '.repeat(width - visible);\n}\n\ntype Style = Parameters<typeof styleText>[0];\n\n/** Same palette as above, but only when the target stream wants color. */\nfunction tint(format: Style, text: string, stream?: { isTTY?: boolean }): string {\n return isColorEnabled(stream) ? styleText(format, text) : text;\n}\n\nexport const cliFmt = {\n bold: (t: string) => tint('bold', t),\n dim: (t: string) => tint('dim', t),\n cyan: (t: string) => tint('cyan', t),\n yellow: (t: string) => tint('yellow', t),\n flag: (t: string) => tint('green', t),\n placeholder: (t: string) => tint('yellow', t),\n section: (t: string) => tint(['cyan', 'bold'], t),\n bool: (v: boolean) => (v ? tint('green', 'true') : tint('red', 'false')),\n};\n"]}
@@ -34,15 +34,6 @@ export interface PendingInput {
34
34
  */
35
35
  readonly multi?: boolean;
36
36
  }
37
- /**
38
- * Boot-time HTTP guard: when the HTTP leg is active (`FS_API_KEY` set) and
39
- * `FS_REQUEST_STATE_KEY` is missing or <32 bytes, refuse to start —
40
- * a multi-instance fleet behind a load balancer would otherwise silently break
41
- * every `input_required` round that lands on a different instance (each node
42
- * mints tokens with its own random per-boot key). No-op outside explicit fleet
43
- * mode. Called from `startHttpServer`, never at module load.
44
- */
45
- export declare function assertFleetRequestStateKey(fleet: boolean): void;
46
37
  /**
47
38
  * The codec: `mint` seals a `PendingState` into the opaque wire string a
48
39
  * handler returns from `inputRequired({ requestState })`; `verify` drops into
@@ -1 +1 @@
1
- {"version":3,"file":"input-required.d.ts","sourceRoot":"","sources":["../../src/core/input-required.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,kBAAkB,EAElB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,8BAA8B,CAAC;AActC,mEAAmE;AACnE,KAAK,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,kEAAkE;AAClE,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC/D,6EAA6E;IAC7E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AAuCD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAM/D;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,YAAY,CAG7D,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CAEvE;AAED;;;;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B,CACjC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC9C,GAAG,EAAE,MAAM,GACV,OAAO,CAET;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC9C,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,SAAS,CAEpB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC9C,GAAG,EAAE,MAAM,GACV,MAAM,EAAE,GAAG,SAAS,CAEtB"}
@@ -8,14 +8,8 @@ import { Logger } from './observability.js';
8
8
  * `FS_REQUEST_STATE_KEY` (UTF-8, must be >=32 bytes); a random
9
9
  * 32-byte key is generated at boot when the env var is unset or too short. A
10
10
  * per-process key is correct for stdio and the single-node HTTP leg (decision
11
- * record 11). For a multi-instance HTTP fleet behind a load balancer, a random
12
- * per-process key silently breaks any `input_required` round that lands on a
13
- * different instance — `assertFleetRequestStateKey()` is the boot-time HTTP
14
- * guard that refuses to start the HTTP leg in that state. It is NOT called at
15
- * module load (the codec is constructed at module scope, before the stdio/HTTP
16
- * decision in `main()`), so a stdio launch with `FS_API_KEY` exported still boots.
17
- * A server restart invalidates in-flight tokens; the client re-requests, which
18
- * is fail-closed and safe.
11
+ * record 11). A server restart invalidates in-flight tokens; the client
12
+ * re-requests, which is fail-closed and safe.
19
13
  */
20
14
  function configuredRequestStateKey() {
21
15
  const env = process.env['FS_REQUEST_STATE_KEY'];
@@ -27,8 +21,8 @@ function configuredRequestStateKey() {
27
21
  }
28
22
  return undefined;
29
23
  }
30
- // Built on first use, not at module load: `startHttpServer` gets to enforce the
31
- // fleet key requirement before anything mints with a random per-boot fallback.
24
+ // Built on first use, not at module load, so an unset env var costs nothing at
25
+ // import and the random per-boot fallback is minted only once something needs it.
32
26
  let codec;
33
27
  function getRequestStateCodec() {
34
28
  codec ??= createRequestStateCodec({
@@ -36,22 +30,6 @@ function getRequestStateCodec() {
36
30
  });
37
31
  return codec;
38
32
  }
39
- /**
40
- * Boot-time HTTP guard: when the HTTP leg is active (`FS_API_KEY` set) and
41
- * `FS_REQUEST_STATE_KEY` is missing or <32 bytes, refuse to start —
42
- * a multi-instance fleet behind a load balancer would otherwise silently break
43
- * every `input_required` round that lands on a different instance (each node
44
- * mints tokens with its own random per-boot key). No-op outside explicit fleet
45
- * mode. Called from `startHttpServer`, never at module load.
46
- */
47
- export function assertFleetRequestStateKey(fleet) {
48
- if (!fleet)
49
- return;
50
- if (!configuredRequestStateKey()) {
51
- throw new Error('FS_REQUEST_STATE_KEY must be >=32 bytes in fleet deployment mode.');
52
- }
53
- getRequestStateCodec();
54
- }
55
33
  /**
56
34
  * The codec: `mint` seals a `PendingState` into the opaque wire string a
57
35
  * handler returns from `inputRequired({ requestState })`; `verify` drops into