aboutsummaryrefslogtreecommitdiff
path: root/.ai/scripts/cross-agent-comms/cross-agent-watch
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-06 21:59:52 -0500
committerCraig Jennings <c@cjennings.net>2026-05-06 21:59:52 -0500
commitd81b23ad6b6e437dfe3c338a00a4be39bc555146 (patch)
tree2d4b0d7890fd1fc70d81282b81fed2808c28a106 /.ai/scripts/cross-agent-comms/cross-agent-watch
parent201377f57430ef28d02e703a2191434bbee55c75 (diff)
downloadrulesets-d81b23ad6b6e437dfe3c338a00a4be39bc555146.tar.gz
rulesets-d81b23ad6b6e437dfe3c338a00a4be39bc555146.zip
chore(ai): initialize project notes and Claude tooling surfaces
Replace the seed notes.org with project-specific context (layout, install modes, task tracker location, recent inflection point). Bring in the synced template surfaces (protocols, workflows, scripts, references, retrospectives, someday-maybe) as tracked content for this content/documentation project.
Diffstat (limited to '.ai/scripts/cross-agent-comms/cross-agent-watch')
-rwxr-xr-x.ai/scripts/cross-agent-comms/cross-agent-watch106
1 files changed, 106 insertions, 0 deletions
diff --git a/.ai/scripts/cross-agent-comms/cross-agent-watch b/.ai/scripts/cross-agent-comms/cross-agent-watch
new file mode 100755
index 0000000..3978f49
--- /dev/null
+++ b/.ai/scripts/cross-agent-comms/cross-agent-watch
@@ -0,0 +1,106 @@
+#!/usr/bin/env bash
+# cross-agent-watch — desktop-notify on new cross-agent messages.
+#
+# See cross-agent-watch.md. Watches every ~/projects/*/inbox/from-agents/ by
+# default. inotifywait fires create + moved_to events; .tmp.* files are
+# filtered out. HALT suppresses notifications but the watcher keeps running
+# and logs each event with "(suppressed by HALT)".
+
+set -uo pipefail
+
+# Defaults.
+PROJECTS_GLOB="${HOME}/projects/*/inbox/from-agents/"
+LOG_FILE="${HOME}/.local/state/cross-agent-comms/watch.log"
+HALT_FILE="${HOME}/.config/cross-agent-comms/HALT"
+QUIET=0
+NO_NOTIFY=0
+
+# Arg parsing.
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --projects-glob)
+ PROJECTS_GLOB="$2"; shift 2 ;;
+ --log)
+ LOG_FILE="$2"; shift 2 ;;
+ --quiet)
+ QUIET=1; shift ;;
+ --no-notify)
+ NO_NOTIFY=1; shift ;;
+ -h|--help)
+ cat <<EOF
+Usage: cross-agent-watch [--projects-glob GLOB] [--log PATH] [--quiet] [--no-notify]
+
+Watches inbox/from-agents/ directories for new cross-agent messages and fires
+desktop notifications. See cross-agent-watch.md for details.
+EOF
+ exit 0 ;;
+ *)
+ echo "unknown flag: $1" >&2; exit 1 ;;
+ esac
+done
+
+# Resolve glob to a concrete list of directories.
+# shellcheck disable=SC2086
+DIRS=( $PROJECTS_GLOB )
+# Filter out non-existent paths (glob may include literal pattern when no match).
+EXISTING=()
+for d in "${DIRS[@]}"; do
+ if [[ -d "$d" ]]; then
+ EXISTING+=( "$d" )
+ fi
+done
+
+if [[ ${#EXISTING[@]} -eq 0 ]]; then
+ echo "cross-agent-watch: glob resolved 0 directories: $PROJECTS_GLOB" >&2
+ exit 1
+fi
+
+# Ensure log dir exists.
+mkdir -p "$(dirname "$LOG_FILE")"
+
+[[ $QUIET -eq 0 ]] && echo "cross-agent-watch: watching ${#EXISTING[@]} dir(s); log: $LOG_FILE"
+
+# Helper: project name from path like /home/.../projects/<name>/inbox/from-agents/...
+project_name() {
+ local path="$1"
+ # Match ~/projects/<name>/...
+ if [[ "$path" =~ ${HOME}/projects/([^/]+)/ ]]; then
+ echo "${BASH_REMATCH[1]}"
+ else
+ basename "$(dirname "$(dirname "$path")")"
+ fi
+}
+
+# Main loop. inotifywait emits one line per event in the format
+# "<full-path>" because we passed --format '%w%f'.
+inotifywait -m -e create,moved_to --format '%w%f' "${EXISTING[@]}" 2>/dev/null \
+ | while IFS= read -r path; do
+ filename="$(basename "$path")"
+
+ # Filter .tmp.* staging files.
+ case "$filename" in
+ .tmp.*) continue ;;
+ esac
+
+ # Filter .asc sidecars — they land first per the atomic-write ordering;
+ # the .org event will fire after.
+ case "$filename" in
+ *.asc) continue ;;
+ esac
+
+ proj="$(project_name "$path")"
+ iso="$(date -u "+%Y-%m-%dT%H:%M:%SZ")"
+
+ if [[ -e "$HALT_FILE" ]]; then
+ printf '%s\t%s\t%s\t(suppressed by HALT)\n' "$iso" "$proj" "$filename" >> "$LOG_FILE"
+ [[ $QUIET -eq 0 ]] && echo "[$iso] $proj: $filename (suppressed by HALT)"
+ continue
+ fi
+
+ printf '%s\t%s\t%s\n' "$iso" "$proj" "$filename" >> "$LOG_FILE"
+ [[ $QUIET -eq 0 ]] && echo "[$iso] $proj: $filename"
+
+ if [[ $NO_NOTIFY -eq 0 ]]; then
+ notify info "Cross-agent message" "${proj}: ${filename}" 2>/dev/null || true
+ fi
+ done