| 92 | const agent = await Agent.get(ctx.agent) |
| 93 | |
| 94 | const checkExternalDirectory = async (dir: string) => { |
| 95 | if (Filesystem.contains(Instance.directory, dir)) return |
| 96 | if (await Permission.isBypassEnabled()) return |
| 97 | const title = `This command references paths outside of ${Instance.directory}` |
| 98 | if (agent.permission.external_directory === "ask") { |
| 99 | await Permission.ask({ |
| 100 | type: "external_directory", |
| 101 | pattern: [dir, path.join(dir, "*")], |
| 102 | sessionID: ctx.sessionID, |
| 103 | messageID: ctx.messageID, |
| 104 | callID: ctx.callID, |
| 105 | title, |
| 106 | metadata: { |
| 107 | command: params.command, |
| 108 | }, |
| 109 | }) |
| 110 | } else if (agent.permission.external_directory === "deny") { |
| 111 | throw new Permission.RejectedError( |
| 112 | ctx.sessionID, |
| 113 | "external_directory", |
| 114 | ctx.callID, |
| 115 | { |
| 116 | command: params.command, |
| 117 | }, |
| 118 | `${title} so this command is not allowed to be executed.`, |
| 119 | ) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | await checkExternalDirectory(cwd) |
| 124 | |