Harden the CLI Access shell snippet against unquoted glob characters

An unquoted prompt containing ?/*/[...] (e.g. `ai Who are you?`) was
getting glob-expanded by zsh before the ai() function ever ran,
aborting with "no matches found" and never reaching the socket server.
A plain function can't protect its own call site from this - filename
generation happens during command-line parsing, before the shell
dispatches to a function. Switched the recommended snippet to
`alias ai='noglob _ai_impl'`, which suppresses globbing for the whole
command line via noglob as a precommand modifier. Quoting remains the
fully robust habit for other shell metacharacters, but this covers the
specific mistake a user is most likely to make by accident.
This commit is contained in:
2026-08-14 10:54:54 +02:00
parent 25028e3405
commit 35b5b09c6d
+9 -1
View File
@@ -1235,13 +1235,21 @@ It's better to admit "I need more information" or "I cannot do that" than to fak
}
}
// `noglob` (applied via the alias, not inside the function) stops zsh from trying to glob-expand
// an unquoted prompt containing `?`/`*`/`[...]` e.g. `ai Who are you?` before `_ai_impl` ever
// runs. A plain `ai() { ... }` function can't protect its own call site this way: filename
// generation happens during command-line parsing, before the shell has even decided this is a
// function call. Quoting the prompt is still the fully robust habit for other shell metacharacters
// (`;`, `|`, backticks, `$()`), but this covers the specific class of crash users are most likely
// to hit by accident (an unquoted question ending in "?").
private static let cliShellFunctionSnippet = """
ai() {
_ai_impl() {
curl -s --unix-socket "$HOME/Library/Application Support/oAI/cli.sock" \\
-H "Content-Type: application/json" \\
-d "$(jq -n --arg p "$*" '{prompt: $p}')" \\
http://localhost/ | jq -r 'if .error then "Error: " + .error else .response end'
}
alias ai='noglob _ai_impl'
"""
private func loadCLIModels() async {