Repository navigation
Expand file tree
/
Copy pathcodexmicro-run
More file actions
executable file
·46 lines (41 loc) · 1.44 KB
/
Copy pathcodexmicro-run
File metadata and controls
executable file
·46 lines (41 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
#**************************************************************
#* File:: codexmicro-run
#*
#* Description:: Runs any command as an "agent" and reports its status to the
#* bridge, for LLM tools that have no hook system. It reports "thinking" while
#* the command runs and "done" or "error" when it exits, then passes the
#* command's own exit code through. Configure with CODEXMICRO_AGENT (which key,
#* default 0), CODEXMICRO_SOCKET (daemon socket), and CODEXMICRO_NOTIFY (path to
#* the notify client, default: found on PATH).
#*
#* Example: codexmicro-run ollama run llama3 "refactor this file"
#*
#**************************************************************
NOTIFY="${CODEXMICRO_NOTIFY:-codexmicro-notify}"
AGENT="${CODEXMICRO_AGENT:-0}"
# Pass the daemon socket through only when one was chosen, so the default path
# keeps working with no extra configuration.
SOCK_ARGS=()
if [ -n "${CODEXMICRO_SOCKET:-}" ]; then
SOCK_ARGS=(--socket "$CODEXMICRO_SOCKET")
fi
if [ "$#" -lt 1 ]; then
echo "usage: codexmicro-run <command> [args...]" >&2
echo " reports 'thinking' while the command runs, then 'done' or 'error'." >&2
exit 1
fi
# A failed status report (e.g. the daemon is not running) must never stop the
# user's command from running, so the notify call is best-effort.
notify() {
"$NOTIFY" "$AGENT" "$1" "${SOCK_ARGS[@]}" 2>/dev/null || true
}
notify thinking
"$@"
rc=$?
if [ "$rc" -eq 0 ]; then
notify done
else
notify error
fi
exit "$rc"