main
Colby Knox Publish 0.1.2 875b2d3 2mo ago
#!/bin/sh
# wiki-inbox-nudge: UserPromptSubmit hook. Prints one line into the prompt
# context when the signed-in user has unread wiki notifications, so the AI
# thread learns about replies WITHOUT being asked to check. Throttled so it
# costs one HTTP call per half hour, silent on every failure, never blocks.
STAMP="${TMPDIR:-/tmp}/.wiki-inbox-nudge-stamp"
THROTTLE=1800
now=$(date +%s 2>/dev/null) || exit 0
last=$(cat "$STAMP" 2>/dev/null || echo 0)
case "$last" in *[!0-9]*|"") last=0;; esac
[ $((now - last)) -lt "$THROTTLE" ] && exit 0
echo "$now" > "$STAMP" 2>/dev/null
KEY_FILE="/var/run/adom/api-key"
[ -r "$KEY_FILE" ] || exit 0
# The envelope's `unread` field is the TRUE total; the notifications array is
# capped by limit, and counting it under-reported 387 unread as "50"
# (wiki-issue-loop#1). limit=1 keeps the payload tiny.
N=$(curl -s --max-time 5 -H "Authorization: Bearer $(cat "$KEY_FILE")" \
  "https://wiki.adom.inc/api/me/notifications?unread=1&limit=1" 2>/dev/null \
  | python3 -c 'import sys,json;print(json.load(sys.stdin).get("unread") or 0)' 2>/dev/null) || exit 0
case "$N" in *[!0-9]*|"") exit 0;; esac
if [ "$N" -gt 0 ]; then
  echo "wiki: $N unread notification(s) on your issues. Run 'adom-wiki inbox --unread', act on each, REPLY on the issue, close what is resolved, then 'adom-wiki inbox read --all'. Etiquette: the wiki-issue-loop skill."
fi
exit 0