From fd13be576c4393e385140e33a848c072f0e0e163 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Wed, 11 Feb 2026 16:30:57 +0100 Subject: [PATCH] Add anvillm-notify script for session state change notifications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add anvillm-notify script that polls session state files - Sends desktop notification when session transitions running→idle - Update mkfile with notify target - Expose state via 9p in main.go - Remove notification idea from IDEAS.md (implemented) --- IDEAS.md | 10 ---------- anvillm-notify | 44 ++++++++++++++++++++++++++++++++++++++++++++ main.go | 9 +++++++++ mkfile | 2 ++ 4 files changed, 55 insertions(+), 10 deletions(-) create mode 100755 anvillm-notify diff --git a/IDEAS.md b/IDEAS.md index 3ccae95..20bdd5e 100644 --- a/IDEAS.md +++ b/IDEAS.md @@ -11,16 +11,6 @@ Implementation sketch: - Extract selected text from current window as the prompt - Send prompt to the target session's tmux pane via `tmux send-keys` -## Notification on State Change - -External polling script monitors 9p state files. When state changes from "running" to "idle", send desktop notification: "session {id} ({alias}) completed its work." - -Implementation sketch: -- Poll `/mnt/anvillm/sessions/*/state` periodically -- Track previous state per session -- On transition running→idle, call `notify-send` or similar -- Bonus: watch all sessions, report which one finished - ## Shared Context Inject context from one session into another. diff --git a/anvillm-notify b/anvillm-notify new file mode 100755 index 0000000..72e4268 --- /dev/null +++ b/anvillm-notify @@ -0,0 +1,44 @@ +#!/bin/sh + +# Poll all anvillm sessions and notify on running->idle transitions + +# Track previous states: session_id=state +prev_states="" + +get_sessions() { + 9p read agent/list 2>/dev/null | awk '{print $1}' +} + +get_state() { + 9p read "agent/$1/state" 2>/dev/null +} + +get_alias() { + 9p read "agent/$1/alias" 2>/dev/null +} + +get_prev() { + echo "$prev_states" | tr ' ' '\n' | grep "^$1=" | cut -d= -f2 +} + +set_prev() { + prev_states=$(echo "$prev_states" | tr ' ' '\n' | grep -v "^$1=" | tr '\n' ' ') + prev_states="$prev_states $1=$2" +} + +while true; do + for id in $(get_sessions); do + [ -z "$id" ] && continue + state=$(get_state "$id") + prev=$(get_prev "$id") + + if [ "$prev" = "running" ] && [ "$state" = "idle" ]; then + name=$(get_alias "$id") + [ -z "$name" ] && name=$id + notify-send "session $name completed its work" + fi + + set_prev "$id" "$state" + done + sleep 1 +done diff --git a/main.go b/main.go index a04c403..425f9e3 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,15 @@ func main() { } defer srv.Close() + // Start notification daemon in background + notifyCmd := exec.Command("anvillm-notify") + notifyCmd.Start() + defer func() { + if notifyCmd.Process != nil { + notifyCmd.Process.Kill() + } + }() + // Rename chat window when alias changes var aliasChangeFunc func(Session) aliasChangeFunc = func(sess Session) { diff --git a/mkfile b/mkfile index c8940c5..377155e 100644 --- a/mkfile +++ b/mkfile @@ -4,6 +4,8 @@ all:V: install build:V: go build -o $INSTALL_PATH/Assist . + cp anvillm-notify $INSTALL_PATH/anvillm-notify + chmod +x $INSTALL_PATH/anvillm-notify install:V: build