37 lines
1.4 KiB
Bash
Executable File
37 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Hook script: read projects/<id>/data/issues/*.pending (spooler tickets) and output JSON with additional_context for sessionStart.
|
|
# No fallback: project id comes only from mail "to" or request token; in hook context there is none, so we aggregate pending from all projects.
|
|
# Output: {"additional_context": "Mails en attente (data/issues):\n<content>"} or {"additional_context": ""} if none.
|
|
set -euo pipefail
|
|
# Consume stdin (hook input JSON)
|
|
cat > /dev/null
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
IA_DEV="$(cd "${SCRIPT_DIR}/../.." && pwd)"
|
|
|
|
CONTENT=""
|
|
for spool in "${IA_DEV}/projects/"*/data/issues; do
|
|
[ -d "$spool" ] || continue
|
|
for f in "${spool}"/*.pending; do
|
|
[ -f "$f" ] || continue
|
|
if command -v jq >/dev/null 2>&1; then
|
|
status="$(jq -r '.status // "pending"' "$f" 2>/dev/null)"
|
|
[[ "$status" != "responded" ]] || continue
|
|
fi
|
|
CONTENT="${CONTENT}--- ${f##*/} ---"$'\n'"$(cat "$f")"$'\n'
|
|
done
|
|
done
|
|
|
|
if [ -n "$CONTENT" ]; then
|
|
if command -v jq >/dev/null 2>&1; then
|
|
printf '%s' "$CONTENT" | jq -R -s '{additional_context: ("Mails en attente (data/issues):\n" + .)}'
|
|
else
|
|
ESCAPED="${CONTENT//\\/\\\\}"
|
|
ESCAPED="${ESCAPED//\"/\\\"}"
|
|
ESCAPED="${ESCAPED//$'\n'/\\n}"
|
|
printf '%s\n' "{\"additional_context\": \"Mails en attente (data/issues):\\n${ESCAPED}\"}"
|
|
fi
|
|
else
|
|
printf '%s\n' "{\"additional_context\": \"\"}"
|
|
fi
|