**Motivations:** - Align master with current codebase (token from projects/<id>/.secrets/<env>/ia_token) - Id resolution by mail To or by API token; no slug **Root causes:** - Token moved from conf.json to .secrets/<env>/ia_token; env from directory name **Correctifs:** - Server and scripts resolve project+env by scanning all projects and envs **Evolutions:** - tickets-fetch-inbox routes by To address; notary-ai agents and API doc updated **Pages affectées:** - ai_working_help/server.js, docs, project_config.py, lib/project_config.sh - projects/README.md, lecoffreio/docs/API.md, gitea-issues/tickets-fetch-inbox.py
48 lines
1.8 KiB
Bash
Executable File
48 lines
1.8 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.
|
|
# Run from project root (Cursor). Repo root = parent of ia_dev when script lives in ia_dev/.cursor/hooks.
|
|
# 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)"
|
|
ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)"
|
|
IA_DEV="${ROOT}/ia_dev"
|
|
PROJECT_SLUG=""
|
|
[ -f "${ROOT}/ai_project_id" ] && PROJECT_SLUG="$(cat "${ROOT}/ai_project_id" | sed 's/[[:space:]]//g')"
|
|
[ -z "$PROJECT_SLUG" ] && [ -f "${ROOT}/.ia_project" ] && PROJECT_SLUG="$(cat "${ROOT}/.ia_project" | sed 's/[[:space:]]//g')"
|
|
if [ -n "$PROJECT_SLUG" ] && [ -d "${IA_DEV}/projects/${PROJECT_SLUG}" ]; then
|
|
SPOOL="${IA_DEV}/projects/${PROJECT_SLUG}/data/issues"
|
|
else
|
|
SPOOL="${ROOT}/data/issues"
|
|
fi
|
|
|
|
if [ ! -d "$SPOOL" ]; then
|
|
printf '%s\n' "{\"additional_context\": \"\"}"
|
|
exit 0
|
|
fi
|
|
|
|
CONTENT=""
|
|
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
|
|
|
|
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
|