netgescon-day0/scripts/ai/topic_checkpoint.sh

81 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd "$ROOT_DIR"
TOPIC_RAW="${1:-}"
NOTE_RAW="${2:-}"
if [[ -z "$TOPIC_RAW" ]]; then
echo "Uso: bash scripts/ai/topic_checkpoint.sh \"Argomento\" \"Nota sintetica\""
exit 1
fi
slug=$(echo "$TOPIC_RAW" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-//;s/-$//')
if [[ -z "$slug" ]]; then
slug="topic"
fi
TS="$(date '+%Y-%m-%d %H:%M:%S')"
TOPICS_DIR="docs/ai/topics"
TOPIC_FILE="$TOPICS_DIR/${slug}.md"
INDEX_FILE="docs/ai/TOPICS_INDEX.md"
BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'n/a')"
LAST_COMMIT="$(git log -1 --pretty='format:%h %ad %s' --date=short 2>/dev/null || echo 'n/a')"
mkdir -p "$TOPICS_DIR"
if [[ ! -f "$TOPIC_FILE" ]]; then
cat > "$TOPIC_FILE" <<EOF
# Topic: $TOPIC_RAW
## Obiettivo
-
## Decisioni stabili
-
## Bug noti
-
## Test validati
-
## Checkpoint cronologici
EOF
fi
cat >> "$TOPIC_FILE" <<EOF
### $TS
- Nota: ${NOTE_RAW:-"(nessuna nota inserita)"}
- Branch: $BRANCH
- Ultimo commit: $LAST_COMMIT
#### File toccati (git status --short)
\`\`\`
$(git status --short 2>/dev/null || true)
\`\`\`
#### Prossimo passo
-
EOF
if [[ ! -f "$INDEX_FILE" ]]; then
cat > "$INDEX_FILE" <<EOF
# NetGescon - Topics Index
Questo indice collega i "capitoli" di sviluppo per mantenere il filo logico anche cambiando chat.
## Topics
EOF
fi
if ! grep -Fq -- "- [$TOPIC_RAW](topics/${slug}.md)" "$INDEX_FILE"; then
echo "- [$TOPIC_RAW](topics/${slug}.md)" >> "$INDEX_FILE"
fi
echo "Topic checkpoint salvato: $TOPIC_FILE"
echo "Indice aggiornato: $INDEX_FILE"