76 lines
1.9 KiB
Bash
Executable File
76 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
THRESHOLD_MB="150"
|
|
APPLY="0"
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--apply) APPLY="1" ;;
|
|
--threshold=*) THRESHOLD_MB="${arg#*=}" ;;
|
|
--help)
|
|
cat <<'EOF'
|
|
Uso:
|
|
bash scripts/ai/archive_heavy_chats.sh [--threshold=150] [--apply]
|
|
|
|
Default: dry-run (non sposta nulla)
|
|
--apply: sposta i file chat più grandi della soglia in una cartella quarantine (reversibile)
|
|
EOF
|
|
exit 0
|
|
;;
|
|
esac
|
|
done
|
|
|
|
BASE="$HOME/.config/Code/User/workspaceStorage"
|
|
if [[ ! -d "$BASE" ]]; then
|
|
echo "workspaceStorage non trovato: $BASE"
|
|
exit 1
|
|
fi
|
|
|
|
TS="$(date +%Y%m%d-%H%M%S)"
|
|
QUARANTINE="$HOME/vscode-chat-backups/quarantine-$TS"
|
|
|
|
mapfile -t FILES < <(find "$BASE" -type f -path '*/chatSessions/*.json' -size +"${THRESHOLD_MB}"M -print 2>/dev/null | sort)
|
|
|
|
if [[ ${#FILES[@]} -eq 0 ]]; then
|
|
echo "Nessuna chat oltre ${THRESHOLD_MB}MB"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Trovate ${#FILES[@]} chat oltre ${THRESHOLD_MB}MB:"
|
|
for f in "${FILES[@]}"; do
|
|
size_mb=$(du -m "$f" | awk '{print $1}')
|
|
echo "- ${size_mb}MB $f"
|
|
done
|
|
|
|
if [[ "$APPLY" != "1" ]]; then
|
|
echo "Dry-run: nessun file spostato. Usa --apply per applicare."
|
|
exit 0
|
|
fi
|
|
|
|
mkdir -p "$QUARANTINE"
|
|
|
|
echo "Sposto in quarantine: $QUARANTINE"
|
|
for f in "${FILES[@]}"; do
|
|
rel="${f#$BASE/}"
|
|
dest_dir="$QUARANTINE/$(dirname "$rel")"
|
|
mkdir -p "$dest_dir"
|
|
mv "$f" "$dest_dir/"
|
|
|
|
ws_id="$(echo "$rel" | cut -d/ -f1)"
|
|
sess_id="$(basename "$rel" .json)"
|
|
|
|
if [[ -f "$BASE/$ws_id/chatSessions/$sess_id.jsonl" ]]; then
|
|
mkdir -p "$QUARANTINE/$ws_id/chatSessions"
|
|
mv "$BASE/$ws_id/chatSessions/$sess_id.jsonl" "$QUARANTINE/$ws_id/chatSessions/"
|
|
fi
|
|
|
|
if [[ -d "$BASE/$ws_id/chatEditingSessions/$sess_id" ]]; then
|
|
mkdir -p "$QUARANTINE/$ws_id/chatEditingSessions"
|
|
mv "$BASE/$ws_id/chatEditingSessions/$sess_id" "$QUARANTINE/$ws_id/chatEditingSessions/"
|
|
fi
|
|
done
|
|
|
|
echo "Fatto. Riavvia VS Code e verifica la velocità chat."
|
|
echo "Ripristino manuale: rsync -a \"$QUARANTINE/\" \"$BASE/\""
|