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/askUser.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* askUserQuestionTool — allows the agent to ask the user a clarifying question mid-turn.
|
|
4
4
|
*
|
|
5
5
|
* Use cases:
|
|
6
6
|
* - Resolving ambiguous requirements before coding.
|
|
7
7
|
* - Getting user preferences (framework choice, styling, naming).
|
|
8
8
|
* - Requesting approval of an implementation plan before proceeding.
|
|
9
9
|
*/
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const askUserQuestionTool: import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
11
|
+
question: z.ZodString;
|
|
12
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
13
|
+
}, z.core.$strip>, {
|
|
14
|
+
question: string;
|
|
15
|
+
options?: string[];
|
|
16
|
+
}, {
|
|
17
|
+
question: string;
|
|
18
|
+
options?: string[] | undefined;
|
|
19
|
+
}, string, "ask_user_question">;
|
package/dist/tools/askUser.js
CHANGED
|
@@ -1,42 +1,30 @@
|
|
|
1
1
|
import { HITLBridge } from "../hitl/bridge.js";
|
|
2
|
+
import { tool } from "langchain";
|
|
3
|
+
import { z } from "zod";
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
5
|
+
* askUserQuestionTool — allows the agent to ask the user a clarifying question mid-turn.
|
|
4
6
|
*
|
|
5
7
|
* Use cases:
|
|
6
8
|
* - Resolving ambiguous requirements before coding.
|
|
7
9
|
* - Getting user preferences (framework choice, styling, naming).
|
|
8
10
|
* - Requesting approval of an implementation plan before proceeding.
|
|
9
11
|
*/
|
|
10
|
-
export const
|
|
12
|
+
export const askUserQuestionTool = tool(async ({ question, options }) => {
|
|
13
|
+
if (!question || question.trim() === "") {
|
|
14
|
+
return "Error: You must provide a non-empty question.";
|
|
15
|
+
}
|
|
16
|
+
const bridge = HITLBridge.getInstance();
|
|
17
|
+
const answer = await bridge.askUser(question, options);
|
|
18
|
+
return answer;
|
|
19
|
+
}, {
|
|
11
20
|
name: "ask_user_question",
|
|
12
21
|
description: "Ask the user a question and wait for their response. " +
|
|
13
22
|
"Use this when you need clarification on the task, user preferences, " +
|
|
14
23
|
"or approval before proceeding with a significant change. " +
|
|
15
24
|
"You may optionally provide a list of answer choices.",
|
|
16
|
-
schema: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
description: "The question to ask the user.",
|
|
22
|
-
},
|
|
23
|
-
options: {
|
|
24
|
-
type: "array",
|
|
25
|
-
items: { type: "string" },
|
|
26
|
-
description: "Optional list of predefined answer choices.",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
required: ["question"],
|
|
30
|
-
},
|
|
31
|
-
async execute(args) {
|
|
32
|
-
const question = args.question;
|
|
33
|
-
const options = args.options;
|
|
34
|
-
if (!question || question.trim() === "") {
|
|
35
|
-
return { content: "Error: You must provide a non-empty question.", isError: true };
|
|
36
|
-
}
|
|
37
|
-
const bridge = HITLBridge.getInstance();
|
|
38
|
-
const answer = await bridge.askUser(question, options);
|
|
39
|
-
return { content: answer };
|
|
40
|
-
},
|
|
41
|
-
};
|
|
25
|
+
schema: z.object({
|
|
26
|
+
question: z.string().describe("The question to ask the user."),
|
|
27
|
+
options: z.array(z.string()).optional().describe("Optional list of predefined answer choices."),
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
42
30
|
//# sourceMappingURL=askUser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"askUser.js","sourceRoot":"","sources":["../../src/tools/askUser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"askUser.js","sourceRoot":"","sources":["../../src/tools/askUser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CACnC,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAA4C,EAAE,EAAE;IACtE,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtC,OAAO,+CAA+C,CAAC;IAC3D,CAAC;IAED,MAAM,MAAM,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IACxC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEvD,OAAO,MAAM,CAAC;AAClB,CAAC,EACD;IACI,IAAI,EAAE,mBAAmB;IACzB,WAAW,EACP,uDAAuD;QACvD,sEAAsE;QACtE,2DAA2D;QAC3D,sDAAsD;IAC1D,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACb,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+BAA+B,CAAC;QAC9D,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,6CAA6C,CAAC;KAClG,CAAC;CACL,CACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SandboxManager } from "../sandbox/manager.js";
|
|
3
|
+
import { FileSync } from "../sandbox/sync.js";
|
|
4
|
+
export declare function bindSandbox(sandbox: SandboxManager, fileSync: FileSync): void;
|
|
5
|
+
export declare const bashTool: import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
6
|
+
command: z.ZodString;
|
|
7
|
+
}, z.core.$strip>, {
|
|
8
|
+
command: string;
|
|
9
|
+
}, {
|
|
10
|
+
command: string;
|
|
11
|
+
}, string, "bash">;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { tool } from "langchain";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const BLOCKED_PATTERNS = [
|
|
4
|
+
// Destructive
|
|
5
|
+
[/rm\s+(-\w*r\w*f\w*|-\w*f\w*r\w*)\s+\/(\*)?(?:\s|$)/, "destructive: rm -rf /"],
|
|
6
|
+
[/mkfs\b/, "destructive: filesystem format"],
|
|
7
|
+
[/\bdd\s+.*of=\/dev\//, "destructive: raw disk write"],
|
|
8
|
+
[/chmod\s+(-\w+\s+)*777\s+\//, "dangerous: chmod 777 on root"],
|
|
9
|
+
// Interactive / hanging
|
|
10
|
+
[/\b(vim|vi|nano|emacs|pico)\b/, "interactive: text editor (hangs the sandbox)"],
|
|
11
|
+
[/\b(less|more)\b/, "interactive: pager (hangs the sandbox)"],
|
|
12
|
+
[/\b(top|htop|glances)\b/, "interactive: process monitor (hangs the sandbox)"],
|
|
13
|
+
[/\bman\s+\w+/, "interactive: man page (hangs the sandbox)"],
|
|
14
|
+
// Network abuse: pipe-to-shell
|
|
15
|
+
[/curl\s+.*\|\s*(sh|bash|zsh)/, "unsafe: pipe remote script to shell"],
|
|
16
|
+
[/wget\s+.*\|\s*(sh|bash|zsh)/, "unsafe: pipe remote script to shell"],
|
|
17
|
+
];
|
|
18
|
+
let _sandboxManager = null;
|
|
19
|
+
let _fileSync = null;
|
|
20
|
+
export function bindSandbox(sandbox, fileSync) {
|
|
21
|
+
_sandboxManager = sandbox;
|
|
22
|
+
_fileSync = fileSync;
|
|
23
|
+
}
|
|
24
|
+
export const bashTool = tool(async ({ command }) => {
|
|
25
|
+
for (const [pattern, reason] of BLOCKED_PATTERNS) {
|
|
26
|
+
if (pattern.test(command)) {
|
|
27
|
+
return (`⚠ Blocked: Command rejected by sanitizer.\n` +
|
|
28
|
+
`Reason: ${reason}\n` +
|
|
29
|
+
`Command: ${command}\n` +
|
|
30
|
+
`Use a safer alternative or refine your approach.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (!_sandboxManager || !_sandboxManager.isActive()) {
|
|
34
|
+
throw new Error("Sandbox is not active. Cannot execute bash commands without an active sandbox session.");
|
|
35
|
+
}
|
|
36
|
+
if (_fileSync && _fileSync.pendingCount() > 0) {
|
|
37
|
+
await _fileSync.syncToSandbox(_sandboxManager);
|
|
38
|
+
}
|
|
39
|
+
const result = await _sandboxManager.exec(command);
|
|
40
|
+
if (result.exitCode !== 0) {
|
|
41
|
+
return `Command failed (exit code ${result.exitCode}):\nSTDOUT:\n${result.stdout}\nSTDERR:\n${result.stderr}`;
|
|
42
|
+
}
|
|
43
|
+
return result.stdout || "(no output)";
|
|
44
|
+
}, {
|
|
45
|
+
name: "bash",
|
|
46
|
+
description: "Runs a shell command inside an isolated sandbox. Use for tests, scripts, or installing dependencies. The host machine is never exposed.",
|
|
47
|
+
schema: z.object({
|
|
48
|
+
command: z.string().describe("The shell command to execute"),
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=bashTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bashTool.js","sourceRoot":"","sources":["../../src/tools/bashTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,MAAM,gBAAgB,GAAuB;IACzC,cAAc;IACd,CAAC,oDAAoD,EAAE,uBAAuB,CAAC;IAC/E,CAAC,QAAQ,EAAE,gCAAgC,CAAC;IAC5C,CAAC,qBAAqB,EAAE,6BAA6B,CAAC;IACtD,CAAC,4BAA4B,EAAE,8BAA8B,CAAC;IAE9D,wBAAwB;IACxB,CAAC,8BAA8B,EAAE,8CAA8C,CAAC;IAChF,CAAC,iBAAiB,EAAE,wCAAwC,CAAC;IAC7D,CAAC,wBAAwB,EAAE,kDAAkD,CAAC;IAC9E,CAAC,aAAa,EAAE,2CAA2C,CAAC;IAE5D,+BAA+B;IAC/B,CAAC,6BAA6B,EAAE,qCAAqC,CAAC;IACtE,CAAC,6BAA6B,EAAE,qCAAqC,CAAC;CACzE,CAAC;AAEF,IAAI,eAAe,GAA0B,IAAI,CAAC;AAClD,IAAI,SAAS,GAAoB,IAAI,CAAC;AAEtC,MAAM,UAAU,WAAW,CAAC,OAAuB,EAAE,QAAkB;IACnE,eAAe,GAAG,OAAO,CAAC;IAC1B,SAAS,GAAG,QAAQ,CAAC;AACzB,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CACxB,KAAK,EAAE,EAAE,OAAO,EAAuB,EAAE,EAAE;IACvC,KAAK,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,gBAAgB,EAAE,CAA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and FileSync instance.
|
|
17
|
-
* Must be called at session start before any tool executions.
|
|
18
|
-
*/
|
|
19
|
-
export declare function bindSandbox(sandbox: SandboxManager, fileSync: FileSync): void;
|
|
20
|
-
/**
|
|
21
|
-
* Security: Validates that a resolved path is strictly inside the given workspace dir.
|
|
22
|
-
* Prevents directory traversal attacks from accessing sensitive host files.
|
|
23
|
-
*/
|
|
24
|
-
export declare function isPathInsideWorkspace(resolvedPath: string, workspaceDir?: string): boolean;
|
|
25
|
-
export declare const BashTool: DynamicToolInterface;
|
|
26
|
-
export declare const ReadFileTool: DynamicToolInterface;
|
|
27
|
-
export declare const WriteFileTool: DynamicToolInterface;
|
|
28
|
-
export declare const CORE_TOOLS: DynamicToolInterface[];
|
|
1
|
+
import { bindSandbox } from "./bashTool.js";
|
|
2
|
+
export { bindSandbox };
|
|
3
|
+
export declare const CORE_TOOLS: (import("langchain").DynamicStructuredTool<import("zod").ZodObject<{
|
|
4
|
+
command: import("zod").ZodString;
|
|
5
|
+
}, import("zod/v4/core").$strip>, {
|
|
6
|
+
command: string;
|
|
7
|
+
}, {
|
|
8
|
+
command: string;
|
|
9
|
+
}, string, "install_host_dependencies"> | import("langchain").DynamicStructuredTool<import("zod").ZodObject<{
|
|
10
|
+
command: import("zod").ZodString;
|
|
11
|
+
}, import("zod/v4/core").$strip>, {
|
|
12
|
+
command: string;
|
|
13
|
+
}, {
|
|
14
|
+
command: string;
|
|
15
|
+
}, string, "bash">)[];
|
package/dist/tools/index.js
CHANGED
|
@@ -1,192 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const MAX_FILE_LINES = 2000;
|
|
9
|
-
// ─── Sandbox reference (set at session start) ───────────────────────────────────
|
|
10
|
-
let _sandboxManager = null;
|
|
11
|
-
let _fileSync = null;
|
|
12
|
-
/**
|
|
13
|
-
* Binds the tools to a SandboxManager and FileSync instance.
|
|
14
|
-
* Must be called at session start before any tool executions.
|
|
15
|
-
*/
|
|
16
|
-
export function bindSandbox(sandbox, fileSync) {
|
|
17
|
-
_sandboxManager = sandbox;
|
|
18
|
-
_fileSync = fileSync;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Security: Validates that a resolved path is strictly inside the given workspace dir.
|
|
22
|
-
* Prevents directory traversal attacks from accessing sensitive host files.
|
|
23
|
-
*/
|
|
24
|
-
export function isPathInsideWorkspace(resolvedPath, workspaceDir = process.cwd()) {
|
|
25
|
-
const normalizedWorkspace = path.resolve(workspaceDir);
|
|
26
|
-
// path.relative returns a path relative to the first argument.
|
|
27
|
-
// If it starts with '..' or is absolute, it means resolvedPath has escaped normalizedWorkspace.
|
|
28
|
-
const relative = path.relative(normalizedWorkspace, resolvedPath);
|
|
29
|
-
return relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
30
|
-
}
|
|
31
|
-
// ─── BashTool ───────────────────────────────────────────────────────────────────
|
|
32
|
-
// Executes shell commands inside the E2B sandbox.
|
|
33
|
-
// The ToolRouter routes this to SANDBOX — the host machine is never exposed.
|
|
34
|
-
export const BashTool = {
|
|
35
|
-
name: "bash",
|
|
36
|
-
description: "Runs a shell command inside an isolated sandbox. Use for tests, scripts, or installing dependencies. The host machine is never exposed.",
|
|
37
|
-
schema: {
|
|
38
|
-
type: "object",
|
|
39
|
-
properties: {
|
|
40
|
-
command: {
|
|
41
|
-
type: "string",
|
|
42
|
-
description: "The shell command to execute",
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
required: ["command"],
|
|
46
|
-
},
|
|
47
|
-
execute: async (args, emitter) => {
|
|
48
|
-
if (emitter)
|
|
49
|
-
emitter.emit("agent:event", { type: "system:script_exec", command: args.command, location: "sandbox" });
|
|
50
|
-
if (!_sandboxManager || !_sandboxManager.isActive()) {
|
|
51
|
-
throw new Error("Sandbox is not active. Cannot execute bash commands without an active sandbox session.");
|
|
52
|
-
}
|
|
53
|
-
// Sync any dirty files from host → sandbox before executing
|
|
54
|
-
if (_fileSync && _fileSync.pendingCount() > 0) {
|
|
55
|
-
await _fileSync.syncToSandbox(_sandboxManager);
|
|
56
|
-
}
|
|
57
|
-
const result = await _sandboxManager.exec(args.command);
|
|
58
|
-
if (result.exitCode !== 0) {
|
|
59
|
-
return {
|
|
60
|
-
content: `Command failed (exit code ${result.exitCode}):\nSTDOUT:\n${result.stdout}\nSTDERR:\n${result.stderr}`,
|
|
61
|
-
metadata: { exitCode: result.exitCode },
|
|
62
|
-
isError: true
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
content: result.stdout || "(no output)",
|
|
67
|
-
metadata: { exitCode: result.exitCode },
|
|
68
|
-
isError: false
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
// ─── ReadFileTool ───────────────────────────────────────────────────────────────
|
|
73
|
-
// Reads files from the HOST filesystem (so the user's real project is visible).
|
|
74
|
-
// Includes a built-in file size guardrail to prevent sending huge files to the LLM.
|
|
75
|
-
export const ReadFileTool = {
|
|
76
|
-
name: "read_file",
|
|
77
|
-
description: "Reads a file from the host filesystem. Includes a file size guardrail — files over 512KB are truncated to prevent context overflow.",
|
|
78
|
-
schema: {
|
|
79
|
-
type: "object",
|
|
80
|
-
properties: {
|
|
81
|
-
path: {
|
|
82
|
-
type: "string",
|
|
83
|
-
description: "Absolute or relative path to the file",
|
|
84
|
-
},
|
|
85
|
-
startLine: {
|
|
86
|
-
type: "number",
|
|
87
|
-
description: "Optional 1-indexed start line for partial reads",
|
|
88
|
-
},
|
|
89
|
-
endLine: {
|
|
90
|
-
type: "number",
|
|
91
|
-
description: "Optional 1-indexed end line for partial reads",
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
required: ["path"],
|
|
95
|
-
},
|
|
96
|
-
execute: async (args, emitter) => {
|
|
97
|
-
const filePath = path.resolve(args.path);
|
|
98
|
-
if (emitter)
|
|
99
|
-
emitter.emit("agent:event", { type: "file:io", action: "read", path: filePath });
|
|
100
|
-
// ── Security Guardrail ──
|
|
101
|
-
if (!isPathInsideWorkspace(filePath)) {
|
|
102
|
-
return {
|
|
103
|
-
content: `Security Error: Access Denied. Cannot read files outside the current project workspace (${process.cwd()}).`,
|
|
104
|
-
isError: true
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
// ── Check existence ──
|
|
108
|
-
if (!fs.existsSync(filePath)) {
|
|
109
|
-
return {
|
|
110
|
-
content: `Error: File not found — ${filePath}`,
|
|
111
|
-
isError: true
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
// ── File Size Guardrail ──
|
|
115
|
-
const stat = fs.statSync(filePath);
|
|
116
|
-
if (stat.size > MAX_FILE_SIZE_BYTES) {
|
|
117
|
-
return {
|
|
118
|
-
content: `Error: File too large (${Math.round(stat.size / 1024)}KB). Maximum size is 512KB. Use line ranges or grep_search.`,
|
|
119
|
-
isError: true
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
123
|
-
const lines = fileContent.split("\n");
|
|
124
|
-
if (args.startLine !== undefined || args.endLine !== undefined) {
|
|
125
|
-
const start = Math.max(1, args.startLine ?? 1) - 1;
|
|
126
|
-
const end = Math.min(lines.length, args.endLine ?? lines.length);
|
|
127
|
-
const sliced = lines.slice(start, end);
|
|
128
|
-
return { content: sliced.map((line, i) => `${start + i + 1}: ${line}`).join("\n") };
|
|
129
|
-
}
|
|
130
|
-
// ── Line count guardrail ──
|
|
131
|
-
if (lines.length > MAX_FILE_LINES) {
|
|
132
|
-
const truncated = lines.slice(0, MAX_FILE_LINES);
|
|
133
|
-
return {
|
|
134
|
-
content: truncated.map((line, i) => `${i + 1}: ${line}`).join("\n") +
|
|
135
|
-
`\n\n--- Truncated at ${MAX_FILE_LINES} lines (total: ${lines.length}) ---`
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return { content: fileContent };
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
// ─── WriteFileTool ──────────────────────────────────────────────────────────────
|
|
142
|
-
// Writes files to the HOST filesystem (so the user sees changes in their IDE).
|
|
143
|
-
// Marks written files as dirty so FileSync uploads them before sandbox execution.
|
|
144
|
-
export const WriteFileTool = {
|
|
145
|
-
name: "write_file",
|
|
146
|
-
description: "Writes content to a file on the host filesystem. The user will see changes in their IDE immediately. The file is automatically synced to the sandbox before the next command execution.",
|
|
147
|
-
schema: {
|
|
148
|
-
type: "object",
|
|
149
|
-
properties: {
|
|
150
|
-
path: {
|
|
151
|
-
type: "string",
|
|
152
|
-
description: "Absolute or relative path to the file",
|
|
153
|
-
},
|
|
154
|
-
content: {
|
|
155
|
-
type: "string",
|
|
156
|
-
description: "The full file content to write",
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
required: ["path", "content"],
|
|
160
|
-
},
|
|
161
|
-
execute: async (args, emitter) => {
|
|
162
|
-
const filePath = path.resolve(args.path);
|
|
163
|
-
if (emitter)
|
|
164
|
-
emitter.emit("agent:event", { type: "file:io", action: "write", path: filePath });
|
|
165
|
-
// ── Security Guardrail ──
|
|
166
|
-
if (!isPathInsideWorkspace(filePath)) {
|
|
167
|
-
return {
|
|
168
|
-
content: `Security Error: Access Denied. Cannot write files outside the current project workspace (${process.cwd()}).`,
|
|
169
|
-
isError: true
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
// Create parent directories if needed
|
|
173
|
-
const dir = path.dirname(filePath);
|
|
174
|
-
if (!fs.existsSync(dir)) {
|
|
175
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
176
|
-
}
|
|
177
|
-
fs.writeFileSync(filePath, args.content, "utf-8");
|
|
178
|
-
// Mark file as dirty for next sandbox sync
|
|
179
|
-
if (_fileSync) {
|
|
180
|
-
_fileSync.markDirty(filePath);
|
|
181
|
-
}
|
|
182
|
-
return { content: `File written: ${filePath}` };
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
// ─── Core Tool Set ──────────────────────────────────────────────────────────────
|
|
1
|
+
import { installHostDependenciesTool } from "./installHostDeps.js";
|
|
2
|
+
import { bashTool, bindSandbox } from "./bashTool.js";
|
|
3
|
+
// Re-export bindSandbox so index.ts can initialize it
|
|
4
|
+
export { bindSandbox };
|
|
5
|
+
// The core custom tools that the agent needs.
|
|
6
|
+
// Note: File I/O (read_file, write_file, edit_file, ls, grep) and Subagents
|
|
7
|
+
// are provided natively by Deep Agents via the FilesystemBackend and createSubAgentMiddleware.
|
|
186
8
|
export const CORE_TOOLS = [
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
WriteFileTool,
|
|
190
|
-
InstallHostDependenciesTool,
|
|
9
|
+
bashTool,
|
|
10
|
+
installHostDependenciesTool,
|
|
191
11
|
];
|
|
192
12
|
//# sourceMappingURL=index.js.map
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEtD,sDAAsD;AACtD,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,8CAA8C;AAC9C,4EAA4E;AAC5E,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG;IACtB,QAAQ;IACR,2BAA2B;CAC9B,CAAC"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const installHostDependenciesTool: import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
3
|
+
command: z.ZodString;
|
|
4
|
+
}, z.core.$strip>, {
|
|
5
|
+
command: string;
|
|
6
|
+
}, {
|
|
7
|
+
command: string;
|
|
8
|
+
}, string, "install_host_dependencies">;
|
|
@@ -1,37 +1,44 @@
|
|
|
1
1
|
import { exec } from "node:child_process";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
|
+
import { tool } from "langchain";
|
|
4
|
+
import { z } from "zod";
|
|
3
5
|
const execAsync = promisify(exec);
|
|
4
|
-
|
|
6
|
+
const ALLOWED_INSTALLERS = {
|
|
7
|
+
npm: new Set(["install", "i", "ci", "add"]),
|
|
8
|
+
yarn: new Set(["add", "install"]),
|
|
9
|
+
pnpm: new Set(["add", "install", "i"]),
|
|
10
|
+
pip: new Set(["install"]),
|
|
11
|
+
pip3: new Set(["install"]),
|
|
12
|
+
cargo: new Set(["add", "install"]),
|
|
13
|
+
poetry: new Set(["add", "install"]),
|
|
14
|
+
gem: new Set(["install"]),
|
|
15
|
+
composer: new Set(["require", "install"]),
|
|
16
|
+
go: new Set(["get", "install"]),
|
|
17
|
+
bun: new Set(["add", "install"]),
|
|
18
|
+
};
|
|
19
|
+
export const installHostDependenciesTool = tool(async ({ command }) => {
|
|
20
|
+
const trimmedCmd = command.trim();
|
|
21
|
+
const parts = trimmedCmd.split(/\s+/);
|
|
22
|
+
const bin = parts[0];
|
|
23
|
+
const subcmd = parts[1];
|
|
24
|
+
if (!ALLOWED_INSTALLERS[bin] || !ALLOWED_INSTALLERS[bin].has(subcmd)) {
|
|
25
|
+
return `Security Error: Command '${bin} ${subcmd}' is not allowed. Only dependency installation commands (like 'npm install') are permitted by this tool.`;
|
|
26
|
+
}
|
|
27
|
+
if (/[&|;`$]/.test(trimmedCmd)) {
|
|
28
|
+
return `Security Error: Command contains forbidden shell operators (&, |, ;, \`, $).`;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const { stdout, stderr } = await execAsync(command, { cwd: process.cwd() });
|
|
32
|
+
return `Successfully ran on host:\nSTDOUT:\n${stdout}\nSTDERR:\n${stderr}`;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return `Host command failed (exit code ${error.code}):\nSTDOUT:\n${error.stdout}\nSTDERR:\n${error.stderr}\nMESSAGE:\n${error.message}`;
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
5
38
|
name: "install_host_dependencies",
|
|
6
39
|
description: "Installs dependencies natively on the host OS (e.g. npm install, pip install). Use this carefully to bootstrap projects outside the sandbox. This runs directly on the user's machine.",
|
|
7
|
-
schema: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type: "string",
|
|
12
|
-
description: "The native installation command (e.g., 'npm install express')",
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
required: ["command"],
|
|
16
|
-
},
|
|
17
|
-
execute: async (args, emitter) => {
|
|
18
|
-
if (emitter) {
|
|
19
|
-
emitter.emit("agent:event", { type: "system:script_exec", command: args.command, location: "host" });
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
const { stdout, stderr } = await execAsync(args.command, { cwd: process.cwd() });
|
|
23
|
-
return {
|
|
24
|
-
content: `Successfully ran on host:\nSTDOUT:\n${stdout}\nSTDERR:\n${stderr}`,
|
|
25
|
-
isError: false,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
return {
|
|
30
|
-
content: `Host command failed (exit code ${error.code}):\nSTDOUT:\n${error.stdout}\nSTDERR:\n${error.stderr}\nMESSAGE:\n${error.message}`,
|
|
31
|
-
metadata: { exitCode: error.code },
|
|
32
|
-
isError: true
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
};
|
|
40
|
+
schema: z.object({
|
|
41
|
+
command: z.string().describe("The native installation command (e.g., 'npm install express')"),
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
37
44
|
//# sourceMappingURL=installHostDeps.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installHostDeps.js","sourceRoot":"","sources":["../../src/tools/installHostD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