From 6701c78a2182699cb4d8adeae90251b429e24cd4 Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Sat, 20 Sep 2025 08:04:45 -0400 Subject: add: zed ai history script --- 2025/2025-09-20-zed-ai-history.sh | 96 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 2025/2025-09-20-zed-ai-history.sh diff --git a/2025/2025-09-20-zed-ai-history.sh b/2025/2025-09-20-zed-ai-history.sh new file mode 100644 index 0000000..a214946 --- /dev/null +++ b/2025/2025-09-20-zed-ai-history.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash + +THREADS_DB="${HOME}/Library/Application Support/Zed/threads/threads.db" + +if ! command -v sqlite3 &> /dev/null; then + echo "Error: sqlite3 is not installed. Please install SQLite to continue." + exit 1 +fi + +if ! command -v duckdb &> /dev/null; then + echo "Error: duckdb is not installed. Please install DuckDB to continue." + exit 1 +fi + +if ! command -v zstd &> /dev/null; then + echo "Error: zstd is not installed. Please install zstd to continue." + exit 1 +fi + +if [ ! -f "${THREADS_DB}" ]; then + echo "Error: Threads database not found at ${THREADS_DB}" + echo "Make sure Zed is installed and has created the threads database." + exit 1 +fi + +rm -rf "$(pwd)/threads/" +mkdir -p "$(pwd)/threads/"{0.1.0,0.2.0,0.3.0} + +cp "${THREADS_DB}" . + +sqlite3 threads.db "SELECT id FROM threads;" | \ + while read id; do + + sqlite3 threads.db "SELECT writefile('temp_${id}.zst', data) FROM threads WHERE id = '$id';" > /dev/null + + zstd --rm -q -d "temp_${id}.zst" -o "$(pwd)/threads/${id}.json" > /dev/null + + [[ $(jq 'has("version") and .version == "0.1.0"' "$(pwd)/threads/${id}.json") == "true" ]] && mv "$(pwd)/threads/${id}.json" "$(pwd)/threads/0.1.0/${id}.json" && continue + + [[ $(jq 'has("version") and .version == "0.2.0"' "$(pwd)/threads/${id}.json") == "true" ]] && mv "$(pwd)/threads/${id}.json" "$(pwd)/threads/0.2.0/${id}.json" && continue + + [[ $(jq 'has("version") and .version == "0.3.0"' "$(pwd)/threads/${id}.json") == "true" ]] && mv "$(pwd)/threads/${id}.json" "$(pwd)/threads/0.3.0/${id}.json" + + done + +duckdb -csv <