|
|
@@ -12,6 +12,7 @@ import { Filesystem } from "@/util/filesystem"
|
|
|
import { Wildcard } from "@/util/wildcard"
|
|
|
import { Permission } from "@/permission"
|
|
|
import { fileURLToPath } from "url"
|
|
|
+import path from "path"
|
|
|
|
|
|
const MAX_OUTPUT_LENGTH = 30_000
|
|
|
const DEFAULT_TIMEOUT = 1 * 60 * 1000
|
|
|
@@ -68,7 +69,8 @@ export const BashTool = Tool.define("bash", {
|
|
|
if (!tree) {
|
|
|
throw new Error("Failed to parse command")
|
|
|
}
|
|
|
- const permissions = await Agent.get(ctx.agent).then((x) => x.permission.bash)
|
|
|
+ const agent = await Agent.get(ctx.agent)
|
|
|
+ const permissions = agent.permission.bash
|
|
|
|
|
|
const askPatterns = new Set<string>()
|
|
|
for (const node of tree.rootNode.descendantsOfType("command")) {
|
|
|
@@ -107,9 +109,30 @@ export const BashTool = Tool.define("bash", {
|
|
|
: resolved
|
|
|
|
|
|
if (!Filesystem.contains(Instance.directory, normalized)) {
|
|
|
- throw new Error(
|
|
|
- `This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,
|
|
|
- )
|
|
|
+ const parentDir = path.dirname(normalized)
|
|
|
+ if (agent.permission.external_directory === "ask") {
|
|
|
+ await Permission.ask({
|
|
|
+ type: "external_directory",
|
|
|
+ pattern: parentDir,
|
|
|
+ sessionID: ctx.sessionID,
|
|
|
+ messageID: ctx.messageID,
|
|
|
+ callID: ctx.callID,
|
|
|
+ title: `This command references paths outside of ${Instance.directory}`,
|
|
|
+ metadata: {
|
|
|
+ command: params.command,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ } else if (agent.permission.external_directory === "deny") {
|
|
|
+ throw new Permission.RejectedError(
|
|
|
+ ctx.sessionID,
|
|
|
+ "external_directory",
|
|
|
+ ctx.callID,
|
|
|
+ {
|
|
|
+ command: params.command,
|
|
|
+ },
|
|
|
+ `This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|