Add user-controlled local file access in chat

This commit is contained in:
Mark Gregory
2026-11-17 11:05:23 +00:00
parent c849b751d3
commit 8748b7ee80
5 changed files with 110 additions and 6 deletions
+28
View File
@@ -1023,6 +1023,8 @@ enum DockerCommand {
struct LocalToolsView: View {
@ObservedObject var studio: StudioModel
@AppStorage("chatFileAccessFolder") private var chatFileAccessFolder = ""
@State private var confirmFullAccess = false
@State private var line = "docker ps"
@State private var pending: [String]?
@State private var output = ""
@@ -1036,6 +1038,26 @@ struct LocalToolsView: View {
var body: some View {
Form {
Section("Chat File Access") {
LabeledContent("Access", value: chatFileAccessFolder.isEmpty ? "Off" :
chatFileAccessFolder == "/" ? "Any readable location" : chatFileAccessFolder)
HStack {
Button("Choose Folder…") {
let panel = NSOpenPanel()
panel.canChooseDirectories = true
panel.canChooseFiles = false
panel.begin { result in
if result == .OK, let url = panel.url { chatFileAccessFolder = url.path }
}
}
Button("Allow Any Readable Location…") { confirmFullAccess = true }
if !chatFileAccessFolder.isEmpty {
Button("Turn Off") { chatFileAccessFolder = "" }
}
}
Text("In chat, use /read followed by a file path, or /ls followed by a folder path. The selected model receives the preview. macOS privacy permissions still apply.")
.foregroundStyle(.secondary)
}
Section("Docker") {
TextField("Command", text: $line, prompt: Text("docker ps --all"))
.font(.system(.body, design: .monospaced))
@@ -1098,6 +1120,12 @@ struct LocalToolsView: View {
}
}
.formStyle(.grouped)
.alert("Allow chat to read from any location?", isPresented: $confirmFullAccess) {
Button("Allow Read Access") { chatFileAccessFolder = "/" }
Button("Cancel", role: .cancel) {}
} message: {
Text("A file you ask chat to read may be included in a request to your selected model, including a remote model.")
}
.fileImporter(isPresented: $picking, allowedContentTypes: [.item, .folder]) { result in
preview = ""
fileStatus = ""