mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-30 05:43:55 +00:00
33 lines
741 B
TypeScript
33 lines
741 B
TypeScript
import path from "path"
|
|
import type { Tool } from "./tool"
|
|
import { Instance } from "../project/instance"
|
|
|
|
type Kind = "file" | "directory"
|
|
|
|
type Options = {
|
|
bypass?: boolean
|
|
kind?: Kind
|
|
}
|
|
|
|
export async function assertExternalDirectory(ctx: Tool.Context, target?: string, options?: Options) {
|
|
if (!target) return
|
|
|
|
if (options?.bypass) return
|
|
|
|
if (Instance.containsPath(target)) return
|
|
|
|
const kind = options?.kind ?? "file"
|
|
const parentDir = kind === "directory" ? target : path.dirname(target)
|
|
const glob = path.join(parentDir, "*").replaceAll("\\", "/")
|
|
|
|
await ctx.ask({
|
|
permission: "external_directory",
|
|
patterns: [glob],
|
|
always: [glob],
|
|
metadata: {
|
|
filepath: target,
|
|
parentDir,
|
|
},
|
|
})
|
|
}
|