The clj tool
Xi agents run sandboxed Clojure instead of single-line shell commands. The clj tool is a Clojure REPL with file helpers that runs inside Xi, so commands are readable scripts rather than pipe chains. They filter and aggregate in the runtime, real commands run one at a time, and only the result enters the conversation.
What an agent executes
;; count TODOs per file — only the summary comes back
(->> (glob "src/**/*.cljs")
(map (fn [f] [f (count (re-seq #"TODO" (cat f)))]))
(filter (fn [[_ n]] (pos? n)))
(into {})){"src/app/core.cljs" 3, "src/app/db.cljs" 1}Instead of a piped shell command:
grep -c TODO $(find src -name '*.cljs') | grep -v ':0$'The REPL is persistent for the chat: something def'd in one call is there in the next. A large log file can be loaded once and queried many times without ever being pasted into the conversation.
There is no bash tool while clj is on. The agent runs real programs through sh, argv-style:
(sh "ffmpeg" "-i" "talk.mp4" "-vn" "talk.mp3")
(sh {:dir "packages/api"} "bb" "test")No shell strings, so no quoting tricks and no hidden pipes. Each call names one program, and you see exactly which.
The helpers
| Helper | Does |
|---|---|
cat head tail ls glob grep find stat | Read files and directories |
spit mkdir cp mv rm touch | Write files and directories |
git | Run git; push, clean, -c, config writes and the like are refused here and go through sh |
curl | HTTP requests |
jq | Query JSON, returns Clojure data |
ports | Which processes listen on which ports |
sh | Run a program |
process/start process/wait process/output process/stop | Long-running commands: dev servers, watchers, slow builds |
Reads and writes inside the project and the temp directory run freely. A path outside them asks once; r allows the whole repository it lives in.
Approving commands
Every sh call is checked before the script runs:
- Read-only programs (
ls,cat,grep,git,wc,sort, …) run without asking, as long as their arguments are read-only too: `find -exec,git pushorgit -c …` ask like any other program. - A program you have allowed runs without asking.
- Anything else shows a dialog naming the program: allow once, always for this chat, or deny.
Destructive commands (rm -rf, git push, kill) ask every time, even for an allowed program. So does running a script or inline code through an interpreter (bb -e, node -e, python x.py), because the gate cannot see what the script does.
To allow a program for good, on every project:
;; ~/.config/xi/ext/clj.edn
{:allow-clis ["ffmpeg" "jq" "pandoc"]}Or as a rule, which can also be narrowed to a command line:
{:match {:tool :sh :cli "bb" :command #"^bb -f scripts/"}
:action {:type :allow}}In a chat, /clj allow <cli> allows a program until the chat ends, and /clj shows what is currently allowed.
The run_task tool
Running a project's tasks is common enough that it is its own tool, run_task: bb.edn tasks, package.json scripts and deno.json tasks. It is gated by trusting the project file rather than the runner program: the first run asks, "always" records that file, and editing the file asks again. The same task run through (sh …) is gated the same way. /clj trust-tasks trusts the files without waiting for a call.
Background processes
A dev server or a long build runs in the background:
(def p (process/start "npm run dev")) ; → {:pid … :log …}
(process/output (:pid p)) ; last lines of its log
(process/stop (:pid p))/ps lists a chat's processes and /kill stops one. A chat with a running process is kept open. In the web client the chat header shows a >_ N chip while processes run; pick one to open its log, which follows the output live, also while the agent is busy.
Reference
Every helper, option and gate: clj tool reference.