Remove anvillm-notify scripts
This commit is contained in:
parent
e96410d599
commit
00d25936a5
2
mkfile
2
mkfile
|
|
@ -4,8 +4,6 @@ all:V: install
|
|||
|
||||
build:V:
|
||||
go build -o $INSTALL_PATH/anvillm .
|
||||
cp scripts/anvillm-notify $INSTALL_PATH/anvillm-notify
|
||||
chmod 0755 $INSTALL_PATH/anvillm-notify
|
||||
cp scripts/anvillm-hook $INSTALL_PATH/anvillm-hook
|
||||
chmod 0755 $INSTALL_PATH/anvillm-hook
|
||||
cp scripts/anvilspawn $INSTALL_PATH/anvilspawn
|
||||
|
|
|
|||
|
|
@ -1,152 +0,0 @@
|
|||
#!/bin/bash
|
||||
# anvillm-inbox-notify — Desktop notification daemon for AnviLLM inbox messages.
|
||||
#
|
||||
# Monitors the AnviLLM event stream for incoming messages addressed to the human
|
||||
# user and fires desktop notifications for configurable message types.
|
||||
#
|
||||
# Usage:
|
||||
# anvillm-inbox-notify [--help]
|
||||
#
|
||||
# Configuration (~/.config/anvillm/notifications.yaml):
|
||||
# notify_on:
|
||||
# - APPROVAL_REQUEST
|
||||
# - REVIEW_REQUEST
|
||||
#
|
||||
# Default notify_on types: APPROVAL_REQUEST, REVIEW_REQUEST
|
||||
# Add QUERY_REQUEST, PROMPT_RESPONSE, etc. as desired.
|
||||
#
|
||||
# State file (deduplication):
|
||||
# ~/.local/share/anvillm/notified-ids.txt
|
||||
# Message IDs are persisted here so restarts do not re-notify.
|
||||
#
|
||||
# Environment:
|
||||
# NAMESPACE — 9P namespace path (default: /tmp/ns.$USER.:0)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# ── help ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
if [[ "${1:-}" == "--help" ]]; then
|
||||
cat <<'EOF'
|
||||
anvillm-inbox-notify — Desktop notification daemon for AnviLLM inbox messages.
|
||||
|
||||
USAGE
|
||||
anvillm-inbox-notify [--help]
|
||||
|
||||
CONFIGURATION
|
||||
~/.config/anvillm/notifications.yaml
|
||||
notify_on:
|
||||
- APPROVAL_REQUEST # default
|
||||
- REVIEW_REQUEST # default
|
||||
- QUERY_REQUEST # optional
|
||||
|
||||
STATE FILE
|
||||
~/.local/share/anvillm/notified-ids.txt
|
||||
Persists seen message IDs across restarts to prevent duplicate notifications.
|
||||
|
||||
ENVIRONMENT
|
||||
NAMESPACE 9P namespace directory (default: /tmp/ns.$USER.:0)
|
||||
EOF
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ── paths ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/anvillm/notifications.yaml"
|
||||
STATE_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/anvillm"
|
||||
STATE_FILE="$STATE_DIR/notified-ids.txt"
|
||||
|
||||
mkdir -p "$STATE_DIR"
|
||||
touch "$STATE_FILE"
|
||||
|
||||
# ── namespace ─────────────────────────────────────────────────────────────────
|
||||
|
||||
NAMESPACE="${NAMESPACE:-/tmp/ns.${USER}.:0}"
|
||||
export NAMESPACE
|
||||
|
||||
# ── load config ───────────────────────────────────────────────────────────────
|
||||
|
||||
# Parse notify_on list from YAML config, falling back to defaults.
|
||||
# Expected YAML format (subset):
|
||||
# notify_on:
|
||||
# - APPROVAL_REQUEST
|
||||
# - REVIEW_REQUEST
|
||||
load_notify_on() {
|
||||
if [[ -f "$CONFIG_FILE" ]]; then
|
||||
# Extract lines under notify_on: that start with " - "
|
||||
awk '/^notify_on:/{found=1; next} found && /^ - /{gsub(/^ - /, ""); print; next} found && /^[^ ]/{exit}' "$CONFIG_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
NOTIFY_ON_ARRAY=()
|
||||
while IFS= read -r line; do
|
||||
[[ -n "$line" ]] && NOTIFY_ON_ARRAY+=("$line")
|
||||
done < <(load_notify_on)
|
||||
|
||||
# Fall back to defaults if config is absent or empty.
|
||||
if [[ ${#NOTIFY_ON_ARRAY[@]} -eq 0 ]]; then
|
||||
NOTIFY_ON_ARRAY=("APPROVAL_REQUEST" "REVIEW_REQUEST")
|
||||
fi
|
||||
|
||||
# Build a jq expression for type matching: (.data.type | IN("T1","T2",...))
|
||||
JQ_TYPES=$(printf '"%s",' "${NOTIFY_ON_ARRAY[@]}")
|
||||
JQ_TYPES="${JQ_TYPES%,}" # strip trailing comma
|
||||
|
||||
echo "anvillm-inbox-notify: watching for types: ${NOTIFY_ON_ARRAY[*]}"
|
||||
echo "anvillm-inbox-notify: namespace: $NAMESPACE"
|
||||
|
||||
# ── helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
already_notified() {
|
||||
grep -qxF "$1" "$STATE_FILE" 2>/dev/null
|
||||
}
|
||||
|
||||
mark_notified() {
|
||||
echo "$1" >> "$STATE_FILE"
|
||||
}
|
||||
|
||||
send_notification() {
|
||||
local from="$1" subject="$2" body="$3" msg_type="$4"
|
||||
local urgency="normal"
|
||||
if [[ "$msg_type" == "APPROVAL_REQUEST" ]]; then
|
||||
urgency="critical"
|
||||
fi
|
||||
notify-send \
|
||||
--urgency="$urgency" \
|
||||
--app-name="AnviLLM" \
|
||||
--icon=dialog-information \
|
||||
"AnviLLM [${from}]: ${subject}" \
|
||||
"${body}"
|
||||
}
|
||||
|
||||
# ── event loop ────────────────────────────────────────────────────────────────
|
||||
|
||||
# Stream events and filter with jq. The jq filter selects UserRecv events
|
||||
# addressed to the human user whose message type is in the notify_on list.
|
||||
#
|
||||
# Full event shape:
|
||||
# {"id":"...", "ts":..., "source":"user", "type":"UserRecv",
|
||||
# "data":{"id":"...", "from":"agent-id", "to":"user",
|
||||
# "type":"APPROVAL_REQUEST", "subject":"...", "body":"..."}}
|
||||
|
||||
JQ_FILTER="
|
||||
select(
|
||||
.type == \"UserRecv\"
|
||||
and .data.to == \"user\"
|
||||
and (.data.type | IN(${JQ_TYPES}))
|
||||
)
|
||||
"
|
||||
|
||||
9p read anvillm/events | jq --unbuffered -c "$JQ_FILTER" | while IFS= read -r event; do
|
||||
msg_id=$(printf '%s' "$event" | jq -r '.data.id // .id')
|
||||
from=$(printf '%s' "$event" | jq -r '.data.from // "unknown"')
|
||||
subject=$(printf '%s' "$event" | jq -r '.data.subject // "(no subject)"')
|
||||
body=$(printf '%s' "$event" | jq -r '.data.body // ""')
|
||||
msg_type=$(printf '%s' "$event"| jq -r '.data.type // "UNKNOWN"')
|
||||
|
||||
if already_notified "$msg_id"; then
|
||||
continue
|
||||
fi
|
||||
|
||||
send_notification "$from" "$subject" "$body" "$msg_type" && mark_notified "$msg_id"
|
||||
done
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# React to anvillm events and notify on running->idle transitions
|
||||
|
||||
get_alias() {
|
||||
9p read "anvillm/$1/alias" 2>/dev/null
|
||||
}
|
||||
|
||||
get_cwd() {
|
||||
9p read "anvillm/$1/cwd" 2>/dev/null
|
||||
}
|
||||
|
||||
get_summary() {
|
||||
9p read "anvillm/$1/summary" 2>/dev/null
|
||||
}
|
||||
|
||||
9p read anvillm/events | while read -r line; do
|
||||
type=$(echo "$line" | jq -r '.type // empty')
|
||||
|
||||
case "$type" in
|
||||
StateChange)
|
||||
old_state=$(echo "$line" | jq -r '.data.old_state // empty')
|
||||
new_state=$(echo "$line" | jq -r '.data.new_state // empty')
|
||||
agent=$(echo "$line" | jq -r '.source // empty')
|
||||
|
||||
if [ "$old_state" = "running" ] && [ "$new_state" = "idle" ]; then
|
||||
name=$(get_alias "$agent")
|
||||
[ -z "$name" ] && name=$agent
|
||||
cwd=$(get_cwd "$agent")
|
||||
heading=$(basename "$cwd")
|
||||
summary=$(get_summary "$agent")
|
||||
[ -z "$summary" ] && summary="completed"
|
||||
notify-send "$heading ($name)" "$summary"
|
||||
fi
|
||||
;;
|
||||
UserRecv)
|
||||
from=$(echo "$line" | jq -r '.data.from // empty')
|
||||
subject=$(echo "$line" | jq -r '.data.subject // empty')
|
||||
body=$(echo "$line" | jq -r '.data.body // empty')
|
||||
notify-send "Message from $from" "$subject"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
Reference in New Issue