@lobu/worker 3.3.0 → 3.4.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/dist/embedded/just-bash-bootstrap.d.ts +16 -1
- package/dist/embedded/just-bash-bootstrap.d.ts.map +1 -1
- package/dist/embedded/just-bash-bootstrap.js +33 -4
- package/dist/embedded/just-bash-bootstrap.js.map +1 -1
- package/dist/embedded/mcp-cli-commands.d.ts +75 -0
- package/dist/embedded/mcp-cli-commands.d.ts.map +1 -0
- package/dist/embedded/mcp-cli-commands.js +336 -0
- package/dist/embedded/mcp-cli-commands.js.map +1 -0
- package/dist/openclaw/sandbox-leak.d.ts +28 -0
- package/dist/openclaw/sandbox-leak.d.ts.map +1 -0
- package/dist/openclaw/sandbox-leak.js +65 -0
- package/dist/openclaw/sandbox-leak.js.map +1 -0
- package/dist/openclaw/session-context.d.ts +13 -10
- package/dist/openclaw/session-context.d.ts.map +1 -1
- package/dist/openclaw/session-context.js +50 -8
- package/dist/openclaw/session-context.js.map +1 -1
- package/dist/openclaw/worker.d.ts +1 -0
- package/dist/openclaw/worker.d.ts.map +1 -1
- package/dist/openclaw/worker.js +143 -42
- package/dist/openclaw/worker.js.map +1 -1
- package/dist/shared/provider-auth-hints.d.ts.map +1 -1
- package/dist/shared/provider-auth-hints.js +9 -5
- package/dist/shared/provider-auth-hints.js.map +1 -1
- package/dist/shared/tool-implementations.d.ts.map +1 -1
- package/dist/shared/tool-implementations.js +3 -1
- package/dist/shared/tool-implementations.js.map +1 -1
- package/package.json +2 -2
|
@@ -9,13 +9,28 @@
|
|
|
9
9
|
* just-bash customCommands that delegate to real exec.
|
|
10
10
|
*/
|
|
11
11
|
import type { BashOperations } from "@mariozechner/pi-coding-agent";
|
|
12
|
+
import type { GatewayParams } from "../shared/tool-implementations";
|
|
13
|
+
import type { McpRuntimeRef } from "./mcp-cli-commands";
|
|
12
14
|
export declare function buildBinaryInvocation(binaryPath: string, args: string[]): {
|
|
13
15
|
command: string;
|
|
14
16
|
args: string[];
|
|
15
17
|
};
|
|
18
|
+
export interface EmbeddedBashOpsOptions {
|
|
19
|
+
/**
|
|
20
|
+
* When provided together with `gw`, MCP servers are exposed as one
|
|
21
|
+
* `just-bash` custom command per server (e.g. `owletto search_knowledge
|
|
22
|
+
* <<<'{...}'`). Only applied when `mcpExposure === "cli"`. The ref's
|
|
23
|
+
* optional `refresh()` is invoked after successful auth operations so
|
|
24
|
+
* CLI handlers pick up freshly-discovered MCP tools without rebuilding Bash.
|
|
25
|
+
*/
|
|
26
|
+
mcpRuntimeRef?: McpRuntimeRef;
|
|
27
|
+
gw?: GatewayParams;
|
|
28
|
+
/** `"tools"` (default) keeps today's first-class MCP tools. `"cli"` swaps to sandboxed bash CLIs. */
|
|
29
|
+
mcpExposure?: "tools" | "cli";
|
|
30
|
+
}
|
|
16
31
|
/**
|
|
17
32
|
* Create a BashOperations adapter backed by a just-bash Bash instance.
|
|
18
33
|
* Reads configuration from environment variables.
|
|
19
34
|
*/
|
|
20
|
-
export declare function createEmbeddedBashOps(): Promise<BashOperations>;
|
|
35
|
+
export declare function createEmbeddedBashOps(options?: EmbeddedBashOpsOptions): Promise<BashOperations>;
|
|
21
36
|
//# sourceMappingURL=just-bash-bootstrap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"just-bash-bootstrap.d.ts","sourceRoot":"","sources":["../../src/embedded/just-bash-bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"just-bash-bootstrap.d.ts","sourceRoot":"","sources":["../../src/embedded/just-bash-bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,oBAAoB,CAAC;AASvE,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EAAE,GACb;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAYrC;AAoGD,MAAM,WAAW,sBAAsB;IACrC;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,EAAE,CAAC,EAAE,aAAa,CAAC;IACnB,qGAAqG;IACrG,WAAW,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;CAC/B;AAgBD;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,cAAc,CAAC,CAyGzB"}
|
|
@@ -52,6 +52,7 @@ const node_child_process_1 = require("node:child_process");
|
|
|
52
52
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
53
53
|
const node_path_1 = __importDefault(require("node:path"));
|
|
54
54
|
const sensitive_env_1 = require("../shared/sensitive-env");
|
|
55
|
+
const mcp_cli_commands_1 = require("./mcp-cli-commands");
|
|
55
56
|
const EMBEDDED_BASH_LIMITS = {
|
|
56
57
|
maxCommandCount: 50_000,
|
|
57
58
|
maxLoopIterations: 50_000,
|
|
@@ -152,11 +153,22 @@ async function buildCustomCommands(binaries) {
|
|
|
152
153
|
}
|
|
153
154
|
return commands;
|
|
154
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Convert an in-process MCP CLI handler into a just-bash `defineCommand` entry.
|
|
158
|
+
*/
|
|
159
|
+
async function adaptMcpCliCommand(cmd) {
|
|
160
|
+
const { defineCommand } = await Promise.resolve().then(() => __importStar(require("just-bash")));
|
|
161
|
+
return defineCommand(cmd.name, async (args, ctx) => {
|
|
162
|
+
const stdin = typeof ctx.stdin === "string" ? ctx.stdin : "";
|
|
163
|
+
const signal = ctx.signal;
|
|
164
|
+
return cmd.execute(args, { stdin, signal });
|
|
165
|
+
});
|
|
166
|
+
}
|
|
155
167
|
/**
|
|
156
168
|
* Create a BashOperations adapter backed by a just-bash Bash instance.
|
|
157
169
|
* Reads configuration from environment variables.
|
|
158
170
|
*/
|
|
159
|
-
async function createEmbeddedBashOps() {
|
|
171
|
+
async function createEmbeddedBashOps(options = {}) {
|
|
160
172
|
const { Bash, ReadWriteFs } = await Promise.resolve().then(() => __importStar(require("just-bash")));
|
|
161
173
|
const workspaceDir = process.env.WORKSPACE_DIR || "/workspace";
|
|
162
174
|
const bashFs = new ReadWriteFs({ root: workspaceDir });
|
|
@@ -179,13 +191,30 @@ async function createEmbeddedBashOps() {
|
|
|
179
191
|
allowedMethods: ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"],
|
|
180
192
|
}
|
|
181
193
|
: undefined;
|
|
182
|
-
//
|
|
194
|
+
// Build MCP CLI commands first so that explicit MCP registrations win over
|
|
195
|
+
// any PATH-discovered binary with the same name (e.g. `owletto` is both an
|
|
196
|
+
// installed nix binary and an MCP server).
|
|
197
|
+
let mcpCliCommands = [];
|
|
198
|
+
if (options.mcpExposure === "cli" && options.mcpRuntimeRef && options.gw) {
|
|
199
|
+
mcpCliCommands = (0, mcp_cli_commands_1.buildMcpCliCommands)(options.mcpRuntimeRef, options.gw);
|
|
200
|
+
}
|
|
201
|
+
const mcpCliNames = new Set(mcpCliCommands.map((c) => c.name));
|
|
202
|
+
// Discover nix binaries and known CLI tools, register as custom commands.
|
|
203
|
+
// Strip names claimed by MCP CLIs so the MCP-backed handler takes precedence.
|
|
183
204
|
const binaries = discoverBinaries();
|
|
184
|
-
const
|
|
205
|
+
for (const name of mcpCliNames) {
|
|
206
|
+
binaries.delete(name);
|
|
207
|
+
}
|
|
208
|
+
const binaryCommands = binaries.size > 0 ? await buildCustomCommands(binaries) : [];
|
|
209
|
+
const mcpCommandEntries = await Promise.all(mcpCliCommands.map((c) => adaptMcpCliCommand(c)));
|
|
210
|
+
const customCommands = [...mcpCommandEntries, ...binaryCommands];
|
|
185
211
|
if (binaries.size > 0) {
|
|
186
212
|
const names = [...binaries.keys()].slice(0, 20).join(", ");
|
|
187
213
|
const suffix = binaries.size > 20 ? `, ... (${binaries.size} total)` : "";
|
|
188
|
-
console.log(`[embedded] Registered ${binaries.size}
|
|
214
|
+
console.log(`[embedded] Registered ${binaries.size} binary commands: ${names}${suffix}`);
|
|
215
|
+
}
|
|
216
|
+
if (mcpCliCommands.length > 0) {
|
|
217
|
+
console.log(`[embedded] Registered ${mcpCliCommands.length} MCP CLI commands: ${mcpCliCommands.map((c) => c.name).join(", ")}`);
|
|
189
218
|
}
|
|
190
219
|
const bashInstance = new Bash({
|
|
191
220
|
fs: bashFs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"just-bash-bootstrap.js","sourceRoot":"","sources":["../../src/embedded/just-bash-bootstrap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"just-bash-bootstrap.js","sourceRoot":"","sources":["../../src/embedded/just-bash-bootstrap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBH,sDAeC;AAoID,sDA2GC;AA7QD,2DAA8C;AAC9C,sDAAyB;AACzB,0DAA6B;AAE7B,2DAAkE;AAGlE,yDAAyD;AAEzD,MAAM,oBAAoB,GAAG;IAC3B,eAAe,EAAE,MAAM;IACvB,iBAAiB,EAAE,MAAM;IACzB,YAAY,EAAE,EAAE;CACR,CAAC;AAEX,SAAgB,qBAAqB,CACnC,UAAkB,EAClB,IAAc;IAEd,IAAI,CAAC;QACH,MAAM,SAAS,GACb,iBAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9D,IAAI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MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YACrC,CAAC;YACD,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YACrC,CAAC;YAED,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker-side MCP-as-CLI bootstrap for embedded deployment mode.
|
|
3
|
+
*
|
|
4
|
+
* Registers one `just-bash` custom command per MCP server (e.g. `owletto`,
|
|
5
|
+
* `gmail`). The agent invokes MCP tools via the sandboxed bash:
|
|
6
|
+
*
|
|
7
|
+
* owletto search_knowledge <<<'{"query":"foo"}'
|
|
8
|
+
* owletto --help
|
|
9
|
+
* owletto save_knowledge --schema
|
|
10
|
+
* owletto auth login
|
|
11
|
+
*
|
|
12
|
+
* Payload is read from `ctx.stdin` as JSON. If stdin is empty, falls back to
|
|
13
|
+
* `args[1]` as a JSON string (defense-in-depth for models that write the JSON
|
|
14
|
+
* inline).
|
|
15
|
+
*/
|
|
16
|
+
import type { McpStatus, McpToolDef } from "@lobu/core";
|
|
17
|
+
import type { GatewayParams } from "../shared/tool-implementations";
|
|
18
|
+
import { callMcpTool } from "../shared/tool-implementations";
|
|
19
|
+
/**
|
|
20
|
+
* Mutable snapshot of MCP session state. CLI handlers read through `current`
|
|
21
|
+
* so that `auth login|check|logout` can refresh tools/state via `refresh()`
|
|
22
|
+
* without rebuilding the Bash instance. New servers discovered after startup
|
|
23
|
+
* are not retro-registered — they require a worker restart.
|
|
24
|
+
*/
|
|
25
|
+
export interface McpRuntimeState {
|
|
26
|
+
mcpTools: Record<string, McpToolDef[]>;
|
|
27
|
+
mcpStatus: McpStatus[];
|
|
28
|
+
mcpContext: Record<string, string>;
|
|
29
|
+
}
|
|
30
|
+
export interface McpRuntimeRef {
|
|
31
|
+
current: McpRuntimeState;
|
|
32
|
+
/** Re-fetch session context and return a fresh snapshot, or `null` on failure. */
|
|
33
|
+
refresh?: () => Promise<McpRuntimeState | null>;
|
|
34
|
+
}
|
|
35
|
+
export interface McpCliCommand {
|
|
36
|
+
name: string;
|
|
37
|
+
execute: (args: string[], ctx: {
|
|
38
|
+
stdin?: string;
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
}) => Promise<{
|
|
41
|
+
stdout: string;
|
|
42
|
+
stderr: string;
|
|
43
|
+
exitCode: number;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
export interface McpCliDeps {
|
|
47
|
+
callTool: typeof callMcpTool;
|
|
48
|
+
}
|
|
49
|
+
/** Check whether an MCP id would collide with a bash builtin or deny-prefix. */
|
|
50
|
+
export declare function isMcpIdReserved(mcpId: string): string | null;
|
|
51
|
+
export declare function renderHelp(mcpId: string, state: McpRuntimeState): {
|
|
52
|
+
stdout: string;
|
|
53
|
+
exitCode: number;
|
|
54
|
+
};
|
|
55
|
+
export declare function parsePayload(stdin: string | undefined, inlineArg: string | undefined): {
|
|
56
|
+
ok: true;
|
|
57
|
+
payload: Record<string, unknown>;
|
|
58
|
+
} | {
|
|
59
|
+
ok: false;
|
|
60
|
+
error: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Build the execute handler for a single MCP server CLI.
|
|
64
|
+
* Exposed for unit testing.
|
|
65
|
+
*/
|
|
66
|
+
export declare function buildMcpServerHandler(mcpId: string, ref: McpRuntimeRef, gw: GatewayParams, deps?: McpCliDeps): McpCliCommand["execute"];
|
|
67
|
+
export declare function summariseAuthStart(rawText: string, mcpId: string): string;
|
|
68
|
+
export declare function summariseAuthCheck(parsed: Record<string, unknown> | null, mcpId: string, fallback: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Build one command per MCP server in `ref.current.mcpStatus`, including
|
|
71
|
+
* servers that currently have no discovered tools (so `<server> auth login`
|
|
72
|
+
* still works for unauthenticated servers).
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildMcpCliCommands(ref: McpRuntimeRef, gw: GatewayParams, deps?: Partial<McpCliDeps>): McpCliCommand[];
|
|
75
|
+
//# sourceMappingURL=mcp-cli-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-cli-commands.d.ts","sourceRoot":"","sources":["../../src/embedded/mcp-cli-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAuB7D;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IACvC,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,eAAe,CAAC;IACzB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CACP,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,KAC1C,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpE;AAED,MAAM,WAAW,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? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.isMcpIdReserved = isMcpIdReserved;
|
|
37
|
+
exports.renderHelp = renderHelp;
|
|
38
|
+
exports.parsePayload = parsePayload;
|
|
39
|
+
exports.buildMcpServerHandler = buildMcpServerHandler;
|
|
40
|
+
exports.summariseAuthStart = summariseAuthStart;
|
|
41
|
+
exports.summariseAuthCheck = summariseAuthCheck;
|
|
42
|
+
exports.buildMcpCliCommands = buildMcpCliCommands;
|
|
43
|
+
const core_1 = require("@lobu/core");
|
|
44
|
+
const tool_implementations_1 = require("../shared/tool-implementations");
|
|
45
|
+
const tool_policy_1 = require("../openclaw/tool-policy");
|
|
46
|
+
const logger = (0, core_1.createLogger)("mcp-cli");
|
|
47
|
+
/** Names reserved by just-bash / POSIX shells that we must not shadow. */
|
|
48
|
+
const RESERVED_COMMAND_NAMES = new Set([
|
|
49
|
+
"cd",
|
|
50
|
+
"echo",
|
|
51
|
+
"export",
|
|
52
|
+
"test",
|
|
53
|
+
"true",
|
|
54
|
+
"false",
|
|
55
|
+
"pwd",
|
|
56
|
+
"set",
|
|
57
|
+
"unset",
|
|
58
|
+
"exit",
|
|
59
|
+
"source",
|
|
60
|
+
".",
|
|
61
|
+
":",
|
|
62
|
+
"[",
|
|
63
|
+
]);
|
|
64
|
+
const DEFAULT_DEPS = {
|
|
65
|
+
callTool: tool_implementations_1.callMcpTool,
|
|
66
|
+
};
|
|
67
|
+
/** Check whether an MCP id would collide with a bash builtin or deny-prefix. */
|
|
68
|
+
function isMcpIdReserved(mcpId) {
|
|
69
|
+
if (RESERVED_COMMAND_NAMES.has(mcpId)) {
|
|
70
|
+
return `reserved bash builtin`;
|
|
71
|
+
}
|
|
72
|
+
// Probe against the package-install denylist using invocations that match
|
|
73
|
+
// its actual patterns (install/add/require/upgrade/etc.).
|
|
74
|
+
const probes = [
|
|
75
|
+
`${mcpId} install`,
|
|
76
|
+
`${mcpId} i`,
|
|
77
|
+
`${mcpId} add`,
|
|
78
|
+
`${mcpId} upgrade`,
|
|
79
|
+
`${mcpId} require`,
|
|
80
|
+
mcpId,
|
|
81
|
+
];
|
|
82
|
+
if (probes.some((p) => (0, tool_policy_1.isDirectPackageInstallCommand)(p))) {
|
|
83
|
+
return `matches package-install denylist`;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
function truncate(text, max) {
|
|
88
|
+
if (!text)
|
|
89
|
+
return "";
|
|
90
|
+
const clean = text.replace(/\s+/g, " ").trim();
|
|
91
|
+
return clean.length > max ? `${clean.slice(0, max - 1)}…` : clean;
|
|
92
|
+
}
|
|
93
|
+
function renderHelp(mcpId, state) {
|
|
94
|
+
const tools = state.mcpTools[mcpId] ?? [];
|
|
95
|
+
const status = state.mcpStatus.find((s) => s.id === mcpId);
|
|
96
|
+
const contextPrefix = state.mcpContext[mcpId];
|
|
97
|
+
const lines = [];
|
|
98
|
+
lines.push(`${mcpId} — MCP server CLI`);
|
|
99
|
+
if (contextPrefix) {
|
|
100
|
+
lines.push(contextPrefix);
|
|
101
|
+
}
|
|
102
|
+
lines.push("");
|
|
103
|
+
lines.push("Usage:");
|
|
104
|
+
lines.push(` ${mcpId} <tool> <<'EOF'`);
|
|
105
|
+
lines.push(` { ...json args... }`);
|
|
106
|
+
lines.push(` EOF`);
|
|
107
|
+
lines.push("");
|
|
108
|
+
lines.push(` ${mcpId} <tool> --schema # print the JSON schema`);
|
|
109
|
+
lines.push(` ${mcpId} --help # this message`);
|
|
110
|
+
if (status?.requiresAuth) {
|
|
111
|
+
lines.push(` ${mcpId} auth login|check|logout`);
|
|
112
|
+
}
|
|
113
|
+
lines.push("");
|
|
114
|
+
if (tools.length === 0) {
|
|
115
|
+
lines.push("(no tools discovered — the server may need authentication or configuration)");
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
lines.push("Tools:");
|
|
119
|
+
for (const tool of tools) {
|
|
120
|
+
const desc = truncate(tool.description ?? "", 80);
|
|
121
|
+
lines.push(` ${tool.name}${desc ? ` ${desc}` : ""}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { stdout: `${lines.join("\n")}\n`, exitCode: 0 };
|
|
125
|
+
}
|
|
126
|
+
function findTool(mcpId, toolName, state) {
|
|
127
|
+
return state.mcpTools[mcpId]?.find((t) => t.name === toolName);
|
|
128
|
+
}
|
|
129
|
+
function parsePayload(stdin, inlineArg) {
|
|
130
|
+
const raw = (stdin && stdin.trim()) || (inlineArg && inlineArg.trim()) || "";
|
|
131
|
+
if (!raw) {
|
|
132
|
+
return { ok: true, payload: {} };
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const parsed = JSON.parse(raw);
|
|
136
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
137
|
+
return { ok: false, error: "expected a JSON object payload" };
|
|
138
|
+
}
|
|
139
|
+
return { ok: true, payload: parsed };
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
return {
|
|
143
|
+
ok: false,
|
|
144
|
+
error: `invalid JSON payload: ${err instanceof Error ? err.message : String(err)}`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Build the execute handler for a single MCP server CLI.
|
|
150
|
+
* Exposed for unit testing.
|
|
151
|
+
*/
|
|
152
|
+
function buildMcpServerHandler(mcpId, ref, gw, deps = DEFAULT_DEPS) {
|
|
153
|
+
return async (args, ctx) => {
|
|
154
|
+
const subcommand = args[0];
|
|
155
|
+
const state = ref.current;
|
|
156
|
+
if (!subcommand || subcommand === "--help" || subcommand === "-h") {
|
|
157
|
+
const { stdout, exitCode } = renderHelp(mcpId, state);
|
|
158
|
+
return { stdout, stderr: "", exitCode };
|
|
159
|
+
}
|
|
160
|
+
if (subcommand === "auth") {
|
|
161
|
+
return runAuthSubcommand(mcpId, args.slice(1), gw, ref);
|
|
162
|
+
}
|
|
163
|
+
// <tool> --schema
|
|
164
|
+
if (args[1] === "--schema") {
|
|
165
|
+
const tool = findTool(mcpId, subcommand, state);
|
|
166
|
+
if (!tool) {
|
|
167
|
+
return {
|
|
168
|
+
stdout: "",
|
|
169
|
+
stderr: `unknown tool: ${subcommand}. Run \`${mcpId} --help\`.\n`,
|
|
170
|
+
exitCode: 2,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const schema = tool.inputSchema ?? {};
|
|
174
|
+
return {
|
|
175
|
+
stdout: `${JSON.stringify(schema, null, 2)}\n`,
|
|
176
|
+
stderr: "",
|
|
177
|
+
exitCode: 0,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
// <tool> [json]
|
|
181
|
+
const tool = findTool(mcpId, subcommand, state);
|
|
182
|
+
if (!tool) {
|
|
183
|
+
return {
|
|
184
|
+
stdout: "",
|
|
185
|
+
stderr: `unknown tool: ${subcommand}. Run \`${mcpId} --help\`.\n`,
|
|
186
|
+
exitCode: 2,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const parsed = parsePayload(ctx.stdin, args[1]);
|
|
190
|
+
if (!parsed.ok) {
|
|
191
|
+
return { stdout: "", stderr: `${parsed.error}\n`, exitCode: 2 };
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const result = await deps.callTool(gw, mcpId, subcommand, parsed.payload);
|
|
195
|
+
const text = result.content
|
|
196
|
+
.filter((c) => c.type === "text")
|
|
197
|
+
.map((c) => c.text)
|
|
198
|
+
.join("\n");
|
|
199
|
+
return { stdout: text ? `${text}\n` : "", stderr: "", exitCode: 0 };
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
return {
|
|
203
|
+
stdout: "",
|
|
204
|
+
stderr: `${err instanceof Error ? err.message : String(err)}\n`,
|
|
205
|
+
exitCode: 1,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
async function refreshRef(ref, mcpId, verb) {
|
|
211
|
+
if (!ref.refresh)
|
|
212
|
+
return;
|
|
213
|
+
try {
|
|
214
|
+
const fresh = await ref.refresh();
|
|
215
|
+
if (fresh)
|
|
216
|
+
ref.current = fresh;
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
logger.warn(`Failed to refresh MCP state after ${mcpId} auth ${verb}: ${err instanceof Error ? err.message : String(err)}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async function runAuthSubcommand(mcpId, args, gw, ref) {
|
|
223
|
+
const verb = args[0];
|
|
224
|
+
// Lazy import to avoid a heavy dependency cycle in tests.
|
|
225
|
+
const impl = await Promise.resolve().then(() => __importStar(require("../shared/tool-implementations")));
|
|
226
|
+
if (verb === "login") {
|
|
227
|
+
const res = await impl.startMcpLogin(gw, { mcpId });
|
|
228
|
+
const text = extractText(res.content);
|
|
229
|
+
return {
|
|
230
|
+
stdout: `${summariseAuthStart(text, mcpId)}\n`,
|
|
231
|
+
stderr: "",
|
|
232
|
+
exitCode: 0,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
if (verb === "check") {
|
|
236
|
+
const res = await impl.checkMcpLogin(gw, { mcpId });
|
|
237
|
+
const text = extractText(res.content);
|
|
238
|
+
const parsed = tryJson(text);
|
|
239
|
+
if (parsed?.authenticated === true) {
|
|
240
|
+
await refreshRef(ref, mcpId, "check");
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
stdout: `${summariseAuthCheck(parsed, mcpId, text)}\n`,
|
|
244
|
+
stderr: "",
|
|
245
|
+
exitCode: 0,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
if (verb === "logout") {
|
|
249
|
+
const res = await impl.logoutMcp(gw, { mcpId });
|
|
250
|
+
const text = extractText(res.content);
|
|
251
|
+
// Tools that required auth are now unreachable — refresh so the next
|
|
252
|
+
// invocation sees the empty state.
|
|
253
|
+
await refreshRef(ref, mcpId, "logout");
|
|
254
|
+
return { stdout: `${text}\n`, stderr: "", exitCode: 0 };
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
stdout: "",
|
|
258
|
+
stderr: `unknown auth subcommand: ${verb ?? "(none)"}. Use login|check|logout.\n`,
|
|
259
|
+
exitCode: 2,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function extractText(content) {
|
|
263
|
+
return content
|
|
264
|
+
.filter((c) => c.type === "text" && typeof c.text === "string")
|
|
265
|
+
.map((c) => c.text)
|
|
266
|
+
.join("\n");
|
|
267
|
+
}
|
|
268
|
+
function summariseAuthStart(rawText, mcpId) {
|
|
269
|
+
const parsed = tryJson(rawText);
|
|
270
|
+
if (!parsed)
|
|
271
|
+
return rawText;
|
|
272
|
+
if (parsed.status === "already_authenticated") {
|
|
273
|
+
return JSON.stringify({ status: "already_authenticated", mcp_id: mcpId });
|
|
274
|
+
}
|
|
275
|
+
if (parsed.status === "login_started") {
|
|
276
|
+
const interactionPosted = Boolean(parsed.interaction_posted);
|
|
277
|
+
// If the link-button side-channel didn't fire, fall back to the raw payload
|
|
278
|
+
// so the verification URL + user_code remain reachable by the model.
|
|
279
|
+
if (!interactionPosted)
|
|
280
|
+
return rawText;
|
|
281
|
+
return JSON.stringify({
|
|
282
|
+
status: "login_started",
|
|
283
|
+
mcp_id: mcpId,
|
|
284
|
+
interaction_posted: true,
|
|
285
|
+
message: `Login link sent directly to the user. Run \`${mcpId} auth check\` after they confirm.`,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return rawText;
|
|
289
|
+
}
|
|
290
|
+
function summariseAuthCheck(parsed, mcpId, fallback) {
|
|
291
|
+
if (!parsed)
|
|
292
|
+
return fallback;
|
|
293
|
+
return JSON.stringify({
|
|
294
|
+
status: parsed.status ?? "unknown",
|
|
295
|
+
mcp_id: mcpId,
|
|
296
|
+
authenticated: parsed.authenticated ?? false,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
function tryJson(text) {
|
|
300
|
+
try {
|
|
301
|
+
const v = JSON.parse(text);
|
|
302
|
+
return v && typeof v === "object" && !Array.isArray(v)
|
|
303
|
+
? v
|
|
304
|
+
: null;
|
|
305
|
+
}
|
|
306
|
+
catch {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Build one command per MCP server in `ref.current.mcpStatus`, including
|
|
312
|
+
* servers that currently have no discovered tools (so `<server> auth login`
|
|
313
|
+
* still works for unauthenticated servers).
|
|
314
|
+
*/
|
|
315
|
+
function buildMcpCliCommands(ref, gw, deps = {}) {
|
|
316
|
+
const resolvedDeps = { ...DEFAULT_DEPS, ...deps };
|
|
317
|
+
const state = ref.current;
|
|
318
|
+
const serverIds = new Set([
|
|
319
|
+
...Object.keys(state.mcpTools ?? {}),
|
|
320
|
+
...(state.mcpStatus ?? []).map((s) => s.id),
|
|
321
|
+
]);
|
|
322
|
+
const commands = [];
|
|
323
|
+
for (const mcpId of serverIds) {
|
|
324
|
+
const reserved = isMcpIdReserved(mcpId);
|
|
325
|
+
if (reserved) {
|
|
326
|
+
logger.warn(`Skipping MCP CLI registration for "${mcpId}" — ${reserved}. Rename the MCP server to enable CLI mode.`);
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
commands.push({
|
|
330
|
+
name: mcpId,
|
|
331
|
+
execute: buildMcpServerHandler(mcpId, ref, gw, resolvedDeps),
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return commands;
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=mcp-cli-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-cli-commands.js","sourceRoot":"","sources":["../../src/embedded/mcp-cli-commands.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,0CAkBC;AAQD,gCAuCC;AAUD,oCAsBC;AAMD,sDAmEC;AA8ED,gDAmBC;AAED,gDAWC;AAkBD,kDA2BC;AAjYD,qCAA0C;AAE1C,yEAA6D;AAC7D,yDAAwE;AAExE,MAAM,MAAM,GAAG,IAAA,mBAAY,EAAC,SAAS,CAAC,CAAC;AAEvC,0EAA0E;AAC1E,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,IAAI;IACJ,MAAM;IACN,QAAQ;IACR,MAAM;IACN,MAAM;IACN,OAAO;IACP,KAAK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IAAI,EAAE,KAAK;YACX,OAAO,EAAE,qBAAqB,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,YAAY,CAAC;SAC7D,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects and redacts "sandbox leaks" — cases where the agent presents a
|
|
3
|
+
* local workspace path (or a Claude `sandbox://` URL) as if it were a
|
|
4
|
+
* user-downloadable artifact, without having actually called
|
|
5
|
+
* `UploadUserFile`.
|
|
6
|
+
*
|
|
7
|
+
* Key design decision: we only flag **structural** delivery claims, not
|
|
8
|
+
* free-text mentions. An agent that *describes* workspace paths in a probe
|
|
9
|
+
* or ls-style answer is legitimate; an agent that hands the path to the
|
|
10
|
+
* user as a clickable link or file URL is not. This eliminates the false
|
|
11
|
+
* positives that the previous broad substring check produced.
|
|
12
|
+
*/
|
|
13
|
+
export interface LeakCheckResult {
|
|
14
|
+
/** True if the final message makes an unfulfilled file-delivery claim. */
|
|
15
|
+
leaked: boolean;
|
|
16
|
+
/** `finalText` with offending link/URL targets neutralised. Equal to
|
|
17
|
+
* `finalText` when `leaked` is false. */
|
|
18
|
+
redactedText: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Inspect the agent's final user-facing message for unfulfilled file-delivery
|
|
22
|
+
* claims. If `sawUploadedFileEvent` is true (the agent actually called
|
|
23
|
+
* UploadUserFile during this turn), no check is performed — the agent did
|
|
24
|
+
* deliver something, and any remaining path references are assumed
|
|
25
|
+
* descriptive.
|
|
26
|
+
*/
|
|
27
|
+
export declare function checkSandboxLeak(finalText: string, sawUploadedFileEvent: boolean): LeakCheckResult;
|
|
28
|
+
//# sourceMappingURL=sandbox-leak.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-leak.d.ts","sourceRoot":"","sources":["../../src/openclaw/sandbox-leak.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAyBH,MAAM,WAAW,eAAe;IAC9B,0EAA0E;IAC1E,MAAM,EAAE,OAAO,CAAC;IAChB;6CACyC;IACzC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,oBAAoB,EAAE,OAAO,GAC5B,eAAe,CAiCjB"}
|