ia_dev/ai_working_help/notary-ai/notary-ai-loop-daemon.sh
Nicolas Cantu e5e07741d3 chore: agents, deploy scripts, notary-ai helpers and samples
**Motivations:** Publish ia_dev workspace updates to remote dev_ia.

**Root causes:** N/A (accumulated local changes).

**Correctifs:** N/A.

**Evolutions:** SmartIde agent docs; deploy change-to-all-branches and deploy-by-script-to; ai_working_help package scripts and lockfile; notary-ai loop shell scripts; sample responded JSON under projects/kogus/data; .cursor/ssh_config stub; kogus Code-Standards doc.

**Pages affectées:** N/A.
2026-04-23 03:06:13 +02:00

48 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Infinite loop: one notary-ai-loop-n-cycles.sh run per iteration, then sleep.
# Lowers average wait when a question arrives just after a cycle (vs a long fixed sleep).
#
# From ia_dev root:
# export AI_AGENT_TOKEN=... # or MAIL_TO
# ./ai_working_help/notary-ai/notary-ai-loop-daemon.sh
#
# Env:
# NOTARY_AI_LOOP_DAEMON_SLEEP_SEC default 15 — pause between iterations (seconds).
# Same prerequisites as notary-ai-loop-n-cycles.sh (MAIL_TO or AI_AGENT_TOKEN).
#
set -euo pipefail
if [ -n "${HOME:-}" ] && [ -r "$HOME/.bashrc" ]; then
set +u
# shellcheck source=/dev/null
source "$HOME/.bashrc" 2>/dev/null || true
set -u
fi
[ -n "${HOME:-}" ] && [ -d "$HOME/.local/bin" ] && export PATH="$HOME/.local/bin:$PATH"
NOTARY_AI_DIR="${NOTARY_AI_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
IA_DEV_ROOT="$(cd "${NOTARY_AI_DIR}/../.." && pwd)"
export NOTARY_AI_DIR
cd "$IA_DEV_ROOT"
if [[ -z "${MAIL_TO:-}" && -z "${AI_AGENT_TOKEN:-}" ]]; then
echo "[notary-ai-loop-daemon] Set MAIL_TO or AI_AGENT_TOKEN (see projects/README.md)." >&2
exit 1
fi
SLEEP_SEC="${NOTARY_AI_LOOP_DAEMON_SLEEP_SEC:-15}"
LOOP_SCRIPT="${IA_DEV_ROOT}/ai_working_help/notary-ai/notary-ai-loop-n-cycles.sh"
if [[ ! -x "$LOOP_SCRIPT" && ! -f "$LOOP_SCRIPT" ]]; then
echo "[notary-ai-loop-daemon] Missing script: $LOOP_SCRIPT" >&2
exit 1
fi
echo "[notary-ai-loop-daemon] $(date -Iseconds) start IA_DEV_ROOT=${IA_DEV_ROOT} sleep_between=${SLEEP_SEC}s"
i=0
while true; do
i=$((i + 1))
echo "[notary-ai-loop-daemon] $(date -Iseconds) iteration $i"
bash "$LOOP_SCRIPT" 1 || true
sleep "$SLEEP_SEC"
done