@namzu/sdk 71.0.1 → 72.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +126 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +1 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/authorization/readonly-commands.d.ts +9 -1
- package/dist/authorization/readonly-commands.d.ts.map +1 -1
- package/dist/authorization/readonly-commands.js +70 -4
- package/dist/authorization/readonly-commands.js.map +1 -1
- package/dist/authorization/shell-paths.d.ts.map +1 -1
- package/dist/authorization/shell-paths.js +68 -16
- package/dist/authorization/shell-paths.js.map +1 -1
- package/dist/compaction/index.d.ts +1 -1
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +1 -1
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/manual.d.ts +8 -0
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +18 -14
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/model-summary.d.ts +24 -6
- package/dist/compaction/model-summary.d.ts.map +1 -1
- package/dist/compaction/model-summary.js +152 -28
- package/dist/compaction/model-summary.js.map +1 -1
- package/dist/compaction/restore.d.ts +23 -0
- package/dist/compaction/restore.d.ts.map +1 -1
- package/dist/compaction/restore.js +59 -1
- package/dist/compaction/restore.js.map +1 -1
- package/dist/compaction/summary.d.ts +37 -2
- package/dist/compaction/summary.d.ts.map +1 -1
- package/dist/compaction/summary.js +46 -6
- package/dist/compaction/summary.js.map +1 -1
- package/dist/config/registry.d.ts +2 -0
- package/dist/config/registry.d.ts.map +1 -1
- package/dist/config/registry.js +76 -5
- package/dist/config/registry.js.map +1 -1
- package/dist/config/runtime.js +3 -3
- package/dist/config/runtime.js.map +1 -1
- package/dist/connector/index.d.ts +2 -2
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +1 -1
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/adapter.d.ts +8 -0
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +131 -1
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +26 -6
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +49 -7
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +2 -0
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +1 -0
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/sandbox-stdio.d.ts +67 -0
- package/dist/connector/mcp/sandbox-stdio.d.ts.map +1 -0
- package/dist/connector/mcp/sandbox-stdio.js +178 -0
- package/dist/connector/mcp/sandbox-stdio.js.map +1 -0
- package/dist/connector/mcp/stdio-program.d.ts +34 -0
- package/dist/connector/mcp/stdio-program.d.ts.map +1 -0
- package/dist/connector/mcp/stdio-program.js +47 -0
- package/dist/connector/mcp/stdio-program.js.map +1 -0
- package/dist/connector/mcp/stdio.d.ts +12 -0
- package/dist/connector/mcp/stdio.d.ts.map +1 -1
- package/dist/connector/mcp/stdio.js +54 -7
- package/dist/connector/mcp/stdio.js.map +1 -1
- package/dist/connector/web/guarded-fetch.d.ts +51 -2
- package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
- package/dist/connector/web/guarded-fetch.js +140 -19
- package/dist/connector/web/guarded-fetch.js.map +1 -1
- package/dist/connector/web/index.d.ts +2 -2
- package/dist/connector/web/index.d.ts.map +1 -1
- package/dist/connector/web/index.js +1 -1
- package/dist/connector/web/index.js.map +1 -1
- package/dist/constants/mcp/index.d.ts +29 -0
- package/dist/constants/mcp/index.d.ts.map +1 -1
- package/dist/constants/mcp/index.js +29 -0
- package/dist/constants/mcp/index.js.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts +18 -1
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +53 -8
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
- package/dist/plugin/hook-module/capabilities.js +24 -13
- package/dist/plugin/hook-module/capabilities.js.map +1 -1
- package/dist/plugin/hook-module/host.d.ts +31 -0
- package/dist/plugin/hook-module/host.d.ts.map +1 -1
- package/dist/plugin/hook-module/host.js +56 -13
- package/dist/plugin/hook-module/host.js.map +1 -1
- package/dist/plugin/hook-module/index.d.ts +3 -2
- package/dist/plugin/hook-module/index.d.ts.map +1 -1
- package/dist/plugin/hook-module/index.js +2 -1
- package/dist/plugin/hook-module/index.js.map +1 -1
- package/dist/plugin/index.d.ts +2 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1 -0
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/shell-hook-execute.d.ts +55 -0
- package/dist/plugin/shell-hook-execute.d.ts.map +1 -0
- package/dist/plugin/shell-hook-execute.js +73 -0
- package/dist/plugin/shell-hook-execute.js.map +1 -0
- package/dist/plugin/shell-hook-restrict.d.ts +31 -0
- package/dist/plugin/shell-hook-restrict.d.ts.map +1 -0
- package/dist/plugin/shell-hook-restrict.js +69 -0
- package/dist/plugin/shell-hook-restrict.js.map +1 -0
- package/dist/plugin/shell-hook.d.ts +73 -4
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +118 -17
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/public-runtime.d.ts +9 -7
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +6 -5
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-types.d.ts +4 -2
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/jobs/websocket-source.d.ts +2 -22
- package/dist/runtime/jobs/websocket-source.d.ts.map +1 -1
- package/dist/runtime/jobs/websocket-source.js +2 -33
- package/dist/runtime/jobs/websocket-source.js.map +1 -1
- package/dist/runtime/query/compact-session.d.ts.map +1 -1
- package/dist/runtime/query/compact-session.js +5 -0
- package/dist/runtime/query/compact-session.js.map +1 -1
- package/dist/runtime/query/events.d.ts +7 -0
- package/dist/runtime/query/events.d.ts.map +1 -1
- package/dist/runtime/query/events.js +29 -11
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +51 -10
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/index.d.ts +6 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +3 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +21 -3
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/path-escalation.d.ts.map +1 -1
- package/dist/runtime/query/path-escalation.js +90 -17
- package/dist/runtime/query/path-escalation.js.map +1 -1
- package/dist/runtime/query/steering.d.ts +15 -0
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js +27 -3
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/scheduler/completion-inbox.d.ts.map +1 -1
- package/dist/scheduler/completion-inbox.js +15 -0
- package/dist/scheduler/completion-inbox.js.map +1 -1
- package/dist/session/workspace/driver.d.ts +12 -0
- package/dist/session/workspace/driver.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.d.ts +16 -0
- package/dist/session/workspace/git-worktree.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.js +35 -0
- package/dist/session/workspace/git-worktree.js.map +1 -1
- package/dist/session/workspace/holds.d.ts +78 -0
- package/dist/session/workspace/holds.d.ts.map +1 -0
- package/dist/session/workspace/holds.js +150 -0
- package/dist/session/workspace/holds.js.map +1 -0
- package/dist/session/workspace/index.d.ts +3 -1
- package/dist/session/workspace/index.d.ts.map +1 -1
- package/dist/session/workspace/index.js +2 -1
- package/dist/session/workspace/index.js.map +1 -1
- package/dist/store/config/index.d.ts +3 -0
- package/dist/store/config/index.d.ts.map +1 -1
- package/dist/store/config/index.js +3 -0
- package/dist/store/config/index.js.map +1 -1
- package/dist/store/session-index/index.d.ts +13 -0
- package/dist/store/session-index/index.d.ts.map +1 -1
- package/dist/store/session-index/index.js +1 -0
- package/dist/store/session-index/index.js.map +1 -1
- package/dist/store/session-index/rebuild.d.ts +12 -0
- package/dist/store/session-index/rebuild.d.ts.map +1 -1
- package/dist/store/session-index/rebuild.js +20 -4
- package/dist/store/session-index/rebuild.js.map +1 -1
- package/dist/store/session-index/sqlite.d.ts +20 -0
- package/dist/store/session-index/sqlite.d.ts.map +1 -1
- package/dist/store/session-index/sqlite.js +50 -12
- package/dist/store/session-index/sqlite.js.map +1 -1
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +59 -0
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +57 -0
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/lsp.d.ts.map +1 -1
- package/dist/tools/builtins/lsp.js +41 -4
- package/dist/tools/builtins/lsp.js.map +1 -1
- package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
- package/dist/tools/coordinator/ask-user-question.js +67 -3
- package/dist/tools/coordinator/ask-user-question.js.map +1 -1
- package/dist/turn/memory-promoter.d.ts.map +1 -1
- package/dist/turn/memory-promoter.js +20 -4
- package/dist/turn/memory-promoter.js.map +1 -1
- package/dist/types/agent/base.d.ts +6 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +5 -0
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/agent/task.js.map +1 -1
- package/dist/types/code-navigation/index.d.ts +34 -4
- package/dist/types/code-navigation/index.d.ts.map +1 -1
- package/dist/types/hitl/index.d.ts +8 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/message/index.d.ts +7 -0
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +21 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/agents/QueryAgent.ts +1 -0
- package/src/authorization/readonly-commands.ts +72 -4
- package/src/authorization/shell-paths.ts +75 -18
- package/src/compaction/index.ts +1 -0
- package/src/compaction/manual.ts +48 -12
- package/src/compaction/model-summary.ts +163 -28
- package/src/compaction/restore.ts +74 -1
- package/src/compaction/summary.ts +69 -3
- package/src/config/registry.ts +87 -5
- package/src/config/runtime.ts +3 -3
- package/src/connector/index.ts +3 -0
- package/src/connector/mcp/adapter.ts +137 -1
- package/src/connector/mcp/client.ts +49 -7
- package/src/connector/mcp/index.ts +5 -0
- package/src/connector/mcp/sandbox-stdio.ts +214 -0
- package/src/connector/mcp/stdio-program.ts +68 -0
- package/src/connector/mcp/stdio.ts +61 -7
- package/src/connector/web/guarded-fetch.ts +197 -30
- package/src/connector/web/index.ts +4 -1
- package/src/constants/mcp/index.ts +31 -0
- package/src/manager/agent/lifecycle.ts +58 -13
- package/src/plugin/hook-module/capabilities.ts +36 -14
- package/src/plugin/hook-module/host.ts +86 -13
- package/src/plugin/hook-module/index.ts +3 -0
- package/src/plugin/index.ts +4 -0
- package/src/plugin/shell-hook-execute.ts +126 -0
- package/src/plugin/shell-hook-restrict.ts +66 -0
- package/src/plugin/shell-hook.ts +209 -16
- package/src/public-runtime.ts +19 -0
- package/src/public-types.ts +20 -0
- package/src/runtime/jobs/websocket-source.ts +2 -46
- package/src/runtime/query/compact-session.ts +5 -0
- package/src/runtime/query/events.ts +29 -11
- package/src/runtime/query/executor/tool-call-admission.ts +62 -17
- package/src/runtime/query/index.ts +10 -0
- package/src/runtime/query/iteration/phases/compaction.ts +26 -2
- package/src/runtime/query/iteration/phases/context.ts +6 -0
- package/src/runtime/query/path-escalation.ts +102 -16
- package/src/runtime/query/steering.ts +38 -3
- package/src/scheduler/completion-inbox.ts +14 -0
- package/src/session/workspace/driver.ts +12 -0
- package/src/session/workspace/git-worktree.ts +49 -0
- package/src/session/workspace/holds.ts +201 -0
- package/src/session/workspace/index.ts +13 -1
- package/src/store/config/index.ts +6 -0
- package/src/store/session-index/index.ts +14 -0
- package/src/store/session-index/rebuild.ts +22 -4
- package/src/store/session-index/sqlite.ts +63 -14
- package/src/tools/admit-facts.ts +64 -0
- package/src/tools/builtins/grep.ts +52 -0
- package/src/tools/builtins/lsp.ts +47 -4
- package/src/tools/coordinator/ask-user-question.ts +88 -4
- package/src/turn/memory-promoter.ts +24 -3
- package/src/types/agent/base.ts +7 -0
- package/src/types/agent/task.ts +5 -0
- package/src/types/code-navigation/index.ts +48 -4
- package/src/types/hitl/index.ts +8 -0
- package/src/types/message/index.ts +7 -0
- package/src/types/tool/presentation.ts +22 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The folder of an installed Desktop's own tools (`<resources>/toolchain`), named by the app when it
|
|
3
|
+
* starts the engine. Absent means the engine runs on whatever the machine has.
|
|
4
|
+
*/
|
|
5
|
+
export declare const TOOLCHAIN_DIR_ENV = "NAMZU_TOOLCHAIN_DIR";
|
|
6
|
+
/** `bundled` when tool servers must run on the app's own Node, `system` when the machine's Node is used. */
|
|
7
|
+
export declare const TOOLCHAIN_NODE_ENV = "NAMZU_TOOLCHAIN_NODE";
|
|
8
|
+
export interface StdioProgram {
|
|
9
|
+
command: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
/** Variables the program needs beyond the server's own environment. */
|
|
12
|
+
env: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export interface StdioProgramContext {
|
|
15
|
+
platform?: NodeJS.Platform;
|
|
16
|
+
/** Where the toolchain variables are read from; the engine's own environment by default. */
|
|
17
|
+
source?: NodeJS.ProcessEnv;
|
|
18
|
+
/** The program running the engine, which is the app's own executable under Desktop. */
|
|
19
|
+
execPath?: string;
|
|
20
|
+
/** True when `execPath` is an Electron executable that needs ELECTRON_RUN_AS_NODE to behave as Node. */
|
|
21
|
+
electron?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What to start for a tool server's command.
|
|
25
|
+
*
|
|
26
|
+
* A server is usually written as `npx -y some-server` or `node server.js`. On a machine with no Node
|
|
27
|
+
* that fails to start, and on Windows `npx` and `npm` are `.cmd` files that `spawn` cannot start
|
|
28
|
+
* without a shell even when Node is installed. When the app declares a toolchain, those three names
|
|
29
|
+
* are started as the app's own Node running its pinned npm; every other command is returned as given.
|
|
30
|
+
* The machine's own Node is kept for `node` when the app says it chose it, and on Windows `npx` and
|
|
31
|
+
* `npm` still run the pinned npm, on that Node.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveStdioProgram(command: string, args: readonly string[], context?: StdioProgramContext): StdioProgram;
|
|
34
|
+
//# sourceMappingURL=stdio-program.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio-program.d.ts","sourceRoot":"","sources":["../../../src/connector/mcp/stdio-program.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,wBAAwB,CAAA;AACtD,4GAA4G;AAC5G,eAAO,MAAM,kBAAkB,yBAAyB,CAAA;AAExD,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC3B;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAA;IAC1B,4FAA4F;IAC5F,MAAM,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;IAC1B,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,wGAAwG;IACxG,QAAQ,CAAC,EAAE,OAAO,CAAA;CAClB;AAWD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,GAAE,mBAAwB,GAC/B,YAAY,CAiBd"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* The folder of an installed Desktop's own tools (`<resources>/toolchain`), named by the app when it
|
|
4
|
+
* starts the engine. Absent means the engine runs on whatever the machine has.
|
|
5
|
+
*/
|
|
6
|
+
export const TOOLCHAIN_DIR_ENV = 'NAMZU_TOOLCHAIN_DIR';
|
|
7
|
+
/** `bundled` when tool servers must run on the app's own Node, `system` when the machine's Node is used. */
|
|
8
|
+
export const TOOLCHAIN_NODE_ENV = 'NAMZU_TOOLCHAIN_NODE';
|
|
9
|
+
const WINDOWS_SPELLING = /\.(exe|cmd|bat)$/i;
|
|
10
|
+
/** `node`, `npx` or `npm` out of a command as written (`npx`, `NPX.CMD`), or undefined for any other program. */
|
|
11
|
+
function toolName(command) {
|
|
12
|
+
if (/[\\/]/.test(command))
|
|
13
|
+
return undefined;
|
|
14
|
+
const name = command.replace(WINDOWS_SPELLING, '').toLowerCase();
|
|
15
|
+
return name === 'node' || name === 'npx' || name === 'npm' ? name : undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* What to start for a tool server's command.
|
|
19
|
+
*
|
|
20
|
+
* A server is usually written as `npx -y some-server` or `node server.js`. On a machine with no Node
|
|
21
|
+
* that fails to start, and on Windows `npx` and `npm` are `.cmd` files that `spawn` cannot start
|
|
22
|
+
* without a shell even when Node is installed. When the app declares a toolchain, those three names
|
|
23
|
+
* are started as the app's own Node running its pinned npm; every other command is returned as given.
|
|
24
|
+
* The machine's own Node is kept for `node` when the app says it chose it, and on Windows `npx` and
|
|
25
|
+
* `npm` still run the pinned npm, on that Node.
|
|
26
|
+
*/
|
|
27
|
+
export function resolveStdioProgram(command, args, context = {}) {
|
|
28
|
+
const source = context.source ?? process.env;
|
|
29
|
+
const platform = context.platform ?? process.platform;
|
|
30
|
+
const dir = source[TOOLCHAIN_DIR_ENV];
|
|
31
|
+
const unchanged = { command, args: [...args], env: {} };
|
|
32
|
+
const name = toolName(command);
|
|
33
|
+
if (!dir || !name)
|
|
34
|
+
return unchanged;
|
|
35
|
+
const bundled = source[TOOLCHAIN_NODE_ENV] === 'bundled';
|
|
36
|
+
const cli = (file) => join(dir, 'npm', 'bin', file);
|
|
37
|
+
if (!bundled && !(platform === 'win32' && name !== 'node'))
|
|
38
|
+
return unchanged;
|
|
39
|
+
const node = bundled ? (context.execPath ?? process.execPath) : 'node';
|
|
40
|
+
const env = bundled && (context.electron ?? Boolean(process.versions.electron))
|
|
41
|
+
? { ELECTRON_RUN_AS_NODE: '1' }
|
|
42
|
+
: {};
|
|
43
|
+
if (name === 'node')
|
|
44
|
+
return { command: node, args: [...args], env };
|
|
45
|
+
return { command: node, args: [cli(name === 'npx' ? 'npx-cli.js' : 'npm-cli.js'), ...args], env };
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=stdio-program.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio-program.js","sourceRoot":"","sources":["../../../src/connector/mcp/stdio-program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,qBAAqB,CAAA;AACtD,4GAA4G;AAC5G,MAAM,CAAC,MAAM,kBAAkB,GAAG,sBAAsB,CAAA;AAmBxD,MAAM,gBAAgB,GAAG,mBAAmB,CAAA;AAE5C,iHAAiH;AACjH,SAAS,QAAQ,C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C,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;IACtE,MAAM,GAAG,GACR,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAClE,CAAC,CAAC,EAAE,oBAAoB,EAAE,GAAG,EAAE;QAC/B,CAAC,CAAC,EAAE,CAAA;IACN,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;IACnE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;AAClG,CAAC"}
|
|
@@ -25,6 +25,12 @@ export declare class StdioTransport implements MCPTransport {
|
|
|
25
25
|
/** True between kill and the process's own `close` event. */
|
|
26
26
|
private exitPending;
|
|
27
27
|
private buffer;
|
|
28
|
+
/**
|
|
29
|
+
* True once the pending line has been refused for length. Everything up
|
|
30
|
+
* to the next newline is then dropped, so one over-long line costs one
|
|
31
|
+
* report and no memory rather than one report per read.
|
|
32
|
+
*/
|
|
33
|
+
private discardingOverlongLine;
|
|
28
34
|
private log;
|
|
29
35
|
constructor(config: MCPStdioTransportConfig, log?: Logger);
|
|
30
36
|
connect(): Promise<void>;
|
|
@@ -39,6 +45,12 @@ export declare class StdioTransport implements MCPTransport {
|
|
|
39
45
|
* sessions that kept their old client state alive.
|
|
40
46
|
*/
|
|
41
47
|
private clearHandlers;
|
|
48
|
+
/**
|
|
49
|
+
* Drop the framing state of a protocol session that ended or is being
|
|
50
|
+
* replaced. Keeping either half across generations would let a refused
|
|
51
|
+
* line swallow the first bytes of the next one.
|
|
52
|
+
*/
|
|
53
|
+
private resetLineBuffer;
|
|
42
54
|
/**
|
|
43
55
|
* Publish one terminal result for the current response channel.
|
|
44
56
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/connector/mcp/stdio.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/connector/mcp/stdio.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACX,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,EACZ,uBAAuB,EACvB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,EAAE,KAAK,MAAM,EAAiB,MAAM,uBAAuB,CAAA;AA0DlE;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,IAAI,CAAC,uBAAuB,EAAE,KAAK,GAAG,YAAY,CAAC,EAC3D,MAAM,GAAE,MAAM,CAAC,UAAwB,GACrC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAaxB;AAED,qBAAa,cAAe,YAAW,YAAY;IAsBjD,OAAO,CAAC,QAAQ,CAAC,MAAM;IArBxB,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,eAAe,CAAkD;IACzE,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,aAAa,CAAoC;IACzD,OAAO,CAAC,SAAS,CAAQ;IACzB,8DAA8D;IAC9D,OAAO,CAAC,OAAO,CAAQ;IACvB,wEAAwE;IACxE,OAAO,CAAC,UAAU,CAAI;IACtB,6DAA6D;IAC7D,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,MAAM,CAAK;IACnB;;;;OAIG;IACH,OAAO,CAAC,sBAAsB,CAAQ;IACtC,OAAO,CAAC,GAAG,CAAQ;gBAGD,MAAM,EAAE,uBAAuB,EAChD,GAAG,CAAC,EAAE,MAAM;IAKP,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2DxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAuD5B;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IAMrB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAKvB;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM;IAgBR,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxF,SAAS,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,IAAI;IAI9D,OAAO,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI;IAIlC,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI;IAI9C,WAAW,IAAI,OAAO;IAItB,OAAO,CAAC,aAAa;CA0CrB"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { MCP_STDIO_MAX_PENDING_LINE_CHARS, MCP_STDIO_STDERR_LOG_CHARS, } from '../../constants/mcp/index.js';
|
|
2
3
|
import { SESSION_CHILD_ENV } from '../../process/session-child.js';
|
|
3
4
|
import { SCOPE_ATTRIBUTE } from '../../utils/log/types.js';
|
|
4
5
|
import { resolveLogger } from '../../utils/logger.js';
|
|
5
6
|
import { WINDOWS_CORE_ENV_KEYS, applyEnvironmentOverrides, pickEnvironmentEntries, readEnvironmentEntry, setEnvironmentEntry, } from '../../utils/process-environment.js';
|
|
7
|
+
import { resolveStdioProgram } from './stdio-program.js';
|
|
6
8
|
/**
|
|
7
9
|
* How long a child gets to honour SIGTERM before SIGKILL. Two seconds is
|
|
8
10
|
* long enough for a server flushing a response and short enough that a
|
|
@@ -88,6 +90,12 @@ export class StdioTransport {
|
|
|
88
90
|
/** True between kill and the process's own `close` event. */
|
|
89
91
|
exitPending = false;
|
|
90
92
|
buffer = '';
|
|
93
|
+
/**
|
|
94
|
+
* True once the pending line has been refused for length. Everything up
|
|
95
|
+
* to the next newline is then dropped, so one over-long line costs one
|
|
96
|
+
* report and no memory rather than one report per read.
|
|
97
|
+
*/
|
|
98
|
+
discardingOverlongLine = false;
|
|
91
99
|
log;
|
|
92
100
|
constructor(config, log) {
|
|
93
101
|
this.config = config;
|
|
@@ -103,9 +111,11 @@ export class StdioTransport {
|
|
|
103
111
|
await this.close();
|
|
104
112
|
const generation = ++this.generation;
|
|
105
113
|
this.retired = false;
|
|
106
|
-
this.
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
this.resetLineBuffer();
|
|
115
|
+
// `npx` and `node` run on the app's own tools when the app declares them (stdio-program.ts).
|
|
116
|
+
const program = resolveStdioProgram(this.config.command, this.config.args ?? []);
|
|
117
|
+
const child = spawn(program.command, program.args, {
|
|
118
|
+
env: { ...buildChildEnv(this.config), ...program.env },
|
|
109
119
|
cwd: this.config.cwd,
|
|
110
120
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
111
121
|
});
|
|
@@ -120,8 +130,14 @@ export class StdioTransport {
|
|
|
120
130
|
child.stdout?.once('close', () => this.retire(generation, 'close'));
|
|
121
131
|
child.stdout?.once('error', (err) => this.retire(generation, 'error', err));
|
|
122
132
|
child.stderr?.on('data', (chunk) => {
|
|
133
|
+
// One record per read, so the read's text is bounded here: a server
|
|
134
|
+
// that floods its error stream otherwise puts the whole of it on
|
|
135
|
+
// the terminal, a read at a time. The length travels beside the
|
|
136
|
+
// head so the record says how much it is not showing.
|
|
137
|
+
const text = chunk.toString('utf-8').trim();
|
|
123
138
|
this.log.warn('MCP server stderr', {
|
|
124
|
-
'namzu.mcp.stderr':
|
|
139
|
+
'namzu.mcp.stderr': text.slice(0, MCP_STDIO_STDERR_LOG_CHARS),
|
|
140
|
+
'namzu.mcp.stderr_chars': text.length,
|
|
125
141
|
});
|
|
126
142
|
});
|
|
127
143
|
child.stdin?.once('close', () => this.retire(generation, 'close'));
|
|
@@ -154,7 +170,7 @@ export class StdioTransport {
|
|
|
154
170
|
this.exitPending = true;
|
|
155
171
|
const child = this.process;
|
|
156
172
|
this.process = null;
|
|
157
|
-
this.
|
|
173
|
+
this.resetLineBuffer();
|
|
158
174
|
// Resolve when the child is actually gone, not when the signal was
|
|
159
175
|
// sent. `kill()` returns as soon as the signal is delivered, so an
|
|
160
176
|
// awaited `close()` meant only "SIGTERM is on its way" — a caller that
|
|
@@ -209,6 +225,15 @@ export class StdioTransport {
|
|
|
209
225
|
this.closeHandlers = [];
|
|
210
226
|
this.errorHandlers = [];
|
|
211
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* Drop the framing state of a protocol session that ended or is being
|
|
230
|
+
* replaced. Keeping either half across generations would let a refused
|
|
231
|
+
* line swallow the first bytes of the next one.
|
|
232
|
+
*/
|
|
233
|
+
resetLineBuffer() {
|
|
234
|
+
this.buffer = '';
|
|
235
|
+
this.discardingOverlongLine = false;
|
|
236
|
+
}
|
|
212
237
|
/**
|
|
213
238
|
* Publish one terminal result for the current response channel.
|
|
214
239
|
*
|
|
@@ -222,7 +247,7 @@ export class StdioTransport {
|
|
|
222
247
|
return;
|
|
223
248
|
this.retired = true;
|
|
224
249
|
this.connected = false;
|
|
225
|
-
this.
|
|
250
|
+
this.resetLineBuffer();
|
|
226
251
|
const closeHandlers = this.closeHandlers;
|
|
227
252
|
const errorHandlers = this.errorHandlers;
|
|
228
253
|
this.clearHandlers();
|
|
@@ -260,8 +285,21 @@ export class StdioTransport {
|
|
|
260
285
|
return this.connected;
|
|
261
286
|
}
|
|
262
287
|
processBuffer() {
|
|
288
|
+
// An already-refused line is skipped to its terminator before anything
|
|
289
|
+
// else is read from the buffer. Without this the rest of that line
|
|
290
|
+
// would be re-buffered, re-measured and re-reported once per read,
|
|
291
|
+
// turning one bad line into an output flood of the transport's own.
|
|
292
|
+
if (this.discardingOverlongLine) {
|
|
293
|
+
const terminator = this.buffer.indexOf('\n');
|
|
294
|
+
if (terminator === -1) {
|
|
295
|
+
this.buffer = '';
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
this.buffer = this.buffer.slice(terminator + 1);
|
|
299
|
+
this.discardingOverlongLine = false;
|
|
300
|
+
}
|
|
263
301
|
const lines = this.buffer.split('\n');
|
|
264
|
-
|
|
302
|
+
let pending = lines.pop() ?? '';
|
|
265
303
|
for (const line of lines) {
|
|
266
304
|
const trimmed = line.trim();
|
|
267
305
|
if (!trimmed)
|
|
@@ -277,6 +315,15 @@ export class StdioTransport {
|
|
|
277
315
|
});
|
|
278
316
|
}
|
|
279
317
|
}
|
|
318
|
+
if (pending.length > MCP_STDIO_MAX_PENDING_LINE_CHARS) {
|
|
319
|
+
this.discardingOverlongLine = true;
|
|
320
|
+
this.log.warn('StdioTransport: dropping MCP server output past the pending-line ceiling', {
|
|
321
|
+
'namzu.mcp.line_chars': pending.length,
|
|
322
|
+
'namzu.mcp.line_ceiling': MCP_STDIO_MAX_PENDING_LINE_CHARS,
|
|
323
|
+
});
|
|
324
|
+
pending = '';
|
|
325
|
+
}
|
|
326
|
+
this.buffer = pending;
|
|
280
327
|
}
|
|
281
328
|
}
|
|
282
329
|
//# sourceMappingURL=stdio.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../../src/connector/mcp/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAOlE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAe,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,EACN,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,GACnB,MAAM,oCAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../../src/connector/mcp/stdio.ts"],"names":[],"mappings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,CAAC,IAAI,CAAC,0EAA0E,EAAE;gBACzF,sBAAsB,EAAE,OAAO,CAAC,MAAM;gBACtC,wBAAwB,EAAE,gCAAgC;aAC1D,CAAC,CAAA;YACF,OAAO,GAAG,EAAE,CAAA;QACb,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,OAAO,CAAA;IACtB,CAAC;CACD"}
|
|
@@ -51,7 +51,8 @@ export declare function isPrivateAddress(address: string): boolean;
|
|
|
51
51
|
* It fails closed: a name that cannot be resolved, or resolves to nothing, is
|
|
52
52
|
* refused, since the fetch that follows would resolve it again for real.
|
|
53
53
|
*/
|
|
54
|
-
export declare function privateAddressProblem(hostname: string, options?:
|
|
54
|
+
export declare function privateAddressProblem(hostname: string, options?: AddressCheckOptions): Promise<string | undefined>;
|
|
55
|
+
export interface AddressCheckOptions {
|
|
55
56
|
readonly resolve?: (hostname: string, signal?: AbortSignal) => Promise<readonly string[]>;
|
|
56
57
|
readonly signal?: AbortSignal;
|
|
57
58
|
/**
|
|
@@ -60,7 +61,55 @@ export declare function privateAddressProblem(hostname: string, options?: {
|
|
|
60
61
|
* that does resolve here is still checked, and a literal address always is.
|
|
61
62
|
*/
|
|
62
63
|
readonly proxied?: boolean;
|
|
63
|
-
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The same check as {@link privateAddressProblem}, with the addresses it looked at.
|
|
67
|
+
*
|
|
68
|
+
* A caller that connects itself passes `addresses` to {@link pinnedFetch} (or
|
|
69
|
+
* {@link pinnedLookup}), so the connection goes to what was checked and the
|
|
70
|
+
* name is not resolved a second time: a name that answers publicly to the
|
|
71
|
+
* check and privately to the connection (DNS rebinding) then has no second
|
|
72
|
+
* answer to differ. `addresses` is empty when there is a `problem`, and when
|
|
73
|
+
* the request goes through a proxy and this machine could not resolve the
|
|
74
|
+
* name (the proxy resolves it, and there is nothing to pin).
|
|
75
|
+
*/
|
|
76
|
+
export declare function checkedAddresses(hostname: string, options?: AddressCheckOptions): Promise<{
|
|
77
|
+
readonly problem?: string;
|
|
78
|
+
readonly addresses: readonly string[];
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* A `lookup` for a socket that answers with the addresses that were checked
|
|
82
|
+
* and nothing else. The URL still names the host, so TLS keeps its SNI and
|
|
83
|
+
* its certificate check on the hostname and not on an address, and the
|
|
84
|
+
* `Host` header is the name the caller wrote.
|
|
85
|
+
*/
|
|
86
|
+
export declare function pinnedLookup(addresses: readonly {
|
|
87
|
+
readonly address: string;
|
|
88
|
+
readonly family: 4 | 6;
|
|
89
|
+
}[]): (_hostname: string, options: {
|
|
90
|
+
all?: boolean;
|
|
91
|
+
family?: number | string;
|
|
92
|
+
} | undefined, callback: (error: NodeJS.ErrnoException | null, address: string | {
|
|
93
|
+
address: string;
|
|
94
|
+
family: number;
|
|
95
|
+
}[], family?: number) => void) => void;
|
|
96
|
+
export interface PinnedRequest {
|
|
97
|
+
readonly method?: string;
|
|
98
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
99
|
+
readonly body?: string;
|
|
100
|
+
readonly signal?: AbortSignal;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* One request that connects to `addresses` (the ones a check looked at) and
|
|
104
|
+
* never asks DNS. Redirects are not followed: each hop is a new call with its
|
|
105
|
+
* own check. The body is decoded the way `fetch` decodes it (gzip, deflate,
|
|
106
|
+
* brotli), so the `Response` reads the same.
|
|
107
|
+
*
|
|
108
|
+
* It does not go through the process-wide proxy and client-certificate setup
|
|
109
|
+
* that the platform `fetch` uses, so a caller behind a proxy keeps using
|
|
110
|
+
* `fetch` (the proxy resolves the name, and there is no address to pin).
|
|
111
|
+
*/
|
|
112
|
+
export declare function pinnedFetch(url: URL, init: PinnedRequest, addresses: readonly string[]): Promise<Response>;
|
|
64
113
|
/**
|
|
65
114
|
* Whether a web request to `host` goes through a proxy: `HTTPS_PROXY` or `HTTP_PROXY` (either case)
|
|
66
115
|
* holds an http or https address and `NO_PROXY` does not name the host. These are the variables
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guarded-fetch.d.ts","sourceRoot":"","sources":["../../../src/connector/web/guarded-fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"guarded-fetch.d.ts","sourceRoot":"","sources":["../../../src/connector/web/guarded-fetch.ts"],"names":[],"mappings":"AAeA,OAAO,EACN,KAAK,gBAAgB,EAErB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,MAAM,YAAY,CAAA;AAkCnB,MAAM,WAAW,kBAAkB;IAClC,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B;;;;;;OAMG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACzC;;;;;;OAMG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAA;IACxC;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAA;CACzF;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAsEzD;AAED;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CAC1C,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,mBAAwB,GAC/B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE7B;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OA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gB,WAAW,CAC1B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,aAAa,EACnB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC1B,OAAO,CAAC,QAAQ,CAAC,CAwDnB;AAiCD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAI5F;AAaD,qBAAa,oBAAqB,YAAW,gBAAgB;IAKhD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAQ;gBAER,MAAM,GAAE,kBAAuB;IAkB5D;;;;;;;;OAQG;YACW,aAAa;IA0FrB,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;CA8H9D"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { lookup } from 'node:dns/promises';
|
|
2
|
+
import { request as httpRequest } from 'node:http';
|
|
3
|
+
import { request as httpsRequest } from 'node:https';
|
|
2
4
|
import { isIP } from 'node:net';
|
|
5
|
+
import { Readable } from 'node:stream';
|
|
6
|
+
import { createBrotliDecompress, createGunzip, createInflate } from 'node:zlib';
|
|
3
7
|
import { ConnectorHttpOperation, DEFAULT_CONNECTOR_MAX_RESPONSE_BYTES, DEFAULT_CONNECTOR_REQUEST_TIMEOUT_MS, validateConnectorMaxResponseBytes, validateConnectorTimeoutMs, } from '../http-operation.js';
|
|
4
8
|
import { isSameSiteRedirect } from './page.js';
|
|
5
9
|
import { WebFetchRefusedError, } from './types.js';
|
|
@@ -139,6 +143,20 @@ export function isPrivateAddress(address) {
|
|
|
139
143
|
* refused, since the fetch that follows would resolve it again for real.
|
|
140
144
|
*/
|
|
141
145
|
export async function privateAddressProblem(hostname, options = {}) {
|
|
146
|
+
return (await checkedAddresses(hostname, options)).problem;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The same check as {@link privateAddressProblem}, with the addresses it looked at.
|
|
150
|
+
*
|
|
151
|
+
* A caller that connects itself passes `addresses` to {@link pinnedFetch} (or
|
|
152
|
+
* {@link pinnedLookup}), so the connection goes to what was checked and the
|
|
153
|
+
* name is not resolved a second time: a name that answers publicly to the
|
|
154
|
+
* check and privately to the connection (DNS rebinding) then has no second
|
|
155
|
+
* answer to differ. `addresses` is empty when there is a `problem`, and when
|
|
156
|
+
* the request goes through a proxy and this machine could not resolve the
|
|
157
|
+
* name (the proxy resolves it, and there is nothing to pin).
|
|
158
|
+
*/
|
|
159
|
+
export async function checkedAddresses(hostname, options = {}) {
|
|
142
160
|
const name = hostname.toLowerCase().replace(/^\[|\]$/g, '');
|
|
143
161
|
let addresses;
|
|
144
162
|
if (isIP(name) !== 0) {
|
|
@@ -152,17 +170,108 @@ export async function privateAddressProblem(hostname, options = {}) {
|
|
|
152
170
|
}
|
|
153
171
|
catch (error) {
|
|
154
172
|
if (options.proxied === true && !options.signal?.aborted)
|
|
155
|
-
return
|
|
156
|
-
return
|
|
173
|
+
return { addresses: [] };
|
|
174
|
+
return {
|
|
175
|
+
problem: `${name} could not be resolved (${error instanceof Error ? error.message : String(error)}), so nothing here can say where it points`,
|
|
176
|
+
addresses: [],
|
|
177
|
+
};
|
|
157
178
|
}
|
|
158
179
|
if (addresses.length === 0)
|
|
159
|
-
return `${name} resolves to no addresses
|
|
180
|
+
return { problem: `${name} resolves to no addresses`, addresses: [] };
|
|
160
181
|
}
|
|
161
182
|
for (const address of addresses) {
|
|
162
183
|
if (isPrivateAddress(address))
|
|
163
|
-
return
|
|
184
|
+
return {
|
|
185
|
+
problem: `${name} resolves to ${address}, inside this host's own network`,
|
|
186
|
+
addresses: [],
|
|
187
|
+
};
|
|
164
188
|
}
|
|
165
|
-
return
|
|
189
|
+
return { addresses };
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* A `lookup` for a socket that answers with the addresses that were checked
|
|
193
|
+
* and nothing else. The URL still names the host, so TLS keeps its SNI and
|
|
194
|
+
* its certificate check on the hostname and not on an address, and the
|
|
195
|
+
* `Host` header is the name the caller wrote.
|
|
196
|
+
*/
|
|
197
|
+
export function pinnedLookup(addresses) {
|
|
198
|
+
return (_hostname, options, callback) => {
|
|
199
|
+
// A caller that wants one family gets that family's addresses; asking for
|
|
200
|
+
// one we hold none of is an error rather than a fall back to DNS.
|
|
201
|
+
const wanted = options?.family === 4 || options?.family === 6 ? options.family : undefined;
|
|
202
|
+
const usable = wanted === undefined ? addresses : addresses.filter((a) => a.family === wanted);
|
|
203
|
+
const first = usable[0];
|
|
204
|
+
if (first === undefined) {
|
|
205
|
+
const error = new Error('no vetted address of that family');
|
|
206
|
+
error.code = 'ENOTFOUND';
|
|
207
|
+
callback(error, '', 0);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (options?.all === true) {
|
|
211
|
+
callback(null, usable.map((a) => ({ address: a.address, family: a.family })));
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
callback(null, first.address, first.family);
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* One request that connects to `addresses` (the ones a check looked at) and
|
|
219
|
+
* never asks DNS. Redirects are not followed: each hop is a new call with its
|
|
220
|
+
* own check. The body is decoded the way `fetch` decodes it (gzip, deflate,
|
|
221
|
+
* brotli), so the `Response` reads the same.
|
|
222
|
+
*
|
|
223
|
+
* It does not go through the process-wide proxy and client-certificate setup
|
|
224
|
+
* that the platform `fetch` uses, so a caller behind a proxy keeps using
|
|
225
|
+
* `fetch` (the proxy resolves the name, and there is no address to pin).
|
|
226
|
+
*/
|
|
227
|
+
export function pinnedFetch(url, init, addresses) {
|
|
228
|
+
return new Promise((resolve, reject) => {
|
|
229
|
+
const send = url.protocol === 'https:' ? httpsRequest : httpRequest;
|
|
230
|
+
const lookupFor = pinnedLookup(addresses.map((address) => ({ address, family: isIP(address) === 6 ? 6 : 4 })));
|
|
231
|
+
const headers = { 'accept-encoding': 'gzip, deflate, br' };
|
|
232
|
+
for (const [key, value] of Object.entries(init.headers ?? {}))
|
|
233
|
+
headers[key.toLowerCase()] = value;
|
|
234
|
+
const req = send(url, {
|
|
235
|
+
method: init.method ?? 'GET',
|
|
236
|
+
headers,
|
|
237
|
+
lookup: lookupFor,
|
|
238
|
+
...(init.signal ? { signal: init.signal } : {}),
|
|
239
|
+
}, (res) => {
|
|
240
|
+
const answered = new Headers();
|
|
241
|
+
for (let i = 0; i + 1 < res.rawHeaders.length; i += 2) {
|
|
242
|
+
answered.append(res.rawHeaders[i], res.rawHeaders[i + 1]);
|
|
243
|
+
}
|
|
244
|
+
const status = res.statusCode ?? 502;
|
|
245
|
+
if (status < 200 || status === 204 || status === 205 || status === 304) {
|
|
246
|
+
res.resume();
|
|
247
|
+
resolve(new Response(null, { status, headers: answered }));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const encoding = (res.headers['content-encoding'] ?? '').toLowerCase().trim();
|
|
251
|
+
const decoder = encoding === 'gzip' || encoding === 'x-gzip'
|
|
252
|
+
? createGunzip()
|
|
253
|
+
: encoding === 'deflate'
|
|
254
|
+
? createInflate()
|
|
255
|
+
: encoding === 'br'
|
|
256
|
+
? createBrotliDecompress()
|
|
257
|
+
: undefined;
|
|
258
|
+
let source = res;
|
|
259
|
+
if (decoder) {
|
|
260
|
+
answered.delete('content-encoding');
|
|
261
|
+
answered.delete('content-length');
|
|
262
|
+
res.on('error', (error) => decoder.destroy(error));
|
|
263
|
+
source = res.pipe(decoder);
|
|
264
|
+
}
|
|
265
|
+
resolve(new Response(Readable.toWeb(source), {
|
|
266
|
+
status,
|
|
267
|
+
headers: answered,
|
|
268
|
+
}));
|
|
269
|
+
});
|
|
270
|
+
req.on('error', reject);
|
|
271
|
+
if (init.body !== undefined)
|
|
272
|
+
req.write(init.body);
|
|
273
|
+
req.end();
|
|
274
|
+
});
|
|
166
275
|
}
|
|
167
276
|
/** Whether a proxy variable holds an http or https proxy address (what the client library uses). */
|
|
168
277
|
function usableProxy(value) {
|
|
@@ -272,17 +381,16 @@ export class GuardedFetchProvider {
|
|
|
272
381
|
}
|
|
273
382
|
if (this.config.allowPrivateAddresses === true) {
|
|
274
383
|
operation.throwIfStopped();
|
|
275
|
-
return url;
|
|
384
|
+
return { url };
|
|
276
385
|
}
|
|
277
386
|
// RESOLVED, not just parsed. A hostname check alone is bypassed by any
|
|
278
387
|
// name whose A record points inside — which is a thing anyone can set
|
|
279
388
|
// up on a domain they own, and costs nothing to try.
|
|
280
389
|
//
|
|
281
|
-
// The
|
|
282
|
-
//
|
|
283
|
-
//
|
|
284
|
-
//
|
|
285
|
-
// needs that guarantee supplies its own `fetch` that does.
|
|
390
|
+
// The addresses checked here are the ones the connection is pinned to
|
|
391
|
+
// (see `fetch`): the name is resolved once per hop, so a name that
|
|
392
|
+
// answers publicly now and privately on the connection's own lookup
|
|
393
|
+
// (DNS rebinding) has no second answer to differ.
|
|
286
394
|
const resolve = this.config.resolve ??
|
|
287
395
|
(async (name) => (await lookup(name, { all: true })).map((r) => r.address));
|
|
288
396
|
let addresses;
|
|
@@ -318,7 +426,7 @@ export class GuardedFetchProvider {
|
|
|
318
426
|
}
|
|
319
427
|
}
|
|
320
428
|
operation.throwIfStopped();
|
|
321
|
-
return url;
|
|
429
|
+
return { url, addresses };
|
|
322
430
|
}
|
|
323
431
|
async fetch(request) {
|
|
324
432
|
const doFetch = this.config.fetch ?? globalThis.fetch;
|
|
@@ -331,7 +439,7 @@ export class GuardedFetchProvider {
|
|
|
331
439
|
}
|
|
332
440
|
const redirects = [];
|
|
333
441
|
let redirectsFollowed = 0;
|
|
334
|
-
let current = await this.assertAllowed(request.url, operation);
|
|
442
|
+
let { url: current, addresses: pinned } = await this.assertAllowed(request.url, operation);
|
|
335
443
|
for (;;) {
|
|
336
444
|
operation.throwIfStopped();
|
|
337
445
|
redirects.push(current.toString());
|
|
@@ -339,11 +447,23 @@ export class GuardedFetchProvider {
|
|
|
339
447
|
// the platform follow redirects is exactly the hole this class
|
|
340
448
|
// exists to close: it would land on the final URL having never
|
|
341
449
|
// asked whether that URL was allowed.
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
450
|
+
//
|
|
451
|
+
// The connection goes to the addresses that were checked. The default
|
|
452
|
+
// transport connects to them by address and keeps the name for the
|
|
453
|
+
// `Host` header and TLS; an injected `fetch` is handed them as
|
|
454
|
+
// `pinnedAddresses`, so a host that brings its own client can pin too.
|
|
455
|
+
const target = current;
|
|
456
|
+
const addresses = pinned;
|
|
457
|
+
const response = await operation.run(() => this.config.fetch === undefined &&
|
|
458
|
+
addresses !== undefined &&
|
|
459
|
+
!proxyConfigured(process.env, target.hostname)
|
|
460
|
+
? pinnedFetch(target, { headers, signal: operation.signal }, addresses)
|
|
461
|
+
: doFetch(target, {
|
|
462
|
+
headers,
|
|
463
|
+
redirect: 'manual',
|
|
464
|
+
signal: operation.signal,
|
|
465
|
+
...(addresses !== undefined ? { pinnedAddresses: addresses } : {}),
|
|
466
|
+
}));
|
|
347
467
|
const location = response.headers.get('location');
|
|
348
468
|
if (response.status >= 300 && response.status < 400 && location) {
|
|
349
469
|
// The budget is about redirects FOLLOWED. Refuse before parsing or
|
|
@@ -384,7 +504,8 @@ export class GuardedFetchProvider {
|
|
|
384
504
|
};
|
|
385
505
|
}
|
|
386
506
|
try {
|
|
387
|
-
|
|
507
|
+
;
|
|
508
|
+
({ url: current, addresses: pinned } = await this.assertAllowed(next.toString(), operation));
|
|
388
509
|
}
|
|
389
510
|
catch (err) {
|
|
390
511
|
operation.throwIfStopped();
|