joonecli 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/config.test.js +1 -0
- package/dist/__tests__/config.test.js.map +1 -1
- package/dist/__tests__/installHostDeps.test.js +45 -0
- package/dist/__tests__/installHostDeps.test.js.map +1 -0
- package/dist/__tests__/whitelistedBackend.test.js +18 -0
- package/dist/__tests__/whitelistedBackend.test.js.map +1 -0
- package/dist/cli/config.d.ts +2 -0
- package/dist/cli/config.js +1 -0
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/index.js +84 -100
- package/dist/cli/index.js.map +1 -1
- package/dist/core/agentLoop.d.ts +10 -29
- package/dist/core/agentLoop.js +66 -237
- package/dist/core/agentLoop.js.map +1 -1
- package/dist/core/promptBuilder.js.map +1 -1
- package/dist/hitl/bridge.js +1 -27
- package/dist/hitl/bridge.js.map +1 -1
- package/dist/middleware/loopDetection.d.ts +7 -23
- package/dist/middleware/loopDetection.js +38 -42
- package/dist/middleware/loopDetection.js.map +1 -1
- package/dist/sandbox/whitelistedBackend.d.ts +5 -0
- package/dist/sandbox/whitelistedBackend.js +27 -0
- package/dist/sandbox/whitelistedBackend.js.map +1 -0
- package/dist/tools/askUser.d.ts +12 -3
- package/dist/tools/askUser.js +16 -28
- package/dist/tools/askUser.js.map +1 -1
- package/dist/tools/bashTool.d.ts +11 -0
- package/dist/tools/bashTool.js +51 -0
- package/dist/tools/bashTool.js.map +1 -0
- package/dist/tools/index.d.ts +15 -28
- package/dist/tools/index.js +9 -189
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/installHostDeps.d.ts +8 -2
- package/dist/tools/installHostDeps.js +38 -31
- package/dist/tools/installHostDeps.js.map +1 -1
- package/dist/ui/App.js +112 -56
- package/dist/ui/App.js.map +1 -1
- package/dist/ui/components/MessageBubble.js +1 -1
- package/dist/ui/components/MessageBubble.js.map +1 -1
- package/package.json +7 -2
- package/dist/__tests__/m55.test.js +0 -160
- package/dist/__tests__/m55.test.js.map +0 -1
- package/dist/__tests__/middleware.test.js +0 -169
- package/dist/__tests__/middleware.test.js.map +0 -1
- package/dist/__tests__/optimizations.test.d.ts +0 -1
- package/dist/__tests__/optimizations.test.js +0 -136
- package/dist/__tests__/optimizations.test.js.map +0 -1
- package/dist/__tests__/security.test.d.ts +0 -1
- package/dist/__tests__/security.test.js +0 -86
- package/dist/__tests__/security.test.js.map +0 -1
- package/dist/__tests__/streaming.test.d.ts +0 -1
- package/dist/__tests__/streaming.test.js +0 -71
- package/dist/__tests__/streaming.test.js.map +0 -1
- package/dist/__tests__/toolRouter.test.d.ts +0 -1
- package/dist/__tests__/toolRouter.test.js +0 -37
- package/dist/__tests__/toolRouter.test.js.map +0 -1
- package/dist/__tests__/tools.test.d.ts +0 -1
- package/dist/__tests__/tools.test.js +0 -112
- package/dist/__tests__/tools.test.js.map +0 -1
- package/dist/core/subAgent.d.ts +0 -56
- package/dist/core/subAgent.js +0 -240
- package/dist/core/subAgent.js.map +0 -1
- package/dist/debug_google.d.ts +0 -1
- package/dist/debug_google.js +0 -23
- package/dist/debug_google.js.map +0 -1
- package/dist/middleware/commandSanitizer.d.ts +0 -18
- package/dist/middleware/commandSanitizer.js +0 -50
- package/dist/middleware/commandSanitizer.js.map +0 -1
- package/dist/middleware/permission.d.ts +0 -17
- package/dist/middleware/permission.js +0 -60
- package/dist/middleware/permission.js.map +0 -1
- package/dist/middleware/pipeline.d.ts +0 -31
- package/dist/middleware/pipeline.js +0 -62
- package/dist/middleware/pipeline.js.map +0 -1
- package/dist/middleware/preCompletion.d.ts +0 -29
- package/dist/middleware/preCompletion.js +0 -82
- package/dist/middleware/preCompletion.js.map +0 -1
- package/dist/middleware/types.d.ts +0 -40
- package/dist/middleware/types.js +0 -8
- package/dist/middleware/types.js.map +0 -1
- package/dist/skills/loader.d.ts +0 -55
- package/dist/skills/loader.js +0 -132
- package/dist/skills/loader.js.map +0 -1
- package/dist/skills/tools.d.ts +0 -5
- package/dist/skills/tools.js +0 -78
- package/dist/skills/tools.js.map +0 -1
- package/dist/test_cache.d.ts +0 -1
- package/dist/test_cache.js +0 -55
- package/dist/test_cache.js.map +0 -1
- package/dist/test_google.d.ts +0 -1
- package/dist/test_google.js +0 -36
- package/dist/test_google.js.map +0 -1
- package/dist/tools/browser.d.ts +0 -19
- package/dist/tools/browser.js +0 -114
- package/dist/tools/browser.js.map +0 -1
- package/dist/tools/registry.d.ts +0 -31
- package/dist/tools/registry.js +0 -168
- package/dist/tools/registry.js.map +0 -1
- package/dist/tools/router.d.ts +0 -34
- package/dist/tools/router.js +0 -76
- package/dist/tools/router.js.map +0 -1
- package/dist/tools/security.d.ts +0 -28
- package/dist/tools/security.js +0 -183
- package/dist/tools/security.js.map +0 -1
- package/dist/tools/spawnAgent.d.ts +0 -19
- package/dist/tools/spawnAgent.js +0 -132
- package/dist/tools/spawnAgent.js.map +0 -1
- package/dist/tools/webSearch.d.ts +0 -6
- package/dist/tools/webSearch.js +0 -120
- package/dist/tools/webSearch.js.map +0 -1
- /package/dist/__tests__/{m55.test.d.ts → installHostDeps.test.d.ts} +0 -0
- /package/dist/__tests__/{middleware.test.d.ts → whitelistedBackend.test.d.ts} +0 -0
package/dist/tools/browser.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
// ─── Sandbox + Installer references ─────────────────────────────────────────
|
|
2
|
-
let _sandboxManager = null;
|
|
3
|
-
let _installer = null;
|
|
4
|
-
export function bindBrowserSandbox(sandbox, installer) {
|
|
5
|
-
_sandboxManager = sandbox;
|
|
6
|
-
_installer = installer;
|
|
7
|
-
}
|
|
8
|
-
// ─── Helpers ────────────────────────────────────────────────────────────────────
|
|
9
|
-
/**
|
|
10
|
-
* Escapes a string so it can be safely used as an argument in a Bash shell command.
|
|
11
|
-
* It wraps the string in single quotes and safely escapes internal single quotes.
|
|
12
|
-
*/
|
|
13
|
-
function escapeBashArg(arg) {
|
|
14
|
-
return `'${arg.replace(/'/g, "'\\''")}'`;
|
|
15
|
-
}
|
|
16
|
-
// ─── BrowserTool ────────────────────────────────────────────────────────────────
|
|
17
|
-
/**
|
|
18
|
-
* Web Browser Tool — wraps Vercel Labs' `agent-browser` CLI.
|
|
19
|
-
*
|
|
20
|
-
* Provides compact accessibility-tree output optimized for LLMs
|
|
21
|
-
* (low token usage vs raw HTML). Runs inside the E2B sandbox.
|
|
22
|
-
*
|
|
23
|
-
* Supported actions:
|
|
24
|
-
* - navigate: Go to a URL
|
|
25
|
-
* - snapshot: Get the accessibility tree (compact text representation)
|
|
26
|
-
* - click: Click an element by ref
|
|
27
|
-
* - type: Type text into a form field by ref
|
|
28
|
-
* - screenshot: Capture a screenshot
|
|
29
|
-
* - scroll: Scroll the page up or down
|
|
30
|
-
*/
|
|
31
|
-
export const BrowserTool = {
|
|
32
|
-
name: "browser",
|
|
33
|
-
description: "Interact with web pages using a headless browser. Actions: navigate, snapshot, click, type, screenshot, scroll. " +
|
|
34
|
-
"Returns compact accessibility-tree text output optimized for AI consumption.",
|
|
35
|
-
schema: {
|
|
36
|
-
type: "object",
|
|
37
|
-
properties: {
|
|
38
|
-
action: {
|
|
39
|
-
type: "string",
|
|
40
|
-
enum: ["navigate", "snapshot", "click", "type", "screenshot", "scroll"],
|
|
41
|
-
description: "The browser action to perform",
|
|
42
|
-
},
|
|
43
|
-
url: {
|
|
44
|
-
type: "string",
|
|
45
|
-
description: "URL to navigate to (required for 'navigate')",
|
|
46
|
-
},
|
|
47
|
-
ref: {
|
|
48
|
-
type: "string",
|
|
49
|
-
description: "Element reference from the accessibility tree (required for 'click' and 'type')",
|
|
50
|
-
},
|
|
51
|
-
text: {
|
|
52
|
-
type: "string",
|
|
53
|
-
description: "Text to type (required for 'type')",
|
|
54
|
-
},
|
|
55
|
-
direction: {
|
|
56
|
-
type: "string",
|
|
57
|
-
enum: ["up", "down"],
|
|
58
|
-
description: "Scroll direction for 'scroll' action (optional, defaults to 'down')",
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
required: ["action"],
|
|
62
|
-
},
|
|
63
|
-
execute: async (args, emitter) => {
|
|
64
|
-
if (args.action === "navigate" && args.url && emitter) {
|
|
65
|
-
emitter.emit("agent:event", { type: "browser:nav", url: args.url });
|
|
66
|
-
}
|
|
67
|
-
if (!_sandboxManager || !_sandboxManager.isActive()) {
|
|
68
|
-
return { content: "Sandbox is not active. Cannot use browser tool.", isError: true };
|
|
69
|
-
}
|
|
70
|
-
// Build the CLI command
|
|
71
|
-
let command;
|
|
72
|
-
switch (args.action) {
|
|
73
|
-
case "navigate":
|
|
74
|
-
if (!args.url)
|
|
75
|
-
return { content: "Error: 'url' is required for navigate action.", isError: true };
|
|
76
|
-
command = `agent-browser navigate ${escapeBashArg(args.url)} 2>&1`;
|
|
77
|
-
break;
|
|
78
|
-
case "snapshot":
|
|
79
|
-
command = "agent-browser snapshot 2>&1";
|
|
80
|
-
break;
|
|
81
|
-
case "click":
|
|
82
|
-
if (!args.ref)
|
|
83
|
-
return { content: "Error: 'ref' is required for click action.", isError: true };
|
|
84
|
-
command = `agent-browser click ${escapeBashArg(args.ref)} 2>&1`;
|
|
85
|
-
break;
|
|
86
|
-
case "type":
|
|
87
|
-
if (!args.ref)
|
|
88
|
-
return { content: "Error: 'ref' is required for type action.", isError: true };
|
|
89
|
-
if (!args.text)
|
|
90
|
-
return { content: "Error: 'text' is required for type action.", isError: true };
|
|
91
|
-
command = `agent-browser type ${escapeBashArg(args.ref)} ${escapeBashArg(args.text)} 2>&1`;
|
|
92
|
-
break;
|
|
93
|
-
case "screenshot":
|
|
94
|
-
command = "agent-browser screenshot 2>&1";
|
|
95
|
-
break;
|
|
96
|
-
case "scroll":
|
|
97
|
-
const dir = args.direction || "down";
|
|
98
|
-
command = `agent-browser scroll ${escapeBashArg(dir)} 2>&1`;
|
|
99
|
-
break;
|
|
100
|
-
default:
|
|
101
|
-
return { content: `Error: Unknown action "${args.action}". Use: navigate, snapshot, click, type, screenshot, scroll.`, isError: true };
|
|
102
|
-
}
|
|
103
|
-
const result = await _sandboxManager.exec(command);
|
|
104
|
-
if (result.exitCode !== 0) {
|
|
105
|
-
return {
|
|
106
|
-
content: `Browser action failed (exit code ${result.exitCode}):\n${result.stdout}\n${result.stderr}`,
|
|
107
|
-
metadata: { exitCode: result.exitCode },
|
|
108
|
-
isError: true
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
return { content: result.stdout || "(no output)", metadata: { exitCode: result.exitCode }, isError: false };
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
//# sourceMappingURL=browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/tools/browser.ts"],"names":[],"mappings":"AAKA,+EAA+E;AAE/E,IAAI,eAAe,GAA0B,IAAI,CAAC;AAClD,IAAI,UAAU,GAAyB,IAAI,CAAC;AAE5C,MAAM,UAAU,kBAAkB,CAChC,OAAuB,EACvB,SAAwB;IAExB,eAAe,GAAG,OAAO,CAAC;IAC1B,UAAU,GAAG,SAAS,CAAC;AACzB,CAAC;AAED,mFAAmF;AAEnF;;;GAGG;AACH,SAAS,aAAa,CAAC,GAAW;IAChC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC;AAC3C,CAAC;AAED,mFAAmF;AAEnF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,WAAW,GAAyB;IAC/C,IAAI,EAAE,SAAS;IACf,WAAW,EACT,kHAAkH;QAClH,8EAA8E;IAChF,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC;gBACvE,WAAW,EAAE,+BAA+B;aAC7C;YACD,GAAG,EAAE;gBACH,IAAI,EAAE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AAO,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,IAAI,aAAa,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9G,CAAC;CACF,CAAC"}
|
package/dist/tools/registry.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { DynamicToolInterface } from "./index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Lazy Tool Registry
|
|
4
|
-
*
|
|
5
|
-
* Instead of loading all complex tools into the System Prompt (which burns tokens
|
|
6
|
-
* and risks cache invalidation if changed), this registry maintains "stubs" —
|
|
7
|
-
* lightweight descriptors that let the agent discover tools on demand.
|
|
8
|
-
*
|
|
9
|
-
* Tools in DeferredToolsDB are NOT sent to the LLM by default. The agent can
|
|
10
|
-
* search for them via SearchToolsTool, then activate them via ActivateToolTool.
|
|
11
|
-
*/
|
|
12
|
-
export declare const DeferredToolsDB: Record<string, DynamicToolInterface>;
|
|
13
|
-
/**
|
|
14
|
-
* Returns a tool that has been dynamically activated.
|
|
15
|
-
*/
|
|
16
|
-
export declare function getActivatedTool(name: string): DynamicToolInterface | undefined;
|
|
17
|
-
/**
|
|
18
|
-
* Returns all currently activated tools.
|
|
19
|
-
*/
|
|
20
|
-
export declare function getActivatedTools(): DynamicToolInterface[];
|
|
21
|
-
/**
|
|
22
|
-
* Activates a tool from the deferred registry, making it available for execution.
|
|
23
|
-
* Returns the activated tool, or undefined if not found.
|
|
24
|
-
*/
|
|
25
|
-
export declare function activateTool(name: string): DynamicToolInterface | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* Resets all activated tools. For testing.
|
|
28
|
-
*/
|
|
29
|
-
export declare function resetActivatedTools(): void;
|
|
30
|
-
export declare const SearchToolsTool: DynamicToolInterface;
|
|
31
|
-
export declare const ActivateToolTool: DynamicToolInterface;
|
package/dist/tools/registry.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lazy Tool Registry
|
|
3
|
-
*
|
|
4
|
-
* Instead of loading all complex tools into the System Prompt (which burns tokens
|
|
5
|
-
* and risks cache invalidation if changed), this registry maintains "stubs" —
|
|
6
|
-
* lightweight descriptors that let the agent discover tools on demand.
|
|
7
|
-
*
|
|
8
|
-
* Tools in DeferredToolsDB are NOT sent to the LLM by default. The agent can
|
|
9
|
-
* search for them via SearchToolsTool, then activate them via ActivateToolTool.
|
|
10
|
-
*/
|
|
11
|
-
// ─── Deferred (Lazy) Tools ─────────────────────────────────────────────────────
|
|
12
|
-
export const DeferredToolsDB = {
|
|
13
|
-
git_commit: {
|
|
14
|
-
name: "git_commit",
|
|
15
|
-
description: "Creates a new git commit with staged changes.",
|
|
16
|
-
schema: {
|
|
17
|
-
type: "object",
|
|
18
|
-
properties: { message: { type: "string" } },
|
|
19
|
-
required: ["message"],
|
|
20
|
-
},
|
|
21
|
-
execute: async (args) => ({ content: `Committed with message: ${args.message}` }),
|
|
22
|
-
},
|
|
23
|
-
git_diff: {
|
|
24
|
-
name: "git_diff",
|
|
25
|
-
description: "Shows the diff of uncommitted changes or between two branches/commits.",
|
|
26
|
-
schema: {
|
|
27
|
-
type: "object",
|
|
28
|
-
properties: {
|
|
29
|
-
target: {
|
|
30
|
-
type: "string",
|
|
31
|
-
description: "Branch, commit, or file path (optional)",
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
execute: async (args) => ({ content: `Diff for: ${args.target || "working directory"}` }),
|
|
36
|
-
},
|
|
37
|
-
git_log: {
|
|
38
|
-
name: "git_log",
|
|
39
|
-
description: "Shows recent commit history with messages and hashes.",
|
|
40
|
-
schema: {
|
|
41
|
-
type: "object",
|
|
42
|
-
properties: {
|
|
43
|
-
count: {
|
|
44
|
-
type: "number",
|
|
45
|
-
description: "Number of recent commits to show (default: 10)",
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
execute: async (args) => ({ content: `Showing last ${args.count || 10} commits.` }),
|
|
50
|
-
},
|
|
51
|
-
grep_search: {
|
|
52
|
-
name: "grep_search",
|
|
53
|
-
description: "Searches for a text pattern across project files using ripgrep. Returns matching lines with filenames and line numbers.",
|
|
54
|
-
schema: {
|
|
55
|
-
type: "object",
|
|
56
|
-
properties: {
|
|
57
|
-
query: { type: "string", description: "Search pattern (regex supported)" },
|
|
58
|
-
path: { type: "string", description: "Directory or file to search in (default: .)" },
|
|
59
|
-
includes: { type: "string", description: "File glob filter (e.g., '*.ts')" },
|
|
60
|
-
},
|
|
61
|
-
required: ["query"],
|
|
62
|
-
},
|
|
63
|
-
execute: async (args) => ({ content: `Search results for '${args.query}'` }),
|
|
64
|
-
},
|
|
65
|
-
list_dir: {
|
|
66
|
-
name: "list_dir",
|
|
67
|
-
description: "Lists the contents of a directory — files and subdirectories with sizes.",
|
|
68
|
-
schema: {
|
|
69
|
-
type: "object",
|
|
70
|
-
properties: {
|
|
71
|
-
path: { type: "string", description: "Directory path to list" },
|
|
72
|
-
},
|
|
73
|
-
required: ["path"],
|
|
74
|
-
},
|
|
75
|
-
execute: async (args) => ({ content: `Directory listing for: ${args.path}` }),
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
// ─── Active Tool Set (starts empty, filled by ActivateToolTool) ─────────────
|
|
79
|
-
const activatedTools = new Map();
|
|
80
|
-
/**
|
|
81
|
-
* Returns a tool that has been dynamically activated.
|
|
82
|
-
*/
|
|
83
|
-
export function getActivatedTool(name) {
|
|
84
|
-
return activatedTools.get(name);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Returns all currently activated tools.
|
|
88
|
-
*/
|
|
89
|
-
export function getActivatedTools() {
|
|
90
|
-
return Array.from(activatedTools.values());
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Activates a tool from the deferred registry, making it available for execution.
|
|
94
|
-
* Returns the activated tool, or undefined if not found.
|
|
95
|
-
*/
|
|
96
|
-
export function activateTool(name) {
|
|
97
|
-
const tool = DeferredToolsDB[name];
|
|
98
|
-
if (!tool)
|
|
99
|
-
return undefined;
|
|
100
|
-
activatedTools.set(name, tool);
|
|
101
|
-
return tool;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Resets all activated tools. For testing.
|
|
105
|
-
*/
|
|
106
|
-
export function resetActivatedTools() {
|
|
107
|
-
activatedTools.clear();
|
|
108
|
-
}
|
|
109
|
-
// ─── SearchToolsTool ────────────────────────────────────────────────────────────
|
|
110
|
-
/**
|
|
111
|
-
* Fuzzy search: matches on tool name OR any word in the description.
|
|
112
|
-
*/
|
|
113
|
-
function fuzzyMatch(query, tool) {
|
|
114
|
-
const q = query.toLowerCase();
|
|
115
|
-
const nameMatch = tool.name.toLowerCase().includes(q);
|
|
116
|
-
const descWords = tool.description.toLowerCase();
|
|
117
|
-
const descMatch = descWords.includes(q);
|
|
118
|
-
return nameMatch || descMatch;
|
|
119
|
-
}
|
|
120
|
-
export const SearchToolsTool = {
|
|
121
|
-
name: "search_tools",
|
|
122
|
-
description: "Search for advanced tools available in the environment. Matches by tool name or description keywords.",
|
|
123
|
-
schema: {
|
|
124
|
-
type: "object",
|
|
125
|
-
properties: {
|
|
126
|
-
query: { type: "string", description: "Search query" },
|
|
127
|
-
},
|
|
128
|
-
required: ["query"],
|
|
129
|
-
},
|
|
130
|
-
execute: async (args) => {
|
|
131
|
-
const matches = Object.values(DeferredToolsDB).filter((tool) => fuzzyMatch(args.query, tool));
|
|
132
|
-
if (matches.length === 0) {
|
|
133
|
-
return { content: `No tools found matching '${args.query}'. Available categories: git, file, search.` };
|
|
134
|
-
}
|
|
135
|
-
const descriptions = matches.map((t) => `- **${t.name}**: ${t.description}`);
|
|
136
|
-
return {
|
|
137
|
-
content: `Found ${matches.length} tool(s):\n${descriptions.join("\n")}\n\n` +
|
|
138
|
-
`To use a tool, call activate_tool with its name.`
|
|
139
|
-
};
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
// ─── ActivateToolTool ───────────────────────────────────────────────────────────
|
|
143
|
-
export const ActivateToolTool = {
|
|
144
|
-
name: "activate_tool",
|
|
145
|
-
description: "Activates a discovered tool for use. Call search_tools first to find available tools.",
|
|
146
|
-
schema: {
|
|
147
|
-
type: "object",
|
|
148
|
-
properties: {
|
|
149
|
-
name: { type: "string", description: "The tool name to activate" },
|
|
150
|
-
},
|
|
151
|
-
required: ["name"],
|
|
152
|
-
},
|
|
153
|
-
execute: async (args) => {
|
|
154
|
-
const tool = activateTool(args.name);
|
|
155
|
-
if (!tool) {
|
|
156
|
-
return {
|
|
157
|
-
content: `Error: Tool '${args.name}' not found in the registry. Use search_tools to see available tools.`,
|
|
158
|
-
isError: true
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
content: `✓ Tool '${args.name}' activated.\n` +
|
|
163
|
-
`Schema: ${JSON.stringify(tool.schema, null, 2)}\n` +
|
|
164
|
-
`You can now call it directly.`
|
|
165
|
-
};
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,kFAAkF;AAElF,MAAM,CAAC,MAAM,eAAe,GAAyC;IACnE,UAAU,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,+CAA+C;QAC5D,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YAC3C,QAAQ,EAAE,CAAC,SAAS,CAAC;SACtB;QACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,2BAA2B,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;KAClF;IACD,QAAQ,EAAE;QACR,IAAI,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ACN,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,2BAA2B,EAAE;SACnE;QACD,QAAQ,EAAE,CAAC,MAAM,CAAC;KACnB;IACD,OAAO,EAAE,KAAK,EAAE,IAAsB,EAAE,EAAE;QACxC,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAErC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO;gBACL,OAAO,EAAE,gBAAgB,IAAI,CAAC,IAAI,uEAAuE;gBACzG,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QAED,OAAO;YACL,OAAO,EACL,WAAW,IAAI,CAAC,IAAI,gBAAgB;gBACpC,WAAW,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI;gBACnD,+BAA+B;SAClC,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/tools/router.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Where a tool executes — on the host machine or in the sandbox.
|
|
3
|
-
*/
|
|
4
|
-
export declare enum ToolTarget {
|
|
5
|
-
/** Run on the host (Node.js process). User sees changes in IDE. */
|
|
6
|
-
HOST = "host",
|
|
7
|
-
/** Run inside the E2B sandbox. Commands are isolated. */
|
|
8
|
-
SANDBOX = "sandbox"
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Routes tool calls to either the host machine or the E2B sandbox.
|
|
12
|
-
*
|
|
13
|
-
* Design principle: File I/O runs on the host so the user sees changes
|
|
14
|
-
* in their IDE in real-time. Code execution runs in the sandbox for safety.
|
|
15
|
-
*
|
|
16
|
-
* Unknown tools default to SANDBOX (safe-by-default).
|
|
17
|
-
*/
|
|
18
|
-
export declare class ToolRouter {
|
|
19
|
-
/**
|
|
20
|
-
* Determines where a tool should execute.
|
|
21
|
-
*
|
|
22
|
-
* @param toolName The name of the tool being invoked.
|
|
23
|
-
* @returns ToolTarget.HOST or ToolTarget.SANDBOX
|
|
24
|
-
*/
|
|
25
|
-
getTarget(toolName: string): ToolTarget;
|
|
26
|
-
/**
|
|
27
|
-
* Returns true if the tool should run on the host.
|
|
28
|
-
*/
|
|
29
|
-
isHostTool(toolName: string): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Returns true if the tool should run in the sandbox.
|
|
32
|
-
*/
|
|
33
|
-
isSandboxTool(toolName: string): boolean;
|
|
34
|
-
}
|
package/dist/tools/router.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Where a tool executes — on the host machine or in the sandbox.
|
|
3
|
-
*/
|
|
4
|
-
export var ToolTarget;
|
|
5
|
-
(function (ToolTarget) {
|
|
6
|
-
/** Run on the host (Node.js process). User sees changes in IDE. */
|
|
7
|
-
ToolTarget["HOST"] = "host";
|
|
8
|
-
/** Run inside the E2B sandbox. Commands are isolated. */
|
|
9
|
-
ToolTarget["SANDBOX"] = "sandbox";
|
|
10
|
-
})(ToolTarget || (ToolTarget = {}));
|
|
11
|
-
/**
|
|
12
|
-
* Tools that execute on the host machine (no code execution risk).
|
|
13
|
-
*/
|
|
14
|
-
const HOST_TOOLS = new Set([
|
|
15
|
-
"write_file",
|
|
16
|
-
"read_file",
|
|
17
|
-
"search_tools",
|
|
18
|
-
"activate_tool",
|
|
19
|
-
"list_files",
|
|
20
|
-
"search_files",
|
|
21
|
-
"web_search",
|
|
22
|
-
"search_skills",
|
|
23
|
-
"load_skill",
|
|
24
|
-
"spawn_agent",
|
|
25
|
-
"check_agent",
|
|
26
|
-
"install_host_dependencies",
|
|
27
|
-
]);
|
|
28
|
-
/**
|
|
29
|
-
* Tools that execute inside the sandboxed environment.
|
|
30
|
-
*/
|
|
31
|
-
const SANDBOX_TOOLS = new Set([
|
|
32
|
-
"bash",
|
|
33
|
-
"run_tests",
|
|
34
|
-
"install_deps",
|
|
35
|
-
"run_command",
|
|
36
|
-
"python",
|
|
37
|
-
"security_scan",
|
|
38
|
-
"dep_scan",
|
|
39
|
-
"browser",
|
|
40
|
-
]);
|
|
41
|
-
/**
|
|
42
|
-
* Routes tool calls to either the host machine or the E2B sandbox.
|
|
43
|
-
*
|
|
44
|
-
* Design principle: File I/O runs on the host so the user sees changes
|
|
45
|
-
* in their IDE in real-time. Code execution runs in the sandbox for safety.
|
|
46
|
-
*
|
|
47
|
-
* Unknown tools default to SANDBOX (safe-by-default).
|
|
48
|
-
*/
|
|
49
|
-
export class ToolRouter {
|
|
50
|
-
/**
|
|
51
|
-
* Determines where a tool should execute.
|
|
52
|
-
*
|
|
53
|
-
* @param toolName The name of the tool being invoked.
|
|
54
|
-
* @returns ToolTarget.HOST or ToolTarget.SANDBOX
|
|
55
|
-
*/
|
|
56
|
-
getTarget(toolName) {
|
|
57
|
-
if (HOST_TOOLS.has(toolName)) {
|
|
58
|
-
return ToolTarget.HOST;
|
|
59
|
-
}
|
|
60
|
-
// Default: sandbox (safe-by-default — never execute unknown tools on host)
|
|
61
|
-
return ToolTarget.SANDBOX;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Returns true if the tool should run on the host.
|
|
65
|
-
*/
|
|
66
|
-
isHostTool(toolName) {
|
|
67
|
-
return this.getTarget(toolName) === ToolTarget.HOST;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Returns true if the tool should run in the sandbox.
|
|
71
|
-
*/
|
|
72
|
-
isSandboxTool(toolName) {
|
|
73
|
-
return this.getTarget(toolName) === ToolTarget.SANDBOX;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=router.js.map
|
package/dist/tools/router.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/tools/router.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,mEAAmE;IACnE,2BAAa,CAAA;IACb,yDAAyD;IACzD,iCAAmB,CAAA;AACrB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAED;;GAEG;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,YAAY;IACZ,WAAW;IACX,cAAc;IACd,eAAe;IACf,YAAY;IACZ,cAAc;IACd,YAAY;IACZ,eAAe;IACf,YAAY;IACZ,aAAa;IACb,aAAa;IACb,2BAA2B;CAC5B,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,MAAM;IACN,WAAW;IACX,cAAc;IACd,aAAa;IACb,QAAQ;IACR,eAAe;IACf,UAAU;IACV,SAAS;CACV,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,OAAO,UAAU;IACrB;;;;;OAKG;IACH,SAAS,CAAC,QAAgB;QACxB,IAAI,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,OAAO,UAAU,CAAC,IAAI,CAAC;QACzB,CAAC;QACD,2EAA2E;QAC3E,OAAO,UAAU,CAAC,OAAO,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,QAAgB;QACzB,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,QAAgB;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC,OAAO,CAAC;IACzD,CAAC;CACF"}
|
package/dist/tools/security.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { SandboxManager } from "../sandbox/manager.js";
|
|
2
|
-
import { LazyInstaller } from "../sandbox/bootstrap.js";
|
|
3
|
-
import { DynamicToolInterface } from "./index.js";
|
|
4
|
-
/**
|
|
5
|
-
* Binds the security tools to the sandbox and installer.
|
|
6
|
-
* Must be called at session start.
|
|
7
|
-
*/
|
|
8
|
-
export declare function bindSecuritySandbox(sandbox: SandboxManager, installer: LazyInstaller): void;
|
|
9
|
-
/**
|
|
10
|
-
* Scans code for security vulnerabilities using the Gemini CLI Security Extension.
|
|
11
|
-
*
|
|
12
|
-
* Execution flow:
|
|
13
|
-
* 1. LazyInstaller ensures Gemini CLI + security extension are in the sandbox.
|
|
14
|
-
* 2. Runs `gemini -x security:analyze` in the sandbox.
|
|
15
|
-
* 3. Returns the generated security report.
|
|
16
|
-
*
|
|
17
|
-
* If Gemini CLI installation fails, returns a descriptive fallback message
|
|
18
|
-
* suggesting manual review or alternative tools.
|
|
19
|
-
*/
|
|
20
|
-
export declare const SecurityScanTool: DynamicToolInterface;
|
|
21
|
-
/**
|
|
22
|
-
* Scans project dependencies for known vulnerabilities.
|
|
23
|
-
*
|
|
24
|
-
* Execution flow:
|
|
25
|
-
* 1. Try OSV-Scanner (more comprehensive, covers multiple ecosystems).
|
|
26
|
-
* 2. Fall back to `npm audit --json` (always available in Node sandboxes).
|
|
27
|
-
*/
|
|
28
|
-
export declare const DepScanTool: DynamicToolInterface;
|
package/dist/tools/security.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
// ─── Sandbox + Installer references (set at session start) ──────────────────
|
|
2
|
-
let _sandboxManager = null;
|
|
3
|
-
let _installer = null;
|
|
4
|
-
/**
|
|
5
|
-
* Binds the security tools to the sandbox and installer.
|
|
6
|
-
* Must be called at session start.
|
|
7
|
-
*/
|
|
8
|
-
export function bindSecuritySandbox(sandbox, installer) {
|
|
9
|
-
_sandboxManager = sandbox;
|
|
10
|
-
_installer = installer;
|
|
11
|
-
}
|
|
12
|
-
// ─── Security Helpers ───────────────────────────────────────────────────────────
|
|
13
|
-
/**
|
|
14
|
-
* Escapes a string so it can be safely used as an argument in a Bash shell command.
|
|
15
|
-
*/
|
|
16
|
-
function escapeBashArg(arg) {
|
|
17
|
-
return `'${arg.replace(/'/g, "'\\''")}'`;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Validates a file path to prevent directory traversal out of the workspace.
|
|
21
|
-
*/
|
|
22
|
-
function isSafePath(pathStr) {
|
|
23
|
-
if (!pathStr || pathStr.trim() === "")
|
|
24
|
-
return false;
|
|
25
|
-
if (pathStr.includes("..") || pathStr.startsWith("/"))
|
|
26
|
-
return false;
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
// ─── SecurityScanTool ───────────────────────────────────────────────────────────
|
|
30
|
-
/**
|
|
31
|
-
* Scans code for security vulnerabilities using the Gemini CLI Security Extension.
|
|
32
|
-
*
|
|
33
|
-
* Execution flow:
|
|
34
|
-
* 1. LazyInstaller ensures Gemini CLI + security extension are in the sandbox.
|
|
35
|
-
* 2. Runs `gemini -x security:analyze` in the sandbox.
|
|
36
|
-
* 3. Returns the generated security report.
|
|
37
|
-
*
|
|
38
|
-
* If Gemini CLI installation fails, returns a descriptive fallback message
|
|
39
|
-
* suggesting manual review or alternative tools.
|
|
40
|
-
*/
|
|
41
|
-
export const SecurityScanTool = {
|
|
42
|
-
name: "security_scan",
|
|
43
|
-
description: "Scans code changes for security vulnerabilities using the Gemini CLI Security Extension. " +
|
|
44
|
-
"Analyzes the current branch diff for common vulnerabilities and generates a security report.",
|
|
45
|
-
schema: {
|
|
46
|
-
type: "object",
|
|
47
|
-
properties: {
|
|
48
|
-
target: {
|
|
49
|
-
type: "string",
|
|
50
|
-
enum: ["changes", "file", "deps"],
|
|
51
|
-
description: 'What to scan: "changes" (branch diff), "file" (specific file), "deps" (dependencies only)',
|
|
52
|
-
},
|
|
53
|
-
path: {
|
|
54
|
-
type: "string",
|
|
55
|
-
description: "File path for single-file scan (required when target is 'file')",
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
required: ["target"],
|
|
59
|
-
},
|
|
60
|
-
execute: async (args) => {
|
|
61
|
-
if (!_sandboxManager || !_sandboxManager.isActive()) {
|
|
62
|
-
return { content: "Sandbox is not active. Cannot run security scan.", isError: true };
|
|
63
|
-
}
|
|
64
|
-
if (!_installer) {
|
|
65
|
-
return { content: "LazyInstaller not initialized. Call bindSecuritySandbox() first.", isError: true };
|
|
66
|
-
}
|
|
67
|
-
// Ensure Gemini CLI is available
|
|
68
|
-
const cliReady = await _installer.ensureGeminiCli(_sandboxManager);
|
|
69
|
-
if (!cliReady) {
|
|
70
|
-
return {
|
|
71
|
-
content: ("⚠ Gemini CLI could not be installed in the sandbox.\n" +
|
|
72
|
-
"Suggestions:\n" +
|
|
73
|
-
' - Use `dep_scan` tool for dependency vulnerability scanning (uses npm audit)\n' +
|
|
74
|
-
" - Manually review code for OWASP Top 10 vulnerabilities\n" +
|
|
75
|
-
" - Set sandboxTemplate to a pre-baked template with Gemini CLI installed"),
|
|
76
|
-
isError: true
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
// Build the command based on target
|
|
80
|
-
let command;
|
|
81
|
-
switch (args.target) {
|
|
82
|
-
case "changes":
|
|
83
|
-
command = "cd /workspace && gemini -x security:analyze 2>&1";
|
|
84
|
-
break;
|
|
85
|
-
case "file":
|
|
86
|
-
if (!args.path) {
|
|
87
|
-
return { content: "Error: 'path' is required when target is 'file'.", isError: true };
|
|
88
|
-
}
|
|
89
|
-
if (!isSafePath(args.path)) {
|
|
90
|
-
return { content: "Error: Invalid file path. Path must be relative and cannot contain traversal characters ('..').", isError: true };
|
|
91
|
-
}
|
|
92
|
-
command = `cd /workspace && gemini -x security:analyze --file ${escapeBashArg(args.path)} 2>&1`;
|
|
93
|
-
break;
|
|
94
|
-
case "deps":
|
|
95
|
-
command = "cd /workspace && gemini -x security:analyze --deps-only 2>&1";
|
|
96
|
-
break;
|
|
97
|
-
default:
|
|
98
|
-
return { content: `Error: Unknown target "${args.target}". Use "changes", "file", or "deps".`, isError: true };
|
|
99
|
-
}
|
|
100
|
-
const result = await _sandboxManager.exec(command);
|
|
101
|
-
if (result.exitCode !== 0) {
|
|
102
|
-
return {
|
|
103
|
-
content: `Security scan failed (exit code ${result.exitCode}):\n${result.stdout}\n${result.stderr}`,
|
|
104
|
-
metadata: { exitCode: result.exitCode },
|
|
105
|
-
isError: true
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
content: result.stdout || "Security scan completed — no issues found.",
|
|
110
|
-
metadata: { exitCode: result.exitCode },
|
|
111
|
-
isError: false
|
|
112
|
-
};
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
// ─── DepScanTool ────────────────────────────────────────────────────────────────
|
|
116
|
-
/**
|
|
117
|
-
* Scans project dependencies for known vulnerabilities.
|
|
118
|
-
*
|
|
119
|
-
* Execution flow:
|
|
120
|
-
* 1. Try OSV-Scanner (more comprehensive, covers multiple ecosystems).
|
|
121
|
-
* 2. Fall back to `npm audit --json` (always available in Node sandboxes).
|
|
122
|
-
*/
|
|
123
|
-
export const DepScanTool = {
|
|
124
|
-
name: "dep_scan",
|
|
125
|
-
description: "Scans project dependencies for known vulnerabilities (CVEs). " +
|
|
126
|
-
"Uses OSV-Scanner when available, falls back to npm audit.",
|
|
127
|
-
schema: {
|
|
128
|
-
type: "object",
|
|
129
|
-
properties: {
|
|
130
|
-
format: {
|
|
131
|
-
type: "string",
|
|
132
|
-
enum: ["summary", "json"],
|
|
133
|
-
description: 'Output format: "summary" (human readable) or "json" (raw)',
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
execute: async (args) => {
|
|
138
|
-
if (!_sandboxManager || !_sandboxManager.isActive()) {
|
|
139
|
-
return { content: "Sandbox is not active. Cannot run dependency scan.", isError: true };
|
|
140
|
-
}
|
|
141
|
-
if (!_installer) {
|
|
142
|
-
return { content: "LazyInstaller not initialized.", isError: true };
|
|
143
|
-
}
|
|
144
|
-
const format = args?.format ?? "summary";
|
|
145
|
-
// Try OSV-Scanner first
|
|
146
|
-
const osvReady = await _installer.ensureOsvScanner(_sandboxManager);
|
|
147
|
-
if (osvReady) {
|
|
148
|
-
const osvCmd = format === "json"
|
|
149
|
-
? "cd /workspace && osv-scanner --json . 2>&1"
|
|
150
|
-
: "cd /workspace && osv-scanner . 2>&1";
|
|
151
|
-
const result = await _sandboxManager.exec(osvCmd);
|
|
152
|
-
if (result.exitCode === 0) {
|
|
153
|
-
return {
|
|
154
|
-
content: result.stdout || "No known vulnerabilities found in dependencies.",
|
|
155
|
-
metadata: { exitCode: result.exitCode },
|
|
156
|
-
isError: false
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
// Exit code 1 from OSV-Scanner means vulnerabilities found — still valid output
|
|
160
|
-
if (result.exitCode === 1 && result.stdout) {
|
|
161
|
-
return {
|
|
162
|
-
content: result.stdout,
|
|
163
|
-
metadata: { exitCode: result.exitCode },
|
|
164
|
-
isError: false
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
// If we reach here, OSV-Scanner failed for another reason (e.g. exit > 1)
|
|
168
|
-
console.warn(`⚠ OSV-Scanner failed (exit code ${result.exitCode}). Falling back to npm audit.\nDetails: ${result.stdout}\n${result.stderr}`);
|
|
169
|
-
}
|
|
170
|
-
// Fallback: npm audit
|
|
171
|
-
const auditCmd = format === "json"
|
|
172
|
-
? "cd /workspace && npm audit --json 2>&1"
|
|
173
|
-
: "cd /workspace && npm audit 2>&1";
|
|
174
|
-
const auditResult = await _sandboxManager.exec(auditCmd);
|
|
175
|
-
// npm audit returns 1 when vulnerabilities are found — that's valid output
|
|
176
|
-
return {
|
|
177
|
-
content: auditResult.stdout || "No known vulnerabilities found in dependencies.",
|
|
178
|
-
metadata: { exitCode: auditResult.exitCode },
|
|
179
|
-
isError: false
|
|
180
|
-
};
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
//# sourceMappingURL=security.js.map
|